Tagcoll::TDBFile Class Reference

Access an on-disk binary index in TDB format. More...

#include <TDBFile.h>

List of all members.

Public Member Functions

 TDBFile (const std::string &filename)
 Create a new TDBFile.
virtual ~TDBFile ()
const std::string & filename () const
 Get the file name.
void open (int tdb_flags, int open_flags, mode_t mode=0666)
 Open the file.
bool has (const std::string &key) const
 Returns true if the database contains the given key.
bool getGeneric (const std::string &key, void *buf, unsigned int size) const
 Generic way of retrieving the value for a key.
template<class ITEM>
bool get (const std::string &key, ITEM &item) const
 Get the value of a key.
OpSet< std::string > getStringSet (const std::string &key) const
 Get the value of a key, parsed as a set of strings.
void setGeneric (const std::string &key, const void *buf, unsigned int size)
 Generic way of setting the value for a key.
template<class ITEM>
void set (const std::string &key, const ITEM &item)
 Set the value of a key.
void setStringSet (const std::string &key, OpSet< std::string > vals)
 Set the value of a key using a set of strings.
void remove (const std::string &key)
 Remove an item.
int traverse (int(*fn)(TDB_CONTEXT *, TDB_DATA, TDB_DATA, void *), void *state) const
 Iterate through all the items in the database.
const TDB_CONTEXT * context () const
 Access the internal TDB context.
TDB_CONTEXT * context ()
 Access the internal TDB context.

Static Public Member Functions

static OpSet< std::string > deserialize_stringset (const TDB_DATA &val)
 Utility function to deserialize a string list.

Protected Attributes

TDB_CONTEXT * db
std::string _filename


Detailed Description

Access an on-disk binary index in TDB format.


Constructor & Destructor Documentation

Tagcoll::TDBFile::TDBFile ( const std::string &  filename  ) 

Create a new TDBFile.

Parameters:
filename The filename of the on-disk database file

Tagcoll::TDBFile::~TDBFile (  )  [virtual]


Member Function Documentation

const std::string& Tagcoll::TDBFile::filename (  )  const [inline]

Get the file name.

const TDB_CONTEXT* Tagcoll::TDBFile::context (  )  const [inline]

Access the internal TDB context.

TDB_CONTEXT* Tagcoll::TDBFile::context (  )  [inline]

Access the internal TDB context.

void Tagcoll::TDBFile::open ( int  tdb_flags,
int  open_flags,
mode_t  mode = 0666 
)

Open the file.

Parameters:
tdb_flags Database flags. See man tdb_open(3) for a description.
open_flags File open flags. See man tdb_open(3) for a description.
mode File permissions to use if it is created. Umask is respected. See man open(2) for a description.
Exceptions:
SystemException if the operation fails

OpSet< string > Tagcoll::TDBFile::deserialize_stringset ( const TDB_DATA &  val  )  [static]

Utility function to deserialize a string list.

Parameters:
val a TDB entry containing a list of strings separated by a null character ('\0')
Returns:
the strings parsed into an OpSet<std::string>

bool Tagcoll::TDBFile::has ( const std::string &  key  )  const

Returns true if the database contains the given key.

bool Tagcoll::TDBFile::getGeneric ( const std::string &  key,
void *  buf,
unsigned int  size 
) const

Generic way of retrieving the value for a key.

Note:
in most cases, you want to use the get() method instead.
Parameters:
key The key to retrieve
buf The buffer where the key value is to be retrieved
size The size of buf. Reading will fail if buf is not big enough to hold the result.
Returns:
true if the key exists in the database and its value fits in the buffer; false otherwise.

template<class ITEM>
bool Tagcoll::TDBFile::get ( const std::string &  key,
ITEM &  item 
) const [inline]

Get the value of a key.

Parameters:
key The key to retrieve.
item The item to set. The size of the item is automatically inferred by its type.
Returns:
true if the key exists in the database and its value fits in the given variable; false otherwise.

OpSet< string > Tagcoll::TDBFile::getStringSet ( const std::string &  key  )  const

Get the value of a key, parsed as a set of strings.

Parameters:
key The key to retrieve.
Returns:
The value parsed as an OpSet<std::string>. The strings are supposed to be encoded one after the other, separated by null ('\0') characters.

void Tagcoll::TDBFile::setGeneric ( const std::string &  key,
const void *  buf,
unsigned int  size 
)

Generic way of setting the value for a key.

Note:
in most cases, you want to use the set() method instead.
Parameters:
key The key to store
buf The buffer with the data to store
size The size of the data in buf
Exceptions:
SystemException in case of error

template<class ITEM>
void Tagcoll::TDBFile::set ( const std::string &  key,
const ITEM &  item 
) [inline]

Set the value of a key.

Parameters:
key The key to store
item The item to store. The size of the item is automatically inferred by its type.
Exceptions:
SystemException in case of error

void Tagcoll::TDBFile::setStringSet ( const std::string &  key,
OpSet< std::string >  vals 
)

Set the value of a key using a set of strings.

Parameters:
key The key to store.
vals The values to store. The strings are encoded one after the other, separated by null ('\0') characters.
Exceptions:
SystemException in case of error

void Tagcoll::TDBFile::remove ( const std::string &  key  ) 

Remove an item.

Parameters:
key The key of the item to remove
Exceptions:
SystemException in case of error

int Tagcoll::TDBFile::traverse ( int(*)(TDB_CONTEXT *, TDB_DATA, TDB_DATA, void *)  fn,
void *  state 
) const

Iterate through all the items in the database.

Parameters:
fn Callback function that gets invoked once for every item in the database.
state Arbitrary value that is passed to fn as-is.
Returns:
The number of items traversed
Exceptions:
SystemException in case of error


Member Data Documentation

TDB_CONTEXT* Tagcoll::TDBFile::db [protected]

std::string Tagcoll::TDBFile::_filename [protected]


The documentation for this class was generated from the following files:
Generated on Sat Jan 17 04:00:36 2009 for libtagcoll by  doxygen 1.5.1