From bee242f29045b82e50a4f112ac17f7e14344df78 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 26 Jul 2007 19:16:52 +0000 Subject: Use PathTable for engine side objects. Re-implement renaming and destroying more cleanly (not to mention workingly). git-svn-id: http://svn.drobilla.net/lad/ingen@638 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/engine/ObjectStore.cpp | 95 ++++++++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 21 deletions(-) (limited to 'src/libs/engine/ObjectStore.cpp') diff --git a/src/libs/engine/ObjectStore.cpp b/src/libs/engine/ObjectStore.cpp index 293adbef..f263db74 100644 --- a/src/libs/engine/ObjectStore.cpp +++ b/src/libs/engine/ObjectStore.cpp @@ -15,13 +15,19 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include +#include #include -#include +#include +#include #include "ObjectStore.hpp" #include "Patch.hpp" #include "Node.hpp" #include "Port.hpp" -#include "Tree.hpp" +#include "ThreadManager.hpp" + +using namespace std; +using namespace Raul; namespace Ingen { @@ -31,7 +37,7 @@ namespace Ingen { Patch* ObjectStore::find_patch(const Path& path) { - GraphObject* const object = find(path); + GraphObject* const object = find_object(path); return dynamic_cast(object); } @@ -41,7 +47,7 @@ ObjectStore::find_patch(const Path& path) Node* ObjectStore::find_node(const Path& path) { - GraphObject* const object = find(path); + GraphObject* const object = find_object(path); return dynamic_cast(object); } @@ -51,7 +57,7 @@ ObjectStore::find_node(const Path& path) Port* ObjectStore::find_port(const Path& path) { - GraphObject* const object = find(path); + GraphObject* const object = find_object(path); return dynamic_cast(object); } @@ -59,9 +65,10 @@ ObjectStore::find_port(const Path& path) /** Find the Object at the given path. */ GraphObject* -ObjectStore::find(const Path& path) +ObjectStore::find_object(const Path& path) { - return _objects.find(path); + Objects::iterator i = _objects.find(path); + return ((i == _objects.end()) ? NULL : i->second); } @@ -70,11 +77,37 @@ ObjectStore::find(const Path& path) void ObjectStore::add(GraphObject* o) { + assert(ThreadManager::current_thread_id() == THREAD_PRE_PROCESS); + cerr << "[ObjectStore] Adding " << o->path() << endl; - _objects.insert(new TreeNode(o->path(), o)); + _objects.insert(make_pair(o->path(), o)); + + Node* node = dynamic_cast(o); + if (node) { + for (size_t i=0; i < node->num_ports(); ++i) { + add(node->ports().at(i)); + } + } } +/** Add a family of objects to the store. Not realtime safe. + */ +void +ObjectStore::add(const Table& table) +{ + assert(ThreadManager::current_thread_id() == THREAD_PRE_PROCESS); + + //cerr << "[ObjectStore] Adding " << o[0].second->path() << endl; + _objects.cram(table); + + cerr << "[ObjectStore] Adding Table:" << endl; + for (Table::const_iterator i = table.begin(); i != table.end(); ++i) { + cerr << i->first << " = " << i->second->path() << endl; + } +} + +#if 0 /** Add an object to the store. Not realtime safe. */ void @@ -83,25 +116,45 @@ ObjectStore::add(TreeNode* tn) cerr << "[ObjectStore] Adding " << tn->key() << endl; _objects.insert(tn); } +#endif - -/** Remove a patch from the store. +/** Remove an object from the store. * - * It it the caller's responsibility to delete the returned Raul::ListNode. - * - * @returns TreeNode containing object removed on success, NULL if not found. + * Returned is a vector containing all descendants of the object removed + * including the object itself, in lexicographically sorted order by Path. */ -TreeNode* -ObjectStore::remove(const string& path) +Table +ObjectStore::remove(const Path& path) { - TreeNode* const removed = _objects.remove(path); + return remove(_objects.find(path)); +} - if (removed == NULL) - cerr << "[ObjectStore] WARNING: Removing " << path << " failed." << endl; - else - cerr << "[ObjectStore] Removed " << path << endl; + +/** Remove an object from the store. + * + * Returned is a vector containing all descendants of the object removed + * including the object itself, in lexicographically sorted order by Path. + */ +Table +ObjectStore::remove(Objects::iterator object) +{ + assert(ThreadManager::current_thread_id() == THREAD_PRE_PROCESS); - return removed; + if (object != _objects.end()) { + Objects::iterator descendants_end = _objects.find_descendants_end(object); + cout << "[ObjectStore] Removing " << object->first << " {" << endl; + Table removed = _objects.yank(object, descendants_end); + for (Table::iterator i = removed.begin(); i != removed.end(); ++i) { + cout << "\t" << i->first << endl; + } + cout << "}" << endl; + + return removed; + + } else { + cerr << "[ObjectStore] WARNING: Removing " << object->first << " failed." << endl; + return Table(); + } } -- cgit v1.2.1