Boost logo

Boost :

From: Scott Woods (scottw_at_[hidden])
Date: 2003-05-25 18:04:27

Is anyone interested in a persistence mechanism? Rather than dumping a bunch
of doc+code and finding that its just inappropriate, here is some summary

Technique uses info available in a variant to manage the type-safe transfer
data between an application and some external storage. It can be
as a replacement for the windows registry or unix profiles. The technique
following properties;

* generic - load and save operations are templates
* portable - library and data are not platform dependent
* standard types - bool, integer, float, string, etc
* complex types - fixed dimension arrays and variable dimension vectors
* user-defined types - records (a set of members of any type)

Simplest usage involves "hand-forming" the variants. This is a bit
(and error-prone) so a "compiler" has been developed. This accepts a
conforming to a grammer and outputs a set of C++ classes (cpp and header).
The application can then derive application classes.

Given an application class "alarm_monitor" the schema might look like;

record sensor_signal { // Generated by raising the signal on an alarm
 time when // Instant of detection
 string line // Expanded text
 void detail[]

record monitor_store { // Persisted image of a monitored sensor
 integer number // Unique id
 integer status // Currently
 sensor_signal log[] // Rolling log of signals
 integer ring_count // Signal count since last ringing transition

The application would derive "alarm_monitor" from "monitor_store" and a
ctor might look like;

alarm_monitor::alarm_monitor( const alarm_sensor &sensor ) :
        // Recover the previously saved image of "this"

        typed_load_file file( );

        load( file.begin(), *this );
    catch( typed_memory_not_found & )
        // No previous image. Set the members of "this"
        // to reasonable defaults and save an image

        number = sensor.number;
        status = monitor_ready;
        ring_count = 0;

        typed_save_file file( );

       save( file.begin(), *this );
    // Resume normal operation

Hope this is enough info. Code is currently getting a good workout (part of
in a 24x7, server-type product). Example above is "para-phrased" to keep it
short and to remove some confusing coding standards.


Boost list run by bdawes at, gregod at, cpdaniel at, john at