qdbm::Curia Class Reference

C++ API of Curia, the extended API of QDBM. More...

Inheritance diagram for qdbm::Curia:
qdbm::ADBM

List of all members.

Public Member Functions

 Curia (const char *name, int omode=Curia::OREADER, int bnum=-1, int dnum=-1) throw (Curia_error)
 Get the database handle.
virtual ~Curia () throw ()
 Release the resources.
virtual void close () throw (Curia_error)
 Close the database handle.
virtual bool put (const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode=Curia::DOVER) throw (Curia_error)
 Store a record.
virtual bool out (const char *kbuf, int ksiz) throw (Curia_error)
 Delete a record.
virtual char * get (const char *kbuf, int ksiz, int start=0, int max=-1, int *sp=0) throw (Curia_error)
 Retrieve a record.
virtual int getwb (const char *kbuf, int ksiz, int start, int max, char *vbuf) throw (Curia_error)
 Retrieve a record and write the value into a buffer.
virtual int vsiz (const char *kbuf, int ksiz) throw (Curia_error)
 Get the size of the value of a record.
virtual void iterinit () throw (Curia_error)
 Initialize the iterator of the database handle.
virtual char * iternext (int *sp=0) throw (Curia_error)
 Get the next key of the iterator.
virtual void setalign (int align) throw (Curia_error)
 Set alignment of the database handle.
virtual void setfbpsiz (int size) throw (Curia_error)
 Set the size of the free block pool.
virtual void sync () throw (Curia_error)
 Synchronize updating contents with the files and the devices.
virtual void optimize (int bnum=-1) throw (Curia_error)
 Optimize the database.
virtual char * name () throw (Curia_error)
 Get the name of the database.
virtual int fsiz () throw (Curia_error)
 Get the total size of database files.
virtual double fsizd () throw (Curia_error)
 Get the total size of database files as double-precision floating-point number.
virtual int bnum () throw (Curia_error)
 Get the total number of the elements of each bucket array.
virtual int busenum () throw (Curia_error)
 Get the total number of the used elements of each bucket array.
virtual int rnum () throw (Curia_error)
 Get the number of the records stored in the database.
virtual bool writable () throw (Curia_error)
 Check whether the database handle is a writer or not.
virtual bool fatalerror () throw (Curia_error)
 Check whether the database has a fatal error or not.
virtual int inode () throw (Curia_error)
 Get the inode number of the database directory.
virtual time_t mtime () throw (Curia_error)
 Get the last modified time of the database.
virtual bool putlob (const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode=Curia::DOVER) throw (Curia_error)
 Store a large object.
virtual bool outlob (const char *kbuf, int ksiz) throw (Curia_error)
 Delete a large object.
virtual char * getlob (const char *kbuf, int ksiz, int start=0, int max=-1, int *sp=0) throw (Curia_error)
 Retrieve a large object.
virtual int getlobfd (const char *kbuf, int ksiz)
 Get the file descriptor of a large object.
virtual int vsizlob (const char *kbuf, int ksiz) throw (Curia_error)
 Get the size of the value of a large object.
virtual int rnumlob () throw (Curia_error)
 Get the number of the large objects stored in the database.
virtual void storerec (const Datum &key, const Datum &val, bool replace=true) throw (Curia_error)
 Store a record.
virtual void deleterec (const Datum &key) throw (Curia_error)
 Delete a record.
virtual Datum fetchrec (const Datum &key) throw (Curia_error)
 Fetch a record.
virtual Datum firstkey () throw (Curia_error)
 Get the first key.
virtual Datum nextkey () throw (Curia_error)
 Get the next key.
virtual bool error () throw (Curia_error)
 Check whether a fatal error occured or not.

Static Public Member Functions

static const char * version () throw ()
 Get the version information.
static void remove (const char *name) throw (Curia_error)
 Remove a database directory.
