CDBWriter Class Reference

A wrapper class to write data (create) tiny-cdb databases. More...

#include <cdbwriter.h>

List of all members.

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.


Detailed Description

A wrapper class to write data (create) tiny-cdb databases.

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.


Constructor & Destructor Documentation

CDBWriter::CDBWriter ( const QString &  path,
QObject *  parent = 0 
) [explicit]

Constructs a new CDBWriter to write to a cdb database at dbpath.

Parameters:
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.

Parameters:
fd An open file descriptor.

CDBWriter::~CDBWriter (  )  [virtual]

Destroys the object closing the file beforehand.


Member Function Documentation

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.

Parameters:
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.

Parameters:
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.

Parameters:
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.


Member Data Documentation

void* CDBWriter::cdbm [private]

A cdb library structure used to read data.

int CDBWriter::fd [private]

A file descriptor pointing to the database.


The documentation for this class was generated from the following files:

Generated on Thu Feb 21 18:31:19 2013 for libcontextsubscriber by  doxygen 1.5.6