DUECA/DUSIME
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...

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. More...
 
 Snapshot (const dueca::smartstring &data, const NameSet &originator, const SnapCoding &coding)
 Constructor with arguments.
 
 Snapshot (const Snapshot &o)
 copy constructor. More...
 
 Snapshot (::dueca::AmorphReStore &r)
 constructor to restore an Snapshot from amorphous storage. More...
 
 ~Snapshot ()
 destructor. More...
 
void packData (::dueca::AmorphStore &s) const
 packs the Snapshot into amorphous storage. More...
 
void packDataDiff (::dueca::AmorphStore &s, const Snapshot &ref) const
 packs the Snapshot into amorphous storage. More...
 
void unPackData (::dueca::AmorphReStore &s)
 unpacks the Snapshot from an amorphous storage. More...
 
void unPackDataDiff (::dueca::AmorphReStore &s)
 unpacks the differences for Snapshot from an amorphous storage. More...
 
bool operator== (const Snapshot &o) const
 Test for equality. More...
 
bool operator!= (const Snapshot &o) const
 Test for inequality. More...
 
Snapshotoperator= (const Snapshot &o)
 Assignment operator. More...
 
std::ostream & print (std::ostream &s) const
 prints the Snapshot to a stream. More...
 
 Snapshot (size_t data_size, SnapCoding coding=UnSpecified)
 Constructor. More...
 
 Snapshot (dueca::DataWriterArraySize data_size, SnapCoding coding=UnSpecified)
 Constructor. More...
 
 Snapshot (size_t data_size, const NameSet &originator, SnapCoding coding=UnSpecified)
 Constructor. More...
 
 Snapshot (const toml::value &coded)
 Constructor from a toml-parsed object.
 
toml::value tomlCode (const std::string &fname=std::string()) const
 Create a toml object.
 
bool saveExternal () const
 return true if the snapshot is to be saved in an external file
 
const char * fileExtension () const
 Return an appropriate extension for an external file.
 
const char * accessData () const
 This directly accesses the data area of the snapshot. More...
 
char * accessData ()
 This directly accesses the data area of the snapshot. More...
 
char * AllocAndAccessData (uint32_t dsize)
 This initializes, and subsequently accesses the data area of the snapshot. More...
 
uint32_t getDataSize () const
 Read back the maximum size of the data.
 
std::string getSample (unsigned size=20) const
 Return the complete snapshot, or a sample. More...
 

Static Public Member Functions

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

Public Attributes

dueca::smartstring data
 A place for the data, variable size. More...
 
NameSet originator
 Identifies the object that sent the snapshot.
 
SnapCoding coding
 Snapshot encoding, if specified.
 
size_t data_size
 For convenience, additional data_size member.
 

Static Public Attributes

static const char *const classname
 The name of this class. More...
 
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. More...
 

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--; ) {
packData(s, my_x_copy[ii]);
}
// done, can now send off the snapshot.

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:
smartstring::json_string_writer writer(snap->data);
// 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.

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 your calls 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
// a json writer, the following gives an appropriate standard writer:
smartstring::xml_string_writer writer(snap->data);
// 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.

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

Constructor & Destructor Documentation

◆ Snapshot() [1/6]

dueca::Snapshot::Snapshot ( )

default constructor.

◆ Snapshot() [2/6]

dueca::Snapshot::Snapshot ( const Snapshot o)

copy constructor.

◆ Snapshot() [3/6]

dueca::Snapshot::Snapshot ( ::dueca::AmorphReStore r)

constructor to restore an Snapshot from amorphous storage.

◆ ~Snapshot()

dueca::Snapshot::~Snapshot ( )

destructor.

◆ Snapshot() [4/6]

dueca::Snapshot::Snapshot ( size_t  data_size,
SnapCoding  coding = UnSpecified 
)

Constructor.

The Snapshot constructor at this point allocates room for the data you want to send. Use the accessData() method to access this room. Careful! There is no protection here, please don't mis-use or your application might fail.

◆ Snapshot() [5/6]

dueca::Snapshot::Snapshot ( dueca::DataWriterArraySize  data_size,
SnapCoding  coding = UnSpecified 
)

Constructor.

The Snapshot constructor at this point allocates room for the data you want to send. Use the accessData() method to access this room. Careful! There is no protection here, please don't mis-use or your application might fail.

◆ Snapshot() [6/6]

dueca::Snapshot::Snapshot ( size_t  data_size,
const NameSet originator,
SnapCoding  coding = UnSpecified 
)

Constructor.

The Snapshot constructor at this point allocates room for the data you want to send. Use the accessData() method to access this room. Careful! There is no protection here, please don't mis-use or your application might fail.

Member Function Documentation

◆ operator new() [1/2]

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.

◆ operator delete()

static void dueca::Snapshot::operator delete ( void *  p)
static

new operator "delete", to go with the new version of operator new.

◆ operator new() [2/2]

static void* dueca::Snapshot::operator new ( size_t  size,
Snapshot *&  o 
)
inlinestatic

placement "new", needed for stl.

◆ packData()

void dueca::Snapshot::packData ( ::dueca::AmorphStore s) const

packs the Snapshot into amorphous storage.

◆ 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.

◆ unPackData()

void dueca::Snapshot::unPackData ( ::dueca::AmorphReStore s)

unpacks the Snapshot from an amorphous storage.

◆ unPackDataDiff()

void dueca::Snapshot::unPackDataDiff ( ::dueca::AmorphReStore s)

unpacks the differences for Snapshot from an amorphous storage.

◆ operator==()

bool dueca::Snapshot::operator== ( const Snapshot o) const

Test for equality.

◆ operator!=()

bool dueca::Snapshot::operator!= ( const Snapshot o) const
inline

Test for inequality.

◆ operator=()

Snapshot& dueca::Snapshot::operator= ( const Snapshot o)

Assignment operator.

◆ print()

std::ostream& dueca::Snapshot::print ( std::ostream &  s) const

prints the Snapshot to a stream.

◆ accessData() [1/2]

const char* dueca::Snapshot::accessData ( ) const
inline

This directly accesses the data area of the snapshot.

Please be careful, there is no protection here.

◆ accessData() [2/2]

char* dueca::Snapshot::accessData ( )
inline

This directly accesses the data area of the snapshot.

Please be careful, there is no protection here.

◆ AllocAndAccessData()

char* dueca::Snapshot::AllocAndAccessData ( uint32_t  dsize)
inline

This initializes, and subsequently accesses the data area of the snapshot.

Please be careful, there is no protection here.

◆ getSample()

std::string dueca::Snapshot::getSample ( unsigned  size = 20) const

Return the complete snapshot, or a sample.

Member Data Documentation

◆ classname

const char* const dueca::Snapshot::classname
static

The name of this class.

◆ data

dueca::smartstring dueca::Snapshot::data

A place for the data, variable size.

Use this with ASCII converted data, or use an AmorphStore to pack. The intention for the future developments is to use snapshots that derive from a base type, allowing more freedom for the user's code

◆ magic_check_number

const uint32_t dueca::Snapshot::magic_check_number
static

a "magic" number, hashed out of the class definition, that will be used to check consistency of the sent objects across the dueca nodes.


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