12#include "ConfigCacheIni.h"
24 template <
typename TARGET,
typename SOURCE>
28 if ((source >= std::numeric_limits<TARGET>::lowest()) &&
29 (source <= std::numeric_limits<TARGET>::max())) {
30 target =
static_cast<TARGET
>(source);
33 UE_LOG(LogCarla, Error, TEXT(
"FIniFile: Type cast failed"));
51 ConfigFile.Read(FileName);
65 return ConfigFile.Combine(FileName);
72 ConfigFile.ProcessInputFileContents(INIFileContents);
80 return (ConfigFile.Num() > 0) && (ConfigFile.Find(Section)!=
nullptr);
87 if (!HasSection(Section)) {
88 ConfigFile.Add(Section, FConfigSection());
95 bool Write(
const FString &Filename)
97 return ConfigFile.Write(Filename);
117 template <
typename T>
118 void GetInt(
const TCHAR* Section,
const TCHAR* Key, T &Target)
const
122 if (ConfigFile.GetInt64(Section, Key, Value)) {
124 SafeCastTo<T>(Value, Target);
132 void GetString(
const TCHAR* Section,
const TCHAR* Key, FString &Target)
const
136 if (ConfigFile.GetString(Section, Key, Value)) {
145 void GetBool(
const TCHAR* Section,
const TCHAR* Key,
bool &Target)
const
149 if (ConfigFile.GetBool(Section, Key, Value)) {
159 void GetFloat(
const TCHAR* Section,
const TCHAR* Key,
float &Target,
const float Factor = 1.0f)
const
163 if (ConfigFile.GetString(Section, Key, Value)) {
165 Target = Factor * FCString::Atof(*Value);
173 void GetLinearColor(
const TCHAR* Section,
const TCHAR* Key, FLinearColor &Target)
const
177 if (ConfigFile.GetString(Section, Key, Value)) {
179 Target.InitFromString(Value);
193 void SetInt(
const TCHAR* Section,
const TCHAR* Key,
const int64 Value)
195 ConfigFile.SetInt64(Section, Key, Value);
202 void SetString(
const TCHAR* Section,
const TCHAR* Key,
const TCHAR* Value)
204 ConfigFile.SetString(Section, Key, Value);
212 void SetString(
const TCHAR* Section,
const TCHAR* Key,
const FString &Value)
214 SetString(Section, Key, *Value);
221 void SetBool(
const TCHAR* Section,
const TCHAR* Key,
const bool Value)
223 SetString(Section, Key, Value? TEXT(
"True") : TEXT(
"False"));
230 void SetFloat(
const TCHAR* Section,
const TCHAR* Key,
const float Value)
232 SetString(Section, Key, FText::AsNumber(Value).ToString());
239 void SetLinearColor(
const TCHAR* Section,
const TCHAR* Key,
const FLinearColor &Value)
241 SetString(Section, Key, Value.ToString());
UE_LOG(LogCarla, Log, TEXT("UActorDispatcher::Destroying actor: '%s' %x"), *Id, Actor)
void SetLinearColor(const TCHAR *Section, const TCHAR *Key, const FLinearColor &Value)
const FConfigFile & GetFConfigFile() const
void ProcessInputFileContents(const FString &INIFileContents)
bool Combine(const FString &FileName)
bool Write(const FString &Filename)
static void SafeCastTo(SOURCE source, TARGET &target)
bool HasSection(const FString &Section) const
void SetFloat(const TCHAR *Section, const TCHAR *Key, const float Value)
FIniFile()=default
使用来明确一个功能组的范围
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