9#include "ConfigCacheIni.h"
19 template <
typename TARGET,
typename SOURCE>
22 if ((source >= std::numeric_limits<TARGET>::lowest()) &&
23 (source <= std::numeric_limits<TARGET>::max())) {
24 target =
static_cast<TARGET
>(source);
26 UE_LOG(LogCarla, Error, TEXT(
"FIniFile: Type cast failed"));
41 ConfigFile.Read(FileName);
52 return ConfigFile.Combine(FileName);
57 ConfigFile.ProcessInputFileContents(INIFileContents);
62 return (ConfigFile.Num() > 0) && (ConfigFile.Find(Section) !=
nullptr);
67 if (!HasSection(Section)) {
68 ConfigFile.Add(Section, FConfigSection());
73 bool Write(
const FString &Filename)
75 return ConfigFile.Write(Filename);
91 void GetInt(
const TCHAR* Section,
const TCHAR* Key, T &Target)
const
94 if (ConfigFile.GetInt64(Section, Key, Value)) {
95 SafeCastTo<T>(Value, Target);
99 void GetString(
const TCHAR* Section,
const TCHAR* Key, FString &Target)
const
102 if (ConfigFile.GetString(Section, Key, Value)) {
107 void GetBool(
const TCHAR* Section,
const TCHAR* Key,
bool &Target)
const
110 if (ConfigFile.GetBool(Section, Key, Value)) {
115 void GetFloat(
const TCHAR* Section,
const TCHAR* Key,
float &Target,
const float Factor = 1.0f)
const
118 if (ConfigFile.GetString(Section, Key, Value)) {
119 Target = Factor * FCString::Atof(*Value);
123 void GetLinearColor(
const TCHAR* Section,
const TCHAR* Key, FLinearColor &Target)
const
126 if (ConfigFile.GetString(Section, Key, Value)) {
127 Target.InitFromString(Value);
137 void SetInt(
const TCHAR* Section,
const TCHAR* Key,
const int64 Value)
139 ConfigFile.SetInt64(Section, Key, Value);
142 void SetString(
const TCHAR* Section,
const TCHAR* Key,
const TCHAR* Value)
144 ConfigFile.SetString(Section, Key, Value);
147 void SetString(
const TCHAR* Section,
const TCHAR* Key,
const FString &Value)
149 SetString(Section, Key, *Value);
152 void SetBool(
const TCHAR* Section,
const TCHAR* Key,
const bool Value)
154 SetString(Section, Key, Value ? TEXT(
"True") : TEXT(
"False"));
157 void SetFloat(
const TCHAR* Section,
const TCHAR* Key,
const float Value)
159 SetString(Section, Key, FText::AsNumber(Value).ToString());
162 void SetLinearColor(
const TCHAR* Section,
const TCHAR* Key,
const FLinearColor &Value)
164 SetString(Section, Key, Value.ToString());
Wrapper around Unreal's INI file.
void SetLinearColor(const TCHAR *Section, const TCHAR *Key, const FLinearColor &Value)
const FConfigFile & GetFConfigFile() const
Retrieve Unreal's FConfigFile.
void ProcessInputFileContents(const FString &INIFileContents)
bool Combine(const FString &FileName)
bool Write(const FString &Filename)
Write contents to disk.
static void SafeCastTo(SOURCE source, TARGET &target)
bool HasSection(const FString &Section) const
void SetFloat(const TCHAR *Section, const TCHAR *Key, const float Value)
void GetBool(const TCHAR *Section, const TCHAR *Key, bool &Target) const
FIniFile(const FString &FileName)
void GetFloat(const TCHAR *Section, const TCHAR *Key, float &Target, const float Factor=1.0f) const
void GetString(const TCHAR *Section, const TCHAR *Key, FString &Target) const
void SetString(const TCHAR *Section, const TCHAR *Key, const TCHAR *Value)
void SetString(const TCHAR *Section, const TCHAR *Key, const FString &Value)
void AddSectionIfMissing(const FString &Section)
void GetInt(const TCHAR *Section, const TCHAR *Key, T &Target) const
void SetInt(const TCHAR *Section, const TCHAR *Key, const int64 Value)
void SetBool(const TCHAR *Section, const TCHAR *Key, const bool Value)
void GetLinearColor(const TCHAR *Section, const TCHAR *Key, FLinearColor &Target) const