settings reader fix
This commit is contained in:
parent
ba885e4e08
commit
179d2b7a25
@ -45,27 +45,35 @@ class Reader : public BasicParser {
|
|||||||
if (is_digit(c)) {
|
if (is_digit(c)) {
|
||||||
number_u num;
|
number_u num;
|
||||||
parseNumber(1, num);
|
parseNumber(1, num);
|
||||||
handler.setValue(name, *dynamic::Value::of(num));
|
if (handler.has(name)) {
|
||||||
|
handler.setValue(name, *dynamic::Value::of(num));
|
||||||
|
}
|
||||||
} else if (c == '-' || c == '+') {
|
} else if (c == '-' || c == '+') {
|
||||||
int sign = c == '-' ? -1 : 1;
|
int sign = c == '-' ? -1 : 1;
|
||||||
pos++;
|
pos++;
|
||||||
number_u num;
|
number_u num;
|
||||||
parseNumber(sign, num);
|
parseNumber(sign, num);
|
||||||
handler.setValue(name, *dynamic::Value::of(num));
|
if (handler.has(name)) {
|
||||||
|
handler.setValue(name, *dynamic::Value::of(num));
|
||||||
|
}
|
||||||
} else if (is_identifier_start(c)) {
|
} else if (is_identifier_start(c)) {
|
||||||
std::string identifier = parseName();
|
std::string identifier = parseName();
|
||||||
if (identifier == "true" || identifier == "false") {
|
if (handler.has(name)) {
|
||||||
bool flag = identifier == "true";
|
if (identifier == "true" || identifier == "false") {
|
||||||
handler.setValue(name, *dynamic::Value::boolean(flag));
|
bool flag = identifier == "true";
|
||||||
} else if (identifier == "inf") {
|
handler.setValue(name, *dynamic::Value::boolean(flag));
|
||||||
handler.setValue(name, *dynamic::Value::of(INFINITY));
|
} else if (identifier == "inf") {
|
||||||
} else if (identifier == "nan") {
|
handler.setValue(name, *dynamic::Value::of(INFINITY));
|
||||||
handler.setValue(name, *dynamic::Value::of(NAN));
|
} else if (identifier == "nan") {
|
||||||
|
handler.setValue(name, *dynamic::Value::of(NAN));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (c == '"' || c == '\'') {
|
} else if (c == '"' || c == '\'') {
|
||||||
pos++;
|
pos++;
|
||||||
std::string str = parseString(c);
|
std::string str = parseString(c);
|
||||||
handler.setValue(name, *dynamic::Value::of(str));
|
if (handler.has(name)) {
|
||||||
|
handler.setValue(name, *dynamic::Value::of(str));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw error("feature is not supported");
|
throw error("feature is not supported");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -113,6 +113,10 @@ Setting* SettingsHandler::getSetting(const std::string& name) const {
|
|||||||
return found->second;
|
return found->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SettingsHandler::has(const std::string& name) const {
|
||||||
|
return map.find(name) != map.end();
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
static void set_numeric_value(T* setting, const dynamic::Value& value) {
|
static void set_numeric_value(T* setting, const dynamic::Value& value) {
|
||||||
switch (value.type) {
|
switch (value.type) {
|
||||||
|
|||||||
@ -26,6 +26,7 @@ public:
|
|||||||
void setValue(const std::string& name, const dynamic::Value& value);
|
void setValue(const std::string& name, const dynamic::Value& value);
|
||||||
std::string toString(const std::string& name) const;
|
std::string toString(const std::string& name) const;
|
||||||
Setting* getSetting(const std::string& name) const;
|
Setting* getSetting(const std::string& name) const;
|
||||||
|
bool has(const std::string& name) const;
|
||||||
|
|
||||||
std::vector<Section>& getSections();
|
std::vector<Section>& getSections();
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user