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.
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
The following implementations are provided: