TBTK
Need a break? Support the development by playing Polarity Puzzles
TBTK::Serializable Class Referenceabstract
Inheritance diagram for TBTK::Serializable:
TBTK::Property::AbstractProperty< double > TBTK::Property::AbstractProperty< SpinMatrix > TBTK::Property::AbstractProperty< std::complex< double > > TBTK::Array< double > TBTK::IndexedDataTree< SerializableVector< double > > TBTK::IndexedDataTree< SerializableVector< TBTK::SourceAmplitude > > TBTK::IndexedDataTree< TBTK::OverlapAmplitude > TBTK::IndexedDataTree< unsigned int > TBTK::Array< DataType > TBTK::BoundaryCondition TBTK::Geometry TBTK::HoppingAmplitudeList TBTK::HoppingAmplitudeSet TBTK::HoppingAmplitudeTree TBTK::IndexDescriptor TBTK::IndexedDataTree< Data > TBTK::IndexTree TBTK::Model TBTK::OverlapAmplitudeSet TBTK::Property::AbstractProperty< DataType > TBTK::Range TBTK::SingleParticleContext TBTK::SourceAmplitude TBTK::SourceAmplitudeSet

Public Types

enum  Mode { Debug, Binary, XML, JSON }
 

Public Member Functions

virtual std::string serialize (Mode mode) const =0
 
template<>
std::string serialize (const bool &data, Mode mode)
 
template<>
std::string serialize (const double &data, Mode mode)
 
template<>
std::string serialize (const std::complex< double > &data, Mode mode)
 
template<>
std::string serialize (const int &data, Mode mode)
 
template<>
std::string serialize (const unsigned int &data, Mode mode)
 
template<>
std::string serialize (const SpinMatrix &data, Mode mode)
 
template<>
std::string serialize (const Statistics &data, Mode mode)
 
template<>
std::string serialize (const std::vector< std::complex< double >> &data, Mode mode)
 
template<>
int deserialize (const std::string &serialization, Mode mode)
 

Static Public Member Functions

static bool hasID (const std::string &serialization, Mode mode)
 
static std::string getID (const std::string &serialization, Mode mode)
 
static std::string extractComponent (const std::string &serialization, const std::string &containerID, const std::string &componentID, const std::string &componentName, Mode mode)
 

Static Protected Member Functions

static bool validate (const std::string &serialization, const std::string &id, Mode mode)
 
static std::string getContent (const std::string &serialization, Mode mode)
 
static std::vector< std::string > split (const std::string &content, Mode mode)
 
template<typename DataType >
static std::enable_if<!std::is_pointer< DataType >::value, std::string >::type serialize (const DataType &data, Mode mode)
 
template<typename DataType >
static std::enable_if< std::is_pointer< DataType >::value, std::string >::type serialize (const DataType &data, Mode mode)
 
template<typename DataType >
static DataType deserialize (const std::string &serialization, Mode mode)
 
static std::string extract (const std::string &serialization, Mode mode, std::string component)
 

Friends

class Index
 
class HoppingAmplitude
 
class SourceAmplitude
 
class OverlapAmplitude
 
template<typename DataType >
class CArray
 

Member Enumeration Documentation

◆ Mode

Serialization modes. Note that debug is not guaranteed to be backward compatible.

Member Function Documentation

◆ deserialize()

template<typename DataType >
DataType TBTK::Serializable::deserialize ( const std::string &  serialization,
Mode  mode 
)
staticprotected

Deserialize.

Parameters
serializationThe serialization from which the data is to be deserialized.
modeThe mode with which the data has been serialized.
Returns
The data after deserialization.

◆ extract()

static std::string TBTK::Serializable::extract ( const std::string &  serialization,
Mode  mode,
std::string  component 
)
staticprotected

Extracts a component of a serialization string, catching potential errors. In particular used to extract the serialization string for parents in the constructor of a child, because no try-catch block is possible to insert at this point.

◆ extractComponent()

static std::string TBTK::Serializable::extractComponent ( const std::string &  serialization,
const std::string &  containerID,
const std::string &  componentID,
const std::string &  componentName,
Mode  mode 
)
static

Extract a component from a container serialization. When serializing classes, their parent are embedded inside the child class serialization. I.e. the parent class is a component contained in the child class serialization. However, when reconstructing a serialized class, its parent constructor has to be called before the child class is constructed. This function provides the means to extract the serialization of a parent class from the serialization of a child class.

Parameters
containerIDID for the container (child class).
componentIDID for the component (parent class).
componentNameName used to refer to the parent object. Only used in some modes.
modeMode with which the string has been serialized.
Returns
The serialization string for the component.

◆ getContent()

static std::string TBTK::Serializable::getContent ( const std::string &  serialization,
Mode  mode 
)
staticprotected

Get the content of a serializtion string.

◆ getID()

static std::string TBTK::Serializable::getID ( const std::string &  serialization,
Mode  mode 
)
static

Get the ID of a serialization string.

◆ hasID()

static bool TBTK::Serializable::hasID ( const std::string &  serialization,
Mode  mode 
)
static

Returns true if the serialization string has an ID.

◆ serialize() [1/2]

template<typename DataType >
std::enable_if< std::is_pointer< DataType >::value, std::string >::type TBTK::Serializable::serialize ( const DataType &  data,
Mode  mode 
)
staticprotected

Serialize.

Parameters
dataThe data to serialize.
modeThe mode with which to serialize the data.
Returns
A string containing the serialization of the data.

◆ serialize() [2/2]

◆ split()

static std::vector<std::string> TBTK::Serializable::split ( const std::string &  content,
Mode  mode 
)
staticprotected

Split content string.

◆ validate()

static bool TBTK::Serializable::validate ( const std::string &  serialization,
const std::string &  id,
Mode  mode 
)
staticprotected

Validate serialization string.

Friends And Related Function Documentation

◆ Index

friend class Index
friend

Friend classes (Classes that are psudo-Serializable because they are so small and often used that a virtual function would have a non-negligible performance penalty).


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