A Demo Project for the UnrealEngineSDK
|
#include <DlgConfigParser.h>
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 UObject * | CreateNewUObject (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 = "" |
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.
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::FDlgConfigParser | ( | const FString & | FilePath, |
const FString & | InPreTag ) |
Creates the parser and finds the first word
FilePath | path to the text file the parser will parse |
InPreTag | Optional pretag added at the front of structs and classes |
Definition at line 23 of file DlgConfigParser.cpp.
|
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.
|
private |
Compares the input string with the active word This function is CASE SENSITIVE
Definition at line 400 of file DlgConfigParser.cpp.
|
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)
ReferenceType | UStruct (or UClass) of SourceObject |
SourceObject | pointer to the object instance the function will copy to config |
Definition at line 223 of file DlgConfigParser.cpp.
|
staticprivate |
TabCount | amount of tabs at the begining of each new line |
OutString | InOut param, new lines will be added |
Definition at line 451 of file DlgConfigParser.cpp.
|
inlinestaticprotectedinherited |
Default way to create new objects
Definition at line 70 of file IDlgParser.h.
|
private |
Jumps to the next word in the parsed config
Definition at line 256 of file DlgConfigParser.cpp.
|
private |
Jumps to the next word in the parsed config warning is printed on eof based on input
Definition at line 352 of file DlgConfigParser.cpp.
|
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
Definition at line 376 of file DlgConfigParser.cpp.
|
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
Definition at line 364 of file DlgConfigParser.cpp.
|
private |
Calculates the line count for the current word TODO: could be counted on the fly
Definition at line 422 of file DlgConfigParser.cpp.
|
inlineprivate |
Should be avoided whenever possible (use CompareToActiveWord)
Definition at line 166 of file DlgConfigParser.h.
|
private |
FloatValue | out float value if the call succeeds |
Definition at line 205 of file DlgConfigParser.cpp.
|
private |
Definition at line 700 of file DlgConfigParser.cpp.
|
private |
Definition at line 711 of file DlgConfigParser.cpp.
|
private |
Definition at line 719 of file DlgConfigParser.cpp.
|
private |
Definition at line 731 of file DlgConfigParser.cpp.
|
private |
Definition at line 743 of file DlgConfigParser.cpp.
|
private |
|
private |
|
inlineprotectedinherited |
Searches the proper not abstract class
ParentClass | the class we are looking for has to inherit from this class |
Name | the name of the class we are looking for (without engine pretags, e.g. Actor for AActor) |
Definition at line 45 of file IDlgParser.h.
|
inlineprivate |
|
overridevirtual |
Initializes the parser with the specified FilePath.
Implements IDlgParser.
Definition at line 30 of file DlgConfigParser.cpp.
|
overridevirtual |
Initializes the parser with the specified input string
Reimplemented from IDlgParser.
Definition at line 52 of file DlgConfigParser.cpp.
|
private |
Checks if the actual word begins with '"' or not
Definition at line 249 of file DlgConfigParser.cpp.
|
inlineinherited |
Definition at line 33 of file IDlgParser.h.
|
private |
Checks if the next parsed word begins with '"' or not
Definition at line 231 of file DlgConfigParser.cpp.
|
inlineoverridevirtual |
|
private |
Definition at line 648 of file DlgConfigParser.cpp.
|
private |
Definition at line 687 of file DlgConfigParser.cpp.
|
overridevirtual |
Reads all property from the config file.
ReferenceClass | UStruct (or UClass) of the TargetObject |
TargetObject | pointer to the object instance the function will modify based on the config values |
DefaultObjectOuter | Outer used for UObject construction if necessary |
Implements IDlgParser.
Definition at line 63 of file DlgConfigParser.cpp.
|
private |
Tries to read a complex object from the config (object/struct)
Target | The struct/object whose properties are searched and modified based on the config string |
Property | can be a PropertyType or an ArrayProperty storing Type-s |
ReferenceType | The uclass/ustruct of the object the function is supposed to read |
OnInitValue | Creates the complex type if necessary (void*: the newly created object, UClass: the type of the object or nullptr, UObject*: outer) |
Outer | the object used as outer for uobject construction |
Definition at line 330 of file DlgConfigParser.h.
|
private |
Return value shows if it was read properly or not
Definition at line 584 of file DlgConfigParser.cpp.
|
private |
Tries to read the actual config value as a Type
Target | The struct/object whose properties are searched and modified based on the config string |
PropertyBase | The property - can be a TypeProperty or an ArrayProperty storing Type-s |
OnGetAsValue | Function returning the actual word converted to Type |
TypeName | The name of the type for logs (e.g. "bool") |
Definition at line 272 of file DlgConfigParser.h.
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)
ReferenceClass | UStruct (or UClass) of the TargetObject |
TargetObject | pointer to the object instance the function will modify based on the config values |
DefaultObjectOuter | Outer used for UObject construction if necessary |
Definition at line 78 of file DlgConfigParser.cpp.
|
private |
Tries to read a block where each entry is a property a block is a '{', then properties, then '}'
TargetObject | pointer to the object instance the function will modify based on the config values |
ReferenceClass | UStruct (or UClass) of the TargetObject |
bBlockStartAlreadyRead | if '{' is the actual word or the next |
DefaultObjectOuter | Outer used for UObject construction if necessary |
Definition at line 181 of file DlgConfigParser.cpp.
|
private |
Return value shows if it was read properly or not
Definition at line 547 of file DlgConfigParser.cpp.
void FDlgConfigParser::ResetParser | ( | ) |
|
inlineinherited |
Definition at line 34 of file IDlgParser.h.
|
private |
gets the UClass from an UObject or from an array of UObjects
Definition at line 662 of file DlgConfigParser.cpp.
|
private |
Definition at line 499 of file DlgConfigParser.cpp.
|
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.
|
private |
used to skip the closing '"'
Definition at line 267 of file DlgConfigParser.h.
|
private |
Definition at line 264 of file DlgConfigParser.h.
|
private |
Definition at line 261 of file DlgConfigParser.h.
|
protectedinherited |
Definition at line 81 of file IDlgParser.h.
|
private |
file path stored for log messages
Definition at line 250 of file DlgConfigParser.h.
|
private |
first character of active word
Definition at line 254 of file DlgConfigParser.h.
|
private |
length of active word
Definition at line 256 of file DlgConfigParser.h.
|
private |
optional pretag before struct and class names
Definition at line 259 of file DlgConfigParser.h.
|
private |
whole config stored in a string
Definition at line 252 of file DlgConfigParser.h.
|
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.