TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
tb_dynamic_structure.hpp
1 
9 #ifndef TurtleBrains_DynamicStructure_hpp
10 #define TurtleBrains_DynamicStructure_hpp
11 
12 #include <turtle_brains/core/tb_string.hpp>
13 #include <turtle_brains/core/tb_types.hpp>
14 #include <turtle_brains/core/tb_file_utilities.hpp>
15 
16 #include <cmath>
17 #include <vector>
18 #include <map>
19 #include <string>
20 #include <limits>
21 #include <initializer_list>
22 
23 //
24 // As of 2025-11-08: TurtleBrains has consistent support for ToString/FromString, ToDynamicStructure/FromDynamicStructure
25 // and WriteBinary/ReadBinary across the board. This was surprisingly done without polluting the global namespace.
26 // There is a bit of setup every project needs to do to make the magic work. Start by creating the following generic
27 // template functions and just let those pass through to TurtleBrains specific ones. Then template specializations for
28 // the objects in your game/project will automatically work along side any of the built-in TurtleBrains types.
29 //
30 // For example project named "Playground"
31 // namespace Playground {
32 // template<typename Type> void ToString(const Type& object) { tbCore::ToString(object); }
33 // template<typename Type> void FromString(const String& string) { return tbCore::FromString<Type>(string); }
34 // template<typename Type> void ToDynamicStructure(const Type& object) { tbCore::ToString(object); }
35 // template<typename Type> void FromDynamicStructure(const DynamicStructure& data) {
36 // return tbCore::FromDynamicStructure<Type>(data);
37 // }
38 // template<typename Type> void WriteBinary(const Type& object, tbCore::OutputFile& outputFile) {
39 // tbCore::FileUtilities::WriteBinary(object, outputFile);
40 // }
41 // template<typename Type> void ReadBinary(const Type& object, tbCore::InputFile& inputFile) {
42 // tbCore::FileUtilities::ReadBinary(object, inputFile);
43 // }
44 // template<typename Type> Type ReadBinary(tbCore::InputFile& inputFile) {
45 // return tbCore::FileUtilities::ReadBinary<Type>(inputFile);
46 // }
47 // };
48 //
49 // Now you'll see ReadBinary has two versions, ReadBinary(inputFile) shouldn't need any specializations, it should call
50 // the ReadBinary(object, inputFile) automatically so you only need to worry about the one matching WriteBinary().
51 //
52 // Any area of your project that knows of those templates can now create a specialization for your specific object with
53 // a template specialization. Lets say you had a Vehicle object;
54 //
55 // template<> void ToString<Vehicle>(const Vehicle& object) { return object.make + " " + object.model; }
56 //
57 //
58 // NOTE!!!! 2025-11-11: If we are using ice we will actually need the project implementations to call InternalCombustion
59 // versions in order to hop through the namespacing. Like using ice::FromDynamicStructure<Type>(data) instead of tbCore.
60 // And if we use TrackBuilder it would need to be TrackBuilder::ToString() which then ice::ToString() which then calls
61 // TurtleBrains::ToString(). This is the only way through the namespace boundaries...
62 //
63 // CRITICAL NOTE: 2025-11-11: ADL (Argument Dependent-Lookup) apparently crosses the namespace borders and will create
64 // an ambiguity without the project specificying Rushcremental::FromDynamicStructure(). Interestingly this ONLY applies
65 // to DynamicStructure, because DynStruct is in the tbCore namespace and and ADL then brings it up as an option? So
66 // if String became an actual tbCore object type (rather than using String = std::string) To/FromString would have the
67 // same ambiguity problems...
68 //
69 
70 namespace TurtleBrains::Core
71 {
72  class DynamicStructure;
73 
74  namespace FileUtilities
75  {
79  template<> void WriteBinary<tbCore::DynamicStructure>(const tbCore::DynamicStructure& data, TurtleBrains::Core::OutputFile& outputFile);
80 
84  template<> void ReadBinary<tbCore::DynamicStructure>(tbCore::DynamicStructure& object, TurtleBrains::Core::InputFile& inputFile);
85  };
86 };
87 
88 namespace TurtleBrains::Core
89 {
95  {
96  public:
97  static const DynamicStructure& Nil(void);
98  static DynamicStructure EmptyArray(void);
99 
103  typedef std::vector<DynamicStructure> ArrayContainer;
104 
108  typedef std::map<String, DynamicStructure> StructureContainer;
109 
114 
119  DynamicStructure(const int& integerValue);
120  DynamicStructure(const tbCore::int64& integerValue);
121  //can't add tbCore::uint32 because size_t could match it...
122  DynamicStructure(const size_t& integerValue);
123 
124  //maybe someday this would be good to add a template ctor for integer types.
125  //template<typename IntegerType> DynamicStructure(const IntegerType
126 
131  DynamicStructure(const float& floatValue);
132 
137  DynamicStructure(const bool& booleanValue);
138 
143  DynamicStructure(const String& stringValue);
144 
149  DynamicStructure(const char* stringValue);
150 
162  template<typename Type> DynamicStructure(std::initializer_list<const Type> arguments) :
163  mValueType(kNilType),
164  mInteger(0)
165  {
166  for (auto value : arguments)
167  {
168  PushValue(value);
169  }
170  }
171 
185  DynamicStructure(std::initializer_list<std::pair<const String, const DynamicStructure>> arguments);
186 
191  DynamicStructure(const DynamicStructure& other) noexcept;
192 
193  DynamicStructure(DynamicStructure&& other) noexcept;
194 
199  DynamicStructure& operator=(const DynamicStructure& other) noexcept;
200 
201  DynamicStructure& operator=(DynamicStructure&& other) noexcept;
202 
209 
210 
217  bool IsNil(void) const;
218 
222  bool IsArray(void) const;
223 
228  bool IsStructure(void) const;
229 
233  bool IsInteger(void) const;
234 
238  bool IsFloat(void) const;
239 
243  bool IsBoolean(void) const;
244 
248  bool IsString(void) const;
249 
250 
259  tbCore::int64 AsInteger(bool implicitConversion = kImplicitConversions) const;
260 
279  // template<typename Type> typename std::enable_if<std::is_unsigned<Type>::value, Type>::type
280  // AsRangedInteger(const String& errorMessage,
281  // const Type minimumValue = MinimumValue<Type>(), const Type maximumValue = MaximumValue<Type>(),
282  // bool implicitConversion = kImplicitConversions) const
283  // {
284  // const tbCore::int64 intValue = AsInteger(implicitConversion);
285 
286  // tb_error_if(std::is_unsigned<Type>::value && intValue < 0, "%s (Expected _value(%d) to be greater than 0 for unsigned ranges.",
287  // errorMessage.c_str(), intValue);
288 
289  // //int32 intValue = -1 : 0x0001FFFF //131k
290 
291  // //uint16 min 0 : 0x00000000
292  // //uint16 max 65 : 0x0000FFFF
293 
294 
295  // //int64 value 0x00000000-FFFFFFFF
296  // //int64 min 0x00000000-00000000
297  // //int64 max 0x00000000-FFFFFFFF
298 
299  // //int32 to uint32 65xxx : 0xFFFFFFFF
300 
301 
302  // tb_error_if(static_cast<Type>(intValue) < (minimumValue) || static_cast<Type>(intValue) > (maximumValue),
303  // "%s (Expected: %d <= _value(%d)_ <= %d", errorMessage.c_str(), minimumValue, intValue, maximumValue);
304  // return static_cast<Type>(intValue);
305  // }
306  template<typename Type> Type AsRangedInteger(const String& errorMessage = "Out of Range",
307  const Type minimumValue = std::numeric_limits<Type>::min(), const Type maximumValue = std::numeric_limits<Type>::max(),
308  bool implicitConversion = kImplicitConversions) const
309  {
310  const tbCore::int64 intValue = AsInteger(implicitConversion);
311 
312  if (std::is_unsigned<Type>::value)
313  { //If type is unsigned, ensure it is not less than 0, then cast to an unsigned to compare vs other unsigned values.
314  tb_error_if(intValue < 0, "%s (Expected _value(%d) to be greater than 0 for unsigned ranges.",
315  errorMessage.c_str(), intValue);
316  tb_error_if(minimumValue < 0, "tbExternalError: Expected minimumValue of unsigned type to be greater than equal to 0.");
317  tb_error_if(maximumValue < 0, "tbExternalError: Expected maximumValue of unsigned type to be greater than equal to 0.");
318  tb_error_if(static_cast<uint64>(intValue) < static_cast<uint64>(minimumValue) || static_cast<uint64>(intValue) > static_cast<uint64>(maximumValue),
319  "%s (Expected: %d <= _value(%d)_ <= %d", errorMessage.c_str(), minimumValue, intValue, maximumValue);
320  }
321  else
322  {
323  tb_error_if(intValue < static_cast<int64>(minimumValue) ||intValue > static_cast<int64>(maximumValue),
324  "%s (Expected: %d <= _value(%d)_ <= %d", errorMessage.c_str(), minimumValue, intValue, maximumValue);
325  }
326 
327  return static_cast<Type>(intValue);
328  }
329 
353  template<typename Type> Type AsRangedIntegerWithDefault(const Type& defaultValue, const String& errorMessage = "Out of Range",
354  const Type minimumValue = std::numeric_limits<Type>::min(), const Type maximumValue = std::numeric_limits<Type>::max(),
355  bool implicitConversion = kImplicitConversions) const
356  {
357  if (true == IsNil() || (false == implicitConversion && false == IsInteger()))
358  {
359  return defaultValue;
360  }
361 
362  return AsRangedInteger(errorMessage, minimumValue, maximumValue, implicitConversion);
363  }
364 
373  float AsFloat(bool implicitConversion = kImplicitConversions) const;
374 
383  bool AsBoolean(bool implicitConversion = kImplicitConversions) const;
384 
393  String AsString(bool implicitConversion = kImplicitConversions) const;
394 
395  //
396  // TODO: TurtleBrains: Planning: Do we want to support this? If so implement and document.
397  // @note Cannot implicitly convert to a string, will assert if type is not a string.
398  //
399  //const String& AsStringRef(void) const;
400 
411  tbCore::int64 AsIntegerWithDefault(const tbCore::int64& defaultValue, bool implicitConversion = kImplicitConversions) const;
412 
426  float AsFloatWithDefault(const float defaultValue, bool implicitConversion = true) const;
427 
441  bool AsBooleanWithDefault(const bool defaultValue, bool implicitConversion = true) const;
442 
456  String AsStringWithDefault(const String& defaultValue, bool implicitConversion = true) const;
457 
467  void SetValue(const int& integerValue, bool implicitTypeChange = kImplicitTypeChange);
468  void SetValue(const tbCore::int64& integerValue, bool implicitTypeChange = kImplicitTypeChange);
469 
479  void SetValue(const float& floatValue, bool implicitTypeChange = kImplicitTypeChange);
480 
490  void SetValue(const bool& booleanValue, bool implicitTypeChange = kImplicitTypeChange);
491 
501  void SetValue(const String& stringValue, bool implicitTypeChange = kImplicitTypeChange);
502 
503  //-------------------------------------------------------------------------------------------------------//
504  // Input and Output
505  //-------------------------------------------------------------------------------------------------------//
506  private:
507 
508  friend void TurtleBrains::Core::FileUtilities::WriteBinary<tbCore::DynamicStructure>(const tbCore::DynamicStructure& data, OutputFile& outputFile);
509  friend void TurtleBrains::Core::FileUtilities::ReadBinary<tbCore::DynamicStructure>(tbCore::DynamicStructure& object, InputFile& inputFile);
510 
511  //-------------------------------------------------------------------------------------------------------//
512  // Ignore the mess of private API:
513  //-------------------------------------------------------------------------------------------------------//
514  private:
515  const tbCore::DynamicStructure& LookupByNameOrIndex(tbCore::uint64 index) const;
516  tbCore::DynamicStructure& LookupByNameOrIndex(tbCore::uint64 index);
517  const tbCore::DynamicStructure& LookupByNameOrIndex(const std::string_view& memberName) const;
518  tbCore::DynamicStructure& LookupByNameOrIndex(const std::string_view& memberName);
519  const tbCore::DynamicStructure& LookupByNameOrIndex(const String& memberName) const;
520  tbCore::DynamicStructure& LookupByNameOrIndex(const String& memberName);
521  const tbCore::DynamicStructure& LookupByNameOrIndex(const char* memberName) const;
522  tbCore::DynamicStructure& LookupByNameOrIndex(const char* memberName);
523 
524  public:
531  template<typename Type> const DynamicStructure& operator[](const Type& nameOrIndex) const { return LookupByNameOrIndex(nameOrIndex); }
532 
536  template<typename Type> DynamicStructure& operator[](const Type& nameOrIndex) { return LookupByNameOrIndex(nameOrIndex); }
537 
538  //-------------------------------------------------------------------------------------------------------//
539  // Used ONLY for Array Values. Type must be kArrayType or kNilType to PushValue
540  //-------------------------------------------------------------------------------------------------------//
541 
552 
563  const DynamicStructure& GetValue(const tbCore::uint64& arrayIndex) const;
564 
576 
584  size_t ArraySize(void) const;
585 
590  size_t size(void) const;
591 
598  ArrayContainer::const_iterator BeginArray(void) const;
599 
603  ArrayContainer::iterator BeginArray(void);
604 
608  ArrayContainer::const_iterator begin(void) const;
609 
613  ArrayContainer::iterator begin(void);
614 
621  ArrayContainer::const_iterator EndArray(void) const;
622 
626  ArrayContainer::iterator EndArray(void);
627 
631  ArrayContainer::const_iterator end(void) const;
632 
636  ArrayContainer::iterator end(void);
637 
647  const ArrayContainer& AsArray(void) const;
648 
653 
654  //-------------------------------------------------------------------------------------------------------//
655  // Used ONLY for Structure Values. Type must be kStructureType or kNilType to AddMember
656  //-------------------------------------------------------------------------------------------------------//
657 
668  DynamicStructure& AddMember(const String& memberName, const DynamicStructure& memberValue);
669 
677  void RemoveMember(const String& memberName);
678 
689  DynamicStructure& SetMember(const String& memberName, const DynamicStructure& memberValue);
690 
712  const DynamicStructure& GetMember(const String& memberName) const;
713 
717  DynamicStructure& GetMember(const String& memberName);
718 
725  bool HasMember(const String& memberName) const;
726 
731  size_t StructureSize(void) const;
732 
737  StructureContainer::const_iterator BeginStructure(void) const;
738 
742  StructureContainer::iterator BeginStructure(void);
743 
748  StructureContainer::const_iterator EndStructure(void) const;
749 
753  StructureContainer::iterator EndStructure(void);
754 
770  const StructureContainer& AsStructure(void) const;
771 
776 
777  //TODO: TIM: Implementation: (Test) Add a way to iterate over all Members in a structure.
778 
779  //-------------------------------------------------------------------------------------------------------//
780  // Used ONLY for Structure or Array Values.
781  //-------------------------------------------------------------------------------------------------------//
782 
783  //Acceptable Inputs:
784  // "engine.pistons[0].isDamaged"
785  //const DynamicStructure& FromPath(const String& path) const;
786 
790  explicit operator tbCore::int64() const { return AsInteger(true); }
791 
792  explicit operator int() const { return AsRangedInteger<int>(); }
793 
797  explicit operator float() const { return AsFloat(true); }
798 
802  explicit operator bool() const { return AsBoolean(true); }
803 
807  explicit operator String() const { return AsString(true); }
808 
816  bool operator==(const DynamicStructure& rightSide) const;
817 
825  bool operator!=(const DynamicStructure& rightSide) const;
826 
827  private:
831  void SetToNil(void);
832 
836  tbCore::int64 ConvertToInteger(void) const;
837 
841  float ConvertToFloat(void) const;
842 
846  bool ConvertToBoolean(void) const;
847 
851  String ConvertToString(void) const;
852 
855  enum class NotFoundPolicy { OnMissingError, OnMissingNull, OnMissingAdd };
856 
871  const DynamicStructure& ActuallyGetMember(const String& memberName, const NotFoundPolicy& policy = NotFoundPolicy::OnMissingError) const;
872  DynamicStructure& ActuallyGetMember(const String& memberName, const NotFoundPolicy& policy = NotFoundPolicy::OnMissingError);
873 
877  enum DynamicStructureValueType : tbCore::uint8
878  {
879  kNilType,
880 
881  kIntegerType,
882  kFloatType,
883  kBooleanType,
884  kStringType,
885 
886  kArrayType,
887  kStructureType,
888  };
889 
893  DynamicStructureValueType mValueType;
894 
895  union
896  { //Unnamed anonymous union so DynamicStrucure contains the contents as its own members, "this->mRawBytes".
897  char mRawBytes[8]; //Reserve 64-bits for whatever types follow.
898  tbCore::int64 mInteger;
899  bool mBoolean;
900  float mFloat;
901 
902  String* mString;
903  ArrayContainer* mArray;
904  StructureContainer* mStructure;
905  };
906 
907  public:
909  static const String kNullAsString;
910  static const String kTrueAsString;
911  static const String kFalseAsString;
912  static const unsigned int kInvalidSize;
913  static const bool kImplicitConversions;
914  static const bool kImplicitTypeChange;
915  static const float kFloatElipson;
916  };
917 
918  namespace Implementation {
919  template<class> constexpr bool tbiDependentTrue = true;
920  };
921 
925  String ToJsonString(const tbCore::DynamicStructure& data, bool prettyJson);
926 
928 
929  std::ostream& operator<<(std::ostream& outputStream, const DynamicStructure& data);
930 
931  //This is actually not _that_ trivial, at least not with how we have implemented the operator<<. So we either
932  //changed that format to make this easier, or ignore doing this for now. You can always save ToJsonString and
933  //then use tbCore::ParseJson() to get back.
934  //std::istream& operator>>(std::istream& inputStream, DynamicStructure& data);
935 
936  /* Overloads to make the DynamicStructure behave like a built in Integer */
937  inline bool operator==(const DynamicStructure& leftSide, const int& rightSide) { return (leftSide.AsInteger() == rightSide) ? true : false; }
938  inline bool operator==(const int& leftSide, const DynamicStructure& rightSide) { return (rightSide.AsInteger() == leftSide) ? true : false; }
939  inline bool operator!=(const DynamicStructure& leftSide, const int& rightSide) { return (leftSide.AsInteger() != rightSide) ? true : false; }
940  inline bool operator!=(const int& leftSide, const DynamicStructure& rightSide) { return (rightSide.AsInteger() != leftSide) ? true : false; }
941 
942  inline bool operator==(const DynamicStructure& leftSide, const tbCore::int64& rightSide) { return (leftSide.AsInteger() == rightSide) ? true : false; }
943  inline bool operator==(const tbCore::int64& leftSide, const DynamicStructure& rightSide) { return (rightSide.AsInteger() == leftSide) ? true : false; }
944  inline bool operator!=(const DynamicStructure& leftSide, const tbCore::int64& rightSide) { return (leftSide.AsInteger() != rightSide) ? true : false; }
945  inline bool operator!=(const tbCore::int64& leftSide, const DynamicStructure& rightSide) { return (rightSide.AsInteger() != leftSide) ? true : false; }
946 
947  inline bool operator==(const DynamicStructure& leftSide, const float& rightSide) { return (fabs(leftSide.AsFloat() - rightSide) <= DynamicStructure::kFloatElipson) ? true : false; }
948  inline bool operator==(const float& leftSide, const DynamicStructure& rightSide) { return (fabs(rightSide.AsFloat() - leftSide) <= DynamicStructure::kFloatElipson) ? true : false; }
949  inline bool operator!=(const DynamicStructure& leftSide, const float& rightSide) { return (fabs(leftSide.AsFloat() - rightSide) > DynamicStructure::kFloatElipson) ? true : false; }
950  inline bool operator!=(const float& leftSide, const DynamicStructure& rightSide) { return (fabs(rightSide.AsFloat() - leftSide) > DynamicStructure::kFloatElipson) ? true : false; }
951 
952  inline bool operator==(const DynamicStructure& leftSide, const bool& rightSide) { return (leftSide.AsBoolean() == rightSide) ? true : false; }
953  inline bool operator==(const bool& leftSide, const DynamicStructure& rightSide) { return (rightSide.AsBoolean() == leftSide) ? true : false; }
954  inline bool operator!=(const DynamicStructure& leftSide, const bool& rightSide) { return (leftSide.AsBoolean() != rightSide) ? true : false; }
955  inline bool operator!=(const bool& leftSide, const DynamicStructure& rightSide) { return (rightSide.AsBoolean() != leftSide) ? true : false; }
956 
957  inline bool operator==(const DynamicStructure& leftSide, const String& rightSide) { return (leftSide.AsString() == rightSide) ? true : false; }
958  inline bool operator==(const String& leftSide, const DynamicStructure& rightSide) { return (rightSide.AsString() == leftSide) ? true : false; }
959  inline bool operator!=(const DynamicStructure& leftSide, const String& rightSide) { return (leftSide.AsString() != rightSide) ? true : false; }
960  inline bool operator!=(const String& leftSide, const DynamicStructure& rightSide) { return (rightSide.AsString() != leftSide) ? true : false; }
961 
963 
964 }; /* namespace TurtleBrains::Core */
965 
966 namespace tbCore = TurtleBrains::Core;
967 
968 namespace TurtleBrains
969 {
970  using DynamicStructure = TurtleBrains::Core::DynamicStructure;
971 
972  template<typename Type> DynamicStructure ToDynamicStructure(const Type& object)
973  { // 2025-11-11: This is to fix something with clang v14.0.0 and static_assert failing even if the function is not
974  // called... This error should only happen if this very function would be used; it means the Type given does
975  // not have a template specialization. The dependentTrue is a workaround before CWG2518/P2593R1
976  tb_static_error_if(true == Core::Implementation::tbiDependentTrue<Type>, "Missing a ToDynamicStructure() overload?");
977  return Type();
978  }
979 
980  template<typename Type> Type FromDynamicStructure(const DynamicStructure& data)
981  { // 2025-11-11: This is to fix something with clang v14.0.0 and static_assert failing even if the function is not
982  // called... This error should only happen if this very function would be used; it means the Type given does
983  // not have a template specialization. The dependentTrue is a workaround before CWG2518/P2593R1
984  tb_static_error_if(true == Core::Implementation::tbiDependentTrue<Type>, "Missing a FromDynamicStructure() overload?");
985  return Type();
986  }
987 
988  template<> inline DynamicStructure ToDynamicStructure<int>(const int& value) { return tbCore::DynamicStructure(value); }
989  template<> inline DynamicStructure ToDynamicStructure<bool>(const bool& value) { return tbCore::DynamicStructure(value); }
990  template<> inline DynamicStructure ToDynamicStructure<float>(const float& value) { return tbCore::DynamicStructure(value); }
991  template<> inline DynamicStructure ToDynamicStructure<String>(const String& value) { return tbCore::DynamicStructure(value); }
992 
993  template<> inline int FromDynamicStructure<int>(const DynamicStructure& data) { return data.AsRangedInteger<int>(); }
994  template<> inline bool FromDynamicStructure<bool>(const DynamicStructure& data) { return data.AsBoolean(); }
995  template<> inline float FromDynamicStructure<float>(const DynamicStructure& data) { return data.AsFloat(); }
996  template<> inline String FromDynamicStructure<String>(const DynamicStructure& data) { return data.AsString(); }
997 };
998 
999 #endif /* TurtleBrains_DynamicStructure_hpp */
Definition: tb_dynamic_structure.hpp:95
DynamicStructure & SetMember(const String &memberName, const DynamicStructure &memberValue)
StructureContainer::iterator EndStructure(void)
std::vector< DynamicStructure > ArrayContainer
Definition: tb_dynamic_structure.hpp:103
const DynamicStructure & operator[](const Type &nameOrIndex) const
Definition: tb_dynamic_structure.hpp:531
DynamicStructure & operator=(const DynamicStructure &other) noexcept
DynamicStructure(std::initializer_list< std::pair< const String, const DynamicStructure >> arguments)
bool operator==(const DynamicStructure &rightSide) const
DynamicStructure & operator[](const Type &nameOrIndex)
Definition: tb_dynamic_structure.hpp:536
static const float kFloatElipson
Definition: tb_dynamic_structure.hpp:915
DynamicStructure & GetValue(const tbCore::uint64 &arrayIndex)
DynamicStructure & GetMember(const String &memberName)
static const bool kImplicitTypeChange
Definition: tb_dynamic_structure.hpp:914
const ArrayContainer & AsArray(void) const
DynamicStructure(const char *stringValue)
float AsFloatWithDefault(const float defaultValue, bool implicitConversion=true) const
float AsFloat(bool implicitConversion=kImplicitConversions) const
tbCore::int64 AsInteger(bool implicitConversion=kImplicitConversions) const
static const DynamicStructure kNullValue
Definition: tb_dynamic_structure.hpp:908
ArrayContainer & AsArray(void)
ArrayContainer::const_iterator EndArray(void) const
static const String kTrueAsString
Definition: tb_dynamic_structure.hpp:910
DynamicStructure & PushValue(const DynamicStructure &value)
static const String kNullAsString
Definition: tb_dynamic_structure.hpp:909
const StructureContainer & AsStructure(void) const
DynamicStructure(std::initializer_list< const Type > arguments)
Definition: tb_dynamic_structure.hpp:162
static const String kFalseAsString
Definition: tb_dynamic_structure.hpp:911
bool operator!=(const DynamicStructure &rightSide) const
ArrayContainer::iterator end(void)
ArrayContainer::iterator BeginArray(void)
static const unsigned int kInvalidSize
Definition: tb_dynamic_structure.hpp:912
bool HasMember(const String &memberName) const
StructureContainer::const_iterator BeginStructure(void) const
const DynamicStructure & GetValue(const tbCore::uint64 &arrayIndex) const
const DynamicStructure & GetMember(const String &memberName) const
std::map< String, DynamicStructure > StructureContainer
Definition: tb_dynamic_structure.hpp:108
Type AsRangedInteger(const String &errorMessage="Out of Range", const Type minimumValue=std::numeric_limits< Type >::min(), const Type maximumValue=std::numeric_limits< Type >::max(), bool implicitConversion=kImplicitConversions) const
Definition: tb_dynamic_structure.hpp:306
void SetValue(const String &stringValue, bool implicitTypeChange=kImplicitTypeChange)
void SetValue(const int &integerValue, bool implicitTypeChange=kImplicitTypeChange)
StructureContainer & AsStructure(void)
void SetValue(const float &floatValue, bool implicitTypeChange=kImplicitTypeChange)
DynamicStructure(const DynamicStructure &other) noexcept
ArrayContainer::const_iterator BeginArray(void) const
DynamicStructure & AddMember(const String &memberName, const DynamicStructure &memberValue)
void SetValue(const bool &booleanValue, bool implicitTypeChange=kImplicitTypeChange)
String AsStringWithDefault(const String &defaultValue, bool implicitConversion=true) const
StructureContainer::const_iterator EndStructure(void) const
bool AsBooleanWithDefault(const bool defaultValue, bool implicitConversion=true) const
StructureContainer::iterator BeginStructure(void)
ArrayContainer::iterator EndArray(void)
DynamicStructure(const String &stringValue)
DynamicStructure(const float &floatValue)
tbCore::int64 AsIntegerWithDefault(const tbCore::int64 &defaultValue, bool implicitConversion=kImplicitConversions) const
Type AsRangedIntegerWithDefault(const Type &defaultValue, const String &errorMessage="Out of Range", const Type minimumValue=std::numeric_limits< Type >::min(), const Type maximumValue=std::numeric_limits< Type >::max(), bool implicitConversion=kImplicitConversions) const
Definition: tb_dynamic_structure.hpp:353
DynamicStructure(const int &integerValue)
void RemoveMember(const String &memberName)
String AsString(bool implicitConversion=kImplicitConversions) const
ArrayContainer::const_iterator begin(void) const
DynamicStructure(const bool &booleanValue)
bool AsBoolean(bool implicitConversion=kImplicitConversions) const
ArrayContainer::const_iterator end(void) const
static const bool kImplicitConversions
Definition: tb_dynamic_structure.hpp:913
ArrayContainer::iterator begin(void)
#define tb_static_error_if(errorTest, message)
Definition: tb_error.hpp:51
#define tb_error_if(errorTest, message,...)
Definition: tb_error.hpp:42
Contains core functionality for each component of the API.
Definition: tb_debug_logger.hpp:125
std::uint8_t uint8
Unsigned integer with a size of 8 bits. Supports values from 0 to 255.
Definition: tb_types.hpp:22
String ToJsonString(const tbCore::DynamicStructure &data, bool prettyJson)
std::string String
Definition: tb_string.hpp:302
std::int64_t int64
Signed integer with a size of 64 bits. Supports values from -(2^63) to (2^63 - 1).
Definition: tb_types.hpp:28
std::uint64_t uint64
Unsigned integer with a size of 64 bits, Supports values from 0 to (2^64 - 1).
Definition: tb_types.hpp:29
Here is some information about the primary namespace.
Definition: tb_application_dialog.hpp:22