ArticyXImporter
ArticyXImporter for Unreal Engine
Loading...
Searching...
No Matches
CodeFileGenerator Class Reference

A class to generate and manage code files with convenience methods for generating code lines, comments, and more. More...

#include <CodeFileGenerator.h>

Public Member Functions

template<typename Lambda>
void SafeExecute (Lambda Lamb)
 Executes a lambda function safely.
template<typename Lambda>
 CodeFileGenerator (const FString &Path, const bool bHeader, Lambda ContentGenerator)
 Creates a new code file generator with default lines and executes a content generator.
void Line (const FString &Line="", const bool bSemicolon=false, const bool bIndent=true, const int IndentOffset=0)
 Adds a line to the file content.
void Comment (const FString &Text)
 Adds a comment to the file content.
void AccessModifier (const FString &Text)
 Adds an access modifier with optional colon.
void UPropertyMacro (const FString &Specifiers)
 Adds a UPROPERTY macro to the file content.
void UFunctionMacro (const FString &Specifiers)
 Adds a UFUNCTION macro to the file content.
template<typename Lambda>
void Block (const bool bIndent, Lambda Content, const bool bSemicolonAtEnd=false)
 Adds a block of code with optional indentation and semicolon.
template<typename Lambda>
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.
template<typename Lambda>
void Struct (const FString &Structname, const FString &Comment, const bool bUStruct, Lambda Content, const FString &InlineDeclaration="")
 Adds a struct definition with optional USTRUCT macro.
template<typename Lambda>
void UInterface (const FString &Classname, const FString &UInterfaceSpecifiers, const FString &Comment, Lambda Content)
 Adds a UINTERFACE definition with corresponding interface class.
template<typename Type>
void Enum (const FString &Enumname, const FString &Comment, const bool bUEnum, TArray< Type > Values)
 Adds an enum definition with optional UENUM macro.
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.
template<typename Lambda>
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.
template<>
void SafeExecute (nullptr_t Lamb)

Detailed Description

A class to generate and manage code files with convenience methods for generating code lines, comments, and more.

Holds a content string that can be written to a file and includes methods for generating code structures like classes and structs.

Constructor & Destructor Documentation

◆ CodeFileGenerator()

template<typename Lambda>
CodeFileGenerator::CodeFileGenerator ( const FString & Path,
const bool bHeader,
Lambda ContentGenerator )

Creates a new code file generator with default lines and executes a content generator.

Template constructor for CodeFileGenerator.

Adds default content such as copyright information and then calls WriteToFile.

Template Parameters
LambdaThe type of the content generator function.
Parameters
PathThe path to the file to be generated.
bHeaderWhether the file is a header file.
ContentGeneratorThe function generating the file content.

Adds default content, executes the content generator, and writes to file.

Template Parameters
LambdaThe type of the content generator function.
Parameters
PathThe path to the file to be generated.
bHeaderWhether the file is a header file.
ContentGeneratorThe function generating the file content.

Member Function Documentation

◆ AccessModifier()

void CodeFileGenerator::AccessModifier ( const FString & Text)

Adds an access modifier with optional colon.

Parameters
TextThe access modifier text.

◆ Block()

template<typename Lambda>
void CodeFileGenerator::Block ( const bool bIndent,
Lambda Content,
const bool bSemicolonAtEnd = false )

Adds a block of code with optional indentation and semicolon.

Template Parameters
LambdaThe type of the content function.
Parameters
bIndentWhether to indent the block.
ContentThe function generating the block content.
bSemicolonAtEndWhether to append a semicolon after the block.

◆ Class()

template<typename Lambda>
void CodeFileGenerator::Class ( const FString & Classname,
const FString & Comment,
const bool bUClass,
Lambda Content,
const FString & UClassSpecifiers = "BlueprintType" )

Adds a class definition with optional UCLASS macro.

Template Parameters
LambdaThe type of the content function.
Parameters
ClassnameThe name of the class.
CommentA comment describing the class.
bUClassWhether the class is a UCLASS.
ContentThe function generating the class content.
UClassSpecifiersThe specifiers for the UCLASS macro.

