46 int GetLength()
const {
return m_list.GetNumItems(); }
87 TBValue(
double value);
89 TBValue(
const TBStr & str) : TBValue((const char *)str) {}
90 TBValue(TBStr && str);
98 void TakeOver(TBValue &source_value);
102 void Copy(
const TBValue &source_value);
105 void SetInt(
long val);
106 void SetFloat(
double val);
124 double GetFloat()
const;
125 TBStr GetString()
const;
126 TBTypedObject *GetObject()
const {
return IsObject() ? val_obj :
nullptr; }
127 TBValueArray *GetArray()
const {
return IsArray() ? val_arr :
nullptr; }
129 bool Equals(
int value)
const {
return Equals((
long)value); }
130 bool Equals(
long value)
const;
131 bool Equals(
double value)
const;
132 bool Equals(
const char * value)
const;
133 bool Equals(
const TBStr & value)
const {
return Equals(value.CStr()); }
134 bool Equals(
const TBValue & value)
const;
136 TYPE GetType()
const {
return (
TYPE) m_packed.type; }
137 bool IsString()
const {
return m_packed.type == TYPE_STRING; }
138 bool IsFloat()
const {
return m_packed.type == TYPE_FLOAT; }
139 bool IsInt()
const {
return m_packed.type == TYPE_INT; }
140 bool IsObject()
const {
return m_packed.type == TYPE_OBJECT; }
141 bool IsArray()
const {
return m_packed.type == TYPE_ARRAY; }
142 int GetArrayLength()
const {
return IsArray() ? val_arr->GetLength() : 0; }
144 const TBValue& operator = (
const TBValue &val) {
Copy(val);
return *
this; }
145 TBValue & operator = (TBValue && val) =
default;
157 TBTypedObject *val_obj;
158 TBValueArray *val_arr;
163 uint32_t allocated : 1;
165 uint32_t m_packed_init;
bool is_number_only(const char *s)
Return true if the string can be represented as a number.
Definition: tb_value.cpp:52
void SetObject(TBTypedObject *object, SET_MODE set)
Set the passed in object.
Definition: tb_value.cpp:267
TYPE
The current type of the value.
Definition: tb_value.h:64
void SetArray(TBValueArray *arr, SET_MODE set)
Set the passed in array.
Definition: tb_value.cpp:278
SET_MODE
How to deal with the dynamic memory when setting string and array.
Definition: tb_value.h:74
void TakeOver(TBValue &source_value)
Take over ownership of content of source_value.
Definition: tb_value.cpp:194
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...
Definition: tb_value.cpp:291
void SetString(const char *val, SET_MODE set)
Set the passed in string.
Definition: tb_value.cpp:254
The data passed in will be stored and freed.
Definition: tb_value.h:76
TBValueArray is an array of TBValue.
Definition: tb_value.h:37
bool is_start_of_number(const char *str)
Return true if the given string starts with a number.
Definition: tb_value.cpp:32
bool contains_non_trailing_space(const char *str)
Returns true if the given string contains space that is not at the end of the string.
Definition: tb_value.cpp:41
A new copy of the data will be made.
Definition: tb_value.h:75
TBListAutoDeleteOf is a list (array) of pointers to the specified object type.
Definition: tb_list.h:118
Definition: tb_object.h:21
TBStr is a simple string class.
Definition: tb_str.h:62
TBValue holds value of a specific type.
Definition: tb_value.h:59
bool is_number_float(const char *str)
Return true if the given number string is a float number.
Definition: tb_value.cpp:63
char * CStr() const
Get the c-string raw (char *)
Definition: tb_str.h:93
void Copy(const TBValue &source_value)
Copy the content of source_value to this value.
Definition: tb_value.cpp:205
void SetString(const TBStr &str)
Set the passed in string.
Definition: tb_value.h:112
The data passed in will be stored but never freed.
Definition: tb_value.h:77