akregator
c4_Storage Class Reference
#include <mk4.h>
List of all members.
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();
Definition at line 534 of file mk4.h.
Constructor & Destructor Documentation
| c4_Storage::c4_Storage |
( |
|
) |
|
Construct streaming-only storage object.
Definition at line 186 of file store.cpp.
| c4_Storage::c4_Storage |
( |
c4_Strategy & |
strategy_, |
|
|
bool |
owned_ = false, |
|
|
int |
mode_ = 1 | |
|
) |
| | |
Construct a storage using the specified strategy handler.
Definition at line 191 of file store.cpp.
| c4_Storage::c4_Storage |
( |
const char * |
fname_, |
|
|
int |
mode_ | |
|
) |
| | |
Construct a storage object, keeping the current structure.
Definition at line 196 of file store.cpp.
| c4_Storage::c4_Storage |
( |
const c4_View & |
root_ |
) |
|
Reconstruct a storage object from a suitable view.
Definition at line 205 of file store.cpp.
| c4_Storage::~c4_Storage |
( |
|
) |
|
Destructor, usually closes file, but does not commit by default.
Definition at line 214 of file store.cpp.
Member Function Documentation
| bool c4_Storage::AutoCommit |
( |
bool |
flag_ = true |
) |
|
Set storage up to always call Commit in the destructor.
Definition at line 378 of file store.cpp.
| bool c4_Storage::Commit |
( |
bool |
full_ = false |
) |
|
Flush pending changes to file right now.
Definition at line 361 of file store.cpp.
| const char * c4_Storage::Description |
( |
const char * |
name_ = 0 |
) |
|
Return a description of the view structure (default is all).
Definition at line 338 of file store.cpp.
| c4_View c4_Storage::GetAs |
( |
const char * |
description_ |
) |
|
Get a named view, redefining it to match the given structure.
Definition at line 253 of file store.cpp.
Return storage used for differential commits, or null.
Definition at line 356 of file store.cpp.
| bool c4_Storage::LoadFrom |
( |
c4_Stream & |
stream_ |
) |
|
Load contents from the specified input stream.
Definition at line 383 of file store.cpp.
| bool c4_Storage::Rollback |
( |
bool |
full_ = false |
) |
|
(Re)initialize for on-demand loading
Calling Rollback will cancel all uncommitted changes.
Definition at line 369 of file store.cpp.
| void c4_Storage::SaveTo |
( |
c4_Stream & |
stream_ |
) |
|
Save contents to the specified output stream.
Definition at line 400 of file store.cpp.
Define the storage to use for differential commits.
Definition at line 347 of file store.cpp.
| void c4_Storage::SetStructure |
( |
const char * |
description_ |
) |
|
Define the complete view structure of the storage.
Definition at line 317 of file store.cpp.
Return the strategy object associated with this storage.
Definition at line 333 of file store.cpp.
| c4_ViewRef c4_Storage::View |
( |
const char * |
name_ |
) |
|
Get or set a named view in this storage object.
Definition at line 228 of file store.cpp.
The documentation for this class was generated from the following files: