summaryrefslogtreecommitdiffstats
path: root/src/ClashAvoider.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ClashAvoider.cpp')
-rw-r--r--src/ClashAvoider.cpp130
1 files changed, 65 insertions, 65 deletions
diff --git a/src/ClashAvoider.cpp b/src/ClashAvoider.cpp
index ece002f8..b782bcc7 100644
--- a/src/ClashAvoider.cpp
+++ b/src/ClashAvoider.cpp
@@ -21,12 +21,11 @@
#include "raul/Path.hpp"
#include "raul/Symbol.hpp"
-#include <boost/optional/optional.hpp>
-
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
+#include <optional>
#include <sstream>
#include <string>
#include <utility>
@@ -42,9 +41,9 @@ ClashAvoider::map_uri(const URI& in)
{
if (uri_is_path(in)) {
return path_to_uri(map_path(uri_to_path(in)));
- } else {
- return in;
}
+
+ return in;
}
raul::Path
@@ -71,68 +70,69 @@ ClashAvoider::map_path(const raul::Path& in)
auto m = _symbol_map.find(in);
if (m != _symbol_map.end()) {
return m->second;
- } else {
- using InsertRecord = std::pair<SymbolMap::iterator, bool>;
-
- // See if parent is mapped
- raul::Path parent = in.parent();
- do {
- auto p = _symbol_map.find(parent);
- if (p != _symbol_map.end()) {
- const raul::Path mapped = raul::Path(
- p->second.base() + in.substr(parent.base().length()));
- InsertRecord i = _symbol_map.emplace(in, mapped);
- return i.first->second;
- }
- parent = parent.parent();
- } while (!parent.is_root());
+ }
+
+ // See if parent is mapped
+ raul::Path parent = in.parent();
+ do {
+ auto p = _symbol_map.find(parent);
+ if (p != _symbol_map.end()) {
+ const auto mapped = raul::Path{p->second.base() +
+ in.substr(parent.base().length())};
- if (!exists(in) && _symbol_map.find(in) == _symbol_map.end()) {
- // No clash, use symbol unmodified
- InsertRecord i = _symbol_map.emplace(in, in);
- assert(i.second);
+ auto i = _symbol_map.emplace(in, mapped);
return i.first->second;
+ }
+ parent = parent.parent();
+ } while (!parent.is_root());
+
+ if (!exists(in) && _symbol_map.find(in) == _symbol_map.end()) {
+ // No clash, use symbol unmodified
+ auto i = _symbol_map.emplace(in, in);
+ assert(i.second);
+ return i.first->second;
+ }
+ // Append _2 _3 etc until an unused symbol is found
+ while (true) {
+ auto o = _offsets.find(base_path);
+ if (o != _offsets.end()) {
+ offset = ++o->second;
} else {
- // Append _2 _3 etc until an unused symbol is found
- while (true) {
- auto o = _offsets.find(base_path);
- if (o != _offsets.end()) {
- offset = ++o->second;
- } else {
- std::string parent_str = in.parent().base();
- parent_str = parent_str.substr(0, parent_str.find_last_of('/'));
- if (parent_str.empty()) {
- parent_str = "/";
- }
- }
-
- if (offset == 0) {
- offset = 2;
- }
-
- std::stringstream ss;
- ss << base_path << "_" << offset;
- if (!exists(raul::Path(ss.str()))) {
- std::string name = base_path.symbol();
- if (name.empty()) {
- name = "_";
- }
- raul::Symbol sym(name);
- std::string str = ss.str();
- InsertRecord i = _symbol_map.emplace(in, raul::Path(str));
- offset = _store.child_name_offset(in.parent(), sym, false);
- _offsets.emplace(base_path, offset);
- return i.first->second;
- } else {
- if (o != _offsets.end()) {
- offset = ++o->second;
- } else {
- ++offset;
- }
- }
+ std::string parent_str = in.parent().base();
+ parent_str = parent_str.substr(0, parent_str.find_last_of('/'));
+ if (parent_str.empty()) {
+ parent_str = "/";
}
}
+
+ if (offset == 0) {
+ offset = 2;
+ }
+
+ std::stringstream ss;
+ ss << base_path << "_" << offset;
+ if (!exists(raul::Path(ss.str()))) {
+ std::string name = base_path.symbol();
+ if (name.empty()) {
+ name = "_";
+ }
+
+ const raul::Symbol sym{name};
+ const std::string str{ss.str()};
+
+ auto i = _symbol_map.emplace(in, raul::Path(str));
+
+ offset = _store.child_name_offset(in.parent(), sym, false);
+ _offsets.emplace(base_path, offset);
+ return i.first->second;
+ }
+
+ if (o != _offsets.end()) {
+ offset = ++o->second;
+ } else {
+ ++offset;
+ }
}
}
@@ -142,7 +142,7 @@ ClashAvoider::exists(const raul::Path& path) const
return _store.find(path) != _store.end();
}
-static boost::optional<size_t>
+static std::optional<size_t>
numeric_suffix_start(const std::string& str)
{
if (!isdigit(str[str.length() - 1])) {
@@ -177,11 +177,11 @@ ClashAvoider::adjust_name(const raul::Path& old_path,
const auto offset = new_suffix - old_suffix;
return (name.substr(0, *name_suffix_start) +
std::to_string(name_suffix + offset));
- } else {
- // Add 1 to previous label suffix
- return (name.substr(0, *name_suffix_start) +
- std::to_string(name_suffix + 1));
}
+
+ // Add 1 to previous label suffix
+ return (name.substr(0, *name_suffix_start) +
+ std::to_string(name_suffix + 1));
}
} // namespace ingen