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. | |
MetainfoSet & | operator= (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) |
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.
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.
key | The key of the pair |
value | The value |
SerializationException | The key exists already |
Definition at line 58 of file MetainfoSet.cpp.
const boost::any & serialbox::stella::MetainfoSet::AsAny | ( | const std::string & | key | ) | const |
Gives access to the internal representation of the requested metainfo.
key | The identification of the metainfo value which is requested |
SerializationException | The key exists already |
Definition at line 78 of file MetainfoSet.cpp.
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.
key | The identification of the metainfo value which is requested |
SerializationException | The key does not exist |
Definition at line 82 of file MetainfoSet.cpp.
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.
key | The identification of the metainfo value which is requested |
SerializationException | The key does not exist |
Definition at line 102 of file MetainfoSet.cpp.
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.
key | The identification of the metainfo value which is requested |
SerializationException | The key does not exist |
Definition at line 97 of file MetainfoSet.cpp.
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.
key | The identification of the metainfo value which is requested |
SerializationException | The key does not exist or the value is not convertible to integer |
Definition at line 87 of file MetainfoSet.cpp.
|
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.
key | The identification of the metainfo value which is requested |
SerializationException | The key does not exist |
Definition at line 150 of file MetainfoSet.h.
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.
key | The identification of the metainfo value which is requested |
SerializationException | The key does not exist |
Definition at line 107 of file MetainfoSet.cpp.
bool serialbox::stella::MetainfoSet::HasKey | ( | const std::string & | key | ) | const |
Check if key exists already in set.
Definition at line 51 of file MetainfoSet.cpp.
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.
Definition at line 138 of file MetainfoSet.cpp.
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.
other | The object to copy from |
Definition at line 44 of file MetainfoSet.cpp.
std::size_t serialbox::stella::MetainfoSet::size | ( | ) | const |
Number elements in the set.
Definition at line 122 of file MetainfoSet.cpp.
std::string serialbox::stella::MetainfoSet::ToString | ( | ) | const |
Creates a string that carries the metainfo in a human-readable form.
Definition at line 112 of file MetainfoSet.cpp.