#pragma once #include "Common/StringConv.h" #include #include #include #include /** * @brief This is a singleton for storing global configuration state */ namespace FEX::Config { template class Value; void Init(); void Shutdown(); void Add(std::string const &Key, std::string_view const Value); void Append(std::string const &Key, std::string_view const Value); bool Exists(std::string const &Key); Value &Get(std::string const &Key); Value *GetIfExists(std::string const &Key); template T Get(std::string const &Key); template T GetIfExists(std::string const &Key, T Default); void GetListIfExists(std::string const &Key, std::list *List); template class Value { public: Value(std::string const &key, std::string_view const Value, bool ConfigBacking) : Key {key} { ValueData = Value; } template ::value, int>::type = 0> Value(std::string const &key, T Default) : Key {key} { ValueData = FEX::Config::GetIfExists(Key, Default); } template ::value, int>::type = 0> Value(std::string const &key, T Default) : Key {key} { ValueData = FEX::Config::GetIfExists(Key, Default); FEX::Config::GetListIfExists(Key, &AppendList); } void Set(T NewValue) { ValueData = NewValue; FEX::Config::Add(Key, std::to_string(NewValue)); } void Append(T NewValue) { AppendList.emplace_back(NewValue); } T operator()() { return ValueData; } std::list &All() { return AppendList; } private: std::string const Key; T ValueData; std::list AppendList; }; }