2 * Copyright (C) 2005-2013 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "ace/Configuration_Import_Export.h"
22 #include "Policies/SingletonImp.h"
24 INSTANTIATE_SINGLETON_1(Config
);
26 static bool GetValueHelper(ACE_Configuration_Heap
* mConf
, const char* name
, ACE_TString
& result
)
31 ACE_TString section_name
;
32 ACE_Configuration_Section_Key section_key
;
33 ACE_Configuration_Section_Key root_key
= mConf
->root_section();
36 while (mConf
->enumerate_sections(root_key
, i
, section_name
) == 0)
38 mConf
->open_section(root_key
, section_name
.c_str(), 0, section_key
);
39 if (mConf
->get_string_value(section_key
, name
, result
) == 0)
57 bool Config::SetSource(const char* file
)
67 mConf
= new ACE_Configuration_Heap
;
69 if (mConf
->open() == 0)
71 ACE_Ini_ImpExp
config_importer(*mConf
);
72 if (config_importer
.import_config(mFilename
.c_str()) == 0)
81 std::string
Config::GetStringDefault(const char* name
, const char* def
)
84 return GetValueHelper(mConf
, name
, val
) ? val
.c_str() : def
;
87 bool Config::GetBoolDefault(const char* name
, bool def
)
90 if (!GetValueHelper(mConf
, name
, val
))
93 const char* str
= val
.c_str();
94 if (strcmp(str
, "true") == 0 || strcmp(str
, "TRUE") == 0 ||
95 strcmp(str
, "yes") == 0 || strcmp(str
, "YES") == 0 ||
96 strcmp(str
, "1") == 0)
103 int32
Config::GetIntDefault(const char* name
, int32 def
)
106 return GetValueHelper(mConf
, name
, val
) ? atoi(val
.c_str()) : def
;
110 float Config::GetFloatDefault(const char* name
, float def
)
113 return GetValueHelper(mConf
, name
, val
) ? (float)atof(val
.c_str()) : def
;