static char * snaffle (const char *name, const char *kbuf, int ksiz, int *sp) throw (Curia_error)
 Retrieve a record directly from a database directory.

Public Attributes

bool silent
 whether to repress frequent exceptions

Static Public Attributes

static const int ENOERR
 error code: no error
static const int EFATAL
 error code: with fatal error
static const int EMODE
 error code: invalid mode
static const int EBROKEN
 error code: broken database file
static const int EKEEP
 error code: existing record
static const int ENOITEM
 error code: no item found
static const int EALLOC
 error code: memory allocation error
static const int EMAP
 error code: memory mapping error
static const int EOPEN
 error code: open error
static const int ECLOSE
 error code: close error
static const int ETRUNC
 error code: trunc error
static const int ESYNC
 error code: sync error
static const int ESTAT
 error code: stat error
static const int ESEEK
 error code: seek error
static const int EREAD
 error code: read error
static const int EWRITE
 error code: write error
static const int ELOCK
 error code: lock error
static const int EUNLINK
 error code: unlink error
static const int EMKDIR
 error code: mkdir error
static const int ERMDIR
 error code: rmdir error
static const int EMISC
 error code: miscellaneous error
static const int OREADER
 open mode: open as a reader
static const int OWRITER
 open mode: open as a writer
static const int OCREAT
 open mode: writer creating
static const int OTRUNC
 open mode: writer truncating
static const int ONOLCK
 open mode: open without locking
static const int OLCKNB
 open mode: lock without blocking
static const int OSPARSE
 open mode: create as sparse files
static const int DOVER
 write mode: overwrite the existing value
static const int DKEEP
 write mode: keep the existing value
static const int DCAT
 write mode: concatenate values

Detailed Description

C++ API of Curia, the extended API of QDBM.


Constructor & Destructor Documentation

qdbm::Curia::Curia ( const char *  name,
int  omode = Curia::OREADER,
int  bnum = -1,
int  dnum = -1 
) throw (Curia_error)

Get the database handle.

