From df1447c665e6c3631961297a9d3e9aff4e94c47f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 12 Jan 2013 23:38:03 +0000 Subject: Remove Raul::SharedPtr and switch to std::shared_ptr. Use project local short type aliases for shared_ptr and friends. Move Raul::Disposable and Raul::Manageable into Raul::Maid. Use sets to store machina nodes and edges to avoid O(n) searches. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4939 a436a847-0d15-0410-975c-d299462d15a1 --- src/client/ClientStore.cpp | 94 +++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 47 deletions(-) (limited to 'src/client/ClientStore.cpp') diff --git a/src/client/ClientStore.cpp b/src/client/ClientStore.cpp index 318d31a5..8c48ab72 100644 --- a/src/client/ClientStore.cpp +++ b/src/client/ClientStore.cpp @@ -31,10 +31,10 @@ using namespace std; namespace Ingen { namespace Client { -ClientStore::ClientStore(URIs& uris, - Log& log, - SharedPtr engine, - SharedPtr emitter) +ClientStore::ClientStore(URIs& uris, + Log& log, + SPtr engine, + SPtr emitter) : _uris(uris) , _log(log) , _engine(engine) @@ -66,16 +66,16 @@ ClientStore::clear() } void -ClientStore::add_object(SharedPtr object) +ClientStore::add_object(SPtr object) { // If we already have "this" object, merge the existing one into the new // one (with precedence to the new values). iterator existing = find(object->path()); if (existing != end()) { - PtrCast(existing->second)->set(object); + dynamic_ptr_cast(existing->second)->set(object); } else { if (!object->path().is_root()) { - SharedPtr parent = _object(object->path().parent()); + SPtr parent = _object(object->path().parent()); if (parent) { assert(object->path().is_child_of(parent->path())); object->set_parent(parent); @@ -97,13 +97,13 @@ ClientStore::add_object(SharedPtr object) object->signal_property().emit(p.first, p.second); } -SharedPtr +SPtr ClientStore::remove_object(const Raul::Path& path) { // Find the object, the "top" of the tree to remove const iterator top = find(path); if (top == end()) { - return SharedPtr(); + return SPtr(); } // Remove the object and all its descendants @@ -111,7 +111,7 @@ ClientStore::remove_object(const Raul::Path& path) remove(top, removed); // Notify everything that needs to know this object is going away - SharedPtr object = PtrCast(top->second); + SPtr object = dynamic_ptr_cast(top->second); if (object) { // Notify the program this object is going away object->signal_destroyed().emit(); @@ -125,43 +125,43 @@ ClientStore::remove_object(const Raul::Path& path) return object; } -SharedPtr +SPtr ClientStore::_plugin(const Raul::URI& uri) { Plugins::iterator i = _plugins->find(uri); if (i == _plugins->end()) - return SharedPtr(); + return SPtr(); else return (*i).second; } -SharedPtr +SPtr ClientStore::plugin(const Raul::URI& uri) const { return const_cast(this)->_plugin(uri); } -SharedPtr +SPtr ClientStore::_object(const Raul::Path& path) { const iterator i = find(path); if (i == end()) { - return SharedPtr(); + return SPtr(); } else { - SharedPtr model = PtrCast(i->second); + SPtr model = dynamic_ptr_cast(i->second); assert(model); assert(model->path().is_root() || model->parent()); return model; } } -SharedPtr +SPtr ClientStore::object(const Raul::Path& path) const { return const_cast(this)->_object(path); } -SharedPtr +SPtr ClientStore::_resource(const Raul::URI& uri) { if (Node::uri_is_path(uri)) { @@ -171,16 +171,16 @@ ClientStore::_resource(const Raul::URI& uri) } } -SharedPtr +SPtr ClientStore::resource(const Raul::URI& uri) const { return const_cast(this)->_resource(uri); } void -ClientStore::add_plugin(SharedPtr pm) +ClientStore::add_plugin(SPtr pm) { - SharedPtr existing = _plugin(pm->uri()); + SPtr existing = _plugin(pm->uri()); if (existing) { existing->set(pm); } else { @@ -235,7 +235,7 @@ ClientStore::put(const Raul::URI& uri, if (plugin_type == Plugin::Graph) { is_graph = true; } else if (plugin_type != Plugin::NIL) { - SharedPtr p( + SPtr p( new PluginModel(uris(), uri, type_uri, properties)); add_plugin(p); return; @@ -250,7 +250,7 @@ ClientStore::put(const Raul::URI& uri, const Raul::Path path(Node::uri_to_path(uri)); - SharedPtr obj = PtrCast(_object(path)); + SPtr obj = dynamic_ptr_cast(_object(path)); if (obj) { obj->set_properties(properties); return; @@ -261,15 +261,15 @@ ClientStore::put(const Raul::URI& uri, } if (is_graph) { - SharedPtr model(new GraphModel(uris(), path)); + SPtr model(new GraphModel(uris(), path)); model->set_properties(properties); add_object(model); } else if (is_block) { const Iterator p = properties.find(_uris.ingen_prototype); - SharedPtr plug; + SPtr plug; if (p->second.is_valid() && p->second.type() == _uris.forge.URI) { if (!(plug = _plugin(Raul::URI(p->second.get_uri())))) { - plug = SharedPtr( + plug = SPtr( new PluginModel(uris(), Raul::URI(p->second.get_uri()), _uris.ingen_nil, @@ -277,7 +277,7 @@ ClientStore::put(const Raul::URI& uri, add_plugin(plug); } - SharedPtr bm(new BlockModel(uris(), plug, path)); + SPtr bm(new BlockModel(uris(), plug, path)); bm->set_properties(properties); add_object(bm); } else { @@ -291,7 +291,7 @@ ClientStore::put(const Raul::URI& uri, const Iterator i = properties.find(_uris.lv2_index); if (i != properties.end() && i->second.type() == _uris.forge.Int) { const uint32_t index = i->second.get_int32(); - SharedPtr p( + SPtr p( new PortModel(uris(), path, index, pdir)); p->set_properties(properties); add_object(p); @@ -331,7 +331,7 @@ ClientStore::delta(const Raul::URI& uri, const Raul::Path path(Node::uri_to_path(uri)); - SharedPtr obj = _object(path); + SPtr obj = _object(path); if (obj) { obj->remove_properties(remove); obj->add_properties(add); @@ -351,7 +351,7 @@ ClientStore::set_property(const Raul::URI& subject_uri, % predicate.c_str() % _uris.forge.str(value)); return; } - SharedPtr subject = _resource(subject_uri); + SPtr subject = _resource(subject_uri); if (subject) { if (predicate == _uris.ingen_activity) { /* Activity is transient, trigger any live actions (like GUI @@ -361,7 +361,7 @@ ClientStore::set_property(const Raul::URI& subject_uri, subject->set_property(predicate, value); } } else { - SharedPtr plugin = _plugin(subject_uri); + SPtr plugin = _plugin(subject_uri); if (plugin) { plugin->set_property(predicate, value); } else if (predicate != _uris.ingen_activity) { @@ -371,23 +371,23 @@ ClientStore::set_property(const Raul::URI& subject_uri, } } -SharedPtr +SPtr ClientStore::connection_graph(const Raul::Path& tail_path, const Raul::Path& head_path) { - SharedPtr graph; + SPtr graph; if (tail_path.parent() == head_path.parent()) - graph = PtrCast(_object(tail_path.parent())); + graph = dynamic_ptr_cast(_object(tail_path.parent())); if (!graph && tail_path.parent() == head_path.parent().parent()) - graph = PtrCast(_object(tail_path.parent())); + graph = dynamic_ptr_cast(_object(tail_path.parent())); if (!graph && tail_path.parent().parent() == head_path.parent()) - graph = PtrCast(_object(head_path.parent())); + graph = dynamic_ptr_cast(_object(head_path.parent())); if (!graph) - graph = PtrCast(_object(tail_path.parent().parent())); + graph = dynamic_ptr_cast(_object(tail_path.parent().parent())); if (!graph) _log.error(Raul::fmt("Unable to find graph for arc %1% => %2%\n") @@ -400,12 +400,12 @@ bool ClientStore::attempt_connection(const Raul::Path& tail_path, const Raul::Path& head_path) { - SharedPtr tail = PtrCast(_object(tail_path)); - SharedPtr head = PtrCast(_object(head_path)); + SPtr tail = dynamic_ptr_cast(_object(tail_path)); + SPtr head = dynamic_ptr_cast(_object(head_path)); if (tail && head) { - SharedPtr graph = connection_graph(tail_path, head_path); - SharedPtr arc(new ArcModel(tail, head)); + SPtr graph = connection_graph(tail_path, head_path); + SPtr arc(new ArcModel(tail, head)); tail->connected_to(head); head->connected_to(tail); @@ -430,8 +430,8 @@ void ClientStore::disconnect(const Raul::Path& src_path, const Raul::Path& dst_path) { - SharedPtr tail = PtrCast(_object(src_path)); - SharedPtr head = PtrCast(_object(dst_path)); + SPtr tail = dynamic_ptr_cast(_object(src_path)); + SPtr head = dynamic_ptr_cast(_object(dst_path)); if (tail) tail->disconnected_from(head); @@ -439,7 +439,7 @@ ClientStore::disconnect(const Raul::Path& src_path, if (head) head->disconnected_from(tail); - SharedPtr graph = connection_graph(src_path, dst_path); + SPtr graph = connection_graph(src_path, dst_path); if (graph) graph->remove_arc(tail.get(), head.get()); } @@ -448,8 +448,8 @@ void ClientStore::disconnect_all(const Raul::Path& parent_graph, const Raul::Path& path) { - SharedPtr graph = PtrCast(_object(parent_graph)); - SharedPtr object = _object(path); + SPtr graph = dynamic_ptr_cast(_object(parent_graph)); + SPtr object = _object(path); if (!graph || !object) { _log.error(Raul::fmt("Bad disconnect all notification %1% in %2%\n") @@ -459,7 +459,7 @@ ClientStore::disconnect_all(const Raul::Path& parent_graph, const GraphModel::Arcs arcs = graph->arcs(); for (auto a : arcs) { - SharedPtr arc = PtrCast(a.second); + SPtr arc = dynamic_ptr_cast(a.second); if (arc->tail()->parent() == object || arc->head()->parent() == object || arc->tail()->path() == path -- cgit v1.2.1