#include <cdbwriter.h>
Public Member Functions | |
CDBWriter (const QString &path, QObject *parent=0) | |
Constructs a new CDBWriter to write to a cdb database at dbpath. | |
CDBWriter (int fd, QObject *parent=0) | |
Constructs a new CDBWriter to write to a cdb database at a file descriptor fd. | |
virtual | ~CDBWriter () |
Destroys the object closing the file beforehand. | |
void | add (const QString &key, const QVariant &val) |
Add a new key with val to the database. | |
void | insert (const QString &key, const QVariant &val) |
Insert a new key with val to the database. | |
void | replace (const QString &key, const QVariant &val) |
Insert a new key with val to the database. | |
void | close () |
Closes the writer and the underlying filesystem resource for writing. | |
bool | isWritable () |
Returns true if the writer is writable. | |
int | fileDescriptor () const |
Returns the file descriptor used by the writer. | |
Private Member Functions | |
void | put (const QString &key, const QVariant &val, int flag) |
Puts a new key with value val into the database. | |
Private Attributes | |
void * | cdbm |
A cdb library structure used to read data. | |
int | fd |
A file descriptor pointing to the database. |
This class is not a part of the public API. The writer operates on string-qvariant pairs. QVariant values can be associated with string keys. Several operations are supported - adding, replacing and inserting. Those operations differ in how they handle existing keys with same name.
The writer automatically cloes the filesystem resource on destruction but can be also closed manually. Writing to a closed writer has no effect.
CDBWriter::CDBWriter | ( | const QString & | path, | |
QObject * | parent = 0 | |||
) | [explicit] |
Constructs a new CDBWriter to write to a cdb database at dbpath.
dbpath | Path to the database. |
CDBWriter::CDBWriter | ( | int | fdd, | |
QObject * | parent = 0 | |||
) | [explicit] |
Constructs a new CDBWriter to write to a cdb database at a file descriptor fd.
You should not manipulate the fd after calling this function.
fd | An open file descriptor. |
CDBWriter::~CDBWriter | ( | ) | [virtual] |
Destroys the object closing the file beforehand.
void CDBWriter::add | ( | const QString & | key, | |
const QVariant & | val | |||
) |
Add a new key with val to the database.
If a value for this key already exists, another one is added.
key | Key name as string. | |
val | Value as string. |
void CDBWriter::insert | ( | const QString & | key, | |
const QVariant & | val | |||
) |
Insert a new key with val to the database.
If a value for this key already exists, nothing is done.
key | Key name as string. | |
val | Value as string. |
void CDBWriter::replace | ( | const QString & | key, | |
const QVariant & | val | |||
) |
Insert a new key with val to the database.
If a value for this key already exists, the old value is replaced with the new one.
key | Key name as string. | |
val | Value as string. |
void CDBWriter::close | ( | ) |
Closes the writer and the underlying filesystem resource for writing.
bool CDBWriter::isWritable | ( | ) |
Returns true if the writer is writable.
The writer is not writable after it has been closed or the target path is not accessible.
int CDBWriter::fileDescriptor | ( | ) | const |
Returns the file descriptor used by the writer.
Returns 0 when the writer is closed.
void CDBWriter::put | ( | const QString & | key, | |
const QVariant & | val, | |||
int | flag | |||
) | [private] |
Puts a new key with value val into the database.
Depending on the flag the key is added, inserted or replaced. The public methods of this class are wrapperes of this method with proper flags.
void* CDBWriter::cdbm [private] |
A cdb library structure used to read data.
int CDBWriter::fd [private] |
A file descriptor pointing to the database.