Parameters:
name the name of a database directory.
omode the connection mode: `CuriaOWRITER' as a writer, `CuriaOREADER' as a reader. If the mode is `CuriaOWRITER', the following may be added by bitwise or: `CuriaOCREAT', which means it creates a new database if not exist, `CuriaOTRUNC', which means it creates a new database regardless if one exists. Both of `CuriaOREADER' and `CuriaOWRITER' can be added to by bitwise or: `CuriaONOLCK', which means it opens a database directory without file locking, or `CuriaOLCKNB', which means locking is performed without blocking. `CuriaOCREAT' can be added to by bitwise or: `CuriaOSPARSE', which means it creates database files as sparse files.
bnum the number of elements of each bucket array. If it is not more than 0, the default value is specified. The size of each bucket array is determined on creating, and can not be changed except for by optimization of the database. Suggested size of each bucket array is about from 0.5 to 4 times of the number of all records to store.
dnum the number of division of the database. If it is not more than 0, the default value is specified. The number of division can not be changed from the initial value. The max number of division is 512.
Note:
While connecting as a writer, an exclusive lock is invoked to the database directory. While connecting as a reader, a shared lock is invoked to the database directory. The thread blocks until the lock is achieved. If `CuriaONOLCK' is used, the application is responsible for exclusion control.
virtual qdbm::Curia::~Curia (  )  throw () [virtual]

Release the resources.

Note:
If the database handle is not closed yet, it is closed.

Member Function Documentation

virtual int qdbm::Curia::bnum (  )  throw (Curia_error) [virtual]

Get the total number of the elements of each bucket array.

Returns:
the total number of the elements of each bucket array.
Exceptions:
Curia_error if an error occurs.
virtual int qdbm::Curia::busenum (  )  throw (Curia_error) [virtual]

Get the total number of the used elements of each bucket array.

Returns:
the total number of the used elements of each bucket array.
Exceptions:
Curia_error if an error occurs.
Note:
This function is inefficient because it accesses all elements of each bucket array.
virtual void qdbm::Curia::close (  )  throw (Curia_error) [virtual]

Close the database handle.

Exceptions:
Curia_error if an error occurs.
Note:
Updating a database is assured to be written when the handle is closed. If a writer opens a database but does not close it appropriately, the database will be broken.

Implements qdbm::ADBM.

virtual void qdbm::Curia::deleterec ( const Datum key  )  throw (Curia_error) [virtual]

Delete a record.

Parameters:
key reference to a key object.
Exceptions:
Curia_error if an error occurs or no record corresponds.

Implements qdbm::ADBM.

virtual bool qdbm::Curia::error (  )  throw (Curia_error) [virtual]

Check whether a fatal error occured or not.

Returns:
true if the database has a fatal error, false if not.
Exceptions:
Curia_error if an error occurs.

Implements qdbm::ADBM.

virtual bool qdbm::Curia::fatalerror (  )  throw (Curia_error) [virtual]

Check whether the database has a fatal error or not.

Returns:
true if the database has a fatal error, false if not.
Exceptions:
Curia_error if an error occurs.
virtual Datum qdbm::Curia::fetchrec ( const Datum key  )  throw (Curia_error) [virtual]

Fetch a record.

Parameters:
key reference to a key object.
Returns:
a temporary instance of the value of the corresponding record.
Exceptions:
Curia_error if an error occurs or no record corresponds.

Implements qdbm::ADBM.

virtual Datum qdbm::Curia::firstkey (  )  throw (Curia_error) [virtual]

Get the first key.

Returns:
a temporary instance of the key of the first record.
Exceptions:
Curia_error if an error occurs or no record corresponds.

Implements qdbm::ADBM.

virtual int qdbm::Curia::fsiz (  )  throw (Curia_error) [virtual]

Get the total size of database files.

Returns:
the total size of the database files.
Exceptions:
Curia_error if an error occurs.
Note:
If the total size is more than 2GB, the return value overflows.
virtual double qdbm::Curia::fsizd (  )  throw (Curia_error) [virtual]

Get the total size of database files as double-precision floating-point number.

Returns:
the total size of the database files.
Exceptions:
Curia_error if an error occurs.
virtual char* qdbm::Curia::get ( const char *  kbuf,
int  ksiz,
int  start = 0,
int  max = -1,
int *  sp = 0 
) throw (Curia_error) [virtual]

Retrieve a record.

Parameters:
kbuf the pointer to the region of a key.
ksiz the size of the region of the key. If it is negative, the size is assigned with `stdstrlen(kbuf)'.
start the offset address of the beginning of the region of the value to be read.
max the max size to read with. If it is negative, the size is unlimited.
sp the pointer to a variable to which the size of the region of the return value is assigned. If it is 0, it is not used.
Returns:
the pointer to the region of the value of the corresponding record. If the silent flag is true and no record corresponds, 0 is returned instead of exception.
Exceptions:
Curia_error if an error occurs, no record corresponds, or the size of the value of the corresponding record is less than `start'.
Note:
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `stdmalloc' call, it should be released with the `stdfree' call if it is no longer in use.
virtual char* qdbm::Curia::getlob ( const char *  kbuf,
int  ksiz,
int  start = 0,
int  max = -1,
int *  sp = 0 
) throw (Curia_error) [virtual]

Retrieve a large object.

Parameters:
kbuf the pointer to the region of a key.
ksiz the size of the region of the key. If it is negative, the size is assigned with `stdstrlen(kbuf)'.
start the offset address of the beginning of the region of the value to be read.
max the max size to be read. If it is negative, the size to read is unlimited.
sp the pointer to a variable to which the size of the region of the return value is assigned. If it is 0, it is not used.
Returns:
the pointer to the region of the value of the corresponding large object. If the silent flag is true and no record corresponds, 0 is returned instead of exception.
Exceptions:
Curia_error if an error occurs, no record corresponds, or the size of the value of the corresponding record is less than `start'.
Note:
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `stdmalloc' call, it should be released with the `stdfree' call if it is no longer in use.
virtual int qdbm::Curia::getlobfd ( const char *  kbuf,
int  ksiz 
) [virtual]

