7#include "CodeGenerator.h"
27 template<
typename Lambda>
40 template<
typename Lambda>
41 CodeFileGenerator(
const FString& Path,
const bool bHeader, Lambda ContentGenerator);
51 void Line(
const FString&
Line =
"",
const bool bSemicolon =
false,
const bool bIndent =
true,
const int IndentOffset = 0);
58 void Comment(
const FString& Text);
91 template<
typename Lambda>
92 void Block(
const bool bIndent, Lambda Content,
const bool bSemicolonAtEnd =
false);
104 template<
typename Lambda>
105 void Class(
const FString& Classname,
const FString&
Comment,
const bool bUClass, Lambda Content,
const FString& UClassSpecifiers =
"BlueprintType");
117 template<
typename Lambda>
118 void Struct(
const FString& Structname,
const FString&
Comment,
const bool bUStruct, Lambda Content,
const FString& InlineDeclaration =
"");
129 template<
typename Lambda>
130 void UInterface(
const FString& Classname,
const FString& UInterfaceSpecifiers,
const FString&
Comment, Lambda Content);
141 template<
typename Type>
142 void Enum(
const FString& Enumname,
const FString&
Comment,
const bool bUEnum, TArray<Type> Values);
156 void Variable(
const FString& Type,
const FString& Name,
const FString& Value =
"",
const FString&
Comment =
"",
157 const bool bUProperty =
false,
const FString& UPropertySpecifiers =
"VisibleAnywhere, BlueprintReadOnly");
172 template<
typename Lambda>
173 void Method(
const FString& ReturnType,
const FString& Name,
const FString& Parameters =
"", Lambda Definition =
nullptr,
const FString&
Comment =
"",
174 const bool bUFunction =
false,
const FString& UFunctionSpecifiers =
"",
const FString& MethodSpecifiers =
"");
180 FString FileContent =
"";
183 uint8 BlockCount = 0;
188 void PushIndent() { ++IndentCount; }
193 void PopIndent() { IndentCount = FMath::Max(0, IndentCount - 1); }
200 void StartBlock(
const bool bIndent =
true);
208 void EndBlock(
const bool bUnindent =
true,
const bool bSemicolon =
false);
218 void StartClass(
const FString& Classname,
const FString&
Comment,
const bool bUClass,
const FString& UClassSpecifiers =
"BlueprintType");
223 void EndClass() { EndBlock(
true,
true); }
232 void StartStruct(
const FString& Structname,
const FString&
Comment,
const bool bUStruct);
239 void EndStruct(
const FString& InlineDeclaration);
246 void AddEnumEntry(FString Name);
254 template <
typename TNameValuePair>
255 void AddEnumEntry(TNameValuePair Pair);
262 static FString GetExportMacro();
267 void WriteToFile()
const;
275 FString SplitName(
const FString& Name);
281template<
typename Lambda>
302template <
typename Lambda>
305 Line(
"// articy Software GmbH & Co. KG");
306 Comment(
"This code file was generated by ArticyImporter. Changes to this file will get lost once the code is regenerated.");
311 Line(
"#pragma once");
316 if (ensure(!std::is_null_pointer<Lambda>::value))
317 ContentGenerator(
this);
330template <
typename Lambda>
338 EndBlock(bIndent, bSemicolonAtEnd);
351template <
typename Lambda>
354 StartClass(Classname,
Comment, bUClass, UClassSpecifiers);
372template <
typename Lambda>
375 StartStruct(Structname,
Comment, bUStruct);
380 EndStruct(InlineDeclaration);
392template <
typename Lambda>
397 Line(FString::Printf(TEXT(
"UINTERFACE(%s)"), *UInterfaceSpecifiers));
398 Line(FString::Printf(TEXT(
"class U%s : public UInterface { GENERATED_BODY() };"), *Classname));
399 Class(
"I" + Classname,
"",
false, [&]
401 Line(
"GENERATED_BODY()");
418template <
typename Type>
422 Line(
"UENUM(BlueprintType)");
425 StartClass(Enumname + (bUEnum ?
" : uint8" :
""),
Comment,
false);
428 for (
auto val : Values)
439inline void CodeFileGenerator::AddEnumEntry(FString Name)
441 Line(FString::Printf(TEXT(
"%s,"), *Name));
450template <
typename TNameValuePair>
451void CodeFileGenerator::AddEnumEntry(TNameValuePair Pair)
453 Line(FString::Printf(TEXT(
"%s = %d,"), *Pair.Name, Pair.Value));
471template<
typename Lambda>
472void CodeFileGenerator::Method(
const FString& ReturnType,
const FString& Name,
const FString& Parameters, Lambda Definition,
const FString&
Comment,
const bool bUFunction,
const FString& UFunctionSpecifiers,
const FString& MethodSpecifiers)
474 if (!ensure(!Name.IsEmpty()))
484 constexpr auto hasDefinition = !std::is_null_pointer<Lambda>::value;
488 Line(FString::Printf(TEXT(
"%s %s(%s) %s"), *ReturnType, *Name, *Parameters, *MethodSpecifiers), !hasDefinition);
492 Block(
true, Definition,
false);
void Class(const FString &Classname, const FString &Comment, const bool bUClass, Lambda Content, const FString &UClassSpecifiers="BlueprintType")
Adds a class definition with optional UCLASS macro.
Definition CodeFileGenerator.h:352
void Variable(const FString &Type, const FString &Name, const FString &Value="", const FString &Comment="", const bool bUProperty=false, const FString &UPropertySpecifiers="VisibleAnywhere, BlueprintReadOnly")
Adds a variable definition, optionally as UPROPERTY.
Definition CodeFileGenerator.cpp:46
void Method(const FString &ReturnType, const FString &Name, const FString &Parameters="", Lambda Definition=nullptr, const FString &Comment="", const bool bUFunction=false, const FString &UFunctionSpecifiers="", const FString &MethodSpecifiers="")
Adds a method definition, optionally as UFUNCTION.
Definition CodeFileGenerator.h:472
void SafeExecute(Lambda Lamb)
Executes a lambda function safely.
Definition CodeFileGenerator.h:282
void UPropertyMacro(const FString &Specifiers)
Adds a UPROPERTY macro to the file content.
Definition CodeFileGenerator.cpp:36
CodeFileGenerator(const FString &Path, const bool bHeader, Lambda ContentGenerator)
Creates a new code file generator with default lines and executes a content generator.
Definition CodeFileGenerator.h:303
void Line(const FString &Line="", const bool bSemicolon=false, const bool bIndent=true, const int IndentOffset=0)
Adds a line to the file content.
Definition CodeFileGenerator.cpp:14
void Comment(const FString &Text)
Adds a comment to the file content.
Definition CodeFileGenerator.cpp:26
void Struct(const FString &Structname, const FString &Comment, const bool bUStruct, Lambda Content, const FString &InlineDeclaration="")
Adds a struct definition with optional USTRUCT macro.
Definition CodeFileGenerator.h:373
void Enum(const FString &Enumname, const FString &Comment, const bool bUEnum, TArray< Type > Values)
Adds an enum definition with optional UENUM macro.
Definition CodeFileGenerator.h:419
void UInterface(const FString &Classname, const FString &UInterfaceSpecifiers, const FString &Comment, Lambda Content)
Adds a UINTERFACE definition with corresponding interface class.
Definition CodeFileGenerator.h:393
void AccessModifier(const FString &Text)
Adds an access modifier with optional colon.
Definition CodeFileGenerator.cpp:31
void UFunctionMacro(const FString &Specifiers)
Adds a UFUNCTION macro to the file content.
Definition CodeFileGenerator.cpp:41
void Block(const bool bIndent, Lambda Content, const bool bSemicolonAtEnd=false)
Adds a block of code with optional indentation and semicolon.
Definition CodeFileGenerator.h:331
Manages the generation, compilation, and asset creation for Articy-imported data.
Definition CodeGenerator.h:19