From 6af49fb89facc67f369ede8cce6c315fd705d3cc Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 26 Jul 2007 16:19:58 +0000 Subject: Fix various Table bugs (and put some way too slow code in there, but hey, it works). Use PathTable for models on the client side. Implement renaming on client side. git-svn-id: http://svn.drobilla.net/lad/ingen@636 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/client/ObjectModel.hpp | 2 +- src/libs/client/PatchModel.cpp | 2 +- src/libs/client/Serializer.hpp | 4 +-- src/libs/client/Store.cpp | 55 +++++++++++++++++++++++++++++++---------- src/libs/client/Store.hpp | 8 +++--- 5 files changed, 50 insertions(+), 21 deletions(-) (limited to 'src/libs/client') diff --git a/src/libs/client/ObjectModel.hpp b/src/libs/client/ObjectModel.hpp index fe0f223c..429f5359 100644 --- a/src/libs/client/ObjectModel.hpp +++ b/src/libs/client/ObjectModel.hpp @@ -81,7 +81,7 @@ protected: ObjectModel(const Path& path); - virtual void set_path(const Path& p) { _path = p; } + virtual void set_path(const Path& p) { _path = p; renamed_sig.emit(); } virtual void set_parent(SharedPtr p) { assert(p); _parent = p; } virtual void add_child(SharedPtr c); virtual bool remove_child(SharedPtr c); diff --git a/src/libs/client/PatchModel.cpp b/src/libs/client/PatchModel.cpp index 615ae562..f67c7706 100644 --- a/src/libs/client/PatchModel.cpp +++ b/src/libs/client/PatchModel.cpp @@ -30,7 +30,7 @@ namespace Client { void PatchModel::set_path(const Path& new_path) { - throw; + ObjectModel::set_path(new_path); #if 0 // FIXME: haack if (new_path == "") { diff --git a/src/libs/client/Serializer.hpp b/src/libs/client/Serializer.hpp index 837d7333..23f93df6 100644 --- a/src/libs/client/Serializer.hpp +++ b/src/libs/client/Serializer.hpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include "ObjectModel.hpp" namespace Ingen { @@ -72,7 +72,7 @@ private: Raul::RDF::Node path_to_node_id(const Path& path); - typedef Raul::Table NodeMap; + typedef Raul::PathTable NodeMap; Mode _mode; NodeMap _node_map; diff --git a/src/libs/client/Store.cpp b/src/libs/client/Store.cpp index a2c9bf6f..674fc24e 100644 --- a/src/libs/client/Store.cpp +++ b/src/libs/client/Store.cpp @@ -24,11 +24,13 @@ #include "PatchModel.hpp" #include "SigClientInterface.hpp" +using namespace std; +using Raul::Path; + namespace Ingen { namespace Client { - Store::Store(SharedPtr engine, SharedPtr emitter) : _engine(engine) , _emitter(emitter) @@ -146,7 +148,7 @@ Store::add_orphan(SharedPtr child) { cerr << "WARNING: Orphan object " << child->path() << " received." << endl; - Raul::Table > >::iterator children + Raul::PathTable > >::iterator children = _orphans.find(child->path().parent()); _engine->request_object(child->path().parent()); @@ -164,7 +166,7 @@ Store::add_orphan(SharedPtr child) void Store::add_metadata_orphan(const Path& subject_path, const string& predicate, const Atom& value) { - Raul::Table > >::iterator orphans + Raul::PathTable > >::iterator orphans = _metadata_orphans.find(subject_path); _engine->request_object(subject_path); @@ -182,7 +184,7 @@ Store::add_metadata_orphan(const Path& subject_path, const string& predicate, co void Store::resolve_metadata_orphans(SharedPtr subject) { - Raul::Table > >::iterator v + Raul::PathTable > >::iterator v = _metadata_orphans.find(subject->path()); if (v != _metadata_orphans.end()) { @@ -202,7 +204,7 @@ Store::resolve_metadata_orphans(SharedPtr subject) void Store::resolve_orphans(SharedPtr parent) { - Raul::Table > >::iterator c + Raul::PathTable > >::iterator c = _orphans.find(parent->path()); if (c != _orphans.end()) { @@ -257,7 +259,7 @@ Store::add_object(SharedPtr object) } - //cout << "[Store] Added " << object->path() << endl; + cout << "[Store] Added " << object->path() << endl; } @@ -348,14 +350,41 @@ Store::destruction_event(const Path& path) void Store::rename_event(const Path& old_path, const Path& new_path) { - SharedPtr object = remove_object(old_path); - if (object) { - object->set_path(new_path); - add_object(object); - object->renamed_sig.emit(); - cerr << "[Store] Renamed " << old_path << " -> " << new_path << endl; - } else { + Objects::iterator parent = _objects.find(old_path); + if (parent == _objects.end()) { cerr << "[Store] Failed to find object " << old_path << " to rename." << endl; + return; + } + + Objects::iterator descendants_end = _objects.find_descendants_end(parent); + + vector > > objs = _objects.yank(parent, descendants_end); + + assert(objs.size() > 0); + + for (vector > >::iterator i = objs.begin(); i != objs.end(); ++i) { + const Path& child_old_path = i->first; + assert(Path::descendant_comparator(old_path, child_old_path)); + + Path child_new_path; + if (child_old_path == old_path) + child_new_path = new_path; + else + child_new_path = new_path.base() + child_old_path.substr(old_path.length()+1); + + cerr << "[Store] Renamed " << child_old_path << " -> " << child_new_path << endl; + i->second->set_path(child_new_path); + i->first = child_new_path; + } + + _objects.cram(objs); + + cerr << "[Store] Table:" << endl; + //for (size_t i=0; i < objs.size(); ++i) { + // cerr << objs[i].first << "\t\t: " << objs[i].second << endl; + //} + for (Objects::iterator i = _objects.begin(); i != _objects.end(); ++i) { + cerr << i->first << "\t\t: " << i->second << endl; } } diff --git a/src/libs/client/Store.hpp b/src/libs/client/Store.hpp index 627d6f8a..25398eaa 100644 --- a/src/libs/client/Store.hpp +++ b/src/libs/client/Store.hpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include "interface/EngineInterface.hpp" using std::string; using std::list; @@ -63,7 +63,7 @@ public: typedef Raul::Table > Plugins; const Plugins& plugins() const { return _plugins; } - typedef Raul::Table > Objects; + typedef Raul::PathTable > Objects; const Objects& objects() const { return _objects; } sigc::signal > new_object_sig; @@ -113,14 +113,14 @@ private: /** Objects we've received, but depend on the existance of another unknown object. * Keyed by the path of the depended-on object (for tolerance of orderless comms) */ - Raul::Table > > _orphans; + Raul::PathTable > > _orphans; /** Same idea, except with plugins instead of parents. * It's unfortunate everything doesn't just have a URI and this was the same.. ahem.. */ Raul::Table > > _plugin_orphans; /** Not orphans OF metadata like the above, but orphans which are metadata */ - Raul::Table > > _metadata_orphans; + Raul::PathTable > > _metadata_orphans; /** Ditto */ list > _connection_orphans; -- cgit v1.2.1