ConfigDB::Database Class Reference

#include <Database.h>

Inheritance diagram for ConfigDB::Database:
Collaboration diagram for ConfigDB::Database:

Public Member Functions

 Database (const DatabaseInfo &typeinfo, const String &path)
 Database instance. More...
 
virtual ~Database ()
 
String getName () const
 
String getPath () const
 
StoreRef openStore (unsigned index)
 Open a store instance, load it and return a shared pointer. More...
 
StoreUpdateRef openStoreForUpdate (unsigned index)
 
void checkStoreRef (const StoreRef &ref)
 Called from StoreRef destructor so database can manage caches. More...
 
void queueUpdate (Store &store, Object::UpdateCallback &&callback)
 Queue an asynchronous update. More...
 
void checkUpdateQueue (Store &store)
 Called by Store on completion of update so any queued updates can be started. More...
 
bool save (Store &store) const
 Called from Store::commit. More...
 
StoreUpdateRef lockStore (StoreRef &store)
 Lock a store for writing (called by Object) More...
 
virtual const FormatgetFormat (const Store &store) const
 Get the storage format to use for a store. More...
 
virtual bool handleFormatError (FormatError err, const Object &object, const String &arg)
 Called during import. More...
 
std::unique_ptr< ExportStreamcreateExportStream (const Format &format, const String &path=nullptr, const ExportOptions &options={})
 Create a read-only stream for serializing the database. More...
 
size_t exportToStream (const Format &format, Print &output, const ExportOptions &options={})
 Serialize the database to a stream. More...
 
bool exportToFile (const Format &format, const String &filename, const ExportOptions &options={})
 Serialize the database to a single file. More...
 
Status importFromStream (const Format &format, Stream &source)
 De-serialize the entire database from a stream. More...
 
Status importFromFile (const Format &format, const String &filename)
 De-serialize the entire database from a file. More...
 
std::unique_ptr< ImportStreamcreateImportStream (const Format &format)
 Create a write-only stream for de-serializing the database. More...
 

Public Attributes

const DatabaseInfotypeinfo
 

Constructor & Destructor Documentation

◆ Database()

ConfigDB::Database::Database ( const DatabaseInfo typeinfo,
const String path 
)
inline

Database instance.

Parameters
pathPath to root directory where all data is stored

◆ ~Database()

virtual ConfigDB::Database::~Database ( )
virtual

Member Function Documentation

◆ checkStoreRef()

void ConfigDB::Database::checkStoreRef ( const StoreRef ref)

Called from StoreRef destructor so database can manage caches.

Parameters
refThe store reference being destroyed

◆ checkUpdateQueue()

void ConfigDB::Database::checkUpdateQueue ( Store store)

Called by Store on completion of update so any queued updates can be started.

Parameters
storeThe store which has just finished updating
Note
The next queued update (if any) is popped from the queue and scheduled for handling via the task queue.

◆ createExportStream()

std::unique_ptr<ExportStream> ConfigDB::Database::createExportStream ( const Format format,
const String path = nullptr,
const ExportOptions options = {} 
)

Create a read-only stream for serializing the database.

Parameters
formatFormatter used to generate output
pathJSONPath-like expression to restrict output to specific store or object
optionsOptions for customising output

◆ createImportStream()

std::unique_ptr<ImportStream> ConfigDB::Database::createImportStream ( const Format format)
inline

Create a write-only stream for de-serializing the database.

Parameters
formatFormatter used to process incoming data from the stream

◆ exportToFile()

bool ConfigDB::Database::exportToFile ( const Format format,
const String filename,
const ExportOptions options = {} 
)

Serialize the database to a single file.

Parameters
formatFormatter used to generate output
filenameWhere to write output. Non-existent directories are created automatically.
optionsOptions for customising output

◆ exportToStream()

size_t ConfigDB::Database::exportToStream ( const Format format,
Print output,
const ExportOptions options = {} 
)
inline

Serialize the database to a stream.

Parameters
formatFormatter used to generate output
outputWhere to write output
optionsOptions for customising output

◆ getFormat()

virtual const Format& ConfigDB::Database::getFormat ( const Store store) const
virtual

Get the storage format to use for a store.

◆ getName()

String ConfigDB::Database::getName ( ) const
inline

◆ getPath()

String ConfigDB::Database::getPath ( ) const
inline

◆ handleFormatError()

virtual bool ConfigDB::Database::handleFormatError ( FormatError  err,
const Object object,
const String arg 
)
virtual

Called during import.

Parameters
objectThe object to which this error relates
argString parameter which failed validation
errThe specific error type
Return values
boolReturn true to continue processing, false to stop

Default behaviour is to report errors but continue processing.

◆ importFromFile()

Status ConfigDB::Database::importFromFile ( const Format format,
const String filename 
)

De-serialize the entire database from a file.

Parameters
formatFormatter used to read the source data
filenameFile containing source data

◆ importFromStream()

Status ConfigDB::Database::importFromStream ( const Format format,
Stream source 
)
inline

De-serialize the entire database from a stream.

Parameters
formatFormatter used to read the source data
sourceThe source data

◆ lockStore()

StoreUpdateRef ConfigDB::Database::lockStore ( StoreRef store)

Lock a store for writing (called by Object)

Parameters
storeStore reference to be locked. If possible, will be locked-in place otherwise it will be copied and updated.
Return values
StoreUpdateRefInvalid if locking fails

◆ openStore()

StoreRef ConfigDB::Database::openStore ( unsigned  index)

Open a store instance, load it and return a shared pointer.

◆ openStoreForUpdate()

StoreUpdateRef ConfigDB::Database::openStoreForUpdate ( unsigned  index)

◆ queueUpdate()

void ConfigDB::Database::queueUpdate ( Store store,
Object::UpdateCallback &&  callback 
)

Queue an asynchronous update.

Parameters
storeThe store to update
callbackCallback which will be invoked when store is available for updates

◆ save()

bool ConfigDB::Database::save ( Store store) const

Called from Store::commit.

Member Data Documentation

◆ typeinfo

const DatabaseInfo& ConfigDB::Database::typeinfo

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