Get the file descriptor of a large object.

Parameters:
kbuf the pointer to the region of a key.
ksiz the size of the region of the key. If it is negative, the size is assigned with `stdstrlen(kbuf)'.
Returns:
the file descriptor of the corresponding large object. If the silent flag is true and no record corresponds, -1 is returned instead of exception.
Exceptions:
Curia_error if an error occurs or no record corresponds.
Note:
The returned file descriptor is opened with the `open' call. If the database handle was opened as a writer, the descriptor is writable (O_RDWR), else, it is not writable (O_RDONLY). The descriptor should be closed with the `close' call if it is no longer in use.
virtual int qdbm::Curia::getwb ( const char *  kbuf,
int  ksiz,
int  start,
int  max,
char *  vbuf 
) throw (Curia_error) [virtual]

Retrieve a record and write the value into a buffer.

Parameters:
kbuf the pointer to the region of a key.
ksiz the size of the region of the key. If it is negative, the size is assigned with `stdstrlen(kbuf)'.
start the offset address of the beginning of the region of the value to be read.
max the max size to be read. It shuld be equal to or less than the size of the writing buffer.
vbuf the pointer to a buffer into which the value of the corresponding record is written.
Returns:
the return value is the size of the written data. If the silent flag is true and no record corresponds, -1 is returned instead of exception.
Exceptions:
Curia_error if an error occurs, no record corresponds, or the size of the value of the corresponding record is less than `start'.
Note:
No additional zero code is appended at the end of the region of the writing buffer.
virtual int qdbm::Curia::inode (  )  throw (Curia_error) [virtual]

Get the inode number of the database directory.

Returns:
the inode number of the database directory.
Exceptions:
Curia_error if an error occurs.
virtual void qdbm::Curia::iterinit (  )  throw (Curia_error) [virtual]

Initialize the iterator of the database handle.

Exceptions:
Curia_error if an error occurs.
Note:
The iterator is used in order to access the key of every record stored in a database.
virtual char* qdbm::Curia::iternext ( int *  sp = 0  )  throw (Curia_error) [virtual]

Get the next key of the iterator.

Parameters:
sp the pointer to a variable to which the size of the region of the return value is assigned. If it is 0, it is not used.
Returns:
the pointer to the region of the next key. If the silent flag is true and no record corresponds, 0 is returned instead of exception.
Exceptions:
Curia_error if an error occurs or no record is to be get out of the iterator.
Note:
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `stdmalloc' call, it should be released with the `stdfree' call if it is no longer in use. It is possible to access every record by iteration of calling this function. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access.
virtual time_t qdbm::Curia::mtime (  )  throw (Curia_error) [virtual]

Get the last modified time of the database.

Returns:
the last modified time the database.
Exceptions:
Curia_error if an error occurs.
virtual char* qdbm::Curia::name (  )  throw (Curia_error) [virtual]

Get the name of the database.

Returns:
the pointer to the region of the name of the database.
Exceptions:
Curia_error if an error occurs.
Note:
Because the region of the return value is allocated with the `stdmalloc' call, it should be released with the `stdfree' call if it is no longer in use.
virtual Datum qdbm::Curia::nextkey (  )  throw (Curia_error) [virtual]

Get the next key.

Returns:
a temporary instance of the key of the next record.
Exceptions:
Curia_error if an error occurs or no record corresponds.

Implements qdbm::ADBM.

virtual void qdbm::Curia::optimize ( int  bnum = -1  )  throw (Curia_error) [virtual]

Optimize the database.

