TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
TurtleBrains::Core::DynamicStructure Class Reference

#include <tb_dynamic_structure.hpp>

Public Types

typedef std::vector< DynamicStructureArrayContainer
 
typedef std::map< tbCore::tbString, DynamicStructureStructureContainer
 

Public Member Functions

 DynamicStructure (void)
 
 DynamicStructure (const int &integerValue)
 
 DynamicStructure (const tbCore::int64 &integerValue)
 
 DynamicStructure (const size_t &intergerValue)
 
 DynamicStructure (const float &floatValue)
 
 DynamicStructure (const bool &booleanValue)
 
 DynamicStructure (const tbCore::tbString &stringValue)
 
 DynamicStructure (const char *stringValue)
 
template<typename Type >
 DynamicStructure (std::initializer_list< const Type > arguments)
 
 DynamicStructure (std::initializer_list< std::pair< const tbCore::tbString, const DynamicStructure >> arguments)
 
 DynamicStructure (const DynamicStructure &other)
 
 DynamicStructure (DynamicStructure &&other)
 
DynamicStructureoperator= (const DynamicStructure &other)
 
DynamicStructureoperator= (DynamicStructure &&other)
 
 ~DynamicStructure (void)
 
bool IsNil (void) const
 
bool IsArray (void) const
 
bool IsStructure (void) const
 
bool IsInteger (void) const
 
bool IsFloat (void) const
 
bool IsBoolean (void) const
 
bool IsString (void) const
 
tbCore::int64 AsInteger (bool implicitConversion=kImplicitConversions) const
 
template<typename Type >
Type AsRangedInteger (const tbCore::tbString &errorMessage="Out of Range", const Type minimumValue=std::numeric_limits< Type >::min(), const Type maximumValue=std::numeric_limits< Type >::max(), bool implicitConversion=kImplicitConversions) const
 
template<typename Type >
Type AsRangedIntegerWithDefault (const tbCore::tbString &errorMessage, const Type &defaultValue, const Type minimumValue=std::numeric_limits< Type >::min(), const Type maximumValue=std::numeric_limits< Type >::max(), bool implicitConversion=kImplicitConversions) const
 
float AsFloat (bool implicitConversion=kImplicitConversions) const
 
bool AsBoolean (bool implicitConversion=kImplicitConversions) const
 
tbCore::tbString AsString (bool implicitConversion=kImplicitConversions) const
 
tbCore::int64 AsIntegerWithDefault (const tbCore::int64 &defaultValue, bool implicitConversion=true) const
 
template<typename Type >
Type AsRangedIntegerWithDefault (const Type &defaultValue, const tbCore::tbString &errorMessage, const Type minimumValue=std::numeric_limits< Type >::min(), const Type maximumValue=std::numeric_limits< Type >::max()) const
 
float AsFloatWithDefault (const float defaultValue, bool implicitConversion=true) const
 
bool AsBooleanWithDefault (const bool defaultValue, bool implicitConversion=true) const
 
tbCore::tbString AsStringWithDefault (const tbCore::tbString &defaultValue, bool implicitConversion=true) const
 
void SetValue (const int &integerValue, bool implicitTypeChange=kImplicitTypeChange)
 
void SetValue (const tbCore::int64 &integerValue, bool implicitTypeChange=kImplicitTypeChange)
 
void SetValue (const float &floatValue, bool implicitTypeChange=kImplicitTypeChange)
 
void SetValue (const bool &booleanValue, bool implicitTypeChange=kImplicitTypeChange)
 
void SetValue (const tbCore::tbString &stringValue, bool implicitTypeChange=kImplicitTypeChange)
 
template<typename Type >
const DynamicStructureoperator[] (const Type &nameOrIndex) const
 
template<typename Type >
DynamicStructureoperator[] (const Type &nameOrIndex)
 
DynamicStructurePushValue (const DynamicStructure &value)
 
const DynamicStructureGetValue (const tbCore::uint64 &arrayIndex) const
 
DynamicStructureGetValue (const tbCore::uint64 &arrayIndex)
 
