Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

WvBdbHash< K, D > Class Template Reference

#include <wvbdbhash.h>

Inherits WvBdbHashBase.

Collaboration diagram for WvBdbHash< K, D >:

[legend]
List of all members.

Detailed Description

template<class K, class D>
class WvBdbHash< K, D >

This hashtable is different from normal WvStreams hashtables in that it stores the data on disk.

This affects memory management for objects stored in it.

For find and operator[], the returned object is only guaranteed to be around until the next find() (or next(), for iterators). Remember that you may not be the only person to do a next() or find() on this database.

You may only have one iterator at a time for a given WvBdbHash (for the moment at least). This is due to the strange way in which the database handles iteration (with its own internal cursor). Note that first() and count() also use iterators!

Definition at line 115 of file wvbdbhash.h.

Public Member Functions

 WvBdbHash (WvStringParm dbfile=WvString::null, bool persist=true)
void add (const K &key, const D &data, bool replace=false)
void remove (const K &key)
D & find (const K &key)
D & operator[] (const K &key)
bool exists (const K &key)
int count ()
bool isempty ()
D & first ()
void opendb (WvStringParm _dbfile, bool persist_dbfile=true)
 Open a new db file.

void closedb ()
 Close the db file.

void add (const datum &key, const datum &data, bool replace)
void remove (const datum &key)
datum find (const datum &key)
bool exists (const datum &key)
void zap ()
 Wipe the db.

virtual bool isok () const
 By default, returns true if geterr() == 0.

virtual int geterr () const
 If isok() is false, return the system error number corresponding to the error, -1 for a special error string (which you can obtain with errstr()) or 0 on end of file.

virtual WvString errstr () const
virtual void seterr (int _errnum)
 Set the errnum variable -- we have an error.

void seterr (WvStringParm specialerr)
void seterr (WVSTRING_FORMAT_DECL)
void seterr (const WvError &err)
void noerr ()
 Reset our error state - there's no error condition anymore.


Static Public Member Functions

template<typename T> T undatumize (datum &data)

Protected Attributes

D * saveddata
int errnum
WvString errstring


Constructor & Destructor Documentation

template<class K, class D>
WvBdbHash< K, D >::WvBdbHash WvStringParm  dbfile = WvString::null,
bool  persist = true
[inline]
 

Definition at line 157 of file wvbdbhash.h.

References WvBdbHash< K, D >::saveddata, and WvStringParm.


Member Function Documentation

void WvBdbHashBase::add const datum key,
const datum data,
bool  replace
[inherited]
 

template<class K, class D>
void WvBdbHash< K, D >::add const K &  key,
const D &  data,
bool  replace = false
[inline]
 

Definition at line 160 of file wvbdbhash.h.

References WvBdbHash< K, D >::add().

Referenced by WvBdbHash< K, D >::add(), and main().

void WvBdbHashBase::closedb  )  [inherited]
 

Close the db file.

Makes isok return false, so you must call opendb() before using it again. The effect on open iterators is undefined.

This can be called when !isok. It will always set the error message to "The db is closed" if it succeeds; if it sets it to anything else, there was an error while flushing the db.

template<class K, class D>
int WvBdbHash< K, D >::count  )  [inline]
 

Definition at line 184 of file wvbdbhash.h.

References WvBdbHash< K, D >::Iter::next(), and WvBdbHash< K, D >::Iter::rewind().

WvString WvError::errstr  )  const [virtual, inherited]
 

Reimplemented in WvHTTPStream, and WvStreamClone.

Definition at line 20 of file wverror.cc.

References WvError::errnum, and WvError::errstring.

Referenced by UniIniGen::commit(), WvStreamClone::errstr(), main(), UniIniGen::refresh(), WvError::seterr(), UniConfDaemon::setupsslsocket(), UniConfDaemon::setuptcpsocket(), UniConfDaemon::setupunixsocket(), WvX509Mgr::WvX509Mgr(), and WvHttpPool::~WvHttpPool().

bool WvBdbHashBase::exists const datum key  )  [inherited]
 

template<class K, class D>
bool WvBdbHash< K, D >::exists const K &  key  )  [inline]
 

Definition at line 181 of file wvbdbhash.h.

References WvBdbHash< K, D >::exists().

Referenced by WvBdbHash< K, D >::exists().

datum WvBdbHashBase::find const datum key  )  [inherited]
 

template<class K, class D>
D& WvBdbHash< K, D >::find const K &  key  )  [inline]
 

Definition at line 169 of file wvbdbhash.h.

References WvBdbHash< K, D >::find(), and WvBdbHash< K, D >::saveddata.

Referenced by WvBdbHash< K, D >::find().

template<class K, class D>
D& WvBdbHash< K, D >::first  )  [inline]
 

Definition at line 200 of file wvbdbhash.h.

References WvBdbHash< K, D >::Iter::next(), and WvBdbHash< K, D >::Iter::rewind().

virtual int WvError::geterr  )  const [inline, virtual, inherited]
 

If isok() is false, return the system error number corresponding to the error, -1 for a special error string (which you can obtain with errstr()) or 0 on end of file.

If isok() is true, returns an undefined number.

Reimplemented in WvHTTPStream, and WvStreamClone.

Definition at line 44 of file wverror.h.

References WvError::errnum.

