Serialbox  2.2.0
Data serialization library and tools for C/C++, Python and Fortran
serialbox::stella::MetainfoSet Class Reference

Meta-information set. More...

#include <MetainfoSet.h>

Public Member Functions

 MetainfoSet ()
 Construct empty map.
 
 MetainfoSet (const boost::shared_ptr< MetainfoMapImpl > &map)
 Construct with MetainfoMapImpl.
 
 MetainfoSet (const MetainfoSet &other)
 Copy constructor.
 
MetainfoSetoperator= (const MetainfoSet &other)
 Assignment operator. More...
 
void Cleanup ()
 Removes all metainfo and frees all memory.
 
std::vector< std::string > keys () const
 Gives access to all existing keys. More...
 
bool HasKey (const std::string &key) const
 Check if key exists already in set. More...
 
const boost::any & AsAny (const std::string &key) const
 Gives access to the internal representation of the requested metainfo. More...
 
bool AsBool (const std::string &key) const
 Extracts a value in bool representation. More...
 
int AsInt (const std::string &key) const
 Extracts a value in int representation. More...
 
float AsFloat (const std::string &key) const
 Extracts a value in single precision floating point representation. More...
 
double AsDouble (const std::string &key) const
 
template<typename RealType >
RealType AsReal (const std::string &key) const
 Extracts a value in RealType representation, where RealType is either float or double More...
 
std::string AsString (const std::string &key) const
 Extracts a value assuming its type is string. More...
 
std::string ToString () const
 Creates a string that carries the metainfo in a human-readable form. More...
 
std::size_t size () const
 Number elements in the set. More...
 
bool operator== (const MetainfoSet &other) const
 Comparison operator.
 
void setImpl (const boost::shared_ptr< MetainfoMapImpl > &metaInfoMap)
 Set implementation pointer.
 
boost::shared_ptr< MetainfoMapImpl > & getImpl ()
 Get implementation pointer.
 
const boost::shared_ptr< MetainfoMapImpl > & getImpl () const
 
void AddMetainfo (const std::string &key, const int &value)
 Add a new key-value pair into the set. The key must not exist yet. More...
 
void AddMetainfo (const std::string &key, const bool &value)
 
void AddMetainfo (const std::string &key, const float &value)
 
void AddMetainfo (const std::string &key, const double &value)
 
void AddMetainfo (const std::string &key, const std::string &value)
 
void AddMetainfo (const std::string &key, const char *value)
 

Detailed Description

Meta-information set.

Objects of this class contain a set of metainformation in form of key = value pair. The keys are strings, while the values can be integers, booleans, floating point numbers (either single or double precision) or strings.

Definition at line 36 of file MetainfoSet.h.

Member Function Documentation

◆ AddMetainfo()

void serialbox::stella::MetainfoSet::AddMetainfo ( const std::string &  key,
const int &  value 
)

Add a new key-value pair into the set. The key must not exist yet.

Parameters
keyThe key of the pair
valueThe value
Exceptions
SerializationExceptionThe key exists already

Definition at line 58 of file MetainfoSet.cpp.

◆ AsAny()

const boost::any & serialbox::stella::MetainfoSet::AsAny ( const std::string &  key) const

Gives access to the internal representation of the requested metainfo.

Parameters
keyThe identification of the metainfo value which is requested
Returns
The metainfo object is returned as constant reference
Exceptions
SerializationExceptionThe key exists already

Definition at line 78 of file MetainfoSet.cpp.

◆ AsBool()

bool serialbox::stella::MetainfoSet::AsBool ( const std::string &  key) const

Extracts a value in bool representation.

If the type is different than bool, the function does its best to convert the value to bool in a meaningful way.

Parameters
keyThe identification of the metainfo value which is requested
Returns
The value of the metainfo is returned as copy
Exceptions
SerializationExceptionThe key does not exist

Definition at line 82 of file MetainfoSet.cpp.

◆ AsDouble()

double serialbox::stella::MetainfoSet::AsDouble ( const std::string &  key) const

Extracts a value in double precision floating point representation

If the type is different than double, the function converts the value to double.

Parameters
keyThe identification of the metainfo value which is requested
Returns
The value of the metainfo is returned as copy
Exceptions
SerializationExceptionThe key does not exist

Definition at line 102 of file MetainfoSet.cpp.

◆ AsFloat()

float serialbox::stella::MetainfoSet::AsFloat ( const std::string &  key) const

Extracts a value in single precision floating point representation.

If the type is different than float, the function converts the value to float.

Parameters
keyThe identification of the metainfo value which is requested
Returns
The value of the metainfo is returned as copy
Exceptions
SerializationExceptionThe key does not exist

Definition at line 97 of file MetainfoSet.cpp.

◆ AsInt()

int serialbox::stella::MetainfoSet::AsInt ( const std::string &  key) const

Extracts a value in int representation.

If the type is different than int, the function does its best to convert the value to int in a meaningful way, and throws a SerializationException if the value is not convertible to int, e.g., in case of a floating point holding a non-integer value.

Parameters
keyThe identification of the metainfo value which is requested
Returns
The value of the metainfo is returned as copy
Exceptions
SerializationExceptionThe key does not exist or the value is not convertible to integer

Definition at line 87 of file MetainfoSet.cpp.

◆ AsReal()

template<typename RealType >
RealType serialbox::stella::MetainfoSet::AsReal ( const std::string &  key) const
inline

Extracts a value in RealType representation, where RealType is either float or double

If the type is different than RealType, the function converts the value to RealType.

Parameters
keyThe identification of the metainfo value which is requested
Returns
The value of the metainfo is returned as copy
Exceptions
SerializationExceptionThe key does not exist

Definition at line 150 of file MetainfoSet.h.

◆ AsString()

std::string serialbox::stella::MetainfoSet::AsString ( const std::string &  key) const

Extracts a value assuming its type is string.

If the type is different than string, the function constructs a string representation of it.

Parameters
keyThe identification of the metainfo value which is requested
Returns
The value of the metainfo is returned as copy
Exceptions
SerializationExceptionThe key does not exist

Definition at line 107 of file MetainfoSet.cpp.

◆ HasKey()

bool serialbox::stella::MetainfoSet::HasKey ( const std::string &  key) const

Check if key exists already in set.

Returns
True is returned iff the key does exist

Definition at line 51 of file MetainfoSet.cpp.

◆ keys()

std::vector< std::string > serialbox::stella::MetainfoSet::keys ( ) const

Gives access to all existing keys.

The order in which the keys are returned is ensured not to change if no keys are added or removed.

Returns
A vector containing all keys is returned

Definition at line 138 of file MetainfoSet.cpp.

◆ operator=()

MetainfoSet & serialbox::stella::MetainfoSet::operator= ( const MetainfoSet other)

Assignment operator.

Discards all previously stored information and copies data from the other object, performing a deep copy.

Parameters
otherThe object to copy from

Definition at line 44 of file MetainfoSet.cpp.

◆ size()

std::size_t serialbox::stella::MetainfoSet::size ( ) const

Number elements in the set.

Returns
The size of the set is returned

Definition at line 122 of file MetainfoSet.cpp.

◆ ToString()

std::string serialbox::stella::MetainfoSet::ToString ( ) const

Creates a string that carries the metainfo in a human-readable form.

Returns
The string representing the set is returned

Definition at line 112 of file MetainfoSet.cpp.


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