DUECA/DUSIME
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
dueca::Snapshot Struct Reference

A Snapshot object can be used to send the data from a state snapshot, i.e. More...

#include <Snapshot.hxx>

Inheritance diagram for dueca::Snapshot:
Inheritance graph
[legend]
Collaboration diagram for dueca::Snapshot:
Collaboration graph
[legend]

Public Types

enum  SnapCoding {
  UnSpecified , Base64 , JSON , XML ,
  Floats , Doubles , BinaryFile , FloatFile ,
  DoubleFile , JSONFile , XMLFile , Base64File
}
 Enumerated type for an automatically generated object class. More...
 
typedef Snapshot __ThisDCOType__
 typedef for internal reference
 

Public Member Functions

 Snapshot ()
 default constructor.
 
 Snapshot (const dueca::smartstring &data, const NameSet &originator, const SnapCoding &coding)
 Constructor with arguments.
 
 Snapshot (const Snapshot &o)
 copy constructor.
 
 Snapshot (::dueca::AmorphReStore &r)
 constructor to restore an Snapshot from amorphous storage.
 
 ~Snapshot ()
 destructor.
 
void packData (::dueca::AmorphStore &s) const
 packs the Snapshot into amorphous storage.
 
void packDataDiff (::dueca::AmorphStore &s, const Snapshot &ref) const
 packs the Snapshot into amorphous storage.
 
void unPackData (::dueca::AmorphReStore &s)
 unpacks the Snapshot from an amorphous storage.
 
void unPackDataDiff (::dueca::AmorphReStore &s)
 unpacks the differences for Snapshot from an amorphous storage.
 
bool operator== (const Snapshot &o) const
 Test for equality.
 
bool operator!= (const Snapshot &o) const
 Test for inequality.
 
Snapshotoperator= (const Snapshot &o)
 Assignment operator.
 
std::ostream & print (std::ostream &s) const
 prints the Snapshot to a stream.
 

Static Public Member Functions

static voidoperator new (size_t size)
 new operator "new", which places objects not on a heap, but in one of the memory arenas.
 
static void operator delete (void *p)
 new operator "delete", to go with the new version of operator new.
 
static voidoperator new (size_t size, Snapshot *&o)
 placement "new", needed for stl.
 

Public Attributes

dueca::smartstring data
 A place for the data, variable size.
 
NameSet originator
 Identifies the object that sent the snapshot.
 
SnapCoding coding
 Snapshot encoding, if specified.
 

Static Public Attributes

static const char *const classname
 The name of this class.
 
static const uint32_t magic_check_number
 a "magic" number, hashed out of the class definition, that will be used to check consistency of the sent objects across the dueca nodes.
 

Detailed Description

A Snapshot object can be used to send the data from a state snapshot, i.e.

the data describing a (piece of) your model state in time, to a repository for snapshot, and conversely, for sending this data back to a SimulationModule, for restoration of an old state.

The Snapshot object allocates a data buffer for you. It is possible to use an AmorphStore object to pack the data in this buffer, like:

// make a snapshot to send later
// note that "DoubleFile" is just one of the options for storage,
// Binary and Base64 would also work here
Snapshot *snap = new Snapshot(5 * sizeof(double), getNameSet(),
// and an AmorphStore to pack the data in there
AmorphStore s(snap->accessData(), snap->getDataSize());
// pack the state
for (int ii = 5; ii--; ) {
}
// done, can now send off the snapshot.
Amorphous storage object of variable size.
Definition AmorphStore.hxx:118
This is a "light weight object" that enables you to read the latest set of data on a StreamChannelEnd...
Definition StreamReaderLatest.hxx:43
A Snapshot object can be used to send the data from a state snapshot, i.e.
Definition Snapshot.hxx:136
void packData(::dueca::AmorphStore &s) const
packs the Snapshot into amorphous storage.
@ DoubleFile
External ASCII formatted file, data AmorphStore packed as double.
Definition Snapshot.hxx:164
Snapshot()
default constructor.

Alternatively, the snapshot can be packed with JSON or XML data. The "data" member in the snapshot is a smart string that can be easily fed with data, first a JSON example, using rapidjson:

// somewhere appropriate, include json
#include "rapidjson/writer.h"
using namespace rapidjson;
// make a snapshot, initially empty string
Snapshot *snap = new Snapshot("", getNameSet(), Snapshot::JSON);
// the data object in the snapshot can be used in combination with
// a json writer, the following gives an appropriate standard writer:
// now code the data; using an array here. Of course you can use
// other formats as well, e.g., Object. See the rapidjson documentation
writer.StartArray()
for (int ii = 5; ii--; ) {
writer.Double(my_x_copy[ii]);
}
writer.EndArray();
// done, can now send off the snapshot.
const T & data()
Access to the data.
Definition DataReader.hxx:456
@ JSON
data directly encoded and stored as JSON string in inco toml
Definition Snapshot.hxx:152
Helper struct to create a json writer.
Definition smartstring.hxx:81

The same can be done with XML, using pugixml. Of course, you might encounter code with the "old" XMLSnapshot approach, that produces equally valid XML

// somewhere appropriate, include pugixml
#include <pugixml.hpp>
using namespace pugi; // or prefix variables with pugi
// make a snapshot, initially empty string
Snapshot *snap = new Snapshot("", getNameSet(), Snapshot::XML);
// the data object in the snapshot can be used in combination with
// an xml writer, the following gives an appropriate standard writer:
// now code the data; the convention/layout of the XML is your choice.
// See also the pugixml documentation
xml_node root = doc.child("state")
for (int ii = 5; ii--; ) {
xml_node element = root.child("value");
xml_attribute idx = element.attribute("idx");
idx.set_value(ii);
element.set_value(my_x_copy[ii]);
}
// this saves the created XML document to the smartstring in the
// snapshot object.
doc.save(writer);
// done, can now send off the snapshot.
@ XML
data directly encoded and stored as XML string in inco toml
Definition Snapshot.hxx:154
Helper struct to use an std::string as buffer for XML writing with pugi.
Definition smartstring.hxx:59

Member Enumeration Documentation

◆ SnapCoding

Enumerated type for an automatically generated object class.

Enumerator
UnSpecified 

old-style, no indication about coding.

Treated as Base64

Base64 

probably AmorphStore coded binary, stored in Base64 in toml

JSON 

data directly encoded and stored as JSON string in inco toml

XML 

data directly encoded and stored as XML string in inco toml

Floats 

data encoded in AmorphStore, all floats, stored in toml

Doubles 

data encoded in AmorphStore, all doubles, stored in toml

BinaryFile 

External binary file, binary storage, no information on format.

FloatFile 

External ASCII formatted file, data AmorphStore packed as floats.

DoubleFile 

External ASCII formatted file, data AmorphStore packed as double.

JSONFile 

data directly encoded and stored as JSON string in external file

XMLFile 

data directly encoded and stored as XML string in external file

Base64File 

data stored in Base64 in external file

Member Function Documentation

◆ operator new()

static void * dueca::Snapshot::operator new ( size_t size)
static

new operator "new", which places objects not on a heap, but in one of the memory arenas.

This to speed up memory management.

◆ packDataDiff()

void dueca::Snapshot::packDataDiff ( ::dueca::AmorphStore & s,
const Snapshot & ref ) const

packs the Snapshot into amorphous storage.

only differences with a previous object are packed.

Member Data Documentation

◆ data

dueca::smartstring dueca::Snapshot::data

A place for the data, variable size.

Use this with ASCII converted data (XML, JSON), or use an AmorphStore to pack as binary data.


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