Evoplex
0.2.1
|
A class for variant data types (tagged union). More...
#include <value.h>
Public Types | |
enum | Type { BOOL, CHAR, DOUBLE, INT, STRING, INVALID } |
This enum defines the types of variable that a Value can contain. | |
Public Member Functions | |
Value () | |
Constructs an invalid Value. More... | |
Value (const Value &value) | |
Constructs a copy of the value passed as the argument to this constructor. | |
Value (bool value) | |
Constructs a new Value with a boolean value. | |
Value (char value) | |
Constructs a new Value with a char value. | |
Value (double value) | |
Constructs a new Value with a double value. | |
Value (int value) | |
Constructs a new Value with an integer value. | |
Value (const char *value) | |
Constructs a new Value with a string value. | |
Value (const QString &value) | |
Constructs a new Value with a string value. | |
Value (std::vector< bool >::reference value) | |
Constructs a new Value with a boolean value. More... | |
~Value () | |
Destroys this Value. | |
Type | type () const |
Returns the storage type of the data stored in the Value. | |
bool | isValid () const |
Returns true if the storage type of this Value is not Type::INVALID. | |
bool | isBool () const |
Returns true if the storage type of this Value is equal to Type::BOOL. | |
bool | isChar () const |
Returns true if the storage type of this Value is equal to Type::CHAR. | |
bool | isDouble () const |
Returns true if the storage type of this Value is equal to Type::DOUBLE. | |
bool | isInt () const |
Returns true if the storage type of this Value is equal to Type::INT. | |
bool | isString () const |
Returns true if the storage type of this Value is equal to Type::STRING. | |
bool | toBool () const |
Returns the Value as a boolean. More... | |
char | toChar () const |
Returns the Value as a char. More... | |
double | toDouble () const |
Returns the Value as a double. More... | |
int | toInt () const |
Returns the Value as an int. More... | |
quint32 | toUInt () const |
Returns the Value as an unsigned integer. More... | |
const char * | toString () const |
Returns the Value as a string. More... | |
QString | toQString (char format='g', int precision=8) const |
Returns the Value as a QString. More... | |
Value & | operator= (const Value &v) |
Assigns the value v to this Value. | |
bool | operator== (const Value &v) const |
Checks if this Value is equal to v . | |
bool | operator!= (const Value &v) const |
Checks if this Value is different from v . | |
bool | operator< (const Value &v) const |
Checks if this Value is less than v . | |
bool | operator> (const Value &v) const |
Checks if this Value is greater than v . | |
bool | operator<= (const Value &v) const |
Checks if this Value is less or equal to v . | |
bool | operator>= (const Value &v) const |
Checks if this Value is greater or equal to v . | |
Friends | |
struct | std::hash< Value > |
A class for variant data types (tagged union).
This is a very important class in Evoplex, it defines a data type that can behave like an integer, double, char, bool or string in a very efficient way.
A Value object holds a single value of a single type() at a time. You can find out what type (T) the Value holds and get its value using one of the toT() functions (e.g., toInt()).
The functions named toT() (e.g., toInt(), toString()) are const. If you ask for the stored type, they return a copy of the stored object.
Here is some example code to demonstrate the use of Value:
evoplex::Value::Value | ( | std::vector< bool >::reference | value | ) |
Constructs a new Value with a boolean value.
This constructor is available just to accept the specialized vector<bool>. http://www.cplusplus.com/reference/vector/vector-bool
|
inline |
|
inline |
|
inline |
|
inline |
QString evoplex::Value::toQString | ( | char | format = 'g' , |
int | precision = 8 |
||
) | const |
Returns the Value as a QString.
It returns a QString for any data type(). For example:
|
inline |
|
inline |