A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
FDlgConfigParser Class Reference

#include <DlgConfigParser.h>

Inheritance diagram for FDlgConfigParser:
[legend]

Public Member Functions

 FDlgConfigParser (const FString &FilePath, const FString &InPreTag)
 
 FDlgConfigParser (const FString InPreTag="")
 
void InitializeParser (const FString &FilePath) override
 
void InitializeParserFromString (const FString &Text) override
 
bool IsLogVerbose () const
 
bool IsValidFile () const override
 
void ReadAllProperty (const UStruct *ReferenceClass, void *TargetObject, UObject *DefaultObjectOuter=nullptr) override
 
bool ReadProperty (const UStruct *ReferenceClass, void *TargetObject, UObject *DefaultObjectOuter=nullptr)
 
void ResetParser ()
 
void SetLogVerbose (bool bValue)
 

Protected Member Functions

const UClass * GetChildClassFromName (const UClass *ParentClass, const FString &Name)
 

Static Protected Member Functions

static UObjectCreateNewUObject (const UClass *StructDefinition, UObject *ObjectOuter)
 

Protected Attributes

bool bLogVerbose = false
 
TArray< UClass * > StructCache
 

Private Member Functions

bool CheckIfBlockEnd (const FString &BlockName)
 
bool CompareToActiveWord (const FString &StringToCompare) const
 
bool FindNextWord ()
 
bool FindNextWord (const FString &ExpectedStuff)
 
bool FindNextWordAndCheckIfBlockEnd (const FString &BlockName)
 
bool FindNextWordAndCheckIfBlockStart (const FString &BlockName)
 
int32 GetActiveLineNumber () const
 
FString GetActiveWord () const
 
bool GetActiveWordAsFloat (float &FloatValue) const
 
bool GetAsBool () const
 
float GetAsFloat () const
 
int32 GetAsInt32 () const
 
int64 GetAsInt64 () const
 
FName GetAsName () const
 
FString GetAsString () const
 
FText GetAsText () const
 
bool HasValidWord () const
 
bool IsActualWordString () const
 
bool IsNextWordString () const
 
void * OnInitObject (void *ValuePtr, const UClass *ChildClass, UObject *OuterInit)
 
void OnInvalidValue (const FString &PropType) const
 
template<typename PropertyType >
bool ReadComplexProperty (void *Target, FNYProperty *Property, const UStruct *ReferenceType, std::function< void *(void *, const UClass *, UObject *)> OnInitValue, UObject *Outer)
 
bool ReadMap (void *TargetObject, FNYMapProperty &Property, UObject *DefaultObjectOuter)
 
template<typename Type , typename PropertyType >
bool ReadPrimitiveProperty (void *Target, FNYProperty *PropertyBase, std::function< Type()> OnGetAsValue, const FString &TypeName, bool bCanBeEmpty)
 
bool ReadPurePropertyBlock (void *TargetObject, const UStruct *ReferenceClass, bool bBlockStartAlreadyRead=false, UObject *DefaultObjectOuter=nullptr)
 
bool ReadSet (void *TargetObject, FNYSetProperty &Property, UObject *DefaultObjectOuter)
 
const UClass * SmartGetPropertyClass (FNYProperty *Property, const FString &TypeName)
 
bool TryToReadEnum (void *TargetObject, FNYProperty *PropertyBase)
 
bool TryToReadPrimitiveProperty (void *Target, FNYProperty *PropertyBase)
 

Static Private Member Functions

static FString ConstructConfigFile (const UStruct *ReferenceType, void *SourceObject)
 
static void ConstructConfigFileInternal (const UStruct *ReferenceType, int32 TabCount, void *SourceObject, FString &OutString)
 

Private Attributes

bool bActiveIsString = false
 
bool bHasNullptr = false
 
bool bHasValidWord = false
 
FString FileName = ""
 
int32 From = 0
 
int32 Len = 0
 
const FString PreTag
 
FString String = ""
 

Detailed Description

