Hasty Badger
Small UI library (a branch of Turbo Badger)
|
TBValue holds value of a specific type. More...
#include <tb_value.h>
Public Types | |
enum | TYPE { TYPE_NULL, TYPE_STRING, TYPE_FLOAT, TYPE_INT, TYPE_OBJECT, TYPE_ARRAY } |
The current type of the value. More... | |
enum | SET_MODE { SET_NEW_COPY, SET_TAKE_OWNERSHIP, SET_AS_STATIC } |
How to deal with the dynamic memory when setting string and array. More... | |
Public Member Functions | |
TBValue (TBValue &&val)=default | |
TBValue (const TBValue &value) | |
TBValue (TYPE type) | |
TBValue (int value) | |
TBValue (long value) | |
TBValue (double value) | |
TBValue (const char *value, SET_MODE set=SET_NEW_COPY) | |
TBValue (const TBStr &str) | |
TBValue (TBStr &&str) | |
TBValue (TBTypedObject *object, SET_MODE set=SET_TAKE_OWNERSHIP) | |
void | TakeOver (TBValue &source_value) |
Take over ownership of content of source_value. More... | |
void | Copy (const TBValue &source_value) |
Copy the content of source_value to this value. More... | |
void | SetNull () |
void | SetInt (long val) |
void | SetFloat (double val) |
void | SetString (const char *val, SET_MODE set) |
Set the passed in string. | |
void | SetString (const TBStr &str) |
Set the passed in string. | |
void | SetObject (TBTypedObject *object, SET_MODE set) |
Set the passed in object. More... | |
void | SetArray (TBValueArray *arr, SET_MODE set) |
Set the passed in array. | |
void | SetFromStringAuto (const char *str, SET_MODE set) |
Set the value either as a string, number or array of numbers, depending of the string syntax. More... | |
long | GetInt () const |
double | GetFloat () const |
TBStr | GetString () const |
TBTypedObject * | GetObject () const |
TBValueArray * | GetArray () const |
bool | Equals (int value) const |
bool | Equals (long value) const |
bool | Equals (double value) const |
bool | Equals (const char *value) const |
bool | Equals (const TBStr &value) const |
bool | Equals (const TBValue &value) const |
TYPE | GetType () const |
bool | IsString () const |
bool | IsFloat () const |
bool | IsInt () const |
bool | IsObject () const |
bool | IsArray () const |
int | GetArrayLength () const |
const TBValue & | operator= (const TBValue &val) |
TBValue & | operator= (TBValue &&val)=default |
TBValue holds value of a specific type.
In addition to NULL, string, float, integer, it may also contain an array of attributes (TBValueArray), or an object (derived from TBTypedObject).
When getting the value as a different type from what it is, it may convert its internal representation to that type. Exceptions are for array and object, which will return 0 when getting as numbers, or "" or object name when getting as string.
enum tb::TBValue::TYPE |
The current type of the value.
It may change when using a getter of a different type.
void tb::TBValue::Copy | ( | const TBValue & | source_value | ) |
Copy the content of source_value to this value.
Note: This value will become TYPE_NULL if source_value holds an owned object. We can't copy objects.
void tb::TBValue::SetFromStringAuto | ( | const char * | str, |
SET_MODE | set | ||
) |
Set the value either as a string, number or array of numbers, depending of the string syntax.
void tb::TBValue::SetObject | ( | TBTypedObject * | object, |
SET_MODE | set | ||
) |
Set the passed in object.
void tb::TBValue::TakeOver | ( | TBValue & | source_value | ) |
Take over ownership of content of source_value.
Note: -If source_value has string or array that are set with SET_AS_STATIC, it will make new copies of those. -value will be nulled on source_value after this call.