◆ Comment()

void CodeFileGenerator::Comment ( const FString & Text)

Adds a comment to the file content.

Parameters
TextThe comment text to add.

◆ Enum()

template<typename Type>
void CodeFileGenerator::Enum ( const FString & Enumname,
const FString & Comment,
const bool bUEnum,
TArray< Type > Values )

Adds an enum definition with optional UENUM macro.

Template Parameters
TypeThe type of the enum values.
Parameters
EnumnameThe name of the enum.
CommentA comment describing the enum.
bUEnumWhether the enum is a UENUM.
ValuesThe values of the enum.

◆ Line()

void CodeFileGenerator::Line ( const FString & Line = "",
const bool bSemicolon = false,
const bool bIndent = true,
const int IndentOffset = 0 )

Adds a line to the file content.

Parameters
LineThe line of code to add.
bSemicolonWhether to append a semicolon at the end of the line.
bIndentWhether to indent the line.
IndentOffsetThe number of additional indentations to apply.

◆ Method()

template<typename Lambda>
void CodeFileGenerator::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.

Template Parameters
LambdaThe type of the method definition function.
Parameters
ReturnTypeThe return type of the method.
NameThe name of the method.
ParametersThe parameters of the method.
DefinitionThe function defining the method.
CommentA comment describing the method.
bUFunctionWhether to add a UFUNCTION macro.
UFunctionSpecifiersThe specifiers for the UFUNCTION macro.
MethodSpecifiersAdditional specifiers for the method.

◆ SafeExecute()

template<typename Lambda>
void CodeFileGenerator::SafeExecute ( Lambda Lamb)

Executes a lambda function safely.

If the Lambda is nullptr (type nullptr_t), nothing happens.

Template Parameters
LambdaThe type of the lambda function to execute.
Parameters
LambThe lambda function to execute.

◆ Struct()

template<typename Lambda>
void CodeFileGenerator::Struct ( const FString & Structname,
const FString & Comment,
const bool bUStruct,
Lambda Content,
const FString & InlineDeclaration = "" )

Adds a struct definition with optional USTRUCT macro.

Template Parameters
LambdaThe type of the content function.
Parameters
StructnameThe name of the struct.
CommentA comment describing the struct.
bUStructWhether the struct is a USTRUCT.
ContentThe function generating the struct content.
InlineDeclarationAn optional inline declaration for the struct.

◆ UFunctionMacro()

void CodeFileGenerator::UFunctionMacro ( const FString & Specifiers)

Adds a UFUNCTION macro to the file content.

Parameters
SpecifiersThe specifiers for the UFUNCTION macro.

◆ UInterface()

template<typename Lambda>
void CodeFileGenerator::UInterface ( const FString & Classname,
const FString & UInterfaceSpecifiers,
const FString & Comment,
Lambda Content )

Adds a UINTERFACE definition with corresponding interface class.

Template Parameters
LambdaThe type of the content function.
Parameters
ClassnameThe name of the interface class.
UInterfaceSpecifiersThe specifiers for the UINTERFACE macro.
CommentA comment describing the interface.
ContentThe function generating the interface content.

◆ UPropertyMacro()

void CodeFileGenerator::UPropertyMacro ( const FString & Specifiers)

Adds a UPROPERTY macro to the file content.

Parameters
SpecifiersThe specifiers for the UPROPERTY macro.

◆ Variable()

void CodeFileGenerator::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.

Parameters
TypeThe type of the variable.
NameThe name of the variable.
ValueThe initial value of the variable.
CommentA comment describing the variable.
bUPropertyWhether to add a UPROPERTY macro.
UPropertySpecifiersThe specifiers for the UPROPERTY macro.

The documentation for this class was generated from the following files:
  • Source/ArticyEditor/Private/CodeGeneration/CodeFileGenerator.h
  • Source/ArticyEditor/Private/CodeGeneration/CodeFileGenerator.cpp