|
@@ -24,7 +24,7 @@ void ConfigFileParser::parse(const std::string& path) {
|
24
|
24
|
std::ifstream is(path);
|
25
|
25
|
|
26
|
26
|
if (!is.good()) {
|
27
|
|
- throw ParseExc(0, 0, "valid file", "file I could not open", path);
|
|
27
|
+ throw ParseFileExc(path);
|
28
|
28
|
}
|
29
|
29
|
|
30
|
30
|
char c;
|
|
@@ -45,12 +45,12 @@ void ConfigFileParser::parse(const std::string& path) {
|
45
|
45
|
case NONE:
|
46
|
46
|
if (std::isspace(c)) continue;
|
47
|
47
|
if (c == '[') {
|
48
|
|
- if (tmp.size()) curKV[tmp] = Val{trim(tmp2), valLine, valPos};
|
|
48
|
+ if (tmp.size()) curKV[tmp] = Val{trim(tmp2), valLine, valPos, path};
|
49
|
49
|
tmp.clear();
|
50
|
50
|
tmp2.clear();
|
51
|
51
|
for (auto h : headers) {
|
52
|
52
|
if (_secs.find(h) != _secs.end()) {
|
53
|
|
- _kvs[_secs[h]].insert(curKV.begin(), curKV.end());
|
|
53
|
+ updateVals(_secs[h], curKV);
|
54
|
54
|
} else {
|
55
|
55
|
_secs[h] = _kvs.size();
|
56
|
56
|
_kvs.push_back(curKV);
|
|
@@ -139,12 +139,12 @@ void ConfigFileParser::parse(const std::string& path) {
|
139
|
139
|
continue;
|
140
|
140
|
}
|
141
|
141
|
if (c == '[') {
|
142
|
|
- curKV[tmp] = Val{trim(tmp2), valLine, valPos};
|
|
142
|
+ curKV[tmp] = Val{trim(tmp2), valLine, valPos, path};
|
143
|
143
|
tmp.clear();
|
144
|
144
|
tmp2.clear();
|
145
|
145
|
for (auto h : headers) {
|
146
|
146
|
if (_secs.find(h) != _secs.end()) {
|
147
|
|
- _kvs[_secs[h]].insert(curKV.begin(), curKV.end());
|
|
147
|
+ updateVals(_secs[h], curKV);
|
148
|
148
|
} else {
|
149
|
149
|
_secs[h] = _kvs.size();
|
150
|
150
|
_kvs.push_back(curKV);
|
|
@@ -156,7 +156,7 @@ void ConfigFileParser::parse(const std::string& path) {
|
156
|
156
|
continue;
|
157
|
157
|
}
|
158
|
158
|
if (isKeyChar(c)) {
|
159
|
|
- curKV[tmp] = Val{trim(tmp2), valLine, valPos};
|
|
159
|
+ curKV[tmp] = Val{trim(tmp2), valLine, valPos, path};
|
160
|
160
|
tmp.clear();
|
161
|
161
|
tmp2.clear();
|
162
|
162
|
tmp.push_back(c);
|
|
@@ -186,12 +186,12 @@ void ConfigFileParser::parse(const std::string& path) {
|
186
|
186
|
throw ParseExc(l, pos, "character", "<EOF>", path);
|
187
|
187
|
}
|
188
|
188
|
|
189
|
|
- if (tmp.size() && tmp2.size()) curKV[tmp] = Val{tmp2, valLine, valPos};
|
|
189
|
+ if (tmp.size() && tmp2.size()) curKV[tmp] = Val{tmp2, valLine, valPos, path};
|
190
|
190
|
tmp.clear();
|
191
|
191
|
tmp2.clear();
|
192
|
192
|
for (auto h : headers) {
|
193
|
193
|
if (_secs.find(h) != _secs.end()) {
|
194
|
|
- _kvs[_secs[h]].insert(curKV.begin(), curKV.end());
|
|
194
|
+ updateVals(_secs[h], curKV);
|
195
|
195
|
} else {
|
196
|
196
|
_secs[h] = _kvs.size();
|
197
|
197
|
_kvs.push_back(curKV);
|
|
@@ -327,3 +327,10 @@ bool ConfigFileParser::hasKey(Sec section, Key key) const {
|
327
|
327
|
|
328
|
328
|
return true;
|
329
|
329
|
}
|
|
330
|
+
|
|
331
|
+// _____________________________________________________________________________
|
|
332
|
+void ConfigFileParser::updateVals(size_t sec, const KeyVals& kvs) {
|
|
333
|
+ for (auto& kv : kvs) {
|
|
334
|
+ _kvs[sec][kv.first] = kv.second;
|
|
335
|
+ }
|
|
336
|
+}
|