// Copyright 2024 Tracer Interactive, LLC. All Rights Reserved. #pragma once #include "CoreMinimal.h" #include "Serialization/JsonTypes.h" #include "Serialization/JsonSerializer.h" #include "Serialization/JsonReader.h" #include "Dom/JsonObject.h" #include "Dom/JsonValue.h" #include "UObject/StructOnScope.h" #include "MatureJsonValue.h" #include "json_cast.hpp" #include "MatureJsonObject.generated.h" typedef struct FMatureJsonList FMatureJsonList; USTRUCT(BlueprintType, meta = (DisplayName = "Mature JSON|Object")) struct MATUREJSON_API FMatureJsonObject { GENERATED_USTRUCT_BODY() public: FMatureJsonObject(); FMatureJsonObject(TSharedPtr Doc, const mature::Object&); FMatureJsonObject(TSharedPtr Doc, const mature::Object&&); FMatureJsonObject(const FMatureJsonObject& rhs); FMatureJsonObject(const FMatureJsonObject&& rhs); public: FMatureJsonValue GetKey(const FString& key) const ; //FMatureJsonObject& SetValue( const FString& key, const FMatureJsonValue& Value); FMatureJsonObject& SetValue( const FLinearColor& Value ); FMatureJsonObject& SetValue( const FRotator& Value ); FMatureJsonObject& SetValue( const FTransform& Value ); FMatureJsonObject& SetValue( const FVector& Value ); FMatureJsonObject& SetValue( const FMatureJsonObject& Value); FMatureJsonObject& SetValue( const TMap& Value ); FMatureJsonObject& SetValue( const TMap& Value ); FMatureJsonObject& SetValue( const TMap& Value ); FMatureJsonObject& SetValue( const TMap& Value ); FMatureJsonObject& SetValue( const TMap& Value ); FMatureJsonObject& SetValue( const TMap& Value ); FMatureJsonObject& SetValue( const TMap& Value ); FMatureJsonObject& SetValue( const TMap& Value ); FMatureJsonObject& SetValue( const TMap& Value ); FMatureJsonObject& SetValue( const TMap& Value ); FMatureJsonObject& SetValue( const TMap& Value ); FMatureJsonObject& SetValue( const TMap& Value ); FMatureJsonObject& SetValue( const TMap& Value ); // Get the number of properties in this object. int32 Size() const; // Check is empty in this object. bool IsEmpty()const; // Clear the properties in this object. void Clear(); // Check if this object has a property. bool HasKey( const FString& Key ) const; // Remove a property from this object. void RemoveKey( const FString& Key ); // Add a JSON object to this object. FMatureJsonObject& AddValue(const FMatureJsonObject& Object); // Add a map of booleans to this object. FMatureJsonObject& AddValue(const TMap& Map); // Add a map of floats to this object. FMatureJsonObject& AddValue(const TMap& Map); // Add a map of integers to this object. FMatureJsonObject& AddValue(const TMap& Map); // Add a map of numbers to this object. FMatureJsonObject& AddValue(const TMap& Map); // Add a map of strings to this object. FMatureJsonObject& AddValue(const TMap& Map); // Add a map of date/times to this object. FMatureJsonObject& AddValue(const TMap& Map); // Add a map of GUIDs to this object. FMatureJsonObject& AddValue(const TMap& Map); // Add a map of colors to this object. FMatureJsonObject& AddValue(const TMap& Map); // Add a map of linear colors to this object. FMatureJsonObject& AddValue(const TMap& Map); // Add a map of rotators to this object. FMatureJsonObject& AddValue(const TMap& Map); // Add a map of transforms to this object. FMatureJsonObject& AddValue(const TMap& Map); // Add a map of vectors to this object. FMatureJsonObject& AddValue(const TMap& Map); // FMatureJsonObject& AddValue(const TMap& Map); // Set a property as a boolean. FMatureJsonObject& AddValue(const FString& Key, bool Value); // Set a property as a float. FMatureJsonObject& AddValue(const FString& Key, float Value); // Set a property as an integer. FMatureJsonObject& AddValue(const FString& Key, int32 Value); // Set a property as a number. FMatureJsonObject& AddValue(const FString& Key, double Value); // Set a property as a string. FMatureJsonObject& AddValue(const FString& Key, const TCHAR* Value); // Set a property as a string. FMatureJsonObject& AddValue(const FString& Key, const FString& Value); // Set a property as a date/time. FMatureJsonObject& AddValue(const FString& Key, const FDateTime& Value); // Set a property as a GUID. FMatureJsonObject& AddValue(const FString& Key, const FGuid& Value); // Set a property as a color. FMatureJsonObject& AddValue(const FString& Key, const FColor& Value); // Set a property as a linear color. FMatureJsonObject& AddValue(const FString& Key, const FLinearColor& Value); // Set a property as a rotator. FMatureJsonObject& AddValue(const FString& Key, const FRotator& Value); // Set a property as a transform. FMatureJsonObject& AddValue(const FString& Key, const FTransform& Value); // Set a property as a vector. FMatureJsonObject& AddValue(const FString& Key, const FVector& Value); // Set a property as a JSON value. FMatureJsonObject& AddValue(const FString& Key, const FMatureJsonValue& Value); // Set a property as a JSON object. FMatureJsonObject& AddValue(const FString& Key, const FMatureJsonObject& Value); // Set a property as a JSON array. FMatureJsonObject& AddValue(const FString& Key, const FMatureJsonList& Value); // Set a property as an array of JSON values. FMatureJsonObject& AddValue(const FString& Key, const TArray& Value); // Set a property as a map of JSON values. FMatureJsonObject& AddValue(const FString& Key, const TMap& Value); // add a property as a list. FMatureJsonList AddList(const FString& Key); // add a property as a object. FMatureJsonObject AddObject(const FString& Key); // FMatureJsonValue AddValue(const FString& key); TArray GetKeys() const; void GetValue(FLinearColor& value); void GetValue(FRotator& value); void GetValue(FTransform& value); void GetValue(FVector& value); bool GetValue(const FString& Key, bool& ) const; bool GetValue(const FString& Key, float&) const; bool GetValue(const FString& Key, uint32&) const; bool GetValue(const FString& Key, int32&) const; bool GetValue(const FString& Key, uint64&) const; bool GetValue(const FString& Key, int64&) const; bool GetValue(const FString& Key, double&) const; bool GetValue(const FString& Key, FString&) const; bool GetValue(const FString& Key, FGuid&) const; bool GetValue(const FString& Key, FColor&) const; bool GetValue(const FString& Key, FDateTime&) const; bool GetValue(const FString& Key, FLinearColor&) const; bool GetValue(const FString& Key, FRotator&) const; bool GetValue(const FString& Key, FTransform&) const; bool GetValue(const FString& Key, FVector&) const; bool GetValue(const FString& Key, FMatureJsonValue&) const; bool GetValue(const FString& Key, FMatureJsonObject&) const; bool GetValue(const FString& Key, FMatureJsonList&) const; FMatureJsonValue ToValue(const FString& Key) const; FMatureJsonObject ToObject(const FString& Key) const; FMatureJsonList ToList(const FString& Key) const; FMatureJsonObject& operator=(const FMatureJsonObject& Value); TSharedPtr Document(); TSharedPtr Document()const; protected: class ObjectWrap { public: ObjectWrap(); //ObjectWrap(TSharedPtr Doc); ObjectWrap(TSharedPtr Doc, const mature::Object& Ref); ObjectWrap(TSharedPtr Doc, const mature::Object&& Ref); mature::MemberIterator Begin(); mature::MemberIterator End(); private: TSharedPtr Document; mature::Object Object; friend struct FMatureJsonObject; friend struct FMatureJsonObjectIterator; }; TSharedPtr ObjectPtr; FMatureJsonValue AddKey(const FString& key) ; inline mature::Object& Object(); inline mature::Object& Object() const; inline mature::Allocator& GetAllocator(); inline mature::Allocator& GetAllocator()const; private: friend struct FMatureJsonList; friend struct FMatureJsonValue; friend struct FMatureJsonObjectIterator; }; USTRUCT(BlueprintType, meta = (DisplayName = "Mature JSON|Object Iterator")) struct MATUREJSON_API FMatureJsonObjectIterator { GENERATED_USTRUCT_BODY() public: FMatureJsonObjectIterator(); FMatureJsonObjectIterator(const FMatureJsonObject& Value); FMatureJsonObjectIterator& Begin(); FMatureJsonObjectIterator& End(); bool IsValid()const; void Next(int step = 1); FString Key() ; FMatureJsonValue Value(); FString Key() const; FMatureJsonValue Value()const; FMatureJsonObjectIterator& operator++(); FMatureJsonObjectIterator& operator--(); FMatureJsonObjectIterator& operator++(int); FMatureJsonObjectIterator& operator--(int); FMatureJsonObjectIterator& operator=(const FMatureJsonObject& Value); FMatureJsonObjectIterator& operator=(const FMatureJsonObjectIterator& Value); private: TSharedPtr ObjectPtr; mature::MemberIterator Iterator; };