My Project
|
The CICConfigManager manages the global configurations of the program. More...
#include <ICConfigManager.h>
Public Member Functions | |
PE_CORE_DECL HRESULT | LoadFromFile (const char *szFilename=NULL, bool bOverwrite=true) |
Load a configuration from a file. More... | |
PE_CORE_DECL HRESULT | SaveToFile (const char *szFilename=NULL, bool bOverwrite=true) |
Save the current configuration to a file. More... | |
PE_CORE_DECL HRESULT | GetSize (const char *szName, DWORD *nSize) |
Get size of a specified name. More... | |
PE_CORE_DECL HRESULT | GetIntValue (const char *szName, int *value, int index=0) |
Get a specified integer value. More... | |
PE_CORE_DECL HRESULT | GetDoubleValue (const char *szName, double *value, int index=0) |
Get a specified double value. More... | |
PE_CORE_DECL HRESULT | GetTextValue (const char *szName, string &value, int index=0) |
Get a specified text value. More... | |
PE_CORE_DECL HRESULT | SetIntValue (const char *szName, int value, int index=0) |
Set a specified integer value. More... | |
PE_CORE_DECL HRESULT | AppendIntValue (const char *szName, int value) |
Appends a specified integer value. More... | |
PE_CORE_DECL HRESULT | SetDoubleValue (const char *szName, double value, int index=0) |
Set a specified double value. More... | |
PE_CORE_DECL HRESULT | AppendDoubleValue (const char *szName, double value) |
Appends a specified double value. More... | |
PE_CORE_DECL HRESULT | SetTextValue (const char *szName, const char *value, int index=0) |
Set a specified string value. More... | |
PE_CORE_DECL HRESULT | AppendTextValue (const char *szName, const char *value) |
Appends a specified text value. More... | |
PE_CORE_DECL void | Lock () |
Lock the configuration manager so that no other thread can access it. More... | |
PE_CORE_DECL void | UnLock () |
Unlock the configuration manager so that other thread can access it. | |
Static Public Member Functions | |
static PE_CORE_DECL CICConfigManager * | GetInstance () |
get the singleton instance of this object. More... | |
The CICConfigManager manages the global configurations of the program.
User can use LoadFromFile to load configurations from a file, SaveToFile to save the current configurations to file. To change the configurations at runtime, you can use SetIntValue, SetDoubleValue and SetTextValue to either add a new value or change the old value. The values are all writable by default. To get the configurations at runtime, you can use GetIntValue, GetDoubleValue and GetTextValue to get the value of a specified configuration. If you have multiple threads and the threads are all trying to access the configurations, the CICConfigManager provides a thread-safe operation. All the functions of the class can only be accessed by one thread at a time. If a thread tries to call a function when another thread is executing any of the class functions. The thread will block and wait until the other thread ends its current execution of its executing function. If you want to make sure that in a serial calling of the class functions, other threads cannot execute any of the class functions. Call Lock before your calling and call UnLock after you finish the job. When one thread is in a Lock-UnLock pair, any other thread's calling to the class functions will return E_ACCESSDENIED. And any other thread's try to call Lock will block at the call until the lock owner release the lock. If you just want to know if another thread is in the Lock-UnLock pair, use TryLock. This will gain a lock if no one is locking and return true. If any one have a lock, it returns false immediately.
HRESULT CICConfigManager::AppendDoubleValue | ( | const char * | szName, |
double | value | ||
) |
Appends a specified double value.
szName | the value name. |
value | the new value. |
HRESULT CICConfigManager::AppendIntValue | ( | const char * | szName, |
int | value | ||
) |
Appends a specified integer value.
szName | the value name. |
value | the new value. |
HRESULT CICConfigManager::AppendTextValue | ( | const char * | szName, |
const char * | value | ||
) |
Appends a specified text value.
szName | the value name. |
value | the new value. |
HRESULT CICConfigManager::GetDoubleValue | ( | const char * | szName, |
double * | value, | ||
int | index = 0 |
||
) |
Get a specified double value.
szName | the value name. |
value | a pointer to the variable to receive the value. |
|
static |
get the singleton instance of this object.
HRESULT CICConfigManager::GetIntValue | ( | const char * | szName, |
int * | value, | ||
int | index = 0 |
||
) |
Get a specified integer value.
szName | the value name. |
value | a pointer to the variable to receive the value. |
HRESULT CICConfigManager::GetSize | ( | const char * | szName, |
DWORD * | nSize | ||
) |
Get size of a specified name.
szName | the value name |
nSize | the pointer to the value that stores the size to get. |
HRESULT CICConfigManager::GetTextValue | ( | const char * | szName, |
string & | value, | ||
int | index = 0 |
||
) |
Get a specified text value.
szName | the value name. |
value | a pointer to the variable to receive the value. |
HRESULT CICConfigManager::LoadFromFile | ( | const char * | szFilename = NULL , |
bool | bOverwrite = true |
||
) |
Load a configuration from a file.
The file is a LUA file with correct scripts to write values to the configuration manager.
szFilename | the file name of the lua file. If it is NULL, it will load the default configuration file "config.lua". The default value is NULL; |
bOverwrite | Whether to overwrite the items if there is one in the configuration. The default value is true. |
void CICConfigManager::Lock | ( | ) |
Lock the configuration manager so that no other thread can access it.
If the configuration manager is already locked by other thread. It will block until the configuration manager is unlocked. Then it will acquire a lock on the configuration manager.
HRESULT CICConfigManager::SaveToFile | ( | const char * | szFilename = NULL , |
bool | bOverwrite = true |
||
) |
Save the current configuration to a file.
The file is a LUA file. The manager will write correct scripts.
szFilename | the file name of the lua file. If it is NULL, it will save to the default configuration file "config.lua". The default value is NULL; |
bOverwrite | Whether to overwrite the configuration file if it exists. The default value is true. |
HRESULT CICConfigManager::SetDoubleValue | ( | const char * | szName, |
double | value, | ||
int | index = 0 |
||
) |
Set a specified double value.
szName | the value name. |
value | the new value. |
HRESULT CICConfigManager::SetIntValue | ( | const char * | szName, |
int | value, | ||
int | index = 0 |
||
) |
Set a specified integer value.
szName | the value name. |
value | the new value. |
index | where, in the chain, you want to set the value. |
HRESULT CICConfigManager::SetTextValue | ( | const char * | szName, |
const char * | value, | ||
int | index = 0 |
||
) |
Set a specified string value.
szName | the value name. |
value | the new value. |