Because there is always another config format Parser can be used to process the config word by word 'word' is defined here as the thing between whitespaces '{' and '}' are exceptions: they can be in block and treated separately as first character recursively (e.g. "}}}}" is valid but "Name}" is not Default functionality can read a whole data structure from the proper config format Supported Primitives: FString, FName, int32, bool, float Supported complex types: Struct, Class Supported containers: Array(*), Map (Key: Primitive + Struct, Value: Primitive + Struct), Set (Primitive) Enum support: limited pure enum array is not supported (enum can be a member in a struct which is in an array, but it can't be in an array directly) enum set, enum in map: NOT IMPLEMENTED

Heterogenous Collections are also supported (e.g. TArray<UObject*>)

Definition at line 30 of file DlgConfigParser.h.

Constructor & Destructor Documentation

◆ FDlgConfigParser() [1/2]

FDlgConfigParser::FDlgConfigParser ( const FString InPreTag = "")

Creates empty parser Call ReinitializeParser() on it to parse a file It is better to use a single parser for more files from the same type if those contain dynamic arrays, because it has to check all class names for the first time for each class

Definition at line 17 of file DlgConfigParser.cpp.

◆ FDlgConfigParser() [2/2]

FDlgConfigParser::FDlgConfigParser ( const FString & FilePath,
const FString & InPreTag )

Creates the parser and finds the first word

Parameters
FilePathpath to the text file the parser will parse
InPreTagOptional pretag added at the front of structs and classes

Definition at line 23 of file DlgConfigParser.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ CheckIfBlockEnd()

bool FDlgConfigParser::CheckIfBlockEnd ( const FString & BlockName)
private

Checks the active word if it is a block end character ("}") Warning is only printed if the end of file is reached @Return Whether the active word is "}"

Definition at line 388 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CompareToActiveWord()

bool FDlgConfigParser::CompareToActiveWord ( const FString & StringToCompare) const
private

Compares the input string with the active word This function is CASE SENSITIVE

Returns
Whether the word and the strings are equal

Definition at line 400 of file DlgConfigParser.cpp.

Here is the caller graph for this function:

◆ ConstructConfigFile()

FString FDlgConfigParser::ConstructConfigFile ( const UStruct * ReferenceType,
void * SourceObject )
staticprivate

Creates a config string from the given top level object WARNING: it exports every non-transient property from the supported types (check the class constructor)

Parameters
ReferenceTypeUStruct (or UClass) of SourceObject
SourceObjectpointer to the object instance the function will copy to config
Returns
the constructed config string

Definition at line 223 of file DlgConfigParser.cpp.

Here is the call graph for this function:

◆ ConstructConfigFileInternal()

void FDlgConfigParser::ConstructConfigFileInternal ( const UStruct * ReferenceType,
int32 TabCount,
void * SourceObject,
FString & OutString )
staticprivate
Parameters
TabCountamount of tabs at the begining of each new line
OutStringInOut param, new lines will be added
Returns
the constructed config string

Definition at line 451 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateNewUObject()

static UObject * IDlgParser::CreateNewUObject ( const UClass * StructDefinition,
UObject * ObjectOuter )
inlinestaticprotectedinherited

Default way to create new objects

Definition at line 70 of file IDlgParser.h.

Here is the caller graph for this function:

◆ FindNextWord() [1/2]

bool FDlgConfigParser::FindNextWord ( )
private

Jumps to the next word in the parsed config

Returns
Whether a new word was found (false -> end of file)

Definition at line 256 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindNextWord() [2/2]

bool FDlgConfigParser::FindNextWord ( const FString & ExpectedStuff)
private

Jumps to the next word in the parsed config warning is printed on eof based on input

Returns
Whether a new word was found (false -> end of file)

Definition at line 352 of file DlgConfigParser.cpp.

Here is the call graph for this function:

◆ FindNextWordAndCheckIfBlockEnd()

bool FDlgConfigParser::FindNextWordAndCheckIfBlockEnd ( const FString & BlockName)
private

Jumps to the next word in the parsed config, and checks if it is a block end character ("}") Warning is only printed if the end of file is reached

Returns
Whether a new word "}" was found

Definition at line 376 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindNextWordAndCheckIfBlockStart()

bool FDlgConfigParser::FindNextWordAndCheckIfBlockStart ( const FString & BlockName)
private

Jumps to the next word in the parsed config, and checks if it is a block start character ("{") warning is printed if the word is not "{" or if the end of file is reached

Returns
Whether a new word "{" was found

Definition at line 364 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetActiveLineNumber()

int32 FDlgConfigParser::GetActiveLineNumber ( ) const
private

Calculates the line count for the current word TODO: could be counted on the fly

Returns
Active line index, or INDEX_NONE if there is no valid word

Definition at line 422 of file DlgConfigParser.cpp.

Here is the caller graph for this function:

◆ GetActiveWord()

FString FDlgConfigParser::GetActiveWord ( ) const
inlineprivate

Should be avoided whenever possible (use CompareToActiveWord)

Returns
the active word, or an empty string if there isn't any

Definition at line 166 of file DlgConfigParser.h.

Here is the caller graph for this function:

◆ GetActiveWordAsFloat()

bool FDlgConfigParser::GetActiveWordAsFloat ( float & FloatValue) const
private
Parameters
FloatValueout float value if the call succeeds
Returns
the active word converted, or an empty string if there isn't any

Definition at line 205 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetAsBool()

bool FDlgConfigParser::GetAsBool ( ) const
private

Definition at line 700 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetAsFloat()

float FDlgConfigParser::GetAsFloat ( ) const
private

Definition at line 711 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetAsInt32()

int32 FDlgConfigParser::GetAsInt32 ( ) const
private

Definition at line 719 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetAsInt64()

int64 FDlgConfigParser::GetAsInt64 ( ) const
private

Definition at line 731 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetAsName()

FName FDlgConfigParser::GetAsName ( ) const
private

Definition at line 743 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetAsString()

FString FDlgConfigParser::GetAsString ( ) const
private

Definition at line 754 of file DlgConfigParser.cpp.

Here is the caller graph for this function:

◆ GetAsText()

FText FDlgConfigParser::GetAsText ( ) const
private

Definition at line 763 of file DlgConfigParser.cpp.

Here is the caller graph for this function:

◆ GetChildClassFromName()

const UClass * IDlgParser::GetChildClassFromName ( const UClass * ParentClass,
const FString & Name )
inlineprotectedinherited

Searches the proper not abstract class

Parameters
ParentClassthe class we are looking for has to inherit from this class
Namethe name of the class we are looking for (without engine pretags, e.g. Actor for AActor)
Returns
the class, or nullptr if it does not exist

Definition at line 45 of file IDlgParser.h.

Here is the caller graph for this function:

◆ HasValidWord()

bool FDlgConfigParser::HasValidWord ( ) const
inlineprivate

Definition at line 160 of file DlgConfigParser.h.

Here is the caller graph for this function:

◆ InitializeParser()

void FDlgConfigParser::InitializeParser ( const FString & FilePath)
overridevirtual

Initializes the parser with the specified FilePath.

Implements IDlgParser.

Definition at line 30 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeParserFromString()

void FDlgConfigParser::InitializeParserFromString ( const FString & Text)
overridevirtual

Initializes the parser with the specified input string

Reimplemented from IDlgParser.

Definition at line 52 of file DlgConfigParser.cpp.

Here is the call graph for this function:

◆ IsActualWordString()

bool FDlgConfigParser::IsActualWordString ( ) const
private

Checks if the actual word begins with '"' or not

Definition at line 249 of file DlgConfigParser.cpp.

Here is the caller graph for this function:

◆ IsLogVerbose()

bool IDlgParser::IsLogVerbose ( ) const
inlineinherited

Definition at line 33 of file IDlgParser.h.

◆ IsNextWordString()

bool FDlgConfigParser::IsNextWordString ( ) const
private

Checks if the next parsed word begins with '"' or not

Definition at line 231 of file DlgConfigParser.cpp.

Here is the caller graph for this function:

◆ IsValidFile()

bool FDlgConfigParser::IsValidFile ( ) const
inlineoverridevirtual

Is the parsed file valid?

Implements IDlgParser.

Definition at line 54 of file DlgConfigParser.h.

◆ OnInitObject()

void * FDlgConfigParser::OnInitObject ( void * ValuePtr,
const UClass * ChildClass,
UObject * OuterInit )
private

Definition at line 648 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnInvalidValue()

void FDlgConfigParser::OnInvalidValue ( const FString & PropType) const
private

Definition at line 687 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadAllProperty()

void FDlgConfigParser::ReadAllProperty ( const UStruct * ReferenceClass,
void * TargetObject,
UObject * DefaultObjectOuter = nullptr )
overridevirtual

Reads all property from the config file.

Parameters
ReferenceClassUStruct (or UClass) of the TargetObject
TargetObjectpointer to the object instance the function will modify based on the config values
DefaultObjectOuterOuter used for UObject construction if necessary

Implements IDlgParser.

Definition at line 63 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadComplexProperty()

template<typename PropertyType >
bool FDlgConfigParser::ReadComplexProperty ( void * Target,
FNYProperty * Property,
const UStruct * ReferenceType,
std::function< void *(void *, const UClass *, UObject *)> OnInitValue,
UObject * Outer )
private

Tries to read a complex object from the config (object/struct)

Parameters
TargetThe struct/object whose properties are searched and modified based on the config string
Propertycan be a PropertyType or an ArrayProperty storing Type-s
ReferenceTypeThe uclass/ustruct of the object the function is supposed to read
OnInitValueCreates the complex type if necessary (void*: the newly created object, UClass: the type of the object or nullptr, UObject*: outer)
Outerthe object used as outer for uobject construction
Returns
true if the complex type was read properly

Definition at line 330 of file DlgConfigParser.h.

Here is the call graph for this function:

◆ ReadMap()

bool FDlgConfigParser::ReadMap ( void * TargetObject,
FNYMapProperty & Property,
UObject * DefaultObjectOuter )
private

Return value shows if it was read properly or not

Definition at line 584 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadPrimitiveProperty()

template<typename Type , typename PropertyType >
bool FDlgConfigParser::ReadPrimitiveProperty ( void * Target,
FNYProperty * PropertyBase,
std::function< Type()> OnGetAsValue,
const FString & TypeName,
bool bCanBeEmpty )
private

Tries to read the actual config value as a Type

Parameters
TargetThe struct/object whose properties are searched and modified based on the config string
PropertyBaseThe property - can be a TypeProperty or an ArrayProperty storing Type-s
OnGetAsValueFunction returning the actual word converted to Type
TypeNameThe name of the type for logs (e.g. "bool")
Returns
true if the property was a PropertyType or an array containging Type

Definition at line 272 of file DlgConfigParser.h.

Here is the call graph for this function:

◆ ReadProperty()

bool FDlgConfigParser::ReadProperty ( const UStruct * ReferenceClass,
void * TargetObject,
UObject * DefaultObjectOuter = nullptr )

Tries to read a property from the config starting from the current word If everything goes well the active word will be the first word after the property value If the initial active word wasn't a property the next word will be the active one (or eof)

Parameters
ReferenceClassUStruct (or UClass) of the TargetObject
TargetObjectpointer to the object instance the function will modify based on the config values
DefaultObjectOuterOuter used for UObject construction if necessary
Returns
Whether the word was interpreted successfully as a property or not

Definition at line 78 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadPurePropertyBlock()

bool FDlgConfigParser::ReadPurePropertyBlock ( void * TargetObject,
const UStruct * ReferenceClass,
bool bBlockStartAlreadyRead = false,
UObject * DefaultObjectOuter = nullptr )
private

Tries to read a block where each entry is a property a block is a '{', then properties, then '}'

Parameters
TargetObjectpointer to the object instance the function will modify based on the config values
ReferenceClassUStruct (or UClass) of the TargetObject
bBlockStartAlreadyReadif '{' is the actual word or the next
DefaultObjectOuterOuter used for UObject construction if necessary
Returns
Whether there was any syntax error or not

Definition at line 181 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadSet()

bool FDlgConfigParser::ReadSet ( void * TargetObject,
FNYSetProperty & Property,
UObject * DefaultObjectOuter )
private

Return value shows if it was read properly or not

Definition at line 547 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ResetParser()

void FDlgConfigParser::ResetParser ( )

Definition at line 69 of file DlgConfigParser.cpp.

Here is the call graph for this function:

◆ SetLogVerbose()

void IDlgParser::SetLogVerbose ( bool bValue)
inlineinherited

Definition at line 34 of file IDlgParser.h.

◆ SmartGetPropertyClass()

const UClass * FDlgConfigParser::SmartGetPropertyClass ( FNYProperty * Property,
const FString & TypeName )
private

gets the UClass from an UObject or from an array of UObjects

Definition at line 662 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TryToReadEnum()

bool FDlgConfigParser::TryToReadEnum ( void * TargetObject,
FNYProperty * PropertyBase )
private

Definition at line 499 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TryToReadPrimitiveProperty()

bool FDlgConfigParser::TryToReadPrimitiveProperty ( void * Target,
FNYProperty * PropertyBase )
private

Tries to read the actual config value as a primitive property (all supported primitive is checked)

Definition at line 464 of file DlgConfigParser.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ bActiveIsString

bool FDlgConfigParser::bActiveIsString = false
private

used to skip the closing '"'

Definition at line 267 of file DlgConfigParser.h.

◆ bHasNullptr

bool FDlgConfigParser::bHasNullptr = false
private

Definition at line 264 of file DlgConfigParser.h.

◆ bHasValidWord

bool FDlgConfigParser::bHasValidWord = false
private

Definition at line 261 of file DlgConfigParser.h.

◆ bLogVerbose

bool IDlgParser::bLogVerbose = false
protectedinherited

Definition at line 81 of file IDlgParser.h.

◆ FileName

FString FDlgConfigParser::FileName = ""
private

file path stored for log messages

Definition at line 250 of file DlgConfigParser.h.

◆ From

int32 FDlgConfigParser::From = 0
private

first character of active word

Definition at line 254 of file DlgConfigParser.h.

◆ Len

int32 FDlgConfigParser::Len = 0
private

length of active word

Definition at line 256 of file DlgConfigParser.h.

◆ PreTag

const FString FDlgConfigParser::PreTag
private

optional pretag before struct and class names

Definition at line 259 of file DlgConfigParser.h.

◆ String

FString FDlgConfigParser::String = ""
private

whole config stored in a string

Definition at line 252 of file DlgConfigParser.h.

◆ StructCache

TArray<UClass*> IDlgParser::StructCache
protectedinherited

each time a class is read it also cached here, so next time when it has to be found based on name it can be found faster

Definition at line 78 of file IDlgParser.h.


The documentation for this class was generated from the following files: