TDBFile.h

Go to the documentation of this file.
00001 #ifndef TAGCOLL_TDB_FILE_H
00002 #define TAGCOLL_TDB_FILE_H
00003 
00008 /*
00009  * Copyright (C) 2005  Enrico Zini <enrico@debian.org>
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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     /* Disable implicit copies */
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 // vim:set ts=4 sw=4:
00219 #endif

Generated on Tue Aug 21 13:07:09 2007 for libtagcoll by  doxygen 1.5.3