Permalink
Browse files

Add an easy way to read bools and ints from config.

  • Loading branch information...
Alexey Sokolov
Alexey Sokolov committed Aug 21, 2011
1 parent afbd741 commit d2b005aaf8be14b16d516bd770c39d5dd05e9c18
Showing with 22 additions and 2 deletions.
  1. +22 −2 Config.h
View
@@ -77,9 +77,9 @@ class CConfig {
return true;
}
- bool FindStringEntry(const CString& sName, CString& sRes) {
+ bool FindStringEntry(const CString& sName, CString& sRes, const CString& sDefault = "") {
EntryMap::iterator it = m_ConfigEntries.find(sName);
- sRes.clear();
+ sRes = sDefault;
if (it == m_ConfigEntries.end() || it->second.empty())
return false;
sRes = it->second.front();
@@ -89,6 +89,26 @@ class CConfig {
return true;
}
+ bool FindBoolEntry(const CString& sName, bool& bRes, bool bDefault = false) {
+ CString s;
+ if (FindStringEntry(sName, s)) {
+ bRes = s.ToBool();
+ return true;
+ }
+ bRes = bDefault;
+ return false;
+ }
+
+ bool FindUIntEntry(const CString& sName, unsigned int& uRes, unsigned int uDefault = 0) {
+ CString s;
+ if (FindStringEntry(sName, s)) {
+ uRes = s.ToUInt();
+ return true;
+ }
+ uRes = uDefault;
+ return false;
+ }
+
bool FindSubConfig(const CString& sName, SubConfig& Config) {
SubConfigMap::iterator it = m_SubConfigs.find(sName);
if (it == m_SubConfigs.end()) {

0 comments on commit d2b005a

Please sign in to comment.