diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/nextpnr.h | 2 | ||||
-rw-r--r-- | common/project.cc | 6 | ||||
-rw-r--r-- | common/settings.h | 20 |
3 files changed, 11 insertions, 17 deletions
diff --git a/common/nextpnr.h b/common/nextpnr.h index 3b17920d..66134456 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -541,7 +541,7 @@ struct BaseCtx mutable std::vector<const std::string *> *idstring_idx_to_str; // Project settings and config switches - std::unordered_map<IdString, std::string> settings; + std::unordered_map<IdString, Property> settings; // Placed nets and cells. std::unordered_map<IdString, std::unique_ptr<NetInfo>> nets; diff --git a/common/project.cc b/common/project.cc index b0ebe961..3b4e67e4 100644 --- a/common/project.cc +++ b/common/project.cc @@ -74,7 +74,7 @@ void ProjectHandler::save(Context *ctx, std::string filename) std::string path = "project.settings."; path += item.first.c_str(ctx); std::replace(path.begin(), path.end(), '/', '.'); - root.put(path, item.second); + root.put(path, item.second.str); } pt::write_json(f, root); } catch (...) { @@ -88,7 +88,9 @@ void addSettings(Context *ctx, std::string path, pt::ptree sub) const std::string &key = v.first; const boost::property_tree::ptree &subtree = v.second; if (subtree.empty()) { - ctx->settings.emplace(ctx->id(path + key), subtree.get_value<std::string>().c_str()); + Property p; + p.setString(subtree.get_value<std::string>().c_str()); + ctx->settings.emplace(ctx->id(path + key), p); } else { addSettings(ctx, path + key + "/", subtree); } diff --git a/common/settings.h b/common/settings.h index b57947c9..9d43c774 100644 --- a/common/settings.h +++ b/common/settings.h @@ -34,10 +34,10 @@ class Settings { try { IdString id = ctx->id(name); - auto pair = ctx->settings.emplace(id, std::to_string(defaultValue)); - if (!pair.second) { - return boost::lexical_cast<T>(pair.first->second); - } + if (ctx->settings.find(id) != ctx->settings.end()) + return boost::lexical_cast<T>(ctx->settings.find(id)->second.str); + else + ctx->settings[ctx->id(name)] = std::to_string(defaultValue); } catch (boost::bad_lexical_cast &) { log_error("Problem reading setting %s, using default value\n", name); @@ -53,20 +53,12 @@ class Settings template <typename T> inline void Settings::set(const char *name, T value) { - IdString id = ctx->id(name); - auto pair = ctx->settings.emplace(id, std::to_string(value)); - if (!pair.second) { - ctx->settings[pair.first->first] = value; - } + ctx->settings[ctx->id(name)] = std::to_string(value); } template <> inline void Settings::set<std::string>(const char *name, std::string value) { - IdString id = ctx->id(name); - auto pair = ctx->settings.emplace(id, value); - if (!pair.second) { - ctx->settings[pair.first->first] = value; - } + ctx->settings[ctx->id(name)] = value; } NEXTPNR_NAMESPACE_END |