Darwin
1.10(beta)
|
Provides indexed storage for multiple records using two files (a binary data file and a text index file). More...
Public Member Functions | |
drwnPersistentStorage (bool bCompressed=false) | |
drwnPersistentStorage (const drwnPersistentStorage &storage) | |
bool | open (const char *indexFile, const char *dataFile) |
open persistent storage index and data files | |
bool | open (const char *fileStem) |
open persistent storage using default extension for index and data files | |
bool | reopen () |
re-open previously opened persistent storage files | |
bool | close () |
close (and write) persistent storage files | |
bool | isOpen () const |
returns true if the persistent storage has been opened and not closed | |
bool | canReopen () const |
returns true if the persistent storage object has valid filenames but is currently closed | |
int | numRecords () const |
number of drwnPersistentRecord records stored on disk | |
size_t | numTotalBytes () const |
total number of bytes on disk used by the data file | |
size_t | numUsedBytes () const |
number of bytes on disk actually needed by the data file | |
size_t | numFreeBytes () const |
number of free bytes (due to fragmentation) in data file | |
bool | hasKey (const char *key) const |
returns true if a record with given key exists in the persistent storage | |
set< string > | getKeys () const |
returns all keys stored in the persistent storage object | |
bool | erase (const char *key) |
erases the record with given key | |
bool | read (const char *key, drwnPersistentRecord *record) |
reads the record with given key | |
bool | write (const char *key, const drwnPersistentRecord *record) |
writes the record with given key | |
size_t | bytes (const char *key) const |
number of bytes on disk used for record with given key | |
bool | clear () |
clears all records from the persistent storage object (takes affect when closed) | |
bool | defragment () |
defragments data file | |
Static Public Attributes | |
static int | MAX_OPEN = 16 |
max. number of open files | |
static string | DEFAULT_INDEX_EXT = string(".index") |
default extension for index files | |
static string | DEFAULT_DATA_EXT = string(".data") |
default extension for data files | |
Protected Member Functions | |
void | suspend () |
self-suspend (close) | |
void | resume () |
reopen if suspended | |
bool | atomic_reopen (bool locked) |
perform an atomic reopen operation | |
bool | atomic_close (bool locked) |
perform an atomic close operation | |
void | atomic_suspend (bool locked) |
perform an atomic suspend operation | |
Protected Attributes | |
string | _indexFilename |
name of index file | |
string | _dataFilename |
name of data file | |
map< string, drwnPersistentBlock > | _recordMapping |
key, start, length | |
list< drwnPersistentBlock > | _freeSpace |
start, length | |
bool | _bCompressed |
data in storage is compressed | |
fstream * | _fsdata |
data file stream (if open) | |
bool | _bSuspended |
self-suspended vs. closed (will reopen on any operation) | |
bool | _bDirty |
data has been written to the storage since opened | |
Static Protected Attributes | |
static list < drwnPersistentStorage * > | _openList |
list of open storage | |
Provides indexed storage for multiple records using two files (a binary data file and a text index file).
The class maintains an open stream to the data file. The index file is written on closing. A closed storage object can be reopened without having to re-parse the index file. The class also manages the maximum number of actively open storage objects. If more storage objects are opened, the oldest ones will be suspended (temporarily closes). Any operation to the storage object will automatically re-open (resume) the storage (possibly suspending other storage objects). To use this class, objects must implement the drwnPersistentRecord interface. Automatic compression of records can be set and is managed by through the drwnCompressionBuffer class.
The erase(), read() and write() methods are thread-safe allowing the same persistent storage object to be accessed from multiple threads.