diff options
author | David Robillard <d@drobilla.net> | 2011-06-07 02:44:16 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-06-07 02:44:16 +0000 |
commit | 00f2ad0069fe4e51e40e6a3b3d41f125b67f89cf (patch) | |
tree | 1a96d7873a700a05815bde3e3119b7055532d861 /src/PatchageCanvas.cpp | |
parent | 9adc6fb021bcde9720a8afcac9a1a87521691fba (diff) | |
download | patchage-00f2ad0069fe4e51e40e6a3b3d41f125b67f89cf.tar.gz patchage-00f2ad0069fe4e51e40e6a3b3d41f125b67f89cf.tar.bz2 patchage-00f2ad0069fe4e51e40e6a3b3d41f125b67f89cf.zip |
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/patchage@3366 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/PatchageCanvas.cpp')
-rw-r--r-- | src/PatchageCanvas.cpp | 95 |
1 files changed, 66 insertions, 29 deletions
diff --git a/src/PatchageCanvas.cpp b/src/PatchageCanvas.cpp index a26e75d..279a852 100644 --- a/src/PatchageCanvas.cpp +++ b/src/PatchageCanvas.cpp @@ -42,14 +42,14 @@ PatchageCanvas::PatchageCanvas(Patchage* app, int width, int height) { } -boost::shared_ptr<PatchageModule> +PatchageModule* PatchageCanvas::find_module(const string& name, ModuleType type) { const ModuleIndex::const_iterator i = _module_index.find(name); if (i == _module_index.end()) - return boost::shared_ptr<PatchageModule>(); + return NULL; - boost::shared_ptr<PatchageModule> io_module; + PatchageModule* io_module = NULL; for (ModuleIndex::const_iterator j = i; j != _module_index.end() && j->first == name; ++j) { if (j->second->type() == type) { return j->second; @@ -62,10 +62,10 @@ PatchageCanvas::find_module(const string& name, ModuleType type) return io_module; } -boost::shared_ptr<PatchagePort> +PatchagePort* PatchageCanvas::find_port(const PortID& id) { - boost::shared_ptr<PatchagePort> pp; + PatchagePort* pp = NULL; PortIndex::iterator i = _port_index.find(id); if (i != _port_index.end()) { @@ -78,17 +78,17 @@ PatchageCanvas::find_port(const PortID& id) if (id.type == PortID::JACK_ID) { jack_port_t* jack_port = jack_port_by_id(_app->jack_driver()->client(), id.id.jack_id); if (!jack_port) - return boost::shared_ptr<PatchagePort>(); + return NULL; string module_name; string port_name; _app->jack_driver()->port_names(id, module_name, port_name); - SharedPtr<PatchageModule> module = find_module( + PatchageModule* module = find_module( module_name, (jack_port_flags(jack_port) & JackPortIsInput) ? Input : Output); if (module) - pp = PtrCast<PatchagePort>(module->get_port(port_name)); + pp = dynamic_cast<PatchagePort*>(module->get_port(port_name)); if (pp) index_port(id, pp); @@ -98,10 +98,10 @@ PatchageCanvas::find_port(const PortID& id) return pp; } -boost::shared_ptr<PatchagePort> +PatchagePort* PatchageCanvas::remove_port(const PortID& id) { - boost::shared_ptr<PatchagePort> port = find_port(id); + PatchagePort* const port = find_port(id); if (!port) return port; @@ -116,29 +116,67 @@ PatchageCanvas::remove_port(const PortID& id) return port; } -boost::shared_ptr<PatchagePort> +void +PatchageCanvas::remove_ports(bool (*pred)(const PatchagePort*)) +{ + std::set<PatchageModule*> empty; + for (Items::iterator i = items().begin(); i != items().end(); ++i) { + PatchageModule* module = dynamic_cast<PatchageModule*>(*i); + if (!module) + continue; + + FlowCanvas::Module::Ports ports = module->ports(); // copy + for (FlowCanvas::Module::Ports::iterator p = ports.begin(); + p != ports.end(); ++p) { + if (pred(dynamic_cast<PatchagePort*>(*p))) { + delete *p; + } + } + + if (module->num_ports() == 0) { + empty.insert(module); + } + } + + for (PortIndex::iterator i = _port_index.begin(); + i != _port_index.end();) { + PortIndex::iterator next = i; + ++next; + if (pred(i->second)) { + _port_index.erase(i); + } + i = next; + } + + for (std::set<PatchageModule*>::iterator i = empty.begin(); + i != empty.end(); ++i) { + delete *i; + } +} + +PatchagePort* PatchageCanvas::find_port_by_name(const std::string& client_name, const std::string& port_name) { const ModuleIndex::const_iterator i = _module_index.find(client_name); if (i == _module_index.end()) - return boost::shared_ptr<PatchagePort>(); + return NULL; for (ModuleIndex::const_iterator j = i; j != _module_index.end() && j->first == client_name; ++j) { - SharedPtr<PatchagePort> port = PtrCast<PatchagePort>(j->second->get_port(port_name)); + PatchagePort* port = dynamic_cast<PatchagePort*>(j->second->get_port(port_name)); if (port) return port; } - return boost::shared_ptr<PatchagePort>(); + return NULL; } void -PatchageCanvas::connect(boost::shared_ptr<FlowCanvas::Connectable> port1, - boost::shared_ptr<FlowCanvas::Connectable> port2) +PatchageCanvas::connect(FlowCanvas::Connectable* port1, + FlowCanvas::Connectable* port2) { - boost::shared_ptr<PatchagePort> p1 = boost::dynamic_pointer_cast<PatchagePort>(port1); - boost::shared_ptr<PatchagePort> p2 = boost::dynamic_pointer_cast<PatchagePort>(port2); + PatchagePort* p1 = dynamic_cast<PatchagePort*>(port1); + PatchagePort* p2 = dynamic_cast<PatchagePort*>(port2); if (!p1 || !p2) return; @@ -157,18 +195,17 @@ PatchageCanvas::connect(boost::shared_ptr<FlowCanvas::Connectable> port1, } void -PatchageCanvas::disconnect(boost::shared_ptr<FlowCanvas::Connectable> port1, - boost::shared_ptr<FlowCanvas::Connectable> port2) +PatchageCanvas::disconnect(FlowCanvas::Connectable* port1, + FlowCanvas::Connectable* port2) { - boost::shared_ptr<PatchagePort> input = boost::dynamic_pointer_cast<PatchagePort>(port1); - boost::shared_ptr<PatchagePort> output = boost::dynamic_pointer_cast<PatchagePort>(port2); - + PatchagePort* input = dynamic_cast<PatchagePort*>(port1); + PatchagePort* output = dynamic_cast<PatchagePort*>(port2); if (!input || !output) return; if (input->is_output() && output->is_input()) { // Damn, guessed wrong - boost::shared_ptr<PatchagePort> swap = input; + PatchagePort* swap = input; input = output; output = swap; } @@ -199,13 +236,13 @@ PatchageCanvas::status_message(const string& msg) } void -PatchageCanvas::add_module(const std::string& name, boost::shared_ptr<PatchageModule> module) +PatchageCanvas::add_module(const std::string& name, PatchageModule* module) { _module_index.insert(std::make_pair(name, module)); // Join partners, if applicable - boost::shared_ptr<PatchageModule> in_module; - boost::shared_ptr<PatchageModule> out_module; + PatchageModule* in_module = NULL; + PatchageModule* out_module = NULL; if (module->type() == Input) { in_module = module; out_module = find_module(name, Output); @@ -220,14 +257,14 @@ PatchageCanvas::add_module(const std::string& name, boost::shared_ptr<PatchageMo } bool -PatchageCanvas::remove_item(boost::shared_ptr<FlowCanvas::Item> i) +PatchageCanvas::remove_item(FlowCanvas::Item* i) { // Remove item from canvas const bool ret = FlowCanvas::Canvas::remove_item(i); if (!ret) return ret; - SharedPtr<PatchageModule> module = PtrCast<PatchageModule>(i); + PatchageModule* const module = dynamic_cast<PatchageModule*>(i); if (!module) return ret; |