My Project
Public Member Functions | Static Public Member Functions | List of all members
ParaInfoCenter::CICConfigManager Class Reference

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 CICConfigManagerGetInstance ()
 get the singleton instance of this object. More...
 

Detailed Description

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.

Member Function Documentation

§ AppendDoubleValue()

HRESULT CICConfigManager::AppendDoubleValue ( const char *  szName,
double  value 
)

Appends a specified double value.

Parameters
szNamethe value name.
valuethe new value.
Returns
: return S_OK if successful. If the szName is NULL, the return value is E_INVALIDARG. If the configuration manager is locked, the return value is E_ACCESSDENIED.
Remarks
: If the specified name is not exist, this functions the same as SetDoubleValue(szName, value, 0); If there is already an instance of the specified name, it will create a new item and append it to the tail of the chain of this specified name.

§ AppendIntValue()

HRESULT CICConfigManager::AppendIntValue ( const char *  szName,
int  value 
)

Appends a specified integer value.

Parameters
szNamethe value name.
valuethe new value.
Returns
: return S_OK if successful. If the szName is NULL, the return value is E_INVALIDARG. If the configuration manager is locked, the return value is E_ACCESSDENIED.
Remarks
: If the specified name is not exist, this functions the same as SetIntValue(szName, value, 0); If there is already an instance of the specified name, it will create a new item and append it to the tail of the chain of this specified name.

§ AppendTextValue()

HRESULT CICConfigManager::AppendTextValue ( const char *  szName,
const char *  value 
)

Appends a specified text value.

Parameters
szNamethe value name.
valuethe new value.
Returns
: return S_OK if successful. If the szName is NULL, the return value is E_INVALIDARG. If the configuration manager is locked, the return value is E_ACCESSDENIED.
Remarks
: If the specified name is not exist, this functions the same as SetTextValue(szName, value, 0); If there is already an instance of the specified name, it will create a new item and append it to the tail of the chain of this specified name.

§ GetDoubleValue()

HRESULT CICConfigManager::GetDoubleValue ( const char *  szName,
double *  value,
int  index = 0 
)

Get a specified double value.

Parameters
szNamethe value name.
valuea pointer to the variable to receive the value.
Returns
: return S_OK if successful. If the szName is NULL or the specified name is not found or value==NULL, the return value is E_INVALIDARG. If the type of the specified name is text, the return value is E_FAIL. If the configuration manager is locked, the return value is E_ACCESSDENIED.
Remarks
: If the type of the specified name is integer, it will be auto-cast to double.

§ GetInstance()

CICConfigManager * CICConfigManager::GetInstance ( )
static

get the singleton instance of this object.

§ GetIntValue()

HRESULT CICConfigManager::GetIntValue ( const char *  szName,
int *  value,
int  index = 0 
)

Get a specified integer value.

Parameters
szNamethe value name.
valuea pointer to the variable to receive the value.
Returns
: return S_OK if successful. If the szName is NULL or the specified name is not found or value==NULL, the return value is E_INVALIDARG. If the type of the specified name is text, the return value is E_FAIL. If the configuration manager is locked, the return value is E_ACCESSDENIED.
Remarks
: If the type of the specified name is double, it will be auto-cast to integer.

§ GetSize()

HRESULT CICConfigManager::GetSize ( const char *  szName,
DWORD *  nSize 
)

Get size of a specified name.

Parameters
szNamethe value name
nSizethe pointer to the value that stores the size to get.
Returns
: S_OK if successful. If the configuration manager is locked, the return value is E_ACCESSDENIED. If the szName is NULL or the specified name is not found or value==NULL, the return value is E_INVALIDARG.
Remarks
: If the specified name exists, nSize will the number of items under this name. If the specified name does not exist, nSize will zero.

§ GetTextValue()

HRESULT CICConfigManager::GetTextValue ( const char *  szName,
string &  value,
int  index = 0 
)

Get a specified text value.

Parameters
szNamethe value name.
valuea pointer to the variable to receive the value.
Returns
: return S_OK if successful. If the szName is NULL or the specified name is not found or value==NULL, the return value is E_INVALIDARG. If the type of the specified name is not text, the data will be casted to a string. If the configuration manager is locked, the return value is E_ACCESSDENIED.

§ LoadFromFile()

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.

Parameters
szFilenamethe file name of the lua file. If it is NULL, it will load the default configuration file "config.lua". The default value is NULL;
bOverwriteWhether to overwrite the items if there is one in the configuration. The default value is true.
Returns
: S_OK if successful. If the configuration manager is locked, the return value is E_ACCESSDENIED. If the file does not exist, the return value is E_FAIL.

§ Lock()

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.

§ SaveToFile()

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.

Parameters
szFilenamethe 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;
bOverwriteWhether to overwrite the configuration file if it exists. The default value is true.
Returns
: S_OK if successful. If the configuration manager is locked, the return value is E_ACCESSDENIED. If bOverwrite==false and the file exists, the return value is E_FAIL If the disk is full or cannot create file because of security or other reasons, the return value is E_FAIL

§ SetDoubleValue()

HRESULT CICConfigManager::SetDoubleValue ( const char *  szName,
double  value,
int  index = 0 
)

Set a specified double value.

Parameters
szNamethe value name.
valuethe new value.
Returns
: return S_OK if successful. If the szName is NULL, the return value is E_INVALIDARG. If the configuration manager is locked, the return value is E_ACCESSDENIED. If the overwrite is false and the value already exists, the return value is E_FAIL.
Remarks
: If the type of the specified name is integer, the new value will be auto-cast to integer and then assigns to the item. If the specified name is text, the new value will be casted to a string and then assigns to the item. If the specified name is not found, a new item will be created. In this case, index will be ignored.

§ SetIntValue()

HRESULT CICConfigManager::SetIntValue ( const char *  szName,
int  value,
int  index = 0 
)

Set a specified integer value.

Parameters
szNamethe value name.
valuethe new value.
indexwhere, in the chain, you want to set the value.
Returns
: return S_OK if successful. If the szName is NULL, the return value is E_INVALIDARG. If the index is not a valid place, the return value is E_INVALIDARG. If the configuration manager is locked, the return value is E_ACCESSDENIED. If the overwrite is false and the value already exists, the return value is E_FAIL.
Remarks
: If the type of the specified name is double, the new value will be auto-cast to double and then assigns to the item. If the specified name is text, the new value will be casted to a string and then assigns to the item. If the specified name is not found, a new item will be created. In this case, index will be ignored.

§ SetTextValue()

HRESULT CICConfigManager::SetTextValue ( const char *  szName,
const char *  value,
int  index = 0 
)

Set a specified string value.

Parameters
szNamethe value name.
valuethe new value.
Returns
: return S_OK if successful. If the szName is NULL, the return value is E_INVALIDARG. If the type of the specified name is integer or double, the return value is E_FAIL. If the overwrite is false and the value already exists, the return value is E_FAIL. If the configuration manager is locked, the return value is E_ACCESSDENIED.
Remarks
: If the specified name is not found, a new item will be created. In this case, index will be ignored.

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