Parameters:
bnum the number of the elements of each bucket array. If it is not more than 0, the default value is specified.
Exceptions:
Curia_error if an error occurs.
Note:
In an alternating succession of deleting and storing with overwrite or concatenate, dispensable regions accumulate. This function is useful to do away with them.
virtual bool qdbm::Curia::out ( const char *  kbuf,
int  ksiz 
) throw (Curia_error) [virtual]

Delete a record.

Parameters:
kbuf the pointer to the region of a key.
ksiz the size of the region of the key. If it is negative, the size is assigned with `stdstrlen(kbuf)'.
Returns:
always true. However, if the silent flag is true and no record corresponds, false is returned instead of exception.
Exceptions:
Curia_error if an error occurs or no record corresponds.
virtual bool qdbm::Curia::outlob ( const char *  kbuf,
int  ksiz 
) throw (Curia_error) [virtual]

Delete a large object.

Parameters:
kbuf the pointer to the region of a key.
ksiz the size of the region of the key. If it is negative, the size is assigned with `stdstrlen(kbuf)'.
Returns:
always true. However, if the silent flag is true and no record corresponds, false is returned instead of exception.
Exceptions:
Curia_error if an error occurs or no large object corresponds.
virtual bool qdbm::Curia::put ( const char *  kbuf,
int  ksiz,
const char *  vbuf,
int  vsiz,
int  dmode = Curia::DOVER 
) throw (Curia_error) [virtual]

Store a record.

Parameters:
kbuf the pointer to the region of a key.
ksiz the size of the region of the key. If it is negative, the size is assigned with `stdstrlen(kbuf)'.
vbuf the pointer to the region of a value.
vsiz the size of the region of the value. If it is negative, the size is assigned with `stdstrlen(vbuf)'.
dmode behavior when the key overlaps, by the following values: `CuriaDOVER', which means the specified value overwrites the existing one, `CuriaDKEEP', which means the existing value is kept, `CuriaDCAT', which means the specified value is concatenated at the end of the existing value.
Returns:
always true. However, if the silent flag is true and replace is cancelled, false is returned instead of exception.
Exceptions:
Curia_error if an error occurs or replace is cancelled.
virtual bool qdbm::Curia::putlob ( const char *  kbuf,
int  ksiz,
const char *  vbuf,
int  vsiz,
int  dmode = Curia::DOVER 
) throw (Curia_error) [virtual]

Store a large object.

Parameters:
kbuf the pointer to the region of a key.
ksiz the size of the region of the key. If it is negative, the size is assigned with `stdstrlen(kbuf)'.
vbuf the pointer to the region of a value.
vsiz the size of the region of the value. If it is negative, the size is assigned with `stdstrlen(vbuf)'.
dmode behavior when the key overlaps, by the following values: `CuriaDOVER', which means the specified value overwrites the existing one, `CuriaDKEEP', which means the existing value is kept, `CuriaDCAT', which means the specified value is concatenated at the end of the existing value.
Returns:
always true. However, if the silent flag is true and replace is cancelled, false is returned instead of exception.
Exceptions:
Curia_error if an error occurs or replace is cancelled.
static void qdbm::Curia::remove ( const char *  name  )  throw (Curia_error) [static]

Remove a database directory.

Parameters:
name the name of a database directory.
Exceptions:
Curia_error if an error occurs.
virtual int qdbm::Curia::rnum (  )  throw (Curia_error) [virtual]

Get the number of the records stored in the database.

Returns:
the number of the records stored in the database.
Exceptions:
Curia_error if an error occurs.
virtual int qdbm::Curia::rnumlob (  )  throw (Curia_error) [virtual]

Get the number of the large objects stored in the database.

Returns:
the number of the large objects stored in the database.
Exceptions:
Curia_error if an error occurs.
virtual void qdbm::Curia::setalign ( int  align  )  throw (Curia_error) [virtual]

Set alignment of the database handle.

