00001 #ifndef TAGCOLL_TDB_FILE_H
00002 #define TAGCOLL_TDB_FILE_H
00003
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <tagcoll/Exception.h>
00027 #include <tagcoll/OpSet.h>
00028 #include <set>
00029 #include <string>
00030 #include <fcntl.h>
00031 #include <tdb.h>
00032
00033 namespace Tagcoll
00034 {
00035
00039 class TDBFile
00040 {
00041 private:
00042
00043 TDBFile(const TDBFile&);
00044 TDBFile operator=(const TDBFile&);
00045
00046 protected:
00047 TDB_CONTEXT* db;
00048 std::string _filename;
00049
00050 public:
00057 TDBFile(const std::string& filename);
00058 virtual ~TDBFile();
00059
00063 const std::string& filename() const { return _filename; }
00064
00068 const TDB_CONTEXT* context() const { return db; }
00069 TDB_CONTEXT* context() { return db; }
00084 void open(int tdb_flags, int open_flags, mode_t mode=0666);
00085
00094 static OpSet<std::string> deserialize_stringset(const TDB_DATA& val);
00095
00099 bool has(const std::string& key) const;
00100
00117 bool getGeneric(const std::string& key, void* buf, unsigned int size) const;
00118
00131 template<class ITEM>
00132 bool get(const std::string& key, ITEM& item) const
00133 {
00134 return getGeneric(key, (void*)&item, sizeof(ITEM));
00135 }
00136
00147 OpSet<std::string> getStringSet(const std::string& key) const;
00148
00162 void setGeneric(const std::string& key, const void* buf, unsigned int size);
00163
00174 template<class ITEM>
00175 void set(const std::string& key, const ITEM& item)
00176 {
00177 setGeneric(key, (void*)&item, sizeof(ITEM));
00178 }
00179
00190 void setStringSet(const std::string& key, OpSet<std::string> vals);
00191
00199 void remove(const std::string& key);
00200
00213 int traverse(int (*fn)(TDB_CONTEXT *,TDB_DATA,TDB_DATA,void *), void *state) const;
00214 };
00215
00216 };
00217
00218
00219 #endif