roadrunner
2.6.0
Fast simulator for SBML models
|
A basic type to hold a variety of data types. More...
#include <_Variant.h>
Public Types | |
enum | TypeId { STRING , BOOL , INT32 , UINT32 , INT64 , UINT64 , FLOAT , DOUBLE , CHAR , UCHAR , EMPTY , DOUBLEVECTOR } |
list of currently supported types that a Variant can hold. | |
Public Member Functions | |
TypeId | type () const |
the current type that this Variant is. | |
Variant () | |
creates an emtpy variant | |
template<typename T > | |
Variant (const T &val) | |
create a new variant from an existing supported data type. More... | |
Variant (const char *str) | |
Variant (const Variant &other) | |
Copy constructor. | |
template<typename T > | |
Variant & | operator= (const T &value) |
Assignment operator for assigning POD to Var same as the constructor, this assigns a value to an existing Variant. | |
Variant & | operator= (const Variant &other) |
Assignment operator. More... | |
virtual | ~Variant () |
clean up any data owned by this object. | |
const std::type_info & | typeInfo () const |
get the type id of the stored data type. More... | |
template<typename T > | |
T | convert () const |
Convert this variant to a supported data type. More... | |
VARIANT_IMPLICIT_CONVERT (std::string) | |
VARIANT_IMPLICIT_CONVERT (long) | |
VARIANT_IMPLICIT_CONVERT (bool) | |
VARIANT_IMPLICIT_CONVERT (float) | |
VARIANT_IMPLICIT_CONVERT (double) | |
VARIANT_IMPLICIT_CONVERT (unsigned long) | |
VARIANT_IMPLICIT_CONVERT (int) | |
VARIANT_IMPLICIT_CONVERT (unsigned int) | |
VARIANT_IMPLICIT_CONVERT (char) | |
VARIANT_IMPLICIT_CONVERT (unsigned char) | |
VARIANT_IMPLICIT_CONVERT (std::vector< double >) | |
std::string | toString () const |
Converts the Variant to a std::string in JSON format. | |
std::string | pythonRepr () const |
Convert to Python-compatible representation. More... | |
bool | isString () const |
is this variant a std::string. | |
bool | isInteger () const |
was an integer stored here. | |
bool | isNumeric () const |
is this a numeric type. | |
bool | isBool () const |
is this a boolean type. | |
bool | isEmpty () const |
true if empty. | |
bool | isSigned () const |
true if this is a signed number. | |
bool | isDoubleVector () const |
Static Public Member Functions | |
static Variant | parse (const std::string &val) |
Parses the std::string which must be in JSON format. More... | |
A basic type to hold a variety of data types.
Unfourtunatly C++ does not have a standard variant type so we have to create one here.
This is a fairly low performance class and is intended soley for infrequent operations such as Variant configuration parameters.
If Python support is enabled, this class can convert to and from a Python object.
Usage: This class can convert to and from any primitive data type, and some collections types. More type conversions will be added as needed.
To store a value, just assign it, the assignment operator automatically takes care of everything for you:
Extraction: To retrieve the stored data, uses the convert function, this is templated so it can convert and extract to any type:
Rationale: C++ does not have a built in variant type. Other variant types exist such as boost::any and Poco dynamic var. However including the one of these as part of our public wrappers would forever tie us to that particular library, and would impose yet another dependency.
Only very basic variant type support is needed and this class exposes the absolute minimum possible wrappers to support such features, and provides just two methods of getting and storing native C++ types in it.
This is currently implemented by Poco but the implementation is fully opaque and may change in the future.
|
inline |
|
inline |
Convert this variant to a supported data type.
This method will try to perform type coercion, i.e. if this variant contains a std::string, and it is asked to convert to a int, the std::string will be parsed as an int. Similary, doubles will be rounded to int, so forth.
Assignment operator.
Assign one variant to another.
|
static |
Parses the std::string which must be in JSON format.
This is a common way to read a Variant from a file or create a new one from a std::string:
std::string rr::Variant::pythonRepr | ( | ) | const |
Convert to Python-compatible representation.
const std::type_info & rr::Variant::typeInfo | ( | ) | const |
get the type id of the stored data type.
This will let you check what kind of data is strored in this variant.