summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2017-03-26 19:10:45 +0200
committerDavid Robillard <d@drobilla.net>2017-03-26 19:10:45 +0200
commit3c3feab0d385a927e77e75485a6f9c0320c954d3 (patch)
treec100549a434755400cfaeb753d492a697dc9a042 /src
parentd5eb49e1e468377fea4c5f13840d0435714d34c4 (diff)
downloadingen-3c3feab0d385a927e77e75485a6f9c0320c954d3.tar.gz
ingen-3c3feab0d385a927e77e75485a6f9c0320c954d3.tar.bz2
ingen-3c3feab0d385a927e77e75485a6f9c0320c954d3.zip
Make Store keyed by URI instead of Path
Diffstat (limited to 'src')
-rw-r--r--src/ClashAvoider.cpp2
-rw-r--r--src/Serialiser.cpp16
-rw-r--r--src/Store.cpp51
-rw-r--r--src/client/ClientStore.cpp4
-rw-r--r--src/gui/GraphCanvas.cpp16
-rw-r--r--src/server/events/Delete.cpp2
6 files changed, 37 insertions, 54 deletions
diff --git a/src/ClashAvoider.cpp b/src/ClashAvoider.cpp
index 3c7ea827..6e9700fc 100644
--- a/src/ClashAvoider.cpp
+++ b/src/ClashAvoider.cpp
@@ -127,7 +127,7 @@ ClashAvoider::map_path(const Raul::Path& in)
bool
ClashAvoider::exists(const Raul::Path& path) const
{
- return _store.find(path) != _store.end();
+ return _store.find(path_to_uri(path)) != _store.end();
}
} // namespace Ingen
diff --git a/src/Serialiser.cpp b/src/Serialiser.cpp
index 70a1d286..c6d1bb59 100644
--- a/src/Serialiser.cpp
+++ b/src/Serialiser.cpp
@@ -356,10 +356,12 @@ Serialiser::Impl::serialise_graph(SPtr<const Node> graph,
std::set<const Resource*> plugins;
- const Store::const_range kids = _world.store()->children_range(graph);
- for (Store::const_iterator n = kids.first; n != kids.second; ++n) {
- if (n->first.parent() != graph->path())
+ for (Store::const_iterator n = _world.store()->find_first_child(graph);
+ n != _world.store()->end() && n->first.is_child_of(graph->uri());
+ ++n) {
+ if (uri_to_path(n->first).parent() != graph->path()) {
continue;
+ }
if (n->second->has_property(uris.rdf_type, uris.ingen_Graph)) {
const SPtr<const Node> subgraph = n->second;
@@ -465,10 +467,12 @@ Serialiser::Impl::serialise_block(SPtr<const Node> block,
}
}
- const Store::const_range kids = _world.store()->children_range(block);
- for (Store::const_iterator n = kids.first; n != kids.second; ++n) {
- if (n->first.parent() != block->path())
+ for (Store::const_iterator n = _world.store()->find_first_child(block);
+ n != _world.store()->end() && n->first.is_child_of(block->uri());
+ ++n) {
+ if (uri_to_path(n->first).parent() != block->path()) {
continue;
+ }
if (n->second->has_property(uris.rdf_type, uris.lv2_InputPort) ||
n->second->has_property(uris.rdf_type, uris.lv2_InputPort)) {
diff --git a/src/Store.cpp b/src/Store.cpp
index e2f0f368..ba41bffc 100644
--- a/src/Store.cpp
+++ b/src/Store.cpp
@@ -25,24 +25,15 @@ namespace Ingen {
void
Store::add(Node* o)
{
- if (find(o->path()) != end()) {
+ if (find(o->uri()) != end()) {
return;
}
- insert(make_pair(o->path(), SPtr<Node>(o)));
+ insert(make_pair(o->uri(), SPtr<Node>(o)));
}
-/*
- TODO: These methods are currently O(n_children) but should logarithmic. The
- std::map methods do not allow passing a comparator, but std::upper_bound
- does. This should be achievable by making a rooted comparator that is a
- normal ordering except compares a special sentinel value as the greatest
- element that is a child of the parent. Searching for this sentinel should
- then find the end of the descendants in logarithmic time.
-*/
-
Store::iterator
-Store::find_descendants_end(const iterator parent)
+Store::find_descendants_end(iterator parent)
{
iterator descendants_end = parent;
++descendants_end;
@@ -55,28 +46,13 @@ Store::find_descendants_end(const iterator parent)
}
Store::const_iterator
-Store::find_descendants_end(const const_iterator parent) const
-{
- const_iterator descendants_end = parent;
- ++descendants_end;
- while (descendants_end != end() &&
- descendants_end->first.is_child_of(parent->first)) {
- ++descendants_end;
- }
-
- return descendants_end;
-}
-
-Store::const_range
-Store::children_range(SPtr<const Node> o) const
+Store::find_first_child(SPtr<const Node> o) const
{
- const const_iterator parent = find(o->path());
- if (parent != end()) {
- const_iterator first_child = parent;
- ++first_child;
- return std::make_pair(first_child, find_descendants_end(parent));
+ const_iterator i = find(o->uri());
+ if (i == end()) {
+ return i;
}
- return make_pair(end(), end());
+ return ++i;
}
void
@@ -92,7 +68,7 @@ Store::remove(const iterator top, Objects& removed)
void
Store::rename(const iterator top, const Raul::Path& new_path)
{
- const Raul::Path old_path = top->first;
+ const Raul::Path old_path = uri_to_path(top->first);
// Remove the object and all its descendants
Objects removed;
@@ -100,14 +76,15 @@ Store::rename(const iterator top, const Raul::Path& new_path)
// Rename all the removed objects
for (Objects::const_iterator i = removed.begin(); i != removed.end(); ++i) {
- const Raul::Path path = (i->first == old_path)
+ const Raul::Path old = uri_to_path(i->first);
+ const Raul::Path path = (old == old_path)
? new_path
: new_path.child(
- Raul::Path(i->first.substr(old_path.base().length() - 1)));
+ Raul::Path(old.substr(old_path.base().length() - 1)));
i->second->set_uri(path_to_uri(path));
assert(find(path) == end()); // Shouldn't be dropping objects!
- insert(make_pair(path, i->second));
+ insert(make_pair(path_to_uri(path), i->second));
}
}
@@ -124,7 +101,7 @@ Store::child_name_offset(const Raul::Path& parent,
if (offset > 0) {
ss << "_" << offset;
}
- if (find(parent.child(Raul::Symbol(ss.str()))) == end() &&
+ if (find(path_to_uri(parent.child(Raul::Symbol(ss.str())))) == end() &&
(allow_zero || offset > 0)) {
break;
} else if (offset == 0) {
diff --git a/src/client/ClientStore.cpp b/src/client/ClientStore.cpp
index a622068c..9f84f660 100644
--- a/src/client/ClientStore.cpp
+++ b/src/client/ClientStore.cpp
@@ -78,13 +78,13 @@ ClientStore::add_object(SPtr<ObjectModel> object)
parent->add_child(object);
assert(parent && (object->parent() == parent));
- (*this)[object->path()] = object;
+ (*this)[object->uri()] = object;
_signal_new_object.emit(object);
} else {
_log.error(fmt("Object %1% with no parent\n") % object->path());
}
} else {
- (*this)[object->path()] = object;
+ (*this)[object->uri()] = object;
_signal_new_object.emit(object);
}
}
diff --git a/src/gui/GraphCanvas.cpp b/src/gui/GraphCanvas.cpp
index e9224cfc..fa5ed149 100644
--- a/src/gui/GraphCanvas.cpp
+++ b/src/gui/GraphCanvas.cpp
@@ -235,13 +235,14 @@ GraphCanvas::build_menus()
void
GraphCanvas::build()
{
- const Store::const_range kids = _app.store()->children_range(_graph);
-
// Create modules for blocks
- for (Store::const_iterator i = kids.first; i != kids.second; ++i) {
- SPtr<BlockModel> block = dynamic_ptr_cast<BlockModel>(i->second);
- if (block && block->parent() == _graph)
+ for (Store::const_iterator n = _app.store()->find_first_child(_graph);
+ n != _app.store()->end() && n->first.is_child_of(_graph->uri());
+ ++n) {
+ SPtr<BlockModel> block = dynamic_ptr_cast<BlockModel>(n->second);
+ if (block && block->parent() == _graph) {
add_block(block);
+ }
}
// Create pseudo modules for ports (ports on this canvas, not on our module)
@@ -699,7 +700,7 @@ GraphCanvas::paste()
float min_x = std::numeric_limits<float>::max();
float min_y = std::numeric_limits<float>::max();
for (const auto& c : clipboard) {
- if (c.first.parent() == Raul::Path("/")) {
+ if (uri_to_path(c.first).parent() == Raul::Path("/")) {
const Atom& x = c.second->get_property(uris.ingen_canvasX);
const Atom& y = c.second->get_property(uris.ingen_canvasY);
if (x.type() == uris.atom_Float) {
@@ -723,7 +724,8 @@ GraphCanvas::paste()
// Put each top level object in the clipboard store
ClashAvoider avoider(*_app.store().get());
for (const auto& c : clipboard) {
- if (c.first.is_root() || c.first.parent() != Raul::Path("/")) {
+ const Raul::Path path(uri_to_path(c.first));
+ if (path.is_root() || path.parent() != Raul::Path("/")) {
continue;
}
diff --git a/src/server/events/Delete.cpp b/src/server/events/Delete.cpp
index b19ffd18..5683f3a4 100644
--- a/src/server/events/Delete.cpp
+++ b/src/server/events/Delete.cpp
@@ -165,7 +165,7 @@ Delete::post_process()
void
Delete::undo(Interface& target)
{
- auto i = _removed_objects.find(_path);
+ auto i = _removed_objects.find(_uri);
if (i != _removed_objects.end()) {
target.put(_uri, i->second->properties());
if (_disconnect_event) {