27 using Values = std::vector<Value>;
58 friend struct std::hash<
Value>;
64 enum Type { BOOL, CHAR, DOUBLE, INT, STRING, INVALID };
101 Value(
const char* value);
106 Value(
const QString& value);
113 Value(std::vector<bool>::reference value);
135 inline bool isBool()
const;
141 inline bool isChar()
const;
153 inline bool isInt()
const;
167 inline bool toBool()
const;
175 inline char toChar()
const;
191 inline int toInt()
const;
199 inline quint32
toUInt()
const;
207 inline const char*
toString()
const;
222 QString
toQString(
char format =
'g',
int precision = 8)
const;
260 union {
bool b;
char c;
double d;
int i;
const char* s; } m_data;
263 std::logic_error throwError()
const;
274 {
return m_type != INVALID; }
277 {
return m_type == BOOL; }
280 {
return m_type == CHAR; }
283 {
return m_type == DOUBLE; }
286 {
return m_type == INT; }
289 {
return m_type == STRING; }
292 {
if (m_type == BOOL) {
return m_data.b; }
throw throwError(); }
295 {
if (m_type == CHAR) {
return m_data.c; }
throw throwError(); }
298 {
if (m_type == DOUBLE) {
return m_data.d; }
throw throwError(); }
301 {
if (m_type == INT) {
return m_data.i; }
throw throwError(); }
304 {
if (m_type == STRING) {
return m_data.s; }
throw throwError(); }
307 if (m_type == INT && m_data.i >= 0) {
return static_cast<quint32
>(m_data.i); }
323 size_t operator()(
const char *s)
const {
327 h = ((h << 5) + h) + c;
341 case evoplex::Value::INT:
return std::hash<int>()(v.m_data.i);
342 case evoplex::Value::DOUBLE:
return std::hash<double>()(v.m_data.d);
343 case evoplex::Value::BOOL:
return std::hash<bool>()(v.m_data.b);
344 case evoplex::Value::CHAR:
return std::hash<char>()(v.m_data.c);
346 default:
throw std::invalid_argument(
"invalid type of Value");
A class for variant data types (tagged union).
Definition: value.h:56
bool isString() const
Returns true if the storage type of this Value is equal to Type::STRING.
Definition: value.h:288
bool isChar() const
Returns true if the storage type of this Value is equal to Type::CHAR.
Definition: value.h:279
Type
This enum defines the types of variable that a Value can contain.
Definition: value.h:64
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 equal to 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.
QString toQString(char format='g', int precision=8) const
Returns the Value as a QString.
const char * toString() const
Returns the Value as a string.
Definition: value.h:303
Type type() const
Returns the storage type of the data stored in the Value.
Definition: value.h:270
bool isInt() const
Returns true if the storage type of this Value is equal to Type::INT.
Definition: value.h:285
bool isDouble() const
Returns true if the storage type of this Value is equal to Type::DOUBLE.
Definition: value.h:282
bool toBool() const
Returns the Value as a boolean.
Definition: value.h:291
Value & operator=(const Value &v)
Assigns the value v to this Value.
bool isBool() const
Returns true if the storage type of this Value is equal to Type::BOOL.
Definition: value.h:276
bool isValid() const
Returns true if the storage type of this Value is not Type::INVALID.
Definition: value.h:273
~Value()
Destroys this Value.
Value()
Constructs an invalid Value.
bool operator<=(const Value &v) const
Checks if this Value is less or equal to v.
double toDouble() const
Returns the Value as a double.
Definition: value.h:297
Definition: abstractgraph.h:29
int toInt() const
Returns the Value as an int.
Definition: value.h:300
bool operator>=(const Value &v) const
Checks if this Value is greater or equal to v.
char toChar() const
Returns the Value as a char.
Definition: value.h:294
quint32 toUInt() const
Returns the Value as an unsigned integer.
Definition: value.h:306
A hash function for char*.
Definition: value.h:321