Changeset View
Changeset View
Standalone View
Standalone View
source/ps/ConfigDB.h
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | enum EConfigNamespace | ||||
CFG_USER, | CFG_USER, | ||||
CFG_HWDETECT, | CFG_HWDETECT, | ||||
CFG_COMMAND, | CFG_COMMAND, | ||||
CFG_LAST | CFG_LAST | ||||
}; | }; | ||||
typedef std::vector<CStr> CConfigValueSet; | typedef std::vector<CStr> CConfigValueSet; | ||||
#define g_ConfigDB CConfigDB::GetSingleton() | #define g_ConfigDB CConfigDB::GetSingleton() | ||||
vladislavbelov: Too common name for the global space. | |||||
Done Inline ActionsYup. wraitii: Yup. | |||||
class CConfigDB : public Singleton<CConfigDB> | class CConfigDB : public Singleton<CConfigDB> | ||||
{ | { | ||||
public: | public: | ||||
/** | /** | ||||
* Attempt to retrieve the value of a config variable with the given name; | * Attempt to retrieve the value of a config variable with the given name; | ||||
* will search CFG_COMMAND first, and then all namespaces from the specified | * will search CFG_COMMAND first, and then all namespaces from the specified | ||||
* namespace down. | * namespace down. | ||||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | public: | ||||
* Returns: | * Returns: | ||||
* true: if the config value was successfully saved and written to the file | * true: if the config value was successfully saved and written to the file | ||||
* false: if an error occurred | * false: if an error occurred | ||||
*/ | */ | ||||
bool WriteValueToFile(EConfigNamespace ns, const CStr& name, const CStr& value, const VfsPath& path); | bool WriteValueToFile(EConfigNamespace ns, const CStr& name, const CStr& value, const VfsPath& path); | ||||
bool WriteValueToFile(EConfigNamespace ns, const CStr& name, const CStr& value); | bool WriteValueToFile(EConfigNamespace ns, const CStr& name, const CStr& value); | ||||
/** | |||||
* Register a simple lambda that will be called anytime the value changes in any namespace | |||||
Not Done Inline ActionsConfigDB. vladislavbelov: `ConfigDB`. | |||||
* This is simple on purpose, the hook is responsible for checking if it should do something. | |||||
* When RegisterHook is called, the hook is immediately triggered. | |||||
*/ | |||||
void RegisterHook(const CStr& name, std::function<void()> hook); | |||||
private: | private: | ||||
static std::map<CStr, CConfigValueSet> m_Map[]; | static std::map<CStr, CConfigValueSet> m_Map[]; | ||||
static std::multimap<CStr, std::function<void()>> m_Hooks; | |||||
Not Done Inline ActionsType duplication. vladislavbelov: Type duplication. | |||||
Done Inline ActionsI'm not sure what you mean by that? Just that I repeat the type in several places? wraitii: I'm not sure what you mean by that? Just that I repeat the type in several places? | |||||
static VfsPath m_ConfigFile[]; | static VfsPath m_ConfigFile[]; | ||||
static bool m_HasChanges[]; | static bool m_HasChanges[]; | ||||
}; | }; | ||||
// stores the value of the given key into <destination>. this quasi-template | // stores the value of the given key into <destination>. this quasi-template | ||||
// convenience wrapper on top of GetValue simplifies user code | // convenience wrapper on top of GetValue simplifies user code | ||||
#define CFG_GET_VAL(name, destination)\ | #define CFG_GET_VAL(name, destination)\ | ||||
g_ConfigDB.GetValue(CFG_USER, name, destination) | g_ConfigDB.GetValue(CFG_USER, name, destination) | ||||
#endif // INCLUDED_CONFIGDB | #endif // INCLUDED_CONFIGDB |
Wildfire Games · Phabricator
Too common name for the global space.