summaryrefslogtreecommitdiffstats
path: root/include/ingen/ClashAvoider.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-08-01 22:41:11 +0200
committerDavid Robillard <d@drobilla.net>2020-08-02 01:48:48 +0200
commitc0f567d3232cbe165e56cb2684cda52df7cfb90f (patch)
tree3ffbe6df3f2056fd579a954e00f0bea49b47104e /include/ingen/ClashAvoider.hpp
parent9eadae8edc7a35f87499f58c3e3b9cec68f74a80 (diff)
downloadingen-c0f567d3232cbe165e56cb2684cda52df7cfb90f.tar.gz
ingen-c0f567d3232cbe165e56cb2684cda52df7cfb90f.tar.bz2
ingen-c0f567d3232cbe165e56cb2684cda52df7cfb90f.zip
Move public headers to a separate include directory
This is more conventional and probably best practice (since it avoids polluting the include path with non-headers), and is supported by the clang-tidy llvm-header-guard check.
Diffstat (limited to 'include/ingen/ClashAvoider.hpp')
-rw-r--r--include/ingen/ClashAvoider.hpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/include/ingen/ClashAvoider.hpp b/include/ingen/ClashAvoider.hpp
new file mode 100644
index 00000000..1d2cebf0
--- /dev/null
+++ b/include/ingen/ClashAvoider.hpp
@@ -0,0 +1,66 @@
+/*
+ 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/>.
+*/
+
+#ifndef INGEN_CLASHAVOIDER_HPP
+#define INGEN_CLASHAVOIDER_HPP
+
+#include "ingen/ingen.h"
+#include "raul/Path.hpp"
+
+#include <map>
+#include <string>
+
+namespace ingen {
+
+class Store;
+class URI;
+
+/** Maps paths so they do not clash with an existing object in a store.
+ *
+ * @ingroup ingen
+ */
+class INGEN_API ClashAvoider
+{
+public:
+ explicit ClashAvoider(const Store& store);
+
+ URI map_uri(const URI& in);
+ Raul::Path map_path(const Raul::Path& in);
+
+ bool exists(const Raul::Path& path) const;
+
+ /** Adjust a new label by increasing the numeric suffix if any.
+ *
+ * @param old_path The old path that was mapped with `map_path()`
+ * @param new_path The new path that `old_path` was mapped to
+ * @param name The old name.
+ */
+ static std::string adjust_name(const Raul::Path& old_path,
+ const Raul::Path& new_path,
+ std::string name);
+
+private:
+ using Offsets = std::map<Raul::Path, unsigned>;
+ using SymbolMap = std::map<Raul::Path, Raul::Path>;
+
+ const Store& _store;
+ Offsets _offsets;
+ SymbolMap _symbol_map;
+};
+
+} // namespace ingen
+
+#endif // INGEN_CLASHAVOIDER_HPP