#include <TDBFile.h>
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 |
Tagcoll::TDBFile::TDBFile | ( | const std::string & | filename | ) |
Tagcoll::TDBFile::~TDBFile | ( | ) | [virtual] |
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.
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. |
SystemException | if the operation fails |
OpSet< string > Tagcoll::TDBFile::deserialize_stringset | ( | const TDB_DATA & | val | ) | [static] |
Utility function to deserialize a string list.
val | a TDB entry containing a list of strings separated by a null character ('\0') |
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.
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. |
bool Tagcoll::TDBFile::get | ( | const std::string & | key, | |
ITEM & | item | |||
) | const [inline] |
Get the value of a key.
key | The key to retrieve. | |
item | The item to set. The size of the item is automatically inferred by its type. |
OpSet< string > Tagcoll::TDBFile::getStringSet | ( | const std::string & | key | ) | const |
Get the value of a key, parsed as a set of strings.
key | The key to retrieve. |
void Tagcoll::TDBFile::setGeneric | ( | const std::string & | key, | |
const void * | buf, | |||
unsigned int | size | |||
) |
Generic way of setting the value for a key.
key | The key to store | |
buf | The buffer with the data to store | |
size | The size of the data in buf |
SystemException | in case of error |
void Tagcoll::TDBFile::set | ( | const std::string & | key, | |
const ITEM & | item | |||
) | [inline] |
Set the value of a key.
key | The key to store | |
item | The item to store. The size of the item is automatically inferred by its type. |
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.
key | The key to store. | |
vals | The values to store. The strings are encoded one after the other, separated by null ('\0') characters. |
SystemException | in case of error |
void Tagcoll::TDBFile::remove | ( | const std::string & | key | ) |
Remove an item.
key | The key of the item to remove |
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.
fn | Callback function that gets invoked once for every item in the database. | |
state | Arbitrary value that is passed to fn as-is. |
SystemException | in case of error |
TDB_CONTEXT* Tagcoll::TDBFile::db [protected] |
std::string Tagcoll::TDBFile::_filename [protected] |