Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

dsDBMi.h

Go to the documentation of this file.
00001 /*
00002  * $Id: dsDBMi.h,v 1.4 2003/08/27 15:40:40 dsamersoff Exp $
00003  */
00004 
00005 #ifndef dsDBMi_h
00006 #define dsDBMi_h
00007 
00008 #ifdef HAVE_CONFIG_H
00009 # include <config.h>
00010 #endif
00011 
00012 
00013 #ifdef HAVE_STL_STRING
00014 # include <string>
00015 #endif
00016 
00017 #include <sys/types.h>
00018 #include <limits.h>
00019 #include <stdlib.h>
00020 #include <fcntl.h>
00021 
00022 #ifdef HAVE_UNISTD_H
00023 # include <unistd.h>
00024 #endif
00025 
00026 
00027 #ifdef HAVE_GDBM_H
00028 #  include <gdbm.h>
00029 #  define  USE_GDBM   1
00030 #else
00031 # ifdef HAVE_NDBM_H
00032 #   include <ndbm.h>
00033 # endif
00034 #endif
00035 
00036 #include <dsSmartException.h>
00037 #include <dsutil.h>
00038 
00039 DECLARE_EXCEPTION(dsDBMi);
00040 
00041 #ifdef USE_GDBM
00042 # define O_DBMSYNC  GDBM_SYNC
00043 #else
00044 # define O_DBMSYNC  0
00045 #endif
00046 
00047 #define O_DBMSETLOCK 0x100
00048 
00052 class dsDBMi
00053 {
00054 public :
00055 #ifdef USE_GDBM       
00056         GDBM_FILE _conn;
00057 #else
00058         DBM *_conn;
00059 #endif
00060 
00061         datum  _res;
00062         datum  _key;
00063         char *_dbName;
00064         int _firstkey;
00065 
00066         char *_str_key;
00067         char *_str_val;     
00068 
00069         dsDBMi(char *database, int flags = O_RDWR, int mode = 0644);
00070        ~dsDBMi();
00071 
00072     void openCursor();
00073     int fetchNext();
00074     int fetchKey();
00075     void closeCursor();
00076 
00077     int add(const char* key, const char *val );
00078     void put(const char* key, const char *val );
00079 
00080     int add(const char* key, void *val, int size );
00081     void put(const char* key, void *val, int size );
00082 
00083     void del(const char* key);
00084     int  get(const char* key);
00085         int  get(datum key);
00086         int  get();
00087         int  exists(const char *key); 
00088 
00089         char *operator[](const char *key){ get(key); return val(); }
00090 
00091         datum& result(){ return _res; }
00092 
00093         char *val(){ if (_str_val) delete _str_val; 
00094                      return (_str_val = ds_strndup((char *) _res.dptr, _res.dsize) ); 
00095                    } 
00096 
00097         char *key(){  if (_str_key) delete _str_key;  
00098                       return (_str_key = ds_strndup((char *) _key.dptr, _key.dsize)); 
00099                    } 
00100 
00101 #ifdef HAVE_STL_STRING
00102         void put(const std::string& key, std::string& val );
00103         void add(const std::string& key, const std::string& val );
00104          int get(const std::string& key);
00105 #endif
00106 
00107 
00108 };
00109 
00110 #endif

Generated on Mon May 16 18:26:57 2005 for libdms4 by doxygen1.3-rc2