From f36e709b68144191d51959d6a2224cd9c3ad7871 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 26 Jul 2007 23:39:01 +0000 Subject: Fix recursive patch serialization (fix ticket 63). git-svn-id: http://svn.drobilla.net/lad/ingen@642 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/client/Serializer.cpp | 44 +++++++++++++++++++++++++++++++++------ src/libs/client/Serializer.hpp | 26 +++++++++++++---------- src/libs/engine/NodeBase.cpp | 2 +- src/libs/gui/PatchWindow.cpp | 4 ++-- src/libs/gui/ThreadedLoader.cpp | 13 ++++-------- src/libs/gui/ThreadedLoader.hpp | 4 ++-- src/libs/serialisation/Loader.cpp | 10 +++++---- 7 files changed, 68 insertions(+), 35 deletions(-) diff --git a/src/libs/client/Serializer.cpp b/src/libs/client/Serializer.cpp index d662b83b..be468202 100644 --- a/src/libs/client/Serializer.cpp +++ b/src/libs/client/Serializer.cpp @@ -57,6 +57,25 @@ Serializer::Serializer(Raul::RDF::World& world) : _world(world) { } + +void +Serializer::to_file(SharedPtr object, const string& filename) +{ + _root_object = object; + start_to_filename(filename); + serialize(object); + finish(); +} + + +string +Serializer::to_string(SharedPtr object) +{ + _root_object = object; + start_to_string(); + serialize(object); + return finish(); +} /** Begin a serialization to a file. @@ -200,7 +219,7 @@ Serializer::serialize(SharedPtr object) throw (std::logic_error) SharedPtr patch = PtrCast(object); if (patch) { - serialize_patch(patch, Node(_model->world(), Node::RESOURCE, _base_uri)); + serialize_patch(patch); return; } @@ -221,11 +240,26 @@ Serializer::serialize(SharedPtr object) throw (std::logic_error) } +Node +Serializer::patch_path_to_rdf_id(const Path& path) +{ + if (path == _root_object->path()) { + return Node(_model->world(), Node::RESOURCE, _base_uri); + } else { + assert(path.length() > _root_object->path().length()); + return Node(_model->world(), Node::RESOURCE, + _base_uri + string("#") + path.substr(_root_object->path().length() + 1)); + } +} + + void -Serializer::serialize_patch(SharedPtr patch, const Node& patch_id) +Serializer::serialize_patch(SharedPtr patch) { assert(_model); + const Node patch_id = patch_path_to_rdf_id(patch->path()); + _model->add_statement( patch_id, "rdf:type", @@ -255,10 +289,8 @@ Serializer::serialize_patch(SharedPtr patch, const Node& patch_id) SharedPtr patch = PtrCast(n->second); SharedPtr node = PtrCast(n->second); if (patch) { - const Node subpatch_id = Node(_model->world(), Node::RESOURCE, - patch_id.to_string() + "#" + patch->path().substr(1)); - _model->add_statement(patch_id, "ingen:node", subpatch_id); - serialize_patch(patch, subpatch_id); + _model->add_statement(patch_id, "ingen:node", patch_path_to_rdf_id(patch->path())); + serialize_patch(patch); } else if (node) { const Node node_id = path_to_node_id(n->second->path()); _model->add_statement(patch_id, "ingen:node", node_id); diff --git a/src/libs/client/Serializer.hpp b/src/libs/client/Serializer.hpp index 23f93df6..bb3b0e8a 100644 --- a/src/libs/client/Serializer.hpp +++ b/src/libs/client/Serializer.hpp @@ -51,34 +51,38 @@ class Serializer public: Serializer(Raul::RDF::World& world); - void start_to_filename(const string& filename); + void to_file(SharedPtr object, const string& filename); + string to_string(SharedPtr object); + void start_to_string(); - - void serialize(SharedPtr object) throw (std::logic_error); + void serialize(SharedPtr object) throw (std::logic_error); void serialize_connection(SharedPtr c) throw (std::logic_error); - string finish(); - + private: enum Mode { TO_FILE, TO_STRING }; + + void start_to_filename(const string& filename); void setup_prefixes(); void serialize_plugin(SharedPtr p); - void serialize_patch(SharedPtr p, const Raul::RDF::Node& id); + void serialize_patch(SharedPtr p); void serialize_node(SharedPtr n, const Raul::RDF::Node& id); void serialize_port(SharedPtr p, const Raul::RDF::Node& id); Raul::RDF::Node path_to_node_id(const Path& path); + Raul::RDF::Node patch_path_to_rdf_id(const Path& path); typedef Raul::PathTable NodeMap; - Mode _mode; - NodeMap _node_map; - string _base_uri; - Raul::RDF::World& _world; - Raul::RDF::Model* _model; + SharedPtr _root_object; + Mode _mode; + NodeMap _node_map; + string _base_uri; + Raul::RDF::World& _world; + Raul::RDF::Model* _model; }; diff --git a/src/libs/engine/NodeBase.cpp b/src/libs/engine/NodeBase.cpp index 7914eab3..d57d4414 100644 --- a/src/libs/engine/NodeBase.cpp +++ b/src/libs/engine/NodeBase.cpp @@ -40,8 +40,8 @@ NodeBase::NodeBase(const Plugin* plugin, const string& name, size_t poly, Patch* _srate(srate), _buffer_size(buffer_size), _activated(false), - _ports(NULL), _traversed(false), + _ports(NULL), _providers(new Raul::List()), _dependants(new Raul::List()) { diff --git a/src/libs/gui/PatchWindow.cpp b/src/libs/gui/PatchWindow.cpp index b0b87c5e..e92f0fd7 100644 --- a/src/libs/gui/PatchWindow.cpp +++ b/src/libs/gui/PatchWindow.cpp @@ -306,7 +306,7 @@ PatchWindow::event_save() if (_patch->filename() == "") event_save_as(); else - App::instance().loader()->save_patch(_patch, _patch->filename(), false); + App::instance().loader()->save_patch(_patch, _patch->filename()); } @@ -363,7 +363,7 @@ PatchWindow::event_save_as() fin.close(); if (confirm) { - App::instance().loader()->save_patch(_patch, filename, true); + App::instance().loader()->save_patch(_patch, filename); _patch->set_filename(filename); //_patch->set_metadata("filename", Atom(filename.c_str())); } diff --git a/src/libs/gui/ThreadedLoader.cpp b/src/libs/gui/ThreadedLoader.cpp index 63c5bf3c..ecabe5e1 100644 --- a/src/libs/gui/ThreadedLoader.cpp +++ b/src/libs/gui/ThreadedLoader.cpp @@ -113,13 +113,13 @@ ThreadedLoader::load_patch(bool merge, void -ThreadedLoader::save_patch(SharedPtr model, const string& filename, bool recursive) +ThreadedLoader::save_patch(SharedPtr model, const string& filename) { _mutex.lock(); _events.push_back(sigc::hide_return(sigc::bind( sigc::mem_fun(this, &ThreadedLoader::save_patch_event), - model, filename, recursive))); + model, filename))); _mutex.unlock(); @@ -128,14 +128,9 @@ ThreadedLoader::save_patch(SharedPtr model, const string& filename, void -ThreadedLoader::save_patch_event(SharedPtr model, const string& filename, bool recursive) +ThreadedLoader::save_patch_event(SharedPtr model, const string& filename) { - if (recursive) - cerr << "FIXME: Recursive save." << endl; - - _serializer.start_to_filename(filename); - _serializer.serialize(model); - _serializer.finish(); + _serializer.to_file(model, filename); } diff --git a/src/libs/gui/ThreadedLoader.hpp b/src/libs/gui/ThreadedLoader.hpp index e8574f6f..a08ee158 100644 --- a/src/libs/gui/ThreadedLoader.hpp +++ b/src/libs/gui/ThreadedLoader.hpp @@ -69,11 +69,11 @@ public: optional engine_name = optional(), optional engine_poly = optional()); - void save_patch(SharedPtr model, const string& filename, bool recursive); + void save_patch(SharedPtr model, const string& filename); private: - void save_patch_event(SharedPtr model, const string& filename, bool recursive); + void save_patch_event(SharedPtr model, const string& filename); /** Returns nothing and takes no parameters (because they have all been bound) */ typedef sigc::slot Closure; diff --git a/src/libs/serialisation/Loader.cpp b/src/libs/serialisation/Loader.cpp index 806dbfc3..ac7141cd 100644 --- a/src/libs/serialisation/Loader.cpp +++ b/src/libs/serialisation/Loader.cpp @@ -55,8 +55,10 @@ Loader::load(SharedPtr engine, RDF::Model model(*rdf_world, document_uri); - //patch_uri = string("<") + patch_uri + ">"; - patch_uri = string("<") + document_uri + ">"; + if (patch_uri == "") + patch_uri = string("<") + document_uri + ">"; + else + patch_uri = string("<") + patch_uri + ">"; cerr << "[Loader] Loading " << patch_uri << " from " << document_uri << " under " << (string)(parent ? (string)parent.get() : "no parent") << endl; @@ -154,12 +156,12 @@ Loader::load(SharedPtr engine, const Path subpatch_path = patch_path.base() + (string)name; if (created.find(subpatch_path) == created.end()) { - load(engine, rdf_world, document_uri, patch_path, name, patch); created[subpatch_path] = true; + load(engine, rdf_world, document_uri, patch_path, name, patch); } } - created.clear(); + //created.clear(); /* Set node port control values */ -- cgit v1.2.1