[10081] Use ACE config library instead dotconfpp

NOTE: all config versions update because in old state
      it's not compatible with new way loading.
      Look for *.conf.dist.in chnages in commit for update configs.

Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
Astellar 2010-06-20 01:50:19 +04:00 committed by VladimirMangos
parent e63dc32f4d
commit 41d178ca7b
7 changed files with 54 additions and 52 deletions

View file

@ -17,12 +17,35 @@
*/
#include "ConfigEnv.h"
#include "ace/Configuration_Import_Export.h"
#include "Policies/SingletonImp.h"
INSTANTIATE_SINGLETON_1(Config);
static bool GetValueHelper(ACE_Configuration_Heap *mConf, const char *name, ACE_TString &result)
{
if (!mConf)
return false;
ACE_TString section_name;
ACE_Configuration_Section_Key section_key;
ACE_Configuration_Section_Key root_key = mConf->root_section();
int i = 0;
while (mConf->enumerate_sections(root_key, i, section_name) == 0)
{
mConf->open_section(root_key, section_name.c_str(), 0, section_key);
if (mConf->get_string_value(section_key, name, result) == 0)
return true;
++i;
}
return false;
}
Config::Config()
: mIgnoreCase(true), mConf(NULL)
: mConf(NULL)
{
}
@ -31,9 +54,8 @@ Config::~Config()
delete mConf;
}
bool Config::SetSource(const char *file, bool ignorecase)
bool Config::SetSource(const char *file)
{
mIgnoreCase = ignorecase;
mFilename = file;
return Reload();
@ -42,43 +64,33 @@ bool Config::SetSource(const char *file, bool ignorecase)
bool Config::Reload()
{
delete mConf;
mConf = new ACE_Configuration_Heap;
mConf = new DOTCONFDocument(mIgnoreCase ?
DOTCONFDocument::CASEINSENSETIVE :
DOTCONFDocument::CASESENSITIVE);
if (mConf->setContent(mFilename.c_str()) == -1)
if (mConf->open() == 0)
{
delete mConf;
mConf = NULL;
return false;
ACE_Ini_ImpExp config_importer(*mConf);
if (config_importer.import_config(mFilename.c_str()) == 0)
return true;
}
return true;
delete mConf;
mConf = NULL;
return false;
}
std::string Config::GetStringDefault(const char* name, const char* def)
{
if (!mConf)
return std::string(def);
DOTCONFDocumentNode const *node = mConf->findNode(name);
if (!node || !node->getValue())
return std::string(def);
return std::string(node->getValue());
ACE_TString val;
return GetValueHelper(mConf, name, val) ? val.c_str() : def;
}
bool Config::GetBoolDefault(const char* name, bool def)
{
if (!mConf)
ACE_TString val;
if (!GetValueHelper(mConf, name, val))
return def;
DOTCONFDocumentNode const *node = mConf->findNode(name);
if (!node || !node->getValue())
return def;
const char* str = node->getValue();
const char* str = val.c_str();
if (strcmp(str, "true") == 0 || strcmp(str, "TRUE") == 0 ||
strcmp(str, "yes") == 0 || strcmp(str, "YES") == 0 ||
strcmp(str, "1") == 0)
@ -90,25 +102,13 @@ bool Config::GetBoolDefault(const char* name, bool def)
int32 Config::GetIntDefault(const char* name, int32 def)
{
if (!mConf)
return def;
DOTCONFDocumentNode const *node = mConf->findNode(name);
if (!node || !node->getValue())
return def;
return atoi(node->getValue());
ACE_TString val;
return GetValueHelper(mConf, name, val) ? atoi(val.c_str()) : def;
}
float Config::GetFloatDefault(const char* name, float def)
{
if (!mConf)
return def;
DOTCONFDocumentNode const *node = mConf->findNode(name);
if (!node || !node->getValue())
return def;
return (float)atof(node->getValue());
ACE_TString val;
return GetValueHelper(mConf, name, val) ? (float)atof(val.c_str()) : def;
}