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)
126 bool IsNil(
void)
const;
216 const Type minimumValue = MinimumValue<Type>(),
const Type maximumValue = MaximumValue<Type>(),
221 if (std::is_unsigned<Type>::value)
223 tb_error_if(std::is_unsigned<Type>::value && intValue < 0,
"%s (Expected _value(%d) to be greater than 0 for unsigned ranges.",
224 errorMessage.c_str(), intValue);
225 tb_error_if(static_cast<uint64>(intValue) < minimumValue || static_cast<uint64>(intValue) > maximumValue,
226 "%s (Expected: %d <= _value(%d)_ <= %d", errorMessage.c_str(), minimumValue, intValue, maximumValue);
230 tb_error_if(intValue < static_cast<int64>(minimumValue) ||intValue > static_cast<int64>(maximumValue),
231 "%s (Expected: %d <= _value(%d)_ <= %d", errorMessage.c_str(), minimumValue, intValue, maximumValue);
234 return static_cast<Type
>(intValue);
307 const Type minimumValue = MinimumValue<Type>(),
const Type maximumValue = MaximumValue<Type>())
const
311 if (std::is_unsigned<Type>::value)
313 tb_error_if(std::is_unsigned<Type>::value && intValue < 0,
"%s (Expected _value(%d) to be greater than 0 for unsigned ranges.",
314 errorMessage.c_str(), intValue);
315 tb_error_if(static_cast<uint64>(intValue) < minimumValue || static_cast<uint64>(intValue) > maximumValue,
316 "%s (Expected: %d <= _value(%d)_ <= %d", errorMessage.c_str(), minimumValue, intValue, maximumValue);
320 tb_error_if(intValue < static_cast<int64>(minimumValue) ||intValue > static_cast<int64>(maximumValue),
321 "%s (Expected: %d <= _value(%d)_ <= %d", errorMessage.c_str(), minimumValue, intValue, maximumValue);
324 return static_cast<Type
>(intValue);
340 float AsFloatWithDefault(
const float defaultValue,
bool implicitConversion =
true)
const;
566 StructureContainer::const_iterator
EndStructure(
void)
const;
593 size_t size(
void)
const;
607 operator float()
const {
return AsFloat(
true); }
651 float ConvertToFloat(
void)
const;
656 bool ConvertToBoolean(
void)
const;
666 enum DynamicStructureValueType
692 DynamicStructureValueType mValueType;
702 ArrayContainer* mArray;
703 StructureContainer* mStructure;
719 std::ostream& operator<<(std::ostream& outputStream,
const DynamicStructure& data);
722 inline bool operator==(
const DynamicStructure& leftSide,
const int& rightSide) {
return (leftSide.
AsInteger() == rightSide) ?
true :
false; }
723 inline bool operator==(
const int& leftSide,
const DynamicStructure& rightSide) {
return (rightSide.AsInteger() == leftSide) ?
true :
false; }
724 inline bool operator!=(
const DynamicStructure& leftSide,
const int& rightSide) {
return (leftSide.AsInteger() != rightSide) ?
true :
false; }
725 inline bool operator!=(
const int& leftSide,
const DynamicStructure& rightSide) {
return (rightSide.AsInteger() != leftSide) ?
true :
false; }
727 inline bool operator==(
const DynamicStructure& leftSide,
const tbCore::int64& rightSide) {
return (leftSide.AsInteger() == rightSide) ?
true :
false; }
728 inline bool operator==(
const tbCore::int64& leftSide,
const DynamicStructure& rightSide) {
return (rightSide.AsInteger() == leftSide) ?
true :
false; }
729 inline bool operator!=(
const DynamicStructure& leftSide,
const tbCore::int64& rightSide) {
return (leftSide.AsInteger() != rightSide) ?
true :
false; }
730 inline bool operator!=(
const tbCore::int64& leftSide,
const DynamicStructure& rightSide) {
return (rightSide.AsInteger() != leftSide) ?
true :
false; }
732 inline bool operator==(
const DynamicStructure& leftSide,
const float& rightSide) {
return (fabs(leftSide.AsFloat() - rightSide) <=
DynamicStructure::kFloatElipson) ?
true :
false; }
733 inline bool operator==(
const float& leftSide,
const DynamicStructure& rightSide) {
return (fabs(rightSide.AsFloat() - leftSide) <=
DynamicStructure::kFloatElipson) ?
true :
false; }
734 inline bool operator!=(
const DynamicStructure& leftSide,
const float& rightSide) {
return (fabs(leftSide.AsFloat() - rightSide) >
DynamicStructure::kFloatElipson) ?
true :
false; }
735 inline bool operator!=(
const float& leftSide,
const DynamicStructure& rightSide) {
return (fabs(rightSide.AsFloat() - leftSide) >
DynamicStructure::kFloatElipson) ?
true :
false; }
737 inline bool operator==(
const DynamicStructure& leftSide,
const bool& rightSide) {
return (leftSide.AsBoolean() == rightSide) ?
true :
false; }
738 inline bool operator==(
const bool& leftSide,
const DynamicStructure& rightSide) {
return (rightSide.AsBoolean() == leftSide) ?
true :
false; }
739 inline bool operator!=(
const DynamicStructure& leftSide,
const bool& rightSide) {
return (leftSide.AsBoolean() != rightSide) ?
true :
false; }
740 inline bool operator!=(
const bool& leftSide,
const DynamicStructure& rightSide) {
return (rightSide.AsBoolean() != leftSide) ?
true :
false; }
742 inline bool operator==(
const DynamicStructure& leftSide,
const tbCore::tbString& rightSide) {
return (leftSide.AsString() == rightSide) ?
true :
false; }
743 inline bool operator==(
const tbCore::tbString& leftSide,
const DynamicStructure& rightSide) {
return (rightSide.AsString() == leftSide) ?
true :
false; }
744 inline bool operator!=(
const DynamicStructure& leftSide,
const tbCore::tbString& rightSide) {
return (leftSide.AsString() != rightSide) ?
true :
false; }
745 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
tbCore::tbString AsStringWithDefault(const tbCore::tbString &defaultValue, bool implicitConversion=true) const
tbCore::int64 AsIntegerWithDefault(const tbCore::int64 &defaultValue, bool implicitConversion=true) const
DynamicStructure & PushValue(const DynamicStructure &value)
static const bool kImplicitConversions
Definition: tb_dynamic_structure.h:712
static const DynamicStructure kNullValue
Definition: tb_dynamic_structure.h:707
tbCore::tbString AsString(bool implicitConversion=kImplicitConversions) 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:215
static const float kFloatElipson
Definition: tb_dynamic_structure.h:714
Here is some information about the primary namespace.
Definition: tb_application_dialog.h:21
float AsFloat(bool implicitConversion=kImplicitConversions) const
static const tbCore::tbString kTrueAsString
Definition: tb_dynamic_structure.h:709
const DynamicStructure & operator[](const size_t &arrayIndex) const
static const unsigned int kInvalidSize
Definition: tb_dynamic_structure.h:711
const DynamicStructure & GetValue(const size_t &arrayIndex) const
bool operator!=(const DynamicStructure &rightSide) const
static const tbCore::tbString kNullAsString
Definition: tb_dynamic_structure.h:708
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:306
bool IsBoolean(void) const
bool AsBooleanWithDefault(const bool defaultValue, bool implicitConversion=true) const
Definition: tb_dynamic_structure.h:57
float AsFloatWithDefault(const float defaultValue, bool implicitConversion=true) const
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:710
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)
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)
static const bool kImplicitTypeChange
Definition: tb_dynamic_structure.h:713
DynamicStructure & SetMember(const tbCore::tbString &memberName, const DynamicStructure &memberValue)