size_t ArraySize (void) const
 
size_t size (void) const
 
ArrayContainer::const_iterator BeginArray (void) const
 
ArrayContainer::iterator BeginArray (void)
 
ArrayContainer::const_iterator begin (void) const
 
ArrayContainer::iterator begin (void)
 
ArrayContainer::const_iterator EndArray (void) const
 
ArrayContainer::iterator EndArray (void)
 
ArrayContainer::const_iterator end (void) const
 
ArrayContainer::iterator end (void)
 
const ArrayContainerAsArray (void) const
 
ArrayContainerAsArray (void)
 
DynamicStructureAddMember (const tbCore::tbString &memberName, const DynamicStructure &memberValue)
 
DynamicStructureSetMember (const tbCore::tbString &memberName, const DynamicStructure &memberValue)
 
const DynamicStructureGetMember (const tbCore::tbString &memberName) const
 
DynamicStructureGetMember (const tbCore::tbString &memberName)
 
size_t StructureSize (void) const
 
StructureContainer::const_iterator BeginStructure (void) const
 
StructureContainer::iterator BeginStructure (void)
 
StructureContainer::const_iterator EndStructure (void) const
 
StructureContainer::iterator EndStructure (void)
 
const StructureContainerAsStructure (void) const
 
StructureContainerAsStructure (void)
 
 operator tbCore::int64 () const
 
 operator int () const
 
 operator float () const
 
 operator bool () const
 
 operator tbCore::tbString () const
 
bool operator== (const DynamicStructure &rightSide) const
 
bool operator!= (const DynamicStructure &rightSide) const
 

Static Public Attributes

static const DynamicStructure kNullValue
 
static const tbCore::tbString kNullAsString
 
static const tbCore::tbString kTrueAsString
 
static const tbCore::tbString kFalseAsString
 
static const unsigned int kInvalidSize
 
static const bool kImplicitConversions
 
static const bool kImplicitTypeChange
 
static const float kFloatElipson
 

Friends

void WriteBinary (const tbCore::DynamicStructure &data, std::ostream &output)
 
tbCore::DynamicStructure ReadBinary (std::istream &input)
 

Detailed Description

Provide a simple interface for creating structures that can be changed dynamically, for file loading, scripting and other exchanges of complex objects or structures in a semi defined manner.

Member Typedef Documentation

TODO: TIM: InternalDoc: This is a TurtleBrains implementation detail, and should be documented as such.

TODO: TIM: InternalDoc: This is a TurtleBrains implementation detail, and should be documented as such.

Constructor & Destructor Documentation

TurtleBrains::Core::DynamicStructure::DynamicStructure ( void  )

Creates an empty "Nil" structure with no values or data contained.

TurtleBrains::Core::DynamicStructure::DynamicStructure ( const int &  integerValue)

Creates a DynamicStructure object from an integer value that will represent the integer.

Note
implicit conversion is desired in this case so we can do: object.AddMember("gearCount", 5);
TurtleBrains::Core::DynamicStructure::DynamicStructure ( const float &  floatValue)

Creates a DynamicStructure object from a float value that will represent the float.

Note
implicit conversion is desired in this case so we can do: object.AddMember("gearRatio", 2.13f);
TurtleBrains::Core::DynamicStructure::DynamicStructure ( const bool &  booleanValue)

Creates a DynamicStructure object from a boolean value that will represent the boolean.

Note
implicit conversion is desired in this case so we can do: object.AddMember("hasReverse", false);
TurtleBrains::Core::DynamicStructure::DynamicStructure ( const tbCore::tbString stringValue)

Creates a DynamicStructure object from a string value that will contain and represent the string.

Note
implicit conversion is desired in this case so we can do: object.AddMember("modelName", stringValue);
TurtleBrains::Core::DynamicStructure::DynamicStructure ( const char *  stringValue)

Creates a DynamicStructure object from a string value that will contain and represent the string.

Note
implicit conversion is desired in this case so we can do: object.AddMember("modelName", "MX5");
template<typename Type >
TurtleBrains::Core::DynamicStructure::DynamicStructure ( std::initializer_list< const Type >  arguments)
inline