Referenced by UniIniGen::commit(), WvStreamClone::geterr(), WvEncoderStream::isok(), WvConf::load_file(), WvLockDev::lock(), main(), WvHTTPStream::pre_select(), UniIniGen::refresh(), WvConf::save(), WvError::seterr(), WvMagicCircle::WvMagicCircle(), and WvHttpPool::~WvHttpPool().

template<class K, class D>
bool WvBdbHash< K, D >::isempty  )  [inline]
 

Definition at line 193 of file wvbdbhash.h.

References WvBdbHash< K, D >::Iter::next(), and WvBdbHash< K, D >::Iter::rewind().

virtual bool WvError::isok  )  const [inline, virtual, inherited]
 

By default, returns true if geterr() == 0.

Might be overridden so that isok() == false even though no error code has been specified.

Reimplemented in UniClientConn, WvBufStream, WvDailyEvent, WvDsp, WvEncoderStream, WvFDStream, WvHTTPStream, WvIStreamList, WvLog, WvPamStream, WvSSLStream, IWvStream, WvStream, WvStreamClone, WvStreamList, WvTCPConn, WvTimeoutStream, WvTimeStream, WvFileWatcher, and UniConfDaemon.

Definition at line 35 of file wverror.h.

References WvError::errnum.

Referenced by WvStreamList::isok(), WvStream::isok(), main(), WvBdbHash< K, D >::Iter::next(), WvRSAEncoder::WvRSAEncoder(), WvRSAStream::WvRSAStream(), and WvX509Mgr::WvX509Mgr().

void WvError::noerr  )  [inline, inherited]
 

Reset our error state - there's no error condition anymore.

Definition at line 65 of file wverror.h.

References WvError::errnum.

Referenced by WvError::WvError().

void WvBdbHashBase::opendb WvStringParm  _dbfile,
bool  persist_dbfile = true
[inherited]
 

Open a new db file.

This will instantly change the contents of the db, and probably mess up all your iterators. Best used just after creation.

if dbfile is NULL, bdb will create an "anonymous" database. It'll still take up disk space, but it disappears when closed. If dbfile is not NULL but persist_dbfile is false, the file will be truncated when opened and deleted when closed.

It is ok to use this if !isok - in fact, it's the expected way to reset it. It may fail and seterr itself, though, so don't get stuck in a loop.

template<class K, class D>
D& WvBdbHash< K, D >::operator[] const K &  key  )  [inline]
 

Definition at line 178 of file wvbdbhash.h.

void WvBdbHashBase::remove const datum key  )  [inherited]
 

template<class K, class D>
void WvBdbHash< K, D >::remove const K &  key  )  [inline]
 

Definition at line 166 of file wvbdbhash.h.

References WvBdbHash< K, D >::remove().

Referenced by WvBdbHash< K, D >::remove().

void WvError::seterr const WvError err  )  [inherited]
 

Definition at line 64 of file wverror.cc.

References WvError::errstr(), WvError::geterr(), and WvError::seterr().

void WvError::seterr WVSTRING_FORMAT_DECL   )  [inline, inherited]
 

Reimplemented in WvStream.

Definition at line 60 of file wverror.h.

References WvError::seterr(), and WVSTRING_FORMAT_CALL.

void WvError::seterr WvStringParm  specialerr  )  [inherited]
 

Reimplemented in WvStream.

Definition at line 54 of file wverror.cc.

References WvError::errnum, WvError::errstring, WvError::seterr(), and WvStringParm.

void WvError::seterr int  _errnum  )  [virtual, inherited]
 

Set the errnum variable -- we have an error.

If called more than once, seterr() doesn't change the error code away from the previous one. That way, we remember the _original_ cause of our problems.

Subclasses may want to override seterr(int) to shut themselves down (eg. WvStream::close()) when an error condition is set.

Note that seterr(WvString) will call seterr(-1).

Reimplemented in WvStream.

Definition at line 47 of file wverror.cc.

References WvError::errnum, and WvError::seterr().

Referenced by main(), and WvError::seterr().

template<class K, class D>
template<typename T>
T WvBdbHash< K, D >::undatumize datum &  data  )  [inline, static]
 

Definition at line 147 of file wvbdbhash.h.

References WvBdbHash< K, D >::undatumize().

Referenced by WvBdbHash< K, D >::undatumize().

void WvBdbHashBase::zap  )  [inherited]
 

Wipe the db.

Calling this while !isok is allowed, but not guaranteed to fix it.

Referenced by main().


Member Data Documentation

int WvError::errnum [protected, inherited]
 

Definition at line 22 of file wverror.h.

Referenced by WvError::errstr(), WvError::geterr(), WvError::isok(), WvError::noerr(), and WvError::seterr().

WvString WvError::errstring [protected, inherited]
 

Definition at line 23 of file wverror.h.

Referenced by WvError::errstr(), and WvError::seterr().

template<class K, class D>
D* WvBdbHash< K, D >::saveddata [protected]
 

Definition at line 154 of file wvbdbhash.h.

Referenced by WvBdbHash< K, D >::find(), and WvBdbHash< K, D >::WvBdbHash().


The documentation for this class was generated from the following file:
Generated on Tue Oct 5 01:09:23 2004 for WvStreams by doxygen 1.3.7