Pyrogenesis  trunk
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
CConfigDB Class Reference

#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, CConfigValueSetGetValuesWithPrefix (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 CConfigDBInstance ()
 

Private Attributes

friend CConfigDBHook
 
std::array< std::map< CStr, CConfigValueSet >, CFG_LASTm_Map
 
std::multimap< CStr, std::function< void()> > m_Hooks
 
std::array< VfsPath, CFG_LASTm_ConfigFile
 
std::array< bool, CFG_LASTm_HasChanges
 
std::recursive_mutex m_Mutex
 

Constructor & Destructor Documentation

◆ CConfigDB() [1/3]

CConfigDB::CConfigDB ( )

◆ ~CConfigDB()

CConfigDB::~CConfigDB ( )

◆ CConfigDB() [2/3]

CConfigDB::CConfigDB ( const CConfigDB )
delete

◆ CConfigDB() [3/3]

CConfigDB::CConfigDB ( CConfigDB &&  )
delete

Member Function Documentation

◆ GetValue() [1/6]

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.

◆ GetValue() [2/6]

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.

◆ GetValue() [3/6]

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.

◆ GetValue() [4/6]

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.

◆ GetValue() [5/6]

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.

◆ GetValue() [6/6]

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.

◆ GetValueNamespace()

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.

◆ GetValues()

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.

◆ GetValuesWithPrefix()

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.

◆ HasChanges()

bool CConfigDB::HasChanges ( EConfigNamespace  ns) const

Returns true if changed with respect to last write on file.

◆ Initialise()

void CConfigDB::Initialise ( )
static

◆ Instance()

CConfigDB * CConfigDB::Instance ( )
static

◆ IsInitialised()

bool CConfigDB::IsInitialised ( )
static

◆ RegisterHookAndCall()

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.

◆ Reload()

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

◆ RemoveValue()

bool CConfigDB::RemoveValue ( EConfigNamespace  ns,
const CStr &  name 
)

Remove a config value in the specified namespace.

◆ SetChanges()

void CConfigDB::SetChanges ( EConfigNamespace  ns,
bool  value 
)

◆ SetConfigFile()

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.

◆ SetValueBool()

void CConfigDB::SetValueBool ( EConfigNamespace  ns,
const CStr &  name,
const bool  value 
)

◆ SetValueList()

void CConfigDB::SetValueList ( EConfigNamespace  ns,
const CStr &  name,
std::vector< CStr >  values 
)

◆ SetValueString()

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.

◆ Shutdown()

void CConfigDB::Shutdown ( )
static

◆ UnregisterHook() [1/2]

void CConfigDB::UnregisterHook ( CConfigDBHook &&  hook)

◆ UnregisterHook() [2/2]

void CConfigDB::UnregisterHook ( std::unique_ptr< CConfigDBHook hook)

◆ WriteFile() [1/2]

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

◆ WriteFile() [2/2]

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

◆ WriteValueToFile() [1/2]

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

◆ WriteValueToFile() [2/2]

bool CConfigDB::WriteValueToFile ( EConfigNamespace  ns,
const CStr &  name,
const CStr &  value 
)

Member Data Documentation

◆ CConfigDBHook

friend CConfigDB::CConfigDBHook
private

◆ m_ConfigFile

std::array<VfsPath, CFG_LAST> CConfigDB::m_ConfigFile
private

◆ m_HasChanges

std::array<bool, CFG_LAST> CConfigDB::m_HasChanges
private

◆ m_Hooks

std::multimap<CStr, std::function<void()> > CConfigDB::m_Hooks
private

◆ m_Map

std::array<std::map<CStr, CConfigValueSet>, CFG_LAST> CConfigDB::m_Map
private

◆ m_Mutex

std::recursive_mutex CConfigDB::m_Mutex
mutableprivate

The documentation for this class was generated from the following files: