Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

c4_Storage Class Reference

Manager for persistent storage of view structures. More...

Inheritance diagram for c4_Storage:

Inheritance graph
[legend]
List of all members.

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_StrategyStrategy () 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_StorageGetAside () 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.

Detailed Description

Manager for persistent storage of view structures.

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();


Member Function Documentation

bool c4_Storage::Rollback bool  full_ = false  ) 
 

(Re)initialize for on-demand loading

Calling Rollback will cancel all uncommitted changes.


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

Metakit C++ API Reference - https://www.equi4.com/metakit.html - extracted with Doxygen