1 |
#include "ConfigFile.h" |
#include "ConfigFile.h" |
2 |
|
|
3 |
#include <fstream> |
#include <fstream> |
4 |
|
#include <sstream> |
5 |
|
|
6 |
const char SEPERATOR = '/'; |
const char SEPERATOR = '/'; |
7 |
|
|
62 |
name = trim(line.substr(0,posEqual)); |
name = trim(line.substr(0,posEqual)); |
63 |
value = trim(line.substr(posEqual+1)); |
value = trim(line.substr(posEqual+1)); |
64 |
|
|
65 |
|
content_.insert(std::make_pair(inSection+SEPERATOR+name,Value(value))); |
|
content_[inSection+SEPERATOR+name]=Value(value); |
|
66 |
} |
} |
67 |
return true; |
return true; |
68 |
} |
} |
70 |
Value const& ConfigFile::GetValue(std::string const& section, std::string const& entry) const |
Value const& ConfigFile::GetValue(std::string const& section, std::string const& entry) const |
71 |
{ |
{ |
72 |
|
|
73 |
std::map<std::string,Value>::const_iterator ci = content_.find(section + SEPERATOR + entry); |
content_iterator ci = content_.find(section + SEPERATOR + entry); |
74 |
|
|
75 |
if (ci == content_.end()) throw "does not exist"; |
if (ci == content_.end()) throw "does not exist"; |
76 |
|
|
77 |
return ci->second; |
return ci->second; |
78 |
} |
} |
79 |
|
|
80 |
|
std::vector<Value> ConfigFile::GetValues(std::string const& section, std::string const& entry) const |
81 |
|
{ |
82 |
|
std::vector<Value> values; |
83 |
|
std::string search = section + SEPERATOR + entry; |
84 |
|
std::pair<content_iterator, content_iterator> range = content_.equal_range(search); |
85 |
|
|
86 |
|
for (content_iterator it=range.first; it != range.second; ++it) |
87 |
|
{ |
88 |
|
values.push_back( it->second ); |
89 |
|
} |
90 |
|
return values; |
91 |
|
} |
92 |
|
|
93 |
Value const& ConfigFile::GetValue(std::string const& section, std::string const& entry, double value) |
Value const& ConfigFile::GetValue(std::string const& section, std::string const& entry, double value) |
94 |
{ |
{ |
95 |
try |
try |
98 |
} |
} |
99 |
catch (const char *) |
catch (const char *) |
100 |
{ |
{ |
101 |
return content_.insert(std::make_pair(section+SEPERATOR+entry, Value(value))).first->second; |
return content_.insert(std::make_pair(section+SEPERATOR+entry, Value(value)))->second; |
102 |
} |
} |
103 |
} |
} |
104 |
|
|
110 |
} |
} |
111 |
catch (const char *) |
catch (const char *) |
112 |
{ |
{ |
113 |
return content_.insert(std::make_pair(section+SEPERATOR+entry, Value(value))).first->second; |
return content_.insert(std::make_pair(section+SEPERATOR+entry, Value(value)))->second; |
114 |
} |
} |
115 |
} |
} |
116 |
|
|
117 |
|
std::string ConfigFile::DumpConfig() const |
118 |
|
{ |
119 |
|
std::ostringstream ss; |
120 |
|
for (content_iterator it=content_.begin(); it!=content_.end(); ++it) |
121 |
|
{ |
122 |
|
ss << it->first << "=" << it->second.StringValue() << std::endl; |
123 |
|
} |
124 |
|
return ss.str(); |
125 |
|
} |