00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00036 #ifndef OW_INDEX_HPP_INCLUDE_GUARD_
00037 #define OW_INDEX_HPP_INCLUDE_GUARD_
00038 #include "OW_config.h"
00039 #include "OW_String.hpp"
00040 #include "OW_IntrusiveReference.hpp"
00041 #include "OW_IntrusiveCountableBase.hpp"
00042 
00043 namespace OW_NAMESPACE
00044 {
00045 
00046 struct IndexEntry;
00047 class Index;
00048 typedef IntrusiveReference<Index> IndexRef;
00049 
00061 class OW_HDB_API Index : public IntrusiveCountableBase
00062 {
00063 public:
00068    virtual ~Index();
00069    enum EDuplicateKeysFlag
00070    {
00071       E_NO_DUPLICATES,
00072       E_ALLDUPLICATES
00073    };
00081    virtual void open(const char* fileName, EDuplicateKeysFlag allowDuplicates = E_NO_DUPLICATES) = 0;
00085    virtual void close() = 0;
00100    virtual IndexEntry findFirst(const char* key=0) = 0;
00108    virtual IndexEntry findNext() = 0;
00116    virtual IndexEntry findPrev() = 0;
00124    virtual IndexEntry find(const char* key) = 0;
00133    virtual bool add(const char* key, Int32 offset) = 0;
00144    virtual bool remove(const char* key, Int32 offset=-1L) = 0;
00153    virtual bool update(const char* key, Int32 newOffset) = 0;
00157    virtual void flush();
00164    static IndexRef createIndexObject();
00165 };
00167 struct OW_HDB_API IndexEntry
00168 {
00172    IndexEntry() : key(), offset(-1) {}
00178    IndexEntry(const String& k, Int32 o) :
00179       key(k), offset(o) {}
00180 
00181    typedef Int32 IndexEntry::*safe_bool;
00185    operator safe_bool() const { return (offset != -1 && !key.empty()) ? &IndexEntry::offset : 0; }
00186    bool operator!() const { return !(offset != -1 && !key.empty()); }
00191    String key;
00196    Int32 offset;
00197 };
00198 
00199 } 
00200 
00201 #endif