9 #ifndef _TurtleBrains_DynamicStructure_h_
10 #define _TurtleBrains_DynamicStructure_h_
12 #include "tb_string.h"
26 #define tb_min_was_defined
30 #define tb_max_was_defined
34 template <
typename Type> Type MinimumValue(
void)
36 return std::numeric_limits<Type>::min();
38 template <
typename Type> Type MaximumValue(
void)
40 return std::numeric_limits<Type>::max();
43 #if defined(tb_min_was_defined)
44 #define min(a,b) ((a) < (b)) ? (a) : (b)
46 #if defined(tb_max_was_defined)
47 #define max(a, b) ((a) < (b)) ? (b) : (a)
125 bool IsNil(
void)
const;
190 const Type minimumValue = MinimumValue<Type>(),
const Type maximumValue = MaximumValue<Type>(),
194 tb_error_if(intValue < static_cast<tbCore::int64>(minimumValue) || intValue > static_cast<tbCore::int64>(maximumValue),
195 "%s (Expected: %d <= _value(%d)_ <= %d", errorMessage.c_str(), minimumValue, intValue, maximumValue);
196 return static_cast<Type
>(intValue);
266 const Type minimumValue = MinimumValue<Type>(),
const Type maximumValue = MaximumValue<Type>())
const
269 tb_error_if(intValue < minimumValue || intValue > maximumValue,
"%s (Expected: %d <= _value_ <= %d",
270 errorMessage.c_str(), minimumValue, maximumValue);
271 return static_cast<Type
>(intValue);
506 StructureContainer::const_iterator
EndStructure(
void)
const;
533 size_t size(
void)
const;
547 operator float()
const {
return AsFloat(
true); }
582 float ConvertToFloat(
void)
const;
587 bool ConvertToBoolean(
void)
const;
597 enum DynamicStructureValueType
623 DynamicStructureValueType mValueType;
633 ArrayContainer* mArray;
634 StructureContainer* mStructure;
651 std::ostream& operator<<(std::ostream& outputStream,
const DynamicStructure& data);
654 inline bool operator==(
const DynamicStructure& leftSide,
const int& rightSide) {
return (leftSide.
AsInteger() == rightSide) ?
true :
false; }
655 inline bool operator==(
const int& leftSide,
const DynamicStructure& rightSide) {
return (rightSide.AsInteger() == leftSide) ?
true :
false; }
656 inline bool operator!=(
const DynamicStructure& leftSide,
const int& rightSide) {
return (leftSide.AsInteger() != rightSide) ?
true :
false; }
657 inline bool operator!=(
const int& leftSide,
const DynamicStructure& rightSide) {
return (rightSide.AsInteger() != leftSide) ?
true :
false; }
659 inline bool operator==(
const DynamicStructure& leftSide,
const float& rightSide) {
return (fabs(leftSide.AsFloat() - rightSide) <=
DynamicStructure::kFloatElipson) ?
true :
false; }
660 inline bool operator==(
const float& leftSide,
const DynamicStructure& rightSide) {
return (fabs(rightSide.AsFloat() - leftSide) <=
DynamicStructure::kFloatElipson) ?
true :
false; }
661 inline bool operator!=(
const DynamicStructure& leftSide,
const float& rightSide) {
return (fabs(leftSide.AsFloat() - rightSide) >
DynamicStructure::kFloatElipson) ?
true :
false; }
662 inline bool operator!=(
const float& leftSide,
const DynamicStructure& rightSide) {
return (fabs(rightSide.AsFloat() - leftSide) >
DynamicStructure::kFloatElipson) ?
true :
false; }
664 inline bool operator==(
const DynamicStructure& leftSide,
const bool& rightSide) {
return (leftSide.AsBoolean() == rightSide) ?
true :
false; }
665 inline bool operator==(
const bool& leftSide,
const DynamicStructure& rightSide) {
return (rightSide.AsBoolean() == leftSide) ?
true :
false; }
666 inline bool operator!=(
const DynamicStructure& leftSide,
const bool& rightSide) {
return (leftSide.AsBoolean() != rightSide) ?
true :
false; }
667 inline bool operator!=(
const bool& leftSide,
const DynamicStructure& rightSide) {
return (rightSide.AsBoolean() != leftSide) ?
true :
false; }
669 inline bool operator==(
const DynamicStructure& leftSide,
const tbCore::tbString& rightSide) {
return (leftSide.AsString() == rightSide) ?
true :
false; }
670 inline bool operator==(
const tbCore::tbString& leftSide,
const DynamicStructure& rightSide) {
return (rightSide.AsString() == leftSide) ?
true :
false; }
671 inline bool operator!=(
const DynamicStructure& leftSide,
const tbCore::tbString& rightSide) {
return (leftSide.AsString() != rightSide) ?
true :
false; }
672 inline bool operator!=(
const tbCore::tbString& leftSide,
const DynamicStructure& rightSide) {
return (rightSide.AsString() != leftSide) ?
true :
false; }
int64_t int64
Signed integer with a size of 64 bits. Supports values from -(2^63) to (2^63 - 1).
Definition: tb_types.h:29
const DynamicStructure & GetMember(const tbCore::tbString &memberName) const
bool IsString(void) const
DynamicStructure & PushValue(const DynamicStructure &value)
static const bool kImplicitConversions
Definition: tb_dynamic_structure.h:644
static const DynamicStructure kNullValue
Definition: tb_dynamic_structure.h:638
tbCore::tbString AsString(bool implicitConversion=kImplicitConversions) const
tbCore::tbString AsStringWithDefault(const tbCore::tbString &defaultValue) const
StructureContainer::const_iterator EndStructure(void) const
Type AsRangedInteger(const tbCore::tbString &errorMessage, const Type minimumValue=MinimumValue< Type >(), const Type maximumValue=MaximumValue< Type >(), bool implicitConversion=kImplicitConversions) const
Definition: tb_dynamic_structure.h:189
static const float kFloatElipson
Definition: tb_dynamic_structure.h:646
Contains all functions, classes and helpers related to game/application development written by Tim "B...
Definition: tb_application_dialog.h:21
float AsFloat(bool implicitConversion=kImplicitConversions) const
static const tbCore::tbString kTrueAsString
Definition: tb_dynamic_structure.h:640
float AsFloatWithDefault(const float defaultValue) const
const DynamicStructure & operator[](const size_t &arrayIndex) const
static const unsigned int kInvalidSize
Definition: tb_dynamic_structure.h:642
const DynamicStructure & GetValue(const size_t &arrayIndex) const
static const bool kTypeSafeArrays
Definition: tb_dynamic_structure.h:643
static const tbCore::tbString kNullAsString
Definition: tb_dynamic_structure.h:639
Type AsRangedIntegerWithDefault(const Type &defaultValue, const tbCore::tbString &errorMessage, const Type minimumValue=MinimumValue< Type >(), const Type maximumValue=MaximumValue< Type >()) const
Definition: tb_dynamic_structure.h:265
bool IsBoolean(void) const
Definition: tb_dynamic_structure.h:57
bool IsInteger(void) const
std::map< tbCore::tbString, DynamicStructure > StructureContainer
Definition: tb_dynamic_structure.h:68
static const tbCore::tbString kFalseAsString
Definition: tb_dynamic_structure.h:641
bool operator==(const DynamicStructure &rightSide) const
bool AsBoolean(bool implicitConversion=kImplicitConversions) const
std::vector< DynamicStructure > ArrayContainer
Definition: tb_dynamic_structure.h:63
StructureContainer::const_iterator BeginStructure(void) const
DynamicStructure & AddMember(const tbCore::tbString &memberName, const DynamicStructure &memberValue)
tbCore::int64 AsIntegerWithDefault(const int defaultValue) const
void SetValue(const int &integerValue, bool implicitTypeChange=kImplicitTypeChange)
Contains core functionality for each component of the API.
Definition: tb_debug_logger.h:91
tbCore::int64 AsInteger(bool implicitConversion=kImplicitConversions) const
#define tb_error_if(errorTest, message,...)
Definition: tb_error.h:37
std::string tbString
Definition: tb_string.h:335
bool IsStructure(void) const
DynamicStructure & operator=(const DynamicStructure &other)
bool AsBooleanWithDefault(const bool defaultValue) const
static const bool kImplicitTypeChange
Definition: tb_dynamic_structure.h:645
DynamicStructure & SetMember(const tbCore::tbString &memberName, const DynamicStructure &memberValue)