5#include "Logging/LogMacros.h"
6#include "UObject/UnrealType.h"
7#include "Misc/FileHelper.h"
8#include "UObject/TextProperty.h"
44 bool bInDontWriteEmptyContainer =
true);
49 void Write(
const UStruct* StructDefinition,
const void*
Object)
override;
57 return FFileHelper::SaveStringToFile(ConfigText, *FileName, FFileHelper::EEncodingOptions::ForceUTF8WithoutBOM);
67 void WriteComplexToString(
const UStruct* StructDefinition,
70 const FString& PreString,
71 const FString& PostString,
72 bool bContainerElement,
76 void WriteComplexMembersToString(
const UStruct* StructDefinition,
78 const FString& PreString,
79 const FString& PostString,
82 bool WritePropertyToString(
const FNYProperty* Property,
84 bool bContainerElement,
85 const FString& PreString,
86 const FString& PostString,
91 bool WritePrimitiveElementToString(
const FNYProperty* Property,
93 bool bContainerElement,
94 const FString& PreString,
95 const FString& PostString,
98 bool WritePrimitiveArrayToString(
const FNYProperty* Property,
100 const FString& PreString,
101 const FString& PostString,
104 bool WriteComplexElementToString(
const FNYProperty* Property,
106 bool bContainerElement,
107 const FString& PreString,
108 const FString& PostString,
112 bool WriteComplexArrayToString(
const FNYProperty* Property,
114 const FString& PreString,
115 const FString& PostString,
120 const FString& PreString,
121 const FString& PostString,
126 const FString& PreString,
127 const FString& PostString,
132 bool IsPrimitiveContainer(
const FNYProperty* Property);
134 bool WouldWriteNonPrimitive(
const UStruct* StructDefinition,
const void* Owner);
136 const UStruct* GetComplexType(
const FNYProperty* Property);
140 FString GetNameWithoutPrefix(
const FNYProperty* StructDefinition,
const UObject* ObjectPtr =
nullptr);
141 FString GetStringWithoutPrefix(
const FString&
String);
145 template <
typename PropertyType,
typename VariableType>
148 bool bContainerElement,
149 std::function<FString(
const VariableType&)> GetAsString,
150 const FString& PreString,
151 const FString& PostString,
154 const PropertyType* CastedProperty = FNYReflectionHelper::CastProperty<PropertyType>(Property);
155 if (CastedProperty !=
nullptr)
157 Target += PreString +
158 (bContainerElement ?
"" : (CastedProperty->GetName() +
" ")) +
168 template <
typename PropertyType,
typename VariableType>
171 std::function<FString(
const VariableType&)> ToString,
172 const FString& PreString,
173 const FString& PostString,
176 if (FNYReflectionHelper::CastProperty<PropertyType>(ArrayProp->Inner) ==
nullptr)
181 const TArray<VariableType>* ArrayPtr = ArrayProp->ContainerPtrToValuePtr<TArray<VariableType>>(
Object);
182 if (ArrayPtr ==
nullptr)
189 const TArray<VariableType>
Array = *ArrayPtr;
190 if (
Array.Num() == 0 && bDontWriteEmptyContainer)
196 FString SubPreString = PreString;
197 for (int32 i = 0; i < ArrayProp->GetName().Len() + 3; ++i)
203 Target += PreString + ArrayProp->GetName() +
" {" + (bLinePerItem ? EOL_String :
" ");
206 for (int32 i = 0; i <
Array.Num(); ++i)
210 Target += SubPreString + ToString(
Array[i]) + EOL;
214 Target += ToString(
Array[i]) +
" ";
219 Target += (bLinePerItem ? PreString :
"") +
"}" + PostString;
225 template <
typename PropertyType,
typename VariableType>
228 bool bContainerElement,
229 std::function<FString(
const VariableType&)> GetAsString,
230 const FString& PreString,
231 const FString& PostString,
234 const PropertyType* CastedProperty = FNYReflectionHelper::CastProperty<PropertyType>(Property);
235 if (CastedProperty !=
nullptr)
237 Target += PreString +
238 (bContainerElement ?
"" : (CastedProperty->GetName() +
" ")) +
250 return Original.Replace(EOL_CRLF, EOL_LF, ESearchCase::IgnoreCase);
260 static const FString EOL_String;
262 FString ConfigText =
"";
264 const void* TopLevelObjectPtr =
nullptr;
269 const std::function<FString(
const bool&)> BoolToString = [](
const bool& bBool) -> FString
271 return bBool ?
"True" :
"False";
274 const std::function<FString(
const int64&)> IntToString = [](
const int64& IntVal) -> FString
276 return FString::Printf(TEXT(
"%lld"), IntVal);
279 const std::function<FString(
const float&)> FloatToString = [](
const float& FloatVal) -> FString
281 return FString::SanitizeFloat(FloatVal);
284 const std::function<FString(
const FString&)> StringToString = [](
const FString&
String) -> FString
286 return FString(
"\"") + NormalizeEndlines(
String) +
"\"";
289 const std::function<FString(
const FName&)> NameToString = [](
const FName&
Name) -> FString
291 return FString(
"\"") + NormalizeEndlines(
Name.ToString()) +
"\"";
294 const std::function<FString(
const FText&)> TextToString = [](
const FText& Text) -> FString
296 return FString(
"\"") + NormalizeEndlines(Text.ToString()) +
"\"";
DECLARE_LOG_CATEGORY_EXTERN(LogDlgConfigWriter, Log, All)
UArrayProperty FNYArrayProperty
static FString NormalizeEndlines(const FString &Original)
bool WritePrimitiveToStringTemplated(const FNYProperty *Property, const void *Object, bool bContainerElement, std::function< FString(const VariableType &)> GetAsString, const FString &PreString, const FString &PostString, FString &Target)
const bool bDontWriteEmptyContainer
bool ExportToFile(const FString &FileName) override
static const TCHAR * EOL_LF
bool WritePrimitiveElementToStringTemplated(const FNYProperty *Property, const void *Object, bool bContainerElement, std::function< FString(const VariableType &)> GetAsString, const FString &PreString, const FString &PostString, FString &Target)
const FString & GetAsString() const override
const FString ComplexNamePrefix
static const TCHAR * EOL_CRLF
bool WritePrimitiveArrayToStringTemplated(const FNYArrayProperty *ArrayProp, const void *Object, std::function< FString(const VariableType &)> ToString, const FString &PreString, const FString &PostString, FString &Target)
virtual const FString & GetAsString() const =0
virtual void Write(const UStruct *StructDefinition, const void *Object)=0
static bool CanWriteOneLinePerItem(const FNYProperty *Property)