76 lines
2.3 KiB
C++
76 lines
2.3 KiB
C++
#pragma once
|
|
#include "ConfigCacheIni.h"
|
|
#include "Singleton/Singleton.h"
|
|
#include "CoreMinimal.h"
|
|
#include "DefaultValueHelper.h"
|
|
|
|
#define ARONA_CONFIG_GET_VALUE_FUNC(Type, Func) \
|
|
template<> \
|
|
inline bool FAronaConfig::GetValue(const FString& Section, const FString& Key, Type& Out) \
|
|
{ \
|
|
return Get().Config.Func(*Section, *Key, Out); \
|
|
}
|
|
|
|
#define ARONA_CONFIG_PARSE_STRING_FUNC(Type, Func) \
|
|
template<> \
|
|
inline bool FAronaConfig::ParseString(const FString& String, Type& Out) \
|
|
{ \
|
|
return FDefaultValueHelper::Func(String, Out); \
|
|
}
|
|
|
|
class FAronaConfig : public TSingleton<FAronaConfig>
|
|
{
|
|
public:
|
|
virtual void Init() override;
|
|
virtual void Release() override;
|
|
|
|
template<typename T>
|
|
static bool GetValue(const FString& Section, const FString& Key, T& Out);
|
|
|
|
template<typename T>
|
|
static bool ParseString(const FString& String, T& Out);
|
|
|
|
template<typename T>
|
|
static int32 GetValueArray(const FString& Section, const FString& Key, TArray<T>& Out)
|
|
{
|
|
TArray<FString> Temp;
|
|
const int32 Count = Get().Config.GetArray(*Section, *Key, Temp);
|
|
for (FString String : Temp)
|
|
{
|
|
T Value;
|
|
if (ParseString(String, Value))
|
|
{
|
|
Out.Add(Value);
|
|
}
|
|
}
|
|
return Count;
|
|
}
|
|
|
|
FConfigFile Config;
|
|
};
|
|
|
|
ARONA_CONFIG_GET_VALUE_FUNC(FString, GetString);
|
|
ARONA_CONFIG_GET_VALUE_FUNC(FText, GetText);
|
|
ARONA_CONFIG_GET_VALUE_FUNC(int32, GetInt);
|
|
ARONA_CONFIG_GET_VALUE_FUNC(float, GetFloat);
|
|
ARONA_CONFIG_GET_VALUE_FUNC(double, GetDouble);
|
|
ARONA_CONFIG_GET_VALUE_FUNC(int64, GetInt64);
|
|
ARONA_CONFIG_GET_VALUE_FUNC(bool, GetBool);
|
|
|
|
ARONA_CONFIG_PARSE_STRING_FUNC(int32, ParseInt);
|
|
ARONA_CONFIG_PARSE_STRING_FUNC(int64, ParseInt64);
|
|
ARONA_CONFIG_PARSE_STRING_FUNC(float, ParseFloat);
|
|
ARONA_CONFIG_PARSE_STRING_FUNC(double, ParseDouble);
|
|
ARONA_CONFIG_PARSE_STRING_FUNC(FVector3f, ParseVector);
|
|
ARONA_CONFIG_PARSE_STRING_FUNC(FVector3d, ParseVector);
|
|
ARONA_CONFIG_PARSE_STRING_FUNC(FVector2f, ParseVector2D);
|
|
ARONA_CONFIG_PARSE_STRING_FUNC(FVector2d, ParseVector2D);
|
|
ARONA_CONFIG_PARSE_STRING_FUNC(FVector4f, ParseVector4);
|
|
ARONA_CONFIG_PARSE_STRING_FUNC(FVector4d, ParseVector4);
|
|
ARONA_CONFIG_PARSE_STRING_FUNC(FRotator3f, ParseRotator);
|
|
ARONA_CONFIG_PARSE_STRING_FUNC(FRotator3d, ParseRotator);
|
|
ARONA_CONFIG_PARSE_STRING_FUNC(FLinearColor, ParseLinearColor);
|
|
ARONA_CONFIG_PARSE_STRING_FUNC(FColor, ParseColor);
|
|
|
|
#undef ARONA_CONFIG_PARSE_STRING_FUNC
|
|
#undef ARONA_CONFIG_GET_VALUE_FUNC |