diff options
author | David Robillard <d@drobilla.net> | 2018-11-24 13:44:03 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-11-24 13:44:03 +0100 |
commit | a7d83f19b08eb4c6f79a82fe60c2b86db13f4420 (patch) | |
tree | d9b620bfba1e7462df4ddb3f6225cc5216c0ca81 /src/ClashAvoider.cpp | |
parent | d63edc742cebd685f8a05936682210aa5c1e69a9 (diff) | |
download | ingen-a7d83f19b08eb4c6f79a82fe60c2b86db13f4420.tar.gz ingen-a7d83f19b08eb4c6f79a82fe60c2b86db13f4420.tar.bz2 ingen-a7d83f19b08eb4c6f79a82fe60c2b86db13f4420.zip |
Squashed 'waflib/' changes from 6e726eb1..5ea8f99f
5ea8f99f Improve test output spacing
0e23b29f Raise exception when test suite fails to ensure non-zero exit status
d6de073b Show run time of unit tests
5b655541 Add short configure option for ultra-strict flags
4687ba6d Use gtest-like test output
258903d9 Fix failure count in test group summaries
da07e738 Fix verbose tests with Python 3
git-subtree-dir: waflib
git-subtree-split: 5ea8f99f6e1246079c1fe6bb590c38a53aadd40d
Diffstat (limited to 'src/ClashAvoider.cpp')
-rw-r--r-- | src/ClashAvoider.cpp | 136 |
1 files changed, 0 insertions, 136 deletions
diff --git a/src/ClashAvoider.cpp b/src/ClashAvoider.cpp deleted file mode 100644 index ae4438a4..00000000 --- a/src/ClashAvoider.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* - This file is part of Ingen. - Copyright 2007-2015 David Robillard <http://drobilla.net/> - - Ingen is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or any later version. - - Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU Affero General Public License for details. - - You should have received a copy of the GNU Affero General Public License - along with Ingen. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include <cassert> -#include <cstdio> -#include <sstream> -#include <string> -#include <utility> - -#include "ingen/ClashAvoider.hpp" -#include "ingen/Store.hpp" -#include "ingen/paths.hpp" - -namespace Ingen { - -ClashAvoider::ClashAvoider(const Store& store) - : _store(store) -{} - -const URI -ClashAvoider::map_uri(const URI& in) -{ - if (uri_is_path(in)) { - return path_to_uri(map_path(uri_to_path(in))); - } else { - return in; - } -} - -const Raul::Path -ClashAvoider::map_path(const Raul::Path& in) -{ - unsigned offset = 0; - bool has_offset = false; - const size_t pos = in.find_last_of('_'); - if (pos != std::string::npos && pos != (in.length()-1)) { - const std::string trailing = in.substr(pos + 1); - has_offset = (sscanf(trailing.c_str(), "%u", &offset) > 0); - } - - // Path without _n suffix - std::string base_path_str = in; - if (has_offset) { - base_path_str = base_path_str.substr(0, base_path_str.find_last_of('_')); - } - - Raul::Path base_path(base_path_str); - - auto m = _symbol_map.find(in); - if (m != _symbol_map.end()) { - return m->second; - } else { - typedef std::pair<SymbolMap::iterator, bool> InsertRecord; - - // 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()); - - 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); - return i.first->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 == "") { - 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; - } - } - } - } - } -} - -bool -ClashAvoider::exists(const Raul::Path& path) const -{ - return _store.find(path) != _store.end(); -} - -} // namespace Ingen |