2 * Copyright (C) 2005-2008 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
19 #include "ConfigEnv.h"
20 #include "Policies/SingletonImp.h"
22 INSTANTIATE_SINGLETON_1(Config
);
24 Config::Config() : mIgnoreCase(true), mConf(NULL
)
35 bool Config::SetSource(const char *file
, bool ignorecase
)
37 mIgnoreCase
= ignorecase
;
47 mConf
= new DOTCONFDocument(mIgnoreCase
?
48 DOTCONFDocument::CASEINSENSETIVE
:
49 DOTCONFDocument::CASESENSETIVE
);
51 if (mConf
->setContent(mFilename
.c_str()) == -1)
61 bool Config::GetString(const char* name
, std::string
*value
)
66 DOTCONFDocumentNode
const *node
= mConf
->findNode(name
);
67 if(!node
|| !node
->getValue())
70 *value
= node
->getValue();
75 bool Config::GetString(const char* name
, char const **value
)
80 DOTCONFDocumentNode
const *node
= mConf
->findNode(name
);
81 if(!node
|| !node
->getValue())
84 *value
= node
->getValue();
90 std::string
Config::GetStringDefault(const char* name
, const char* def
)
93 return std::string(def
);
95 DOTCONFDocumentNode
const *node
= mConf
->findNode(name
);
96 if(!node
|| !node
->getValue())
97 return std::string(def
);
99 return std::string(node
->getValue());
103 bool Config::GetBool(const char* name
, bool *value
)
108 DOTCONFDocumentNode
const *node
= mConf
->findNode(name
);
109 if(!node
|| !node
->getValue())
112 const char* str
= node
->getValue();
113 if(strcmp(str
, "true") == 0 || strcmp(str
, "TRUE") == 0 ||
114 strcmp(str
, "yes") == 0 || strcmp(str
, "YES") == 0 ||
115 strcmp(str
, "1") == 0)
126 bool Config::GetBoolDefault(const char* name
, const bool def
)
129 return GetBool(name
, &val
) ? val
: def
;
133 bool Config::GetInt(const char* name
, int *value
)
138 DOTCONFDocumentNode
const *node
= mConf
->findNode(name
);
139 if(!node
|| !node
->getValue())
142 *value
= atoi(node
->getValue());
148 bool Config::GetFloat(const char* name
, float *value
)
153 DOTCONFDocumentNode
const *node
= mConf
->findNode(name
);
154 if(!node
|| !node
->getValue())
157 *value
= atof(node
->getValue());
163 int Config::GetIntDefault(const char* name
, const int def
)
166 return GetInt(name
, &val
) ? val
: def
;
170 float Config::GetFloatDefault(const char* name
, const float def
)
173 return (GetFloat(name
, &val
) ? val
: def
);