WebÞing

AnyDBM
A general-purpose DBM library

BASE_DBM

BASE_DBM is a virtual base class, defining the interface for all the DBM implementations as well as an applications framework for programmers interested in writing other implementations. BASE_DBM is templateized on the object type T to be stored.

Interface

The BASE_DBM interface is similar to that of the various DBM packages:

public:
  virtual int put(const char* key, const T& object) ;
		// insert object at key
  virtual int put_new(const char* key, const T& object) ;
		// as above, but fail with duplicate key error
		// if there is already an entry at key
  virtual int del(const char* key) ;
		// delete 
  virtual T get(const char*) ;
		// lookup
  virtual const char* seq(const char*) ;
		// firstkey/nextkey.
  virtual int sync() ;

  virtual int fetch(const char* key) { return ! get(key) ; }
  virtual int nextkey(const char* key) { return ! seq(key) ; }
  virtual int firstkey() { return nextkey("") ; }

/* Error handling is DBM dependent.  Errors may come from the Implementor
   or from AnyDBM.  AnyDBM's errors (see rdbm.const) start at 101
   (dbm errors) and -101 (RPC/Network errors) in an attempt to avoid
   conflicts with the implementor errors without inflicting an extra
   errnum on programmers.
*/
  virtual int errnum() const ;
  virtual const char* errmsg() const ;
  virtual const char* errmsg1(const int) const ;


/* clear_err() is dbm-dependent: use with caution if you're
   writing portable code
*/
  virtual void clear_err() {}

  virtual ~BASE_DBM() {}

The functions returning int all return zero for success and an errnum for failure. get and seq return a value if successful, and should be tested with something like:


  if ( value = dbm.get(key) , !value)
	// check dbm.errnum
  else
	// all's well

Implementations

The following implementations are provided:

NDBM
Implements BASE_DBM with ndbm. May not work correctly if your "ndbm" is an emulation, as is typically the case on Free Unices.
GDBM
Implements BASE_DBM with GNU gdbm.
DB_HASH
Implements BASE_DBM with a Berkeley DB hash.
DB_BTREE
Implements BASE_DBM with a Berkeley DB btree. This implementation gives you a DBM that is ordered on its keys.
DB_RECNO
If anyone gets this to work, please let me know what I'm doing wrong. Not that I can see any use for it!
RDBM
Implements BASE_DBM as a Network Client, to a Server which may be any of the above.