libmoost
/home/mhx/git/github/libmoost/include/moost/kvds/kvds_template.hpp
Go to the documentation of this file.
00001 /* vim:set ts=3 sw=3 sts=3 et: */
00028 
00029 
00030 
00031 
00032 #include "ikvds.hpp"
00033 
00034 #ifndef MOOST_KVDS_KVDS_TEMPLATE_HPP__
00035 #define MOOST_KVDS_KVDS_TEMPLATE_HPP__
00036 
00037 namespace moost { namespace kvds {
00038 
00040 
00041    class KvdsTemplate : public IKvds
00042    {
00043    public:
00045       typedef void * store_type;
00046 
00048       KvdsTemplate() : store_(0)
00049       {
00050          // Construction code goes here
00051       }
00052 
00053       ~KvdsTemplate()
00054       {
00055          if(!dsname_.empty())
00056          {
00057             close(); // Ensure DB is closed
00058          }
00059       }
00060 
00061       void open(char const dsname [], bool newdb = false)
00062       {
00063          dsname_ = dsname;
00064 
00065          if(newdb)
00066          {
00067             // Truncate database if it already exists
00068          }
00069          else
00070          {
00071             // Open database
00072          }
00073       }
00074 
00075       void save()
00076       {
00077          // Add save code here
00078       }
00079 
00080       void close()
00081       {
00082          if(!dsname_.empty())
00083          {
00084             save();
00085 
00086             // Add close code
00087 
00088             dsname_.clear(); // Make sure closed isn't called mutliple times
00089          }
00090       }
00091 
00092    public:
00096 
00097       store_type & get_store() { return store_; } // Remove if not applicable
00098 
00099    public:
00100       // IKvds interface implementation
00101 
00102       bool put(
00103          void const * pkey, size_t const ksize,
00104          void const * pval, size_t const vsize
00105          )
00106       {
00107          return false;
00108       }
00109 
00110       bool get(
00111          void const * pkey, size_t const ksize,
00112          void * pval, size_t & vsize
00113          )
00114       {
00115          return false;
00116       }
00117 
00118       bool add(
00119          void const * pkey, size_t const ksize,
00120          void const * pval, size_t const vsize
00121          )
00122       {
00123          return false;
00124       }
00125 
00126       bool all(
00127          void const * pkey, size_t const ksize,
00128          void * pval, size_t & vsize
00129          )
00130       {
00131          return false;
00132       }
00133 
00134       bool xst(
00135          void const * pkey, size_t const ksize
00136          )
00137       {
00138          return false;
00139       }
00140 
00141       bool del(
00142          void const * pkey, size_t const ksize
00143          )
00144       {
00145          return false;
00146 
00147       }
00148 
00149       bool clr()
00150       {
00151          return true;
00152       }
00153 
00154       bool beg()
00155       {
00156          return false;
00157       }
00158 
00159       bool nxt(
00160          void * pkey, size_t & ksize
00161          )
00162       {
00163          return false;
00164 
00165       }
00166 
00167       bool end()
00168       {
00169          return true;
00170       }
00171 
00172       bool siz(
00173          void const * pkey, size_t const ksize,
00174          size_t & vsize
00175          )
00176 
00177       {
00178          return false;
00179       }
00180 
00181       bool cnt(boost::uint64_t & cnt)
00182       {
00183          return false;
00184       }
00185 
00186       bool nil(bool & isnil)
00187       {
00188          isnil = true;
00189          return true;
00190       }
00191 
00192    private:
00193       store_type store_;
00194       std::string dsname_;
00195    };
00196 }}
00197 
00198 #endif // MOOST_KVDS_KVDS_TEMPLATE_HPP__