Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
|
#include <ConfigDB.h>
Public Member Functions | |
CConfigDB () | |
~CConfigDB () | |
CConfigDB (const CConfigDB &)=delete | |
CConfigDB (CConfigDB &&)=delete | |
void | GetValue (EConfigNamespace ns, const CStr &name, bool &value) |
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 namespace down. More... | |
void | GetValue (EConfigNamespace ns, const CStr &name, int &value) |
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 namespace down. More... | |
void | GetValue (EConfigNamespace ns, const CStr &name, u32 &value) |
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 namespace down. More... | |
void | GetValue (EConfigNamespace ns, const CStr &name, float &value) |
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 namespace down. More... | |
void | GetValue (EConfigNamespace ns, const CStr &name, double &value) |
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 namespace down. More... | |
void | GetValue (EConfigNamespace ns, const CStr &name, std::string &value) |
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 namespace down. More... | |
bool | HasChanges (EConfigNamespace ns) const |
Returns true if changed with respect to last write on file. More... | |
void | SetChanges (EConfigNamespace ns, bool value) |
void | GetValues (EConfigNamespace ns, const CStr &name, CConfigValueSet &values) const |
Attempt to retrieve a vector of values corresponding to the given setting; will search CFG_COMMAND first, and then all namespaces from the specified namespace down. More... | |
EConfigNamespace | GetValueNamespace (EConfigNamespace ns, const CStr &name) const |
Returns the namespace that the value returned by GetValues was defined in, or CFG_LAST if it wasn't defined at all. More... | |
std::map< CStr, CConfigValueSet > | GetValuesWithPrefix (EConfigNamespace ns, const CStr &prefix) const |
Retrieve a map of values corresponding to settings whose names begin with the given prefix; will search all namespaces from default up to the specified namespace. More... | |
void | SetValueString (EConfigNamespace ns, const CStr &name, const CStr &value) |
Save a config value in the specified namespace. More... | |
void | SetValueBool (EConfigNamespace ns, const CStr &name, const bool value) |
void | SetValueList (EConfigNamespace ns, const CStr &name, std::vector< CStr > values) |
bool | RemoveValue (EConfigNamespace ns, const CStr &name) |
Remove a config value in the specified namespace. More... | |
void | SetConfigFile (EConfigNamespace ns, const VfsPath &path) |
Set the path to the config file used to populate the specified namespace Note that this function does not actually load the config file. More... | |
bool | Reload (EConfigNamespace) |
Reload the config file associated with the specified config namespace (the last config file path set with SetConfigFile) More... | |
bool | WriteFile (EConfigNamespace ns, const VfsPath &path) const |
Write the current state of the specified config namespace to the file specified by 'path'. More... | |
bool | WriteFile (EConfigNamespace ns) const |
Write the current state of the specified config namespace to the file it was originally loaded from. More... | |
bool | WriteValueToFile (EConfigNamespace ns, const CStr &name, const CStr &value, const VfsPath &path) |
Write a config value to the file specified by 'path'. More... | |
bool | WriteValueToFile (EConfigNamespace ns, const CStr &name, const CStr &value) |
CConfigDBHook | RegisterHookAndCall (const CStr &name, std::function< void()> hook) |
Register a simple lambda that will be called anytime the value changes in any namespace This is simple on purpose, the hook is responsible for checking if it should do something. More... | |
void | UnregisterHook (CConfigDBHook &&hook) |
void | UnregisterHook (std::unique_ptr< CConfigDBHook > hook) |
Static Public Member Functions | |
static void | Initialise () |
static void | Shutdown () |
static bool | IsInitialised () |
static CConfigDB * | Instance () |
Private Attributes | |
friend | CConfigDBHook |
std::array< std::map< CStr, CConfigValueSet >, CFG_LAST > | m_Map |
std::multimap< CStr, std::function< void()> > | m_Hooks |
std::array< VfsPath, CFG_LAST > | m_ConfigFile |
std::array< bool, CFG_LAST > | m_HasChanges |
std::recursive_mutex | m_Mutex |
CConfigDB::CConfigDB | ( | ) |
CConfigDB::~CConfigDB | ( | ) |
|
delete |
|
delete |
void CConfigDB::GetValue | ( | EConfigNamespace | ns, |
const CStr & | name, | ||
bool & | value | ||
) |
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 namespace down.
void CConfigDB::GetValue | ( | EConfigNamespace | ns, |
const CStr & | name, | ||
double & | value | ||
) |
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 namespace down.
void CConfigDB::GetValue | ( | EConfigNamespace | ns, |
const CStr & | name, | ||
float & | value | ||
) |
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 namespace down.
void CConfigDB::GetValue | ( | EConfigNamespace | ns, |
const CStr & | name, | ||
int & | value | ||
) |
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 namespace down.
void CConfigDB::GetValue | ( | EConfigNamespace | ns, |
const CStr & | name, | ||
std::string & | value | ||
) |
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 namespace down.
void CConfigDB::GetValue | ( | EConfigNamespace | ns, |
const CStr & | name, | ||
u32 & | value | ||
) |
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 namespace down.
EConfigNamespace CConfigDB::GetValueNamespace | ( | EConfigNamespace | ns, |
const CStr & | name | ||
) | const |
Returns the namespace that the value returned by GetValues was defined in, or CFG_LAST if it wasn't defined at all.
void CConfigDB::GetValues | ( | EConfigNamespace | ns, |
const CStr & | name, | ||
CConfigValueSet & | values | ||
) | const |
Attempt to retrieve a vector of values corresponding to the given setting; will search CFG_COMMAND first, and then all namespaces from the specified namespace down.
std::map< CStr, CConfigValueSet > CConfigDB::GetValuesWithPrefix | ( | EConfigNamespace | ns, |
const CStr & | prefix | ||
) | const |
Retrieve a map of values corresponding to settings whose names begin with the given prefix; will search all namespaces from default up to the specified namespace.
bool CConfigDB::HasChanges | ( | EConfigNamespace | ns | ) | const |
Returns true if changed with respect to last write on file.
|
static |
|
static |
|
static |
CConfigDBHook CConfigDB::RegisterHookAndCall | ( | const CStr & | name, |
std::function< void()> | hook | ||
) |
Register a simple lambda that will be called anytime the value changes in any namespace This is simple on purpose, the hook is responsible for checking if it should do something.
When RegisterHookAndCall is called, the hook is immediately triggered. NB: CConfigDBHook will auto-unregister the hook when destroyed, so you can use it to tie the lifetime of the hook to your object. The hook will be deleted alongside ConfigDB anyways.
bool CConfigDB::Reload | ( | EConfigNamespace | ns | ) |
Reload the config file associated with the specified config namespace (the last config file path set with SetConfigFile)
Returns: true: if the reload succeeded, false: if the reload failed
bool CConfigDB::RemoveValue | ( | EConfigNamespace | ns, |
const CStr & | name | ||
) |
Remove a config value in the specified namespace.
void CConfigDB::SetChanges | ( | EConfigNamespace | ns, |
bool | value | ||
) |
void CConfigDB::SetConfigFile | ( | EConfigNamespace | ns, |
const VfsPath & | path | ||
) |
Set the path to the config file used to populate the specified namespace Note that this function does not actually load the config file.
Use the Reload() method if you want to read the config file at the same time.
'path': The path to the config file.
void CConfigDB::SetValueBool | ( | EConfigNamespace | ns, |
const CStr & | name, | ||
const bool | value | ||
) |
void CConfigDB::SetValueList | ( | EConfigNamespace | ns, |
const CStr & | name, | ||
std::vector< CStr > | values | ||
) |
void CConfigDB::SetValueString | ( | EConfigNamespace | ns, |
const CStr & | name, | ||
const CStr & | value | ||
) |
Save a config value in the specified namespace.
If the config variable existed the value is replaced.
|
static |
void CConfigDB::UnregisterHook | ( | CConfigDBHook && | hook | ) |
void CConfigDB::UnregisterHook | ( | std::unique_ptr< CConfigDBHook > | hook | ) |
bool CConfigDB::WriteFile | ( | EConfigNamespace | ns | ) | const |
Write the current state of the specified config namespace to the file it was originally loaded from.
Returns: true: if the config namespace was successfully written to the file false: if an error occurred
bool CConfigDB::WriteFile | ( | EConfigNamespace | ns, |
const VfsPath & | path | ||
) | const |
Write the current state of the specified config namespace to the file specified by 'path'.
Returns: true: if the config namespace was successfully written to the file false: if an error occurred
bool CConfigDB::WriteValueToFile | ( | EConfigNamespace | ns, |
const CStr & | name, | ||
const CStr & | value | ||
) |
bool CConfigDB::WriteValueToFile | ( | EConfigNamespace | ns, |
const CStr & | name, | ||
const CStr & | value, | ||
const VfsPath & | path | ||
) |
Write a config value to the file specified by 'path'.
Returns: true: if the config value was successfully saved and written to the file false: if an error occurred
|
private |
|
private |
|
private |
|
private |
|
mutableprivate |