Inheritance diagram for c4_Storage:
Public Member Functions | |
c4_Storage () | |
Construct streaming-only storage object. | |
c4_Storage (c4_Strategy &, bool=false, int=1) | |
Construct a storage using the specified strategy handler. | |
c4_Storage (const char *, int) | |
Construct a storage object, keeping the current structure. | |
c4_Storage (const c4_View &) | |
Reconstruct a storage object from a suitable view. | |
~c4_Storage () | |
Destructor, usually closes file, but does not commit by default. | |
void | SetStructure (const char *) |
Define the complete view structure of the storage. | |
bool | AutoCommit (bool=true) |
Set storage up to always call Commit in the destructor. | |
c4_Strategy & | Strategy () const |
Return the strategy object associated with this storage. | |
const char * | Description (const char *=0) |
Return a description of the view structure (default is all). | |
bool | SetAside (c4_Storage &) |
Define the storage to use for differential commits. | |
c4_Storage * | GetAside () const |
Return storage used for differential commits, or null. | |
bool | Commit (bool=false) |
Flush pending changes to file right now. | |
bool | Rollback (bool=false) |
(Re)initialize for on-demand loading | |
c4_ViewRef | View (const char *) |
Get or set a named view in this storage object. | |
c4_View | GetAs (const char *) |
Get a named view, redefining it to match the given structure. | |
bool | LoadFrom (c4_Stream &) |
Load contents from the specified input stream. | |
void | SaveTo (c4_Stream &) |
Save contents to the specified output stream. |
The storage class uses a view, with additional functionality to be able to store and reload the data it contains (including nested subviews).
By default, data is loaded on demand, i.e. whenever data which has not yet been referenced is used for the first time. Loading is limited to the lifetime of this storage object, since the storage object carries the file descriptor with it that is needed to access the data file.
To save changes, call the Commit member. This is the only time that data is written to file - when using a read-only file simply avoid calling Commit.
The LoadFromStream and SaveToStream members can be used to serialize the contents of this storage row using only sequential I/O (no seeking, only read or write calls).
The data storage mechanism implementation provides fail-safe operation: if anything prevents Commit from completing its task, the last succesfully committed version of the saved data will be recovered on the next open. This also includes changes made to the table structure.
The following code creates a view with 1 row and stores it on file:
c4_StringProp pName ("Name"); c4_IntProp pAge ("Age"); c4_Storage storage ("myfile.dat", true); c4_View myView = storage.GetAs("Musicians[Name:S,Age:I]"); myView.Add(pName ["John Williams"] + pAge [43]); storage.Commit();
|
(Re)initialize for on-demand loading Calling Rollback will cancel all uncommitted changes. |