MatureJsonList.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. // Copyright 2024 Tracer Interactive, LLC. All Rights Reserved.
  2. #pragma once
  3. #include "CoreMinimal.h"
  4. #include "json_cast.hpp"
  5. #include "MatureJsonList.generated.h"
  6. typedef struct FMatureJsonObject FMatureJsonObject;
  7. typedef struct FMatureJsonValue FMatureJsonValue;
  8. USTRUCT(BlueprintType, meta = (DisplayName = "Mature JSON|List"))
  9. struct MATUREJSON_API FMatureJsonList
  10. {
  11. GENERATED_USTRUCT_BODY()
  12. public:
  13. FMatureJsonList();
  14. FMatureJsonList(const TSharedPtr<mature::Document>& Doc, const mature::Array& );
  15. FMatureJsonList(const TSharedPtr<mature::Document>& Doc, const mature::Array&&);
  16. FMatureJsonList(const FMatureJsonList& rhs);
  17. public:
  18. // Get the number of items in this list.
  19. int32 Size() const;
  20. // Check is null in this list.
  21. bool IsEmpty() const;
  22. // Clear the items in this list.
  23. void Clear();
  24. // Append a JSON array to this list.
  25. FMatureJsonList& Append(const FMatureJsonList& List);
  26. // Append an array of JSON values to this list.
  27. FMatureJsonList& Append(const TArray<FMatureJsonValue>& Value);
  28. // Add a boolean to this list.
  29. FMatureJsonList& AddValue( bool Value );
  30. // Add a float to this list.
  31. FMatureJsonList& AddValue( float Value );
  32. // Add an integer to this list.
  33. FMatureJsonList& AddValue( int32 Value );
  34. // Add a number to this list.
  35. FMatureJsonList& AddValue( double Value );
  36. // Add a string to this list.
  37. FMatureJsonList& AddValue( const TCHAR* Value);
  38. // Add a string to this list.
  39. FMatureJsonList& AddValue( const FString& Value );
  40. // Add a date/time to this list.
  41. FMatureJsonList& AddValue( const FDateTime& Value );
  42. // Add a GUID to this list.
  43. FMatureJsonList& AddValue( const FGuid& Value );
  44. // Add a color to this list.
  45. FMatureJsonList& AddValue( const FColor& Value );
  46. // Add a color to this list.
  47. FMatureJsonList& AddValue( const FLinearColor& Value);
  48. // Add a color to this list.
  49. FMatureJsonList& AddValue( const FRotator& Value);
  50. // Add a color to this list.
  51. FMatureJsonList& AddValue( const FTransform& Value);
  52. // Set an item as a vector.
  53. FMatureJsonList& AddValue( const FVector& Value);
  54. // Add a JSON value to this list.
  55. FMatureJsonList& AddValue( const FMatureJsonValue& Value );
  56. // Add a JSON object to this list.
  57. FMatureJsonList& AddValue( const FMatureJsonObject& Value );
  58. // Add a JSON array to this list.
  59. FMatureJsonList& AddValue( const FMatureJsonList& Value );
  60. // Add an array of JSON values to this list.
  61. FMatureJsonList& AddValue( const TArray<FMatureJsonValue>& Value );
  62. // Set an item as a boolean.
  63. FMatureJsonList& AddValue(const TArray<bool>& Value);
  64. // Set an item as a float.
  65. FMatureJsonList& AddValue(const TArray<float>& Value);
  66. // Set an item as an integer.
  67. FMatureJsonList& AddValue(const TArray<int32>& Value);
  68. // Set an item as a number.
  69. FMatureJsonList& AddValue(const TArray<double>& Value);
  70. // Set an item as a string.
  71. FMatureJsonList& AddValue(const TArray<FString>& Value);
  72. // Set an item as a date/time.
  73. FMatureJsonList& AddValue(const TArray<FDateTime>& Value);
  74. // Set an item as a GUID.
  75. FMatureJsonList& AddValue(const TArray<FGuid>& Value);
  76. // Set an item as a color.
  77. FMatureJsonList& AddValue(const TArray<FColor>& Value);
  78. // Set an item as a linear color.
  79. FMatureJsonList& AddValue(const TArray<FLinearColor>& Value);
  80. // Set an item as a rotator.
  81. FMatureJsonList& AddValue(const TArray<FRotator>& Value);
  82. // Set an item as a transform.
  83. FMatureJsonList& AddValue(const TArray<FTransform>& Value);
  84. // Set an item as a vector.
  85. FMatureJsonList& AddValue(const TArray<FVector>& Value);
  86. // Add a null value to this list
  87. FMatureJsonValue AddValue() const;
  88. // Add a null value to this list
  89. FMatureJsonObject AddObject();
  90. // Add a null value to this list
  91. FMatureJsonList AddList();
  92. // Set an item as a boolean.
  93. FMatureJsonList AddList(const TArray<bool>& Value);
  94. // Set an item as a float.
  95. FMatureJsonList AddList(const TArray<float>& Value);
  96. // Set an item as an integer.
  97. FMatureJsonList AddList(const TArray<int32>& Value);
  98. // Set an item as a number.
  99. FMatureJsonList AddList(const TArray<double>& Value);
  100. // Set an item as a string.
  101. FMatureJsonList AddList(const TArray<FString>& Value);
  102. // Set an item as a date/time.
  103. FMatureJsonList AddList(const TArray<FDateTime>& Value);
  104. // Set an item as a GUID.
  105. FMatureJsonList AddList(const TArray<FGuid>& Value);
  106. // Set an item as a color.
  107. FMatureJsonList AddList(const TArray<FColor>& Value);
  108. // Set an item as a linear color.
  109. FMatureJsonList AddList(const TArray<FLinearColor>& Value);
  110. // Set an item as a rotator.
  111. FMatureJsonList AddList(const TArray<FRotator>& Value);
  112. // Set an item as a transform.
  113. FMatureJsonList AddList(const TArray<FTransform>& Value);
  114. // Set an item as a vector.
  115. FMatureJsonList AddList(const TArray<FVector>& Value);
  116. // Set an item as a vector.
  117. FMatureJsonList& MergeList(const FMatureJsonList&);
  118. // Set an item as a boolean.
  119. FMatureJsonList& SetValue( int32 Index);
  120. // Set an item as a boolean.
  121. FMatureJsonList& SetValue( int32 Index, bool Value );
  122. // Set an item as a float.
  123. FMatureJsonList& SetValue( int32 Index, float Value );
  124. // Set an item as an integer.
  125. FMatureJsonList& SetValue( int32 Index, int32 Value );
  126. // Set an item as a number.
  127. FMatureJsonList& SetValue( int32 Index, double Value );
  128. // Set an item as a string.
  129. FMatureJsonList& SetValue(int32 Index, const TCHAR* Value);
  130. // Set an item as a string.
  131. FMatureJsonList& SetValue( int32 Index, const FString& Value );
  132. // Set an item as a date/time.
  133. FMatureJsonList& SetValue( int32 Index, const FDateTime& Value );
  134. // Set an item as a GUID.
  135. FMatureJsonList& SetValue( int32 Index, const FGuid& Value );
  136. // Set an item as a color.
  137. FMatureJsonList& SetValue( int32 Index, const FColor& Value );
  138. // Set an item as a linear color.
  139. FMatureJsonList& SetValue( int32 Index, const FLinearColor& Value );
  140. // Set an item as a rotator.
  141. FMatureJsonList& SetValue( int32 Index, const FRotator& Value );
  142. // Set an item as a transform.
  143. FMatureJsonList& SetValue( int32 Index, const FTransform& Value );
  144. // Set an item as a vector.
  145. FMatureJsonList& SetValue( int32 Index, const FVector& Value );
  146. // Set an item as a JSON value.
  147. FMatureJsonList& SetValue( int32 Index, const FMatureJsonValue& Value );
  148. // Set an item as a JSON object.
  149. FMatureJsonList& SetValue( int32 Index, const FMatureJsonObject& Value );
  150. // Set an item as a JSON array.
  151. FMatureJsonList& SetValue( int32 Index, const FMatureJsonList& Value );
  152. // Set an item as an array of JSON values.
  153. FMatureJsonList& SetValue( int32 Index, const TArray<FMatureJsonValue>& Value );
  154. // Set an item as a map of JSON values.
  155. FMatureJsonList& SetValue( int32 Index, const TMap<FString, FMatureJsonValue>& Value );
  156. FMatureJsonValue GetValue(int Index) const;
  157. // Get an item as a boolean.
  158. bool GetValue(int32 Index, bool& Value) const;
  159. // Get an item as a float.
  160. bool GetValue(int32 Index, float& Value)const;
  161. // Get an item as an integer.
  162. bool GetValue(int32 Index, int32& Value)const;
  163. // Get an item as a number.
  164. bool GetValue(int32 Index, double& Value)const;
  165. // Get an item as a string.
  166. bool GetValue(int32 Index, FString& Value)const;
  167. // Get an item as a date/time.
  168. bool GetValue(int32 Index, FDateTime& Value)const;
  169. // Get an item as a GUID.
  170. bool GetValue(int32 Index, FGuid& Value)const;
  171. // Get an item as a color.
  172. bool GetValue(int32 Index, FColor& Value)const;
  173. // Get an item as a linear color.
  174. bool GetValue(int32 Index, FLinearColor& Value)const;
  175. // Get an item as a rotator.
  176. bool GetValue(int32 Index, FRotator& Value)const;
  177. // Get an item as a transform.
  178. bool GetValue(int32 Index, FTransform& Value)const;
  179. // Get an item as a vector.
  180. bool GetValue(int32 Index, FVector& Value)const;
  181. // Get an item as a JSON value.
  182. bool GetValue(int32 Index, FMatureJsonValue& Value)const;
  183. // Get an item as a JSON object.
  184. bool GetValue(int32 Index, FMatureJsonObject& Value)const;
  185. // Get an item as a JSON array.
  186. bool GetValue(int32 Index, FMatureJsonList& Value)const;
  187. FMatureJsonValue ToValue(int32 Index) const;
  188. FMatureJsonObject ToObject(int32 Index) const;
  189. FMatureJsonList ToList(int32 Index) const;
  190. // Remove an item from this list.
  191. FMatureJsonList& Remove(unsigned int Index,unsigned int num );
  192. FMatureJsonList& operator=(const FMatureJsonList& Value);
  193. TSharedPtr<mature::Document> Document();
  194. TSharedPtr<mature::Document> Document()const;
  195. protected:
  196. class ListWrap {
  197. public:
  198. ListWrap();
  199. ListWrap(TSharedPtr<mature::Document> Doc, const mature::Array& Ref);
  200. ListWrap(TSharedPtr<mature::Document> Doc, const mature::Array&& Ref);
  201. private:
  202. TSharedPtr<mature::Document> Document;
  203. mature::Array List;
  204. friend struct FMatureJsonList;
  205. };
  206. TSharedPtr<ListWrap> ListPtr;
  207. inline mature::Array& List();
  208. inline mature::Array& List()const;
  209. inline mature::Allocator& GetAllocator();
  210. inline mature::Allocator& GetAllocator()const;
  211. //TSharedPtr<mature::Document> Document;
  212. //mature::Array ArrayRef;
  213. private:
  214. friend struct FMatureJsonObject;
  215. friend struct FMatureJsonValue;
  216. };