Hasty Badger
Small UI library (a branch of Turbo Badger)
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends Groups Pages
tb::TBValue Class Reference

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
 
TBTypedObjectGetObject () const
 
TBValueArrayGetArray () 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 TBValueoperator= (const TBValue &val)
 
TBValueoperator= (TBValue &&val)=default
 

Detailed Description

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.

Member Enumeration Documentation

How to deal with the dynamic memory when setting string and array.

Enumerator
SET_NEW_COPY 

A new copy of the data will be made.

SET_TAKE_OWNERSHIP 

The data passed in will be stored and freed.

SET_AS_STATIC 

The data passed in will be stored but never freed.

The current type of the value.

It may change when using a getter of a different type.

Member Function Documentation

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.


The documentation for this class was generated from the following files: