From d42b83ffe581651886ca0874b6b75dcbb6127aea Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 7 Jun 2011 02:44:16 +0000 Subject: Remove use of smart pointers in FlowCanvas entirely. Since FlowCanvas's containers own their children, there is no real benefit to using smart pointers for objects, though there is overhead. There are no longer any add or remove methods for containers, simply create (new) and destroy (delete) objects and things should work as expected. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@3366 a436a847-0d15-0410-975c-d299462d15a1 --- src/gui/App.cpp | 7 ++-- src/gui/Connection.cpp | 12 +++---- src/gui/Connection.hpp | 10 +++--- src/gui/NodeModule.cpp | 33 +++++++++--------- src/gui/NodeModule.hpp | 9 ++--- src/gui/PatchCanvas.cpp | 82 +++++++++++++++++++-------------------------- src/gui/PatchCanvas.hpp | 10 +++--- src/gui/PatchPortModule.cpp | 7 ++-- src/gui/Port.cpp | 17 +++++----- src/gui/Port.hpp | 16 ++++----- 10 files changed, 95 insertions(+), 108 deletions(-) (limited to 'src/gui') diff --git a/src/gui/App.cpp b/src/gui/App.cpp index d76ca7d6..edd4ec06 100644 --- a/src/gui/App.cpp +++ b/src/gui/App.cpp @@ -218,10 +218,11 @@ App::port_activity(Port* port) inserted.first->second = false; if (port->is_output()) { - for (Port::Connections::const_iterator i = port->connections().begin(); i != port->connections().end(); ++i) { - const SharedPtr dst = PtrCast(i->lock()->dest().lock()); + for (Port::Connections::const_iterator i = port->connections().begin(); + i != port->connections().end(); ++i) { + Port* const dst = dynamic_cast((*i)->dest()); if (dst) - port_activity(dst.get()); + port_activity(dst); } } diff --git a/src/gui/Connection.cpp b/src/gui/Connection.cpp index 5d1ceed7..511f6044 100644 --- a/src/gui/Connection.cpp +++ b/src/gui/Connection.cpp @@ -25,15 +25,15 @@ using namespace std; namespace Ingen { namespace GUI { -Connection::Connection(FlowCanvas::Canvas& canvas, - boost::shared_ptr model, - boost::shared_ptr src, - boost::shared_ptr dst, - uint32_t color) +Connection::Connection(FlowCanvas::Canvas& canvas, + boost::shared_ptr model, + FlowCanvas::Connectable* src, + FlowCanvas::Connectable* dst, + uint32_t color) : FlowCanvas::Connection(canvas, src, dst, color) , _connection_model(model) { - boost::shared_ptr src_port = boost::dynamic_pointer_cast(src); + Port* const src_port = dynamic_cast(src); if (src_port) _bpath.property_dash() = src_port->dash(); } diff --git a/src/gui/Connection.hpp b/src/gui/Connection.hpp index 7bd39ff5..395f5e62 100644 --- a/src/gui/Connection.hpp +++ b/src/gui/Connection.hpp @@ -37,11 +37,11 @@ namespace GUI { class Connection : public FlowCanvas::Connection { public: - Connection(FlowCanvas::Canvas& canvas, - boost::shared_ptr model, - boost::shared_ptr src, - boost::shared_ptr dst, - uint32_t color); + Connection(FlowCanvas::Canvas& canvas, + boost::shared_ptr model, + FlowCanvas::Connectable* src, + FlowCanvas::Connectable* dst, + uint32_t color); SharedPtr model() const { return _connection_model; } diff --git a/src/gui/NodeModule.cpp b/src/gui/NodeModule.cpp index 20f6beb3..ebbca29a 100644 --- a/src/gui/NodeModule.cpp +++ b/src/gui/NodeModule.cpp @@ -53,9 +53,9 @@ NodeModule::NodeModule(PatchCanvas& canvas, assert(_node); node->signal_new_port().connect( - sigc::bind(sigc::mem_fun(this, &NodeModule::add_port), true)); + sigc::bind(sigc::mem_fun(this, &NodeModule::new_port_view), true)); node->signal_removed_port().connect( - sigc::hide_return(sigc::mem_fun(this, &NodeModule::remove_port))); + sigc::hide_return(sigc::mem_fun(this, &NodeModule::delete_port_view))); node->signal_property().connect( sigc::mem_fun(this, &NodeModule::property_changed)); node->signal_moved().connect( @@ -105,7 +105,7 @@ NodeModule::create(PatchCanvas& canvas, for (NodeModel::Ports::const_iterator p = node->ports().begin(); p != node->ports().end(); ++p) - ret->add_port(*p, false); + ret->new_port_view(*p, false); ret->set_stacked_border(node->polyphonic()); @@ -134,7 +134,7 @@ NodeModule::show_human_names(bool b) } for (Ports::const_iterator i = ports().begin(); i != ports().end(); ++i) { - SharedPtr port = PtrCast(*i); + Ingen::GUI::Port* const port = dynamic_cast(*i); Glib::ustring label(port->model()->symbol().c_str()); if (b) { const Raul::Atom& name_property = port->model()->get_property(uris.lv2_name); @@ -178,7 +178,7 @@ void NodeModule::plugin_changed() { for (Ports::iterator p = ports().begin(); p != ports().end(); ++p) - PtrCast(*p)->update_metadata(); + dynamic_cast(*p)->update_metadata(); } void @@ -251,10 +251,10 @@ NodeModule::rename() } void -NodeModule::add_port(SharedPtr port, bool resize_to_fit) +NodeModule::new_port_view(SharedPtr port, bool resize_to_fit) { - Module::add_port(Port::create(PtrCast(shared_from_this()), port, - App::instance().configuration()->name_style() == Configuration::HUMAN)); + Port::create(*this, port, + App::instance().configuration()->name_style() == Configuration::HUMAN); port->signal_value_changed().connect( sigc::bind<0>(sigc::mem_fun(this, &NodeModule::value_changed), @@ -264,24 +264,23 @@ NodeModule::add_port(SharedPtr port, bool resize_to_fit) resize(); } -boost::shared_ptr +Port* NodeModule::port(boost::shared_ptr model) { for (Ports::const_iterator p = ports().begin(); p != ports().end(); ++p) { - SharedPtr port = PtrCast(*p); + Port* const port = dynamic_cast(*p); if (port->model() == model) return port; } - return boost::shared_ptr(); + return NULL; } void -NodeModule::remove_port(SharedPtr model) +NodeModule::delete_port_view(SharedPtr model) { - SharedPtr p = port(model); + Port* p = port(model); if (p) { - Module::remove_port(p); - p.reset(); + delete p; } else { warn << "Failed to find port on module " << model->path() << endl; } @@ -401,9 +400,9 @@ NodeModule::property_changed(const URI& key, const Atom& value) } else if (key == uris.ingen_selected) { if (value.get_bool() != selected()) { if (value.get_bool()) - _canvas->select_item(shared_from_this()); + _canvas->select_item(this); else - _canvas->unselect_item(shared_from_this()); + _canvas->unselect_item(this); } } break; diff --git a/src/gui/NodeModule.hpp b/src/gui/NodeModule.hpp index 7a62b87f..7bf6f996 100644 --- a/src/gui/NodeModule.hpp +++ b/src/gui/NodeModule.hpp @@ -1,4 +1,5 @@ -/* This file is part of In* Copyright 2007-2011 David Robillard +/* This file is part of Ingen + * Copyright 2007-2011 David Robillard * * Ingen is free software; you can redistribute it and/or modify it under the * terms of the GNU General Public License as published by the Free Software @@ -55,9 +56,9 @@ public: virtual ~NodeModule(); - boost::shared_ptr port(boost::shared_ptr model); + Port* port(boost::shared_ptr model); - void remove_port(SharedPtr port); + void delete_port_view(SharedPtr port); virtual void store_location(); void show_human_names(bool b); @@ -78,7 +79,7 @@ protected: void rename(); void property_changed(const Raul::URI& predicate, const Raul::Atom& value); - void add_port(SharedPtr port, bool resize=true); + void new_port_view(SharedPtr port, bool resize=true); void value_changed(uint32_t index, const Raul::Atom& value); void plugin_changed(); diff --git a/src/gui/PatchCanvas.cpp b/src/gui/PatchCanvas.cpp index 68a4cbab..0b5d4056 100644 --- a/src/gui/PatchCanvas.cpp +++ b/src/gui/PatchCanvas.cpp @@ -305,11 +305,11 @@ PatchCanvas::show_human_names(bool b) { _human_names = b; FOREACH_ITEM(m, items()) { - boost::shared_ptr mod = boost::dynamic_pointer_cast(*m); + NodeModule* mod = dynamic_cast(*m); if (mod) mod->show_human_names(b); - boost::shared_ptr pmod = boost::dynamic_pointer_cast(*m); + PatchPortModule* pmod = dynamic_cast(*m); if (pmod) pmod->show_human_names(b); } @@ -320,7 +320,7 @@ PatchCanvas::show_port_names(bool b) { _show_port_names = b; FOREACH_ITEM(i, items()) { - boost::shared_ptr m = boost::dynamic_pointer_cast(*i); + FlowCanvas::Module* m = dynamic_cast(*i); if (m) m->set_show_port_labels(b); } @@ -390,7 +390,6 @@ PatchCanvas::add_node(SharedPtr nm) module->set_icon(App::instance().icon_from_path(plugm->icon_path(), 100)); } - add_item(module); module->show(); _views.insert(std::make_pair(nm, module)); } @@ -401,7 +400,6 @@ PatchCanvas::remove_node(SharedPtr nm) Views::iterator i = _views.find(nm); if (i != _views.end()) { - remove_item(i->second); _views.erase(i); } } @@ -411,7 +409,6 @@ PatchCanvas::add_port(SharedPtr pm) { SharedPtr view = PatchPortModule::create(*this, pm, _human_names); _views.insert(std::make_pair(pm, view)); - add_item(view); view->show(); } @@ -422,43 +419,39 @@ PatchCanvas::remove_port(SharedPtr pm) // Port on this patch if (i != _views.end()) { - bool ret = remove_item(i->second); - if (!ret) - warn << "Failed to remove port item " << pm->path() << endl; - i->second.reset(); _views.erase(i); } else { SharedPtr module = PtrCast(_views[pm->parent()]); - module->remove_port(pm); + module->delete_port_view(pm); } assert(_views.find(pm) == _views.end()); } -SharedPtr +FlowCanvas::Port* PatchCanvas::get_port_view(SharedPtr port) { SharedPtr module = _views[port]; // Port on this patch if (module) { - return (PtrCast(module)) - ? *(PtrCast(module)->ports().begin()) - : PtrCast(module); + return (dynamic_cast(module.get())) + ? *(dynamic_cast(module.get())->ports().begin()) + : dynamic_cast(module.get()); } else { module = PtrCast(_views[port->parent()]); if (module) { for (Module::Ports::const_iterator p = module->ports().begin(); p != module->ports().end(); ++p) { - boost::shared_ptr pv = boost::dynamic_pointer_cast(*p); + GUI::Port* pv = dynamic_cast(*p); if (pv && pv->model() == port) return pv; } } } - return SharedPtr(); + return NULL; } void @@ -466,14 +459,13 @@ PatchCanvas::connection(SharedPtr cm) { assert(cm); - const SharedPtr src = get_port_view(cm->src_port()); - const SharedPtr dst = get_port_view(cm->dst_port()); + FlowCanvas::Port* const src = get_port_view(cm->src_port()); + FlowCanvas::Port* const dst = get_port_view(cm->dst_port()); if (src && dst) { add_connection( - boost::shared_ptr( - new GUI::Connection(*this, cm, src, dst, - src->color() + 0x22222200))); + new GUI::Connection(*this, cm, src, dst, + src->color() + 0x22222200)); } else { LOG(error) << "Unable to find ports to connect " << cm->src_port_path() << " -> " << cm->dst_port_path() << endl; @@ -483,8 +475,8 @@ PatchCanvas::connection(SharedPtr cm) void PatchCanvas::disconnection(SharedPtr cm) { - const SharedPtr src = get_port_view(cm->src_port()); - const SharedPtr dst = get_port_view(cm->dst_port()); + FlowCanvas::Port* const src = get_port_view(cm->src_port()); + FlowCanvas::Port* const dst = get_port_view(cm->dst_port()); if (src && dst) remove_connection(src, dst); @@ -494,14 +486,14 @@ PatchCanvas::disconnection(SharedPtr cm) } void -PatchCanvas::connect(boost::shared_ptr src_port, - boost::shared_ptr dst_port) +PatchCanvas::connect(FlowCanvas::Connectable* src_port, + FlowCanvas::Connectable* dst_port) { - const boost::shared_ptr src - = boost::dynamic_pointer_cast(src_port); + const Ingen::GUI::Port* const src + = dynamic_cast(src_port); - const boost::shared_ptr dst - = boost::dynamic_pointer_cast(dst_port); + const Ingen::GUI::Port* const dst + = dynamic_cast(dst_port); if (!src || !dst) return; @@ -510,14 +502,14 @@ PatchCanvas::connect(boost::shared_ptr src_port, } void -PatchCanvas::disconnect(boost::shared_ptr src_port, - boost::shared_ptr dst_port) +PatchCanvas::disconnect(FlowCanvas::Connectable* src_port, + FlowCanvas::Connectable* dst_port) { - const boost::shared_ptr src - = boost::dynamic_pointer_cast(src_port); + const Ingen::GUI::Port* const src + = dynamic_cast(src_port); - const boost::shared_ptr dst - = boost::dynamic_pointer_cast(dst_port); + const Ingen::GUI::Port* const dst + = dynamic_cast(dst_port); App::instance().engine()->disconnect(src->model()->path(), dst->model()->path()); @@ -606,13 +598,11 @@ void PatchCanvas::destroy_selection() { FOREACH_ITEM(m, selected_items()) { - boost::shared_ptr module( - boost::dynamic_pointer_cast(*m)); + NodeModule* module = dynamic_cast(*m); if (module) { App::instance().engine()->del(module->node()->path()); } else { - boost::shared_ptr port_module( - boost::dynamic_pointer_cast(*m)); + PatchPortModule* port_module = dynamic_cast(*m); if (port_module) App::instance().engine()->del(port_module->port()->path()); } @@ -624,7 +614,7 @@ PatchCanvas::select_all() { unselect_ports(); FOREACH_ITEM(m, items()) - if (boost::dynamic_pointer_cast(*m)) + if (dynamic_cast(*m)) if (!(*m)->selected()) select_item(*m); } @@ -637,21 +627,19 @@ PatchCanvas::copy_selection() serialiser.start_to_string(_patch->path(), base_uri); FOREACH_ITEM(m, selected_items()) { - boost::shared_ptr module( - boost::dynamic_pointer_cast(*m)); + NodeModule* module = dynamic_cast(*m); if (module) { serialiser.serialise(module->node()); } else { - boost::shared_ptr port_module( - boost::dynamic_pointer_cast(*m)); + PatchPortModule* port_module = dynamic_cast(*m); if (port_module) serialiser.serialise(port_module->port()); } } - for (list >::iterator c = selected_connections().begin(); + for (SelectedConnections::iterator c = selected_connections().begin(); c != selected_connections().end(); ++c) { - boost::shared_ptr connection = boost::dynamic_pointer_cast(*c); + Connection* const connection = dynamic_cast(*c); if (connection) { const Sord::URI subject(*App::instance().world()->rdf_world(), base_uri); diff --git a/src/gui/PatchCanvas.hpp b/src/gui/PatchCanvas.hpp index cd9e038f..243f76ae 100644 --- a/src/gui/PatchCanvas.hpp +++ b/src/gui/PatchCanvas.hpp @@ -124,13 +124,13 @@ private: GraphObject::Properties get_initial_data(); - SharedPtr get_port_view(SharedPtr port); + FlowCanvas::Port* get_port_view(SharedPtr port); - void connect(boost::shared_ptr src, - boost::shared_ptr dst); + void connect(FlowCanvas::Connectable* src, + FlowCanvas::Connectable* dst); - void disconnect(boost::shared_ptr src, - boost::shared_ptr dst); + void disconnect(FlowCanvas::Connectable* src, + FlowCanvas::Connectable* dst); SharedPtr _patch; diff --git a/src/gui/PatchPortModule.cpp b/src/gui/PatchPortModule.cpp index b04cc6ba..df4d8dc8 100644 --- a/src/gui/PatchPortModule.cpp +++ b/src/gui/PatchPortModule.cpp @@ -59,9 +59,8 @@ PatchPortModule::create(PatchCanvas& canvas, bool human) { boost::shared_ptr ret(new PatchPortModule(canvas, model)); - boost::shared_ptr port(Port::create(ret, model, human, true)); + boost::shared_ptr port(Port::create(*ret, model, human, true)); - ret->add_port(port); ret->set_port(port); ret->set_menu(port->menu()); @@ -149,9 +148,9 @@ PatchPortModule::property_changed(const URI& key, const Atom& value) } else if (key == uris.ingen_selected) { if (value.get_bool() != selected()) { if (value.get_bool()) { - _canvas->select_item(shared_from_this()); + _canvas->select_item(this); } else { - _canvas->unselect_item(shared_from_this()); + _canvas->unselect_item(this); } } } diff --git a/src/gui/Port.cpp b/src/gui/Port.cpp index 94b8851e..72c37b12 100644 --- a/src/gui/Port.cpp +++ b/src/gui/Port.cpp @@ -41,10 +41,10 @@ namespace GUI { ArtVpathDash* Port::_dash; SharedPtr -Port::create(boost::shared_ptr module, - SharedPtr pm, - bool human_name, - bool flip) +Port::create(FlowCanvas::Module& module, + SharedPtr pm, + bool human_name, + bool flip) { Glib::ustring label(human_name ? "" : pm->path().symbol()); if (human_name) { @@ -62,10 +62,10 @@ Port::create(boost::shared_ptr module, /** @a flip Make an input port appear as an output port, and vice versa. */ -Port::Port(boost::shared_ptr module, - SharedPtr pm, - const string& name, - bool flip) +Port::Port(FlowCanvas::Module& module, + SharedPtr pm, + const string& name, + bool flip) : FlowCanvas::Port(module, name, flip ? (!pm->is_input()) : pm->is_input(), App::instance().configuration()->get_port_color(pm.get())) @@ -73,7 +73,6 @@ Port::Port(boost::shared_ptr module, , _pressed(false) , _flipped(flip) { - assert(module); assert(pm); delete _menu; diff --git a/src/gui/Port.hpp b/src/gui/Port.hpp index 3d8fc763..17b1c37b 100644 --- a/src/gui/Port.hpp +++ b/src/gui/Port.hpp @@ -41,10 +41,10 @@ class Port : public FlowCanvas::Port { public: static SharedPtr create( - boost::shared_ptr module, - SharedPtr pm, - bool human_name, - bool flip=false); + FlowCanvas::Module& module, + SharedPtr pm, + bool human_name, + bool flip = false); ~Port(); @@ -62,10 +62,10 @@ public: ArtVpathDash* dash(); private: - Port(boost::shared_ptr module, - SharedPtr pm, - const std::string& name, - bool flip = false); + Port(FlowCanvas::Module& module, + SharedPtr pm, + const std::string& name, + bool flip=false); void property_changed(const Raul::URI& key, const Raul::Atom& value); -- cgit v1.2.1