From f7368e7850307de97b024238a4f520afe1150c8b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 26 Jul 2007 09:32:49 +0000 Subject: Add const find interface to Raul::Table, fix bugs. Use Raul::Table on Ingen client side instead of std::map for objects, plugins. Work on renaming (still broken). git-svn-id: http://svn.drobilla.net/lad/ingen@634 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/client/PatchModel.cpp | 132 ++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 82 deletions(-) (limited to 'src/libs/client/PatchModel.cpp') diff --git a/src/libs/client/PatchModel.cpp b/src/libs/client/PatchModel.cpp index 85cf3dc7..615ae562 100644 --- a/src/libs/client/PatchModel.cpp +++ b/src/libs/client/PatchModel.cpp @@ -30,6 +30,8 @@ namespace Client { void PatchModel::set_path(const Path& new_path) { + throw; +#if 0 // FIXME: haack if (new_path == "") { _path = ""; @@ -37,7 +39,7 @@ PatchModel::set_path(const Path& new_path) } NodeModel::set_path(new_path); - for (NodeModelMap::iterator i = _nodes.begin(); i != _nodes.end(); ++i) + for (Children::iterator i = _children.begin(); i != _children.end(); ++i) (*i).second->set_path(_path +"/"+ (*i).second->path().name()); #ifdef DEBUG @@ -48,6 +50,7 @@ PatchModel::set_path(const Path& new_path) assert((*j)->src_port_path().parent().parent() == new_path); } #endif +#endif } @@ -55,100 +58,65 @@ void PatchModel::add_child(SharedPtr c) { assert(c->parent().get() == this); - - SharedPtr pm = PtrCast(c); - if (pm) { - add_port(pm); - return; - } - SharedPtr nm = PtrCast(c); - if (nm) { - add_node(nm); - return; - } -} - - -void -PatchModel::remove_child(SharedPtr c) -{ - assert(c->path().is_child_of(_path)); - assert(c->parent().get() == this); + ObjectModel::add_child(c); SharedPtr pm = PtrCast(c); if (pm) { - remove_port(pm); + add_port(pm); return; } SharedPtr nm = PtrCast(c); - if (nm) { - remove_node(nm); - return; - } + if (nm) + new_node_sig.emit(nm); } - SharedPtr PatchModel::get_node(const string& name) const { - assert(name.find("/") == string::npos); - NodeModelMap::const_iterator i = _nodes.find(name); - return ((i != _nodes.end()) ? (*i).second : SharedPtr()); + return PtrCast(get_child(name)); } -void -PatchModel::add_node(SharedPtr nm) +bool +PatchModel::remove_child(SharedPtr o) { - assert(nm); - assert(nm->path().is_child_of(_path)); - assert(nm->parent().get() == this); - - NodeModelMap::iterator existing = _nodes.find(nm->path().name()); + assert(o->path().is_child_of(_path)); + assert(o->parent().get() == this); - // Store should have handled this by merging the two - assert(existing == _nodes.end()); + SharedPtr pm = PtrCast(o); + if (pm) + remove_port(pm); + + // Remove any connections which referred to this object, + // since they can't possibly exist anymore + for (ConnectionList::iterator j = _connections.begin(); j != _connections.end() ; ) { - _nodes[nm->path().name()] = nm; - new_node_sig.emit(nm); -} + list >::iterator next = j; + ++next; + SharedPtr cm = (*j); -void -PatchModel::remove_node(SharedPtr nm) -{ - assert(nm->path().is_child_of(_path)); - assert(nm->parent().get() == this); - - NodeModelMap::iterator i = _nodes.find(nm->path().name()); - if (i != _nodes.end()) { - assert(i->second == nm); - - // Remove any connections which referred to this node, - // since they can't possibly exist anymore - for (list >::iterator j = _connections.begin(); - j != _connections.end() ; ) { - list >::iterator next = j; - ++next; - SharedPtr cm = (*j); - if (cm->src_port_path().parent() == nm->path() - || cm->dst_port_path().parent() == nm->path()) { - removed_connection_sig.emit(cm); - _connections.erase(j); // cuts our reference - assert(!get_connection(cm->src_port_path(), cm->dst_port_path())); // no duplicates - } - j = next; + if (cm->src_port_path().parent() == o->path() + || cm->src_port_path() == o->path() + || cm->dst_port_path().parent() == o->path() + || cm->dst_port_path() == o->path()) { + removed_connection_sig.emit(cm); + _connections.erase(j); // cuts our reference + assert(!get_connection(cm->src_port_path(), cm->dst_port_path())); // no duplicates } - - // Remove the Node itself - _nodes.erase(i); - removed_node_sig.emit(nm); + j = next; + } + if (ObjectModel::remove_child(o)) { + SharedPtr nm = PtrCast(o); + if (nm) { + removed_node_sig.emit(nm); + } + return true; } else { - cerr << "[PatchModel::remove_node] " << _path - << ": failed to find node " << nm->path().name() << endl; + return false; } } @@ -157,10 +125,10 @@ void PatchModel::remove_node(const string& name) { assert(name.find("/") == string::npos); - NodeModelMap::iterator i = _nodes.find(name); - if (i != _nodes.end()) { + NodeModelMap::iterator i = _children.find(name); + if (i != _children.end()) { //delete i->second; - _nodes.erase(i); + _children.erase(i); removed_node_sig.emit(name); i->second->parent().reset(); return; @@ -176,17 +144,17 @@ PatchModel::clear() //for (list >::iterator j = _connections.begin(); j != _connections.end(); ++j) // delete (*j); - for (NodeModelMap::iterator i = _nodes.begin(); i != _nodes.end(); ++i) { + /*for (Children::iterator i = _children.begin(); i != _children.end(); ++i) { (*i).second->clear(); //delete (*i).second; - } + }*/ - _nodes.clear(); + _children.clear(); _connections.clear(); NodeModel::clear(); - assert(_nodes.empty()); + assert(_children.empty()); assert(_connections.empty()); assert(_ports.empty()); } @@ -205,9 +173,9 @@ PatchModel::rename_node(const Path& old_path, const Path& new_path) assert(old_path.parent() == path()); assert(new_path.parent() == path()); - NodeModelMap::iterator i = _nodes.find(old_path.name()); + NodeModelMap::iterator i = _children.find(old_path.name()); - if (i != _nodes.end()) { + if (i != _children.end()) { SharedPtr nm = (*i).second; for (list >::iterator j = _connections.begin(); j != _connections.end(); ++j) { if ((*j)->src_port_path().parent() == old_path) @@ -215,9 +183,9 @@ PatchModel::rename_node(const Path& old_path, const Path& new_path) if ((*j)->dst_port_path().parent() == old_path) (*j)->dst_port_path(new_path.base() + (*j)->dst_port_path().name()); } - _nodes.erase(i); + _children.erase(i); assert(nm->path() == new_path); - _nodes[new_path.name()] = nm; + _children[new_path.name()] = nm; return; } -- cgit v1.2.1