Parameters:
align the basic size of alignment.
Exceptions:
Curia_error if an error occurs.
Note:
If alignment is set to a database, the efficiency of overwriting values is improved. The size of alignment is suggested to be average size of the values of the records to be stored. If alignment is positive, padding whose size is multiple number of the alignment is placed. If alignment is negative, as `vsiz' is the size of a value, the size of padding is calculated with `(vsiz / pow(2, abs(align) - 1))'. Because alignment setting is not saved in a database, you should specify alignment every opening a database.
virtual void qdbm::Curia::setfbpsiz ( int  size  )  throw (Curia_error) [virtual]

Set the size of the free block pool.

Parameters:
size the size of the free block pool of a database.
Exceptions:
Curia_error if an error occurs.
Note:
The default size of the free block pool is 16. If the size is greater, the space efficiency of overwriting values is improved with the time efficiency sacrificed.
static char* qdbm::Curia::snaffle ( const char *  name,
const char *  kbuf,
int  ksiz,
int *  sp 
) throw (Curia_error) [static]

Retrieve a record directly from a database directory.

Parameters:
name the name of a database directory.
kbuf the pointer to the region of a key.
ksiz the size of the region of the key. If it is negative, the size is assigned with `stdstrlen(kbuf)'.
sp the pointer to a variable to which the size of the region of the return value is assigned. If it is 0, it is not used.
Returns:
the pointer to the region of the value of the corresponding record.
Exceptions:
Curia_error if an error occurs or no record corresponds.
Note:
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `stdmalloc' call, it should be released with the `stdfree' call if it is no longer in use. Although this method can be used even while the database directory is locked by another process, it is not assured that recent updated is reflected.
virtual void qdbm::Curia::storerec ( const Datum key,
const Datum val,
bool  replace = true 
) throw (Curia_error) [virtual]

Store a record.

Parameters:
key reference to a key object.
val reference to a value object.
replace whether the existing value is to be overwritten or not.
Exceptions:
Curia_error if an error occurs or replace is cancelled.

Implements qdbm::ADBM.

virtual void qdbm::Curia::sync (  )  throw (Curia_error) [virtual]

Synchronize updating contents with the files and the devices.

Note:
Curia_error if an error occurs. This function is useful when another process uses the connected database directory.
static const char* qdbm::Curia::version (  )  throw () [static]

Get the version information.

Returns:
the string of the version information.
virtual int qdbm::Curia::vsiz ( const char *  kbuf,
int  ksiz 
) throw (Curia_error) [virtual]

Get the size of the value of a record.

Parameters:
kbuf the pointer to the region of a key.
ksiz the size of the region of the key. If it is negative, the size is assigned with `stdstrlen(kbuf)'.
Returns:
the size of the value of the corresponding record. If the silent flag is true and no record corresponds, -1 is returned instead of exception.
Exceptions:
Curia_error if an error occurs or no record corresponds.
Note:
Because this function does not read the entity of a record, it is faster than `get'.
virtual int qdbm::Curia::vsizlob ( const char *  kbuf,
int  ksiz 
) throw (Curia_error) [virtual]

Get the size of the value of a large object.

Parameters:
kbuf the pointer to the region of a key.
ksiz the size of the region of the key. If it is negative, the size is assigned with `stdstrlen(kbuf)'.
Returns:
the size of the value of the corresponding large object. If the silent flag is true and no record corresponds, -1 is returned instead of exception.
Exceptions:
Curia_error if an error occurs or no large object corresponds.
Note:
Because this function does not read the entity of a large object, it is faster than `getlob'.
virtual bool qdbm::Curia::writable (  )  throw (Curia_error) [virtual]

Check whether the database handle is a writer or not.

Returns:
true if the handle is a writer, false if not.
Exceptions:
Curia_error if an error occurs.

The documentation for this class was generated from the following file:
Generated on Thu Aug 5 01:52:09 2010 for QDBM for C++ by  doxygen 1.6.3