Use emplace result for get,set of settings
This commit is contained in:
parent
b400cd8d73
commit
eaf824ca73
@ -34,10 +34,11 @@ class Settings
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
IdString id = ctx->id(name);
|
IdString id = ctx->id(name);
|
||||||
if (ctx->settings.find(id) != ctx->settings.end()) {
|
auto pair = ctx->settings.emplace(id, std::to_string(defaultValue));
|
||||||
return boost::lexical_cast<T>(ctx->settings[id]);
|
if (!pair.second) {
|
||||||
|
return boost::lexical_cast<T>(pair.first->second);
|
||||||
}
|
}
|
||||||
ctx->settings.emplace(id, std::to_string(defaultValue));
|
|
||||||
} catch (boost::bad_lexical_cast &) {
|
} catch (boost::bad_lexical_cast &) {
|
||||||
log_error("Problem reading setting %s, using default value\n", name);
|
log_error("Problem reading setting %s, using default value\n", name);
|
||||||
}
|
}
|
||||||
@ -47,11 +48,10 @@ class Settings
|
|||||||
template <typename T> void set(const char *name, T value)
|
template <typename T> void set(const char *name, T value)
|
||||||
{
|
{
|
||||||
IdString id = ctx->id(name);
|
IdString id = ctx->id(name);
|
||||||
if (ctx->settings.find(id) != ctx->settings.end()) {
|
auto pair = ctx->settings.emplace(id, std::to_string(value));
|
||||||
ctx->settings[id] = value;
|
if (!pair.second) {
|
||||||
return;
|
ctx->settings[pair.first->first] = value;
|
||||||
}
|
}
|
||||||
ctx->settings.emplace(id, std::to_string(value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user