Creates a DynamicStructure array from a list of values so that initialization from within code can look/act very close to the json it resembles:

tbCore::DynamicStructure object = { { "names", { "TimBeaudet", "shakesoda", "tsjost" } }, { "numbers", { 42, 8, 35, 10 } }, };

Parameters
argumentsThe initializer list to initialize the array from.
TurtleBrains::Core::DynamicStructure::DynamicStructure ( std::initializer_list< std::pair< const tbCore::tbString, const DynamicStructure >>  arguments)

Creates a DynamicStructure object from key-value pairs so that initialization from within code can look/act very close to the json it resembles:

tbCore::DynamicStructure object = { { "name", "TimBeaudet" }, { "fortyTwo", 42 }, { "pi", 3.14159f }, { "valid", true, } };

Parameters
argumentsThe initializer list to initialize the object from.
TurtleBrains::Core::DynamicStructure::DynamicStructure ( const DynamicStructure other)

Creates a DynamicStruction object from an existing object. Because the objects can be quite large and complex, this could potentially use a fair bit of memory or copy overhead.

TurtleBrains::Core::DynamicStructure::~DynamicStructure ( void  )

Cleans up after the DynamicStructure which for simple objects does not require any cleanup but for strings, arrays or structure objects can involve deleting any memory allocated during the lifespan of the structure, and any child structure as well.

Member Function Documentation

DynamicStructure& TurtleBrains::Core::DynamicStructure::AddMember ( const tbCore::tbString memberName,
const DynamicStructure memberValue 
)

Attempts to add a member with name and value to an object with type Structure or Nil. Any other types will cause an error condition to be triggered. If the type is Nil, the type will become Structure and the first member will be added. If a value already exists for the member an error condition will be triggered. A reference to the added value object will then be returned.

Parameters
memberNameThe name of the member to be able to retrieve the value later. If a value with the memberName has already been added to the Structure an error condition will be triggered.
memberValueThe value of the member which will be retrieved by it's name.
size_t TurtleBrains::Core::DynamicStructure::ArraySize ( void  ) const

Returns the number of values contained within an array type structure. If the type is NOT an array-type then 0 will be returned so a loop could be used on an Array type without checking that the array object was valid.

Note
To count the number of values in a structure, use StructureSize().
const ArrayContainer& TurtleBrains::Core::DynamicStructure::AsArray ( void  ) const

Returns the underlying structure type for the array object. This should only be used to iterate over the items in an array object.

for (const DynamicStructure& object : myArrayObject.AsArray() { ... }

Note
This is experimental, and may actually get removed in future versions of the API, but as long as it was used only for iteration, there is always BeginArray() / EndArray() to solve that requirement.
ArrayContainer& TurtleBrains::Core::DynamicStructure::AsArray ( void  )

Returns the underlying structure type for the array object. This should only be used to iterate over the items in an array object.

for (const DynamicStructure& object : myArrayObject.AsArray() { ... }

Note
This is experimental, and may actually get removed in future versions of the API, but as long as it was used only for iteration, there is always BeginArray() / EndArray() to solve that requirement.
bool TurtleBrains::Core::DynamicStructure::AsBoolean ( bool  implicitConversion = kImplicitConversions) const

Gets the value of the object as a bool using implicit conversions if allowed, otherwise an error condition will be triggered if the Type is not a bool and implicitConversion is false.

Parameters
implicitConversionSet to true to allow other basic types (Integer, Float, String, Nil) to convert to an integer value automatically. If false, no conversion will be attempted and an error condition will be triggered.
bool TurtleBrains::Core::DynamicStructure::AsBooleanWithDefault ( const bool  defaultValue,
bool  implicitConversion = true 
) const

First checks to make sure the type of the object is a boolean, then returns the value as a boolean without any conversions*. If the type is not a boolean the defaultValue will be returned.

Parameters
defaultValueThe boolean value to return if the type is not specifically a boolean, even if the type could be implicitly converted.
implicitConversionSet to true to allow other basic types (Bool, Integer, Float) to convert to an integer value automatically, although a Nil value will return default. If false, no conversion will be attempted and the defaultValue will be returned.
Note
Current implementation does not allow any implicit conversions, but in the future this may change and it may become the default behavior of the WithDefault functions.
float TurtleBrains::Core::DynamicStructure::AsFloat ( bool  implicitConversion = kImplicitConversions) const

Gets the value of the object as a float using implicit conversions if allowed, otherwise an error condition will be triggered if the Type is not a float and implicitConversion is false.

Parameters
implicitConversionSet to true to allow other basic types (Bool, Integer, String, Nil) to convert to an integer value automatically. If false, no conversion will be attempted and an error condition will be triggered.
float TurtleBrains::Core::DynamicStructure::AsFloatWithDefault ( const float  defaultValue,
bool  implicitConversion = true 
) const

First checks to make sure the type of the object is a float, then returns the value as a float without any conversions*. If the type is not a float the defaultValue will be returned.

Parameters
defaultValueThe float value to return if the type is not specifically a float, even if the type could be implicitly converted.
implicitConversionSet to true to allow other basic types (Bool, Integer, Float) to convert to an integer value automatically, although a Nil value will return default. If false, no conversion will be attempted and the defaultValue will be returned.
Note
Current implementation does not allow any implicit conversions, but in the future this may change and it may become the default behavior of the WithDefault functions.
tbCore::int64 TurtleBrains::Core::DynamicStructure::AsInteger ( bool  implicitConversion = kImplicitConversions) const

Gets the value of the object as an integer using implicit conversions if allowed, otherwise an error condition will be triggered if the Type is not an integer and implicitConversion is false.

Parameters
implicitConversionSet to true to allow other basic types (Bool, Float, String, Nil) to convert to an integer value automatically. If false, no conversion will be attempted and an error condition will be triggered.
tbCore::int64 TurtleBrains::Core::DynamicStructure::AsIntegerWithDefault ( const tbCore::int64 defaultValue,
bool  implicitConversion = true 
) const

First checks to make sure the type of the object is an integer, then returns the value as an integer without any conversions*. If the type is not an integer the defaultValue will be returned.

Parameters
defaultValueThe integer value to return if the type is not specifically an integer, even if the type could be implicitly converted.
implicitConversionSet to true to allow other basic types (Bool, Integer, Float) to convert to an integer value automatically, although a Nil value will return default. If false, no conversion will be attempted and the defaultValue will be returned.
Note
Current implementation does not allow any implicit conversions, but in the future this may change and it may become the default behavior of the WithDefault functions.
template<typename Type >
Type TurtleBrains::Core::DynamicStructure::AsRangedInteger ( const tbCore::tbString errorMessage = "Out of Range",
const Type  minimumValue = std::numeric_limits<Type>::min(),
const Type  maximumValue = std::numeric_limits<Type>::max(),
bool  implicitConversion = kImplicitConversions 
) const
inline

First grabs the integer value by calling AsInteger, (using implicit conversion if allowed) then checks the range with minimum and maximum value parameters that default to min/max of the type, throwing the errorMessage if it fails to match range.

Parameters
errorMessageThe message to display if the values range is less than min or greater than max. An additional string will be added to the end showing the expected range.
minimumValueThis is the inclusive minimum value of the range. Passes when value is >= minimum. This will default to the minimum value supported by the Type as given by std::numeric_limits.
maximumValueThis is the inclusive maximum value of the range. Passes when value is <= maximum. This will default to the maximum value supported by the Type as given by std::numeric_limits.
implicitConversionSet to true to allow other basic types (Bool, Float, String, Nil) to convert to an integer value automatically. If false, no conversion will be attempted and an error condition will be triggered.
Note
This will throw an error with errorMessage if the value is not within the range. minimum <= value <= maximum
template<typename Type >
Type TurtleBrains::Core::DynamicStructure::AsRangedIntegerWithDefault ( const Type &  defaultValue,
const tbCore::tbString errorMessage,
const Type  minimumValue = std::numeric_limits<Type>::min(),
const Type  maximumValue = std::numeric_limits<Type>::max() 
) const
inline

First grabs the integer value by calling AsIntegerWithDefault, (ensuring the object is an integer) then checks the range with minimum and maximum value parameters that default to min/max of the type, throwing the errorMessage if it fails to match range.

Parameters
defaultValueThe integer value to return if the type is not specifically an integer, even if the type could be implicitly converted.
errorMessageThe message to display if the values range is less than min or greater than max. An additional string will be added to the end showing the expected range.
minimumValueThis is the inclusive minimum value of the range. Passes when value is >= minimum. This will default to the minimum value supported by the Type as given by std::numeric_limits.
maximumValueThis is the inclusive maximum value of the range. Passes when value is <= maximum. This will default to the maximum value supported by the Type as given by std::numeric_limits.
Note
This will throw an error with errorMessage if the value is not within the range. minimum <= value <= maximum
tbCore::tbString TurtleBrains::Core::DynamicStructure::AsString ( bool  implicitConversion = kImplicitConversions) const

Gets the value of the object as a string using implicit conversions if allowed, otherwise an error condition will be triggered if the Type is not a string and implicitConversion is false.

Parameters
implicitConversionSet to true to allow other basic types (Bool, Integer, Float, Nil) to convert to an integer value automatically. If false, no conversion will be attempted and an error condition will be triggered.
tbCore::tbString TurtleBrains::Core::DynamicStructure::AsStringWithDefault ( const tbCore::tbString defaultValue,
bool  implicitConversion = true 
) const

First checks to make sure the type of the object is a string, then returns the value as a string without any conversions*. If the type is not a string the defaultValue will be returned.

Parameters
defaultValueThe string value to return if the type is not specifically a string, even if the type could be implicitly converted.
implicitConversionSet to true to allow other basic types (Bool, Integer, Float) to convert to an integer value automatically, although a Nil value will return default. If false, no conversion will be attempted and the defaultValue will be returned.
Note
Current implementation does not allow any implicit conversions, but in the future this may change and it may become the default behavior of the WithDefault functions.
const StructureContainer& TurtleBrains::Core::DynamicStructure::AsStructure ( void  ) const

Returns the underlying structure type for the structure object. This should only be used to iterate over the items in a structure object, for saving or exporting etc.

for (const DynamicStructure& keyValue : myStructureObject.AsStructure() { const tbCore::tbString& keyName = keyValue.first; const tbCore::DynamicStructure& value = keyValue.second; ... }

Note
This is experimental, and may actually get removed in future versions of the API, but as long as it was used only for iteration, there is always BeginArray() / EndArray() to solve that requirement.
If the object is NOT a structure, the reference to an empty structure container is returned.
StructureContainer& TurtleBrains::Core::DynamicStructure::AsStructure ( void  )

Returns the underlying structure type for the structure object. This should only be used to iterate over the items in a structure object, for saving or exporting etc.

for (const DynamicStructure& keyValue : myStructureObject.AsStructure() { const tbCore::tbString& keyName = keyValue.first; const tbCore::DynamicStructure& value = keyValue.second; ... }

Note
This is experimental, and may actually get removed in future versions of the API, but as long as it was used only for iteration, there is always BeginArray() / EndArray() to solve that requirement.
If the object is NOT a structure, the reference to an empty structure container is returned.
ArrayContainer::const_iterator TurtleBrains::Core::DynamicStructure::begin ( void  ) const

Returns an array iterator at the start of the container. To be used to iterate over each member in the array.

Note
This will trigger an error condition if the dynamic structure is not an Array.
ArrayContainer::iterator TurtleBrains::Core::DynamicStructure::begin ( void  )

Returns an array iterator at the start of the container. To be used to iterate over each member in the array.

Note
This will trigger an error condition if the dynamic structure is not an Array.
ArrayContainer::const_iterator TurtleBrains::Core::DynamicStructure::BeginArray ( void  ) const

Returns an array iterator at the start of the container. To be used to iterate over each member in the array.

Note
This will trigger an error condition if the dynamic structure is not an Array.
ArrayContainer::iterator TurtleBrains::Core::DynamicStructure::BeginArray ( void  )

Returns an array iterator at the start of the container. To be used to iterate over each member in the array.

Note
This will trigger an error condition if the dynamic structure is not an Array.
StructureContainer::const_iterator TurtleBrains::Core::DynamicStructure::BeginStructure ( void  ) const

Returns a structure iterator at the start of the container for a Structure value. To be used to iterate over each member in the structure, typically for saving/exporting the dynamic structure.

StructureContainer::iterator TurtleBrains::Core::DynamicStructure::BeginStructure ( void  )

Returns a structure iterator at the start of the container for a Structure value. To be used to iterate over each member in the structure, typically for saving/exporting the dynamic structure.

ArrayContainer::const_iterator TurtleBrains::Core::DynamicStructure::end ( void  ) const

Returns an array iterator at the end of the container. To be used to iterate over each member in the array.

Note
This will trigger an error condition if the dynamic structure is not an Array.
ArrayContainer::iterator TurtleBrains::Core::DynamicStructure::end ( void  )

Returns an array iterator at the end of the container. To be used to iterate over each member in the array.

Note
This will trigger an error condition if the dynamic structure is not an Array.
ArrayContainer::const_iterator TurtleBrains::Core::DynamicStructure::EndArray ( void  ) const

Returns an array iterator at the end of the container. To be used to iterate over each member in the array.

Note
This will trigger an error condition if the dynamic structure is not an Array.
ArrayContainer::iterator TurtleBrains::Core::DynamicStructure::EndArray ( void  )

Returns an array iterator at the end of the container. To be used to iterate over each member in the array.

Note
This will trigger an error condition if the dynamic structure is not an Array.
StructureContainer::const_iterator TurtleBrains::Core::DynamicStructure::EndStructure ( void  ) const

Returns a structure iterator representing the end of the container for a Structure value. To be used to iterate over each member in the structure.

StructureContainer::iterator TurtleBrains::Core::DynamicStructure::EndStructure ( void  )

Returns a structure iterator representing the end of the container for a Structure value. To be used to iterate over each member in the structure.

const DynamicStructure& TurtleBrains::Core::DynamicStructure::GetMember ( const tbCore::tbString memberName) const

Attempts to retrieve a DynamicStructure object for the memberName given, if this object is of type Nil then a Nil object will be returned,* but if this object is a Structure the member will be searched for and returned if found otherwise if not found a Nil object will be returned.*

Parameters
memberNameThe name of the member as it was added during AddMember.
Note
The Nil object and unfound member issues may cause an error condition to trigger in the future.
DynamicStructure& TurtleBrains::Core::DynamicStructure::GetMember ( const tbCore::tbString memberName)

Attempts to retrieve a DynamicStructure object for the memberName given, if this object is of type Nil then a Nil object will be returned,* but if this object is a Structure the member will be searched for and returned if found otherwise if not found a Nil object will be returned.*

Parameters
memberNameThe name of the member as it was added during AddMember.
Note
The Nil object and unfound member issues may cause an error condition to trigger in the future.
const DynamicStructure& TurtleBrains::Core::DynamicStructure::GetValue ( const tbCore::uint64 arrayIndex) const

Returns a const reference to the value in the array at the specified index. If this object is not an Array type an error condition will be triggered.

Parameters
arrayIndexis the index of the desired element. Must be within the range: 0 <= arrayIndex <= size() or an error condition will be triggered for going out of range.
Note
This can only be called on DynamicStructures with the Array type, any other type, including Nil will cause an error condition to be triggered.
DynamicStructure& TurtleBrains::Core::DynamicStructure::GetValue ( const tbCore::uint64 arrayIndex)

Returns a reference to the value in the array at the specified index. If this object is not an Array type an error condition will be triggered.

Parameters
arrayIndexis the index of the desired element. Must be within the range: 0 <= arrayIndex <= size() or an error condition will be triggered for going out of range.
Note
This can only be called on DynamicStructures with the Array type, any other type, including Nil will cause an error condition to be triggered.
bool TurtleBrains::Core::DynamicStructure::IsArray ( void  ) const

Checks to see if the object is holding an array returning true if it is, otherwise false.

bool TurtleBrains::Core::DynamicStructure::IsBoolean ( void  ) const

Checks to see if the object is holding an boolean type returning true if it is.

bool TurtleBrains::Core::DynamicStructure::IsFloat ( void  ) const

Checks to see if the object is holding an float type returning true if it is.

bool TurtleBrains::Core::DynamicStructure::IsInteger ( void  ) const

Checks to see if the object is holding an integer type returning true if it is.

bool TurtleBrains::Core::DynamicStructure::IsNil ( void  ) const

Checks to see if the dynamic structure is a Nil object, representing no data, empty/clean, and returns the result, true if the object is Nil otherwise false.

Note
This may be renamed to IsNull().
bool TurtleBrains::Core::DynamicStructure::IsString ( void  ) const

Checks to see if the object is holding an string type returning true if it is.

bool TurtleBrains::Core::DynamicStructure::IsStructure ( void  ) const

Checks to see if the object is a structure type which could hold multiple other objects within returning true if it is a structure type, otherwise false.

TurtleBrains::Core::DynamicStructure::operator bool ( ) const
inlineexplicit

This operator will cast a DynamicStructure object into a bool with implicit conversion allowed.

TurtleBrains::Core::DynamicStructure::operator float ( ) const
inlineexplicit

This operator will cast a DynamicStructure object into a float with implicit conversion allowed.

TurtleBrains::Core::DynamicStructure::operator tbCore::int64 ( ) const
inlineexplicit

This operator will cast a DynamicStructure object into an integer with implicit conversion allowed.

TurtleBrains::Core::DynamicStructure::operator tbCore::tbString ( ) const
inlineexplicit

This operator will cast a DynamicStructure object into a string with implicit conversion allowed.

bool TurtleBrains::Core::DynamicStructure::operator!= ( const DynamicStructure rightSide) const

Checks two DynamicStructures for non-equality. This can only check the basic types (Nil, Integer, Float, Boolean and String) for equality with another of the same type. Checking for inequality with an Array or Structure type will result in an error condition being triggered.

Note
Checking for inequality of an Array or Structure type will trigger an error condition.
DynamicStructure& TurtleBrains::Core::DynamicStructure::operator= ( const DynamicStructure other)

Cleans up the current object then assigns itself to an existing object. Because the objects can be quite large and complex, this could potentially use a fair bit of memory or copy overhead.

bool TurtleBrains::Core::DynamicStructure::operator== ( const DynamicStructure rightSide) const

Checks two DynamicStructures for equality. This can only check the basic types (Nil, Integer, Float, Boolean and String) for equality with another of the same type. Checking for equality with an Array or Structure type will result in an error condition being triggered.

Note
Checking for equality of an Array or Structure type will trigger an error condition.
DynamicStructure& TurtleBrains::Core::DynamicStructure::PushValue ( const DynamicStructure value)

Attempts to push the value onto the back of a standard vector if this object is either a Nil type or an Array type. If the type is not Nil or an Array an error condition will be triggered.

Parameters
valueThe value to push into the array of values, it can be of any type.
Note
This can only be called on DynamicStructures with the Nil type or Array type, any other type will cause an error condition to be triggered.
DynamicStructure& TurtleBrains::Core::DynamicStructure::SetMember ( const tbCore::tbString memberName,
const DynamicStructure memberValue 
)

Sets the value of an existing structure member, or adds the member if it did not exists, to an object with type Structure or Nil. Any other types will cause an error condition to be triggered. If the type is Nil, the object/type will become a Structure and the member will be added. If a value already exists for the member, it will be set to the new value. A reference to the object will then be returned.

Parameters
memberNameThe name of the member to be able to retrieve the value later. If a value with the memberName has already been added to the Structure an error condition will be triggered.
memberValueThe value of the member which will be retrieved by it's name.
void TurtleBrains::Core::DynamicStructure::SetValue ( const int &  integerValue,
bool  implicitTypeChange = kImplicitTypeChange 
)

Attempts to change the value of the object to the value specified, if the object Type is an integer, Nil or implicityTypeChange is allowed this will succeed, otherwise an error condition will be triggered. The object type will become an integer type during this process.

Parameters
integerValueThe value for the object to hold as an integer type.
implicitTypeChangeSet to true the value and type will always be set properly, however if false, and the object is not already an integer or Nil type this will cause an error condition to trigger.
void TurtleBrains::Core::DynamicStructure::SetValue ( const float &  floatValue,
bool  implicitTypeChange = kImplicitTypeChange 
)

Attempts to change the value of the object to the value specified, if the object Type is a float, Nil or implicityTypeChange is allowed this will succeed, otherwise an error condition will be triggered. The object type will become a float type during this process.

Parameters
floatValueThe value for the object to hold as a float type.
implicitTypeChangeSet to true the value and type will always be set properly, however if false, and the object is not already a float or Nil type this will cause an error condition to trigger.
void TurtleBrains::Core::DynamicStructure::SetValue ( const bool &  booleanValue,
bool  implicitTypeChange = kImplicitTypeChange 
)

Attempts to change the value of the object to the value specified, if the object Type is a boolean, Nil or implicityTypeChange is allowed this will succeed, otherwise an error condition will be triggered. The object type will become a float type during this process.

Parameters
booleanValueThe value for the object to hold as a boolean type.
implicitTypeChangeSet to true the value and type will always be set properly, however if false, and the object is not already a boolean or Nil type this will cause an error condition to trigger.
void TurtleBrains::Core::DynamicStructure::SetValue ( const tbCore::tbString stringValue,
bool  implicitTypeChange = kImplicitTypeChange 
)

Attempts to change the value of the object to the value specified, if the object Type is a string, Nil or implicityTypeChange is allowed this will succeed, otherwise an error condition will be triggered. The object type will become a string type during this process.

Parameters
stringValueThe value for the object to hold as a string type.
implicitTypeChangeSet to true the value and type will always be set properly, however if false, and the object is not already a string or Nil type this will cause an error condition to trigger.
size_t TurtleBrains::Core::DynamicStructure::size ( void  ) const

Returns the number of values contained with an array type structure or the number of values within an object like structure. Returns 0 for any other type.

size_t TurtleBrains::Core::DynamicStructure::StructureSize ( void  ) const

Returns the number of values contained within an structure type structure. If the type is NOT an structure-type then 0 will be returned without triggering an error condition.

Friends And Related Function Documentation

void WriteBinary ( const tbCore::DynamicStructure data,
std::ostream &  output 
)
friend

TODO: TurtleBrains: Documentation: Teach the user how to use.

Member Data Documentation

const tbCore::tbString TurtleBrains::Core::DynamicStructure::kFalseAsString
static

The value returned when a false boolean is converted to a string.

const float TurtleBrains::Core::DynamicStructure::kFloatElipson
static

Consider two floating point values equal if the difference is less than epsilon.

const bool TurtleBrains::Core::DynamicStructure::kImplicitConversions
static

Changes the behavior of the DynamicStructure's AsType functions.

const bool TurtleBrains::Core::DynamicStructure::kImplicitTypeChange
static

Allows the DynamicStructure to change type on the fly.

const unsigned int TurtleBrains::Core::DynamicStructure::kInvalidSize
static

The value returned when size() is called with an invalid type, likely to be 0.

const tbCore::tbString TurtleBrains::Core::DynamicStructure::kNullAsString
static

The value returned when a null structure is converted to a string.

const DynamicStructure TurtleBrains::Core::DynamicStructure::kNullValue
static

The value returned to represent a const-reference to null.

const tbCore::tbString TurtleBrains::Core::DynamicStructure::kTrueAsString
static

The value returned when a true boolean is converted to a string.