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/BlockModel.cpp | 42 ++++++++++---------- src/client/ClientStore.cpp | 94 ++++++++++++++++++++++----------------------- src/client/GraphModel.cpp | 26 ++++++------- src/client/ObjectModel.cpp | 4 +- src/client/PluginModel.cpp | 10 ++--- src/client/PluginUI.cpp | 20 +++++----- src/client/PortModel.cpp | 4 +- src/client/ingen_client.cpp | 4 +- 8 files changed, 102 insertions(+), 102 deletions(-) (limited to 'src/client') diff --git a/src/client/BlockModel.cpp b/src/client/BlockModel.cpp index eb982f0d..0ed58c7a 100644 --- a/src/client/BlockModel.cpp +++ b/src/client/BlockModel.cpp @@ -25,9 +25,9 @@ namespace Ingen { namespace Client { -BlockModel::BlockModel(URIs& uris, - SharedPtr plugin, - const Raul::Path& path) +BlockModel::BlockModel(URIs& uris, + SPtr plugin, + const Raul::Path& path) : ObjectModel(uris, path) , _plugin_uri(plugin->uri()) , _plugin(plugin) @@ -65,7 +65,7 @@ BlockModel::~BlockModel() } void -BlockModel::remove_port(SharedPtr port) +BlockModel::remove_port(SPtr port) { for (Ports::iterator i = _ports.begin(); i != _ports.end(); ++i) { if ((*i) == port) { @@ -99,26 +99,26 @@ BlockModel::clear() } void -BlockModel::add_child(SharedPtr c) +BlockModel::add_child(SPtr c) { assert(c->parent().get() == this); //ObjectModel::add_child(c); - SharedPtr pm = PtrCast(c); + SPtr pm = dynamic_ptr_cast(c); assert(pm); add_port(pm); } bool -BlockModel::remove_child(SharedPtr c) +BlockModel::remove_child(SPtr c) { assert(c->path().is_child_of(path())); assert(c->parent().get() == this); //bool ret = ObjectModel::remove_child(c); - SharedPtr pm = PtrCast(c); + SPtr pm = dynamic_ptr_cast(c); assert(pm); remove_port(pm); @@ -127,7 +127,7 @@ BlockModel::remove_child(SharedPtr c) } void -BlockModel::add_port(SharedPtr pm) +BlockModel::add_port(SPtr pm) { assert(pm); assert(pm->path().is_child_of(path())); @@ -140,13 +140,13 @@ BlockModel::add_port(SharedPtr pm) _signal_new_port.emit(pm); } -SharedPtr +SPtr BlockModel::get_port(const Raul::Symbol& symbol) const { for (auto p : _ports) if (p->symbol() == symbol) return p; - return SharedPtr(); + return SPtr(); } Ingen::Node* @@ -158,10 +158,10 @@ BlockModel::port(uint32_t index) const } void -BlockModel::default_port_value_range(SharedPtr port, - float& min, - float& max, - uint32_t srate) const +BlockModel::default_port_value_range(SPtr port, + float& min, + float& max, + uint32_t srate) const { // Default control values min = 0.0; @@ -190,8 +190,10 @@ BlockModel::default_port_value_range(SharedPtr port, } void -BlockModel::port_value_range(SharedPtr port, - float& min, float& max, uint32_t srate) const +BlockModel::port_value_range(SPtr port, + float& min, + float& max, + uint32_t srate) const { assert(port->parent().get() == this); @@ -228,7 +230,7 @@ BlockModel::label() const } std::string -BlockModel::port_label(SharedPtr port) const +BlockModel::port_label(SPtr port) const { const Raul::Atom& name = port->get_property(Raul::URI(LV2_CORE__name)); if (name.is_valid()) { @@ -255,9 +257,9 @@ BlockModel::port_label(SharedPtr port) const } void -BlockModel::set(SharedPtr model) +BlockModel::set(SPtr model) { - SharedPtr block = PtrCast(model); + SPtr block = dynamic_ptr_cast(model); if (block) { _plugin_uri = block->_plugin_uri; _plugin = block->_plugin; 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 diff --git a/src/client/GraphModel.cpp b/src/client/GraphModel.cpp index 98155138..8586f168 100644 --- a/src/client/GraphModel.cpp +++ b/src/client/GraphModel.cpp @@ -28,24 +28,24 @@ namespace Ingen { namespace Client { void -GraphModel::add_child(SharedPtr c) +GraphModel::add_child(SPtr c) { assert(c->parent().get() == this); - SharedPtr pm = PtrCast(c); + SPtr pm = dynamic_ptr_cast(c); if (pm) { add_port(pm); return; } - SharedPtr bm = PtrCast(c); + SPtr bm = dynamic_ptr_cast(c); if (bm) { _signal_new_block.emit(bm); } } bool -GraphModel::remove_child(SharedPtr o) +GraphModel::remove_child(SPtr o) { assert(o->path().is_child_of(path())); assert(o->parent().get() == this); @@ -56,7 +56,7 @@ GraphModel::remove_child(SharedPtr o) Arcs::iterator next = j; ++next; - SharedPtr arc = PtrCast(j->second); + SPtr arc = dynamic_ptr_cast(j->second); if (arc->tail_path().parent() == o->path() || arc->tail_path() == o->path() || arc->head_path().parent() == o->path() @@ -67,11 +67,11 @@ GraphModel::remove_child(SharedPtr o) j = next; } - SharedPtr pm = PtrCast(o); + SPtr pm = dynamic_ptr_cast(o); if (pm) remove_port(pm); - SharedPtr bm = PtrCast(o); + SPtr bm = dynamic_ptr_cast(o); if (bm) { _signal_removed_block.emit(bm); } @@ -90,14 +90,14 @@ GraphModel::clear() assert(_ports.empty()); } -SharedPtr +SPtr GraphModel::get_arc(const Node* tail, const Node* head) { Arcs::iterator i = _arcs.find(make_pair(tail, head)); if (i != _arcs.end()) - return PtrCast(i->second); + return dynamic_ptr_cast(i->second); else - return SharedPtr(); + return SPtr(); } /** Add a connection to this graph. @@ -108,7 +108,7 @@ GraphModel::get_arc(const Node* tail, const Node* head) * this graph is a fatal error. */ void -GraphModel::add_arc(SharedPtr arc) +GraphModel::add_arc(SPtr arc) { // Store should have 'resolved' the connection already assert(arc); @@ -122,7 +122,7 @@ GraphModel::add_arc(SharedPtr arc) assert(arc->head()->parent().get() == this || arc->head()->parent()->parent().get() == this); - SharedPtr existing = get_arc( + SPtr existing = get_arc( arc->tail().get(), arc->head().get()); if (existing) { @@ -141,7 +141,7 @@ GraphModel::remove_arc(const Node* tail, const Node* head) { Arcs::iterator i = _arcs.find(make_pair(tail, head)); if (i != _arcs.end()) { - SharedPtr arc = PtrCast(i->second); + SPtr arc = dynamic_ptr_cast(i->second); _signal_removed_arc.emit(arc); _arcs.erase(i); } diff --git a/src/client/ObjectModel.cpp b/src/client/ObjectModel.cpp index 51427f90..9fc22c03 100644 --- a/src/client/ObjectModel.cpp +++ b/src/client/ObjectModel.cpp @@ -73,7 +73,7 @@ ObjectModel::polyphonic() const * @a o as correct. The paths of the two models MUST be equal. */ void -ObjectModel::set(SharedPtr o) +ObjectModel::set(SPtr o) { assert(_path == o->path()); if (o->_parent) @@ -94,7 +94,7 @@ ObjectModel::set_path(const Raul::Path& p) } void -ObjectModel::set_parent(SharedPtr p) +ObjectModel::set_parent(SPtr p) { assert(_path.is_child_of(p->path())); _parent = p; diff --git a/src/client/PluginModel.cpp b/src/client/PluginModel.cpp index 5dc6ec2a..206aebab 100644 --- a/src/client/PluginModel.cpp +++ b/src/client/PluginModel.cpp @@ -151,7 +151,7 @@ PluginModel::get_property(const Raul::URI& key) const } void -PluginModel::set(SharedPtr p) +PluginModel::set(SPtr p) { _type = p->_type; @@ -229,12 +229,12 @@ PluginModel::has_ui() const } -SharedPtr -PluginModel::ui(Ingen::World* world, - SharedPtr block) const +SPtr +PluginModel::ui(Ingen::World* world, + SPtr block) const { if (!_lilv_plugin) { - return SharedPtr(); + return SPtr(); } return PluginUI::create(world, block, _lilv_plugin); diff --git a/src/client/PluginUI.cpp b/src/client/PluginUI.cpp index 7a4c88e8..24144b42 100644 --- a/src/client/PluginUI.cpp +++ b/src/client/PluginUI.cpp @@ -47,7 +47,7 @@ lv2_ui_write(SuilController controller, return; } - SharedPtr port = ports[port_index]; + SPtr port = ports[port_index]; const URIs& uris = ui->world()->uris(); @@ -77,9 +77,9 @@ lv2_ui_write(SuilController controller, } } -PluginUI::PluginUI(Ingen::World* world, - SharedPtr block, - const LilvNode* ui_node) +PluginUI::PluginUI(Ingen::World* world, + SPtr block, + const LilvNode* ui_node) : _world(world) , _block(block) , _instance(NULL) @@ -93,10 +93,10 @@ PluginUI::~PluginUI() lilv_node_free(_ui_node); } -SharedPtr -PluginUI::create(Ingen::World* world, - SharedPtr block, - const LilvPlugin* plugin) +SPtr +PluginUI::create(Ingen::World* world, + SPtr block, + const LilvPlugin* plugin) { if (!PluginUI::ui_host) { PluginUI::ui_host = suil_host_new(lv2_ui_write, NULL, NULL, NULL); @@ -123,10 +123,10 @@ PluginUI::create(Ingen::World* world, if (!ui) { lilv_node_free(gtk_ui); - return SharedPtr(); + return SPtr(); } - SharedPtr ret(new PluginUI(world, block, lilv_ui_get_uri(ui))); + SPtr ret(new PluginUI(world, block, lilv_ui_get_uri(ui))); ret->_features = world->lv2_features().lv2_features( world, const_cast(block.get())); diff --git a/src/client/PortModel.cpp b/src/client/PortModel.cpp index a4261202..eb645791 100644 --- a/src/client/PortModel.cpp +++ b/src/client/PortModel.cpp @@ -64,11 +64,11 @@ PortModel::is_uri() const } void -PortModel::set(SharedPtr model) +PortModel::set(SPtr model) { ObjectModel::set(model); - SharedPtr port = PtrCast(model); + SPtr port = dynamic_ptr_cast(model); if (port) { _index = port->_index; _direction = port->_direction; diff --git a/src/client/ingen_client.cpp b/src/client/ingen_client.cpp index 46a14dc1..6f873f14 100644 --- a/src/client/ingen_client.cpp +++ b/src/client/ingen_client.cpp @@ -16,15 +16,13 @@ #include "ingen/Module.hpp" #include "ingen/World.hpp" -#include "raul/SharedPtr.hpp" #include "ingen_config.h" using namespace Ingen; struct IngenClientModule : public Ingen::Module { - void load(Ingen::World* world) { - } + void load(Ingen::World* world) {} }; extern "C" { -- cgit v1.2.1