summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-07-26 23:39:01 +0000
committerDavid Robillard <d@drobilla.net>2007-07-26 23:39:01 +0000
commitf36e709b68144191d51959d6a2224cd9c3ad7871 (patch)
tree19f6f9ad4dd573d90224c56052c7bacfc1f76f08
parent23d74f838521320dc1682426341d1874061337a6 (diff)
downloadingen-f36e709b68144191d51959d6a2224cd9c3ad7871.tar.gz
ingen-f36e709b68144191d51959d6a2224cd9c3ad7871.tar.bz2
ingen-f36e709b68144191d51959d6a2224cd9c3ad7871.zip
Fix recursive patch serialization (fix ticket 63).
git-svn-id: http://svn.drobilla.net/lad/ingen@642 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--src/libs/client/Serializer.cpp44
-rw-r--r--src/libs/client/Serializer.hpp26
-rw-r--r--src/libs/engine/NodeBase.cpp2
-rw-r--r--src/libs/gui/PatchWindow.cpp4
-rw-r--r--src/libs/gui/ThreadedLoader.cpp13
-rw-r--r--src/libs/gui/ThreadedLoader.hpp4
-rw-r--r--src/libs/serialisation/Loader.cpp10
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<ObjectModel> object, const string& filename)
+{
+ _root_object = object;
+ start_to_filename(filename);
+ serialize(object);
+ finish();
+}
+
+
+string
+Serializer::to_string(SharedPtr<ObjectModel> object)
+{
+ _root_object = object;
+ start_to_string();
+ serialize(object);
+ return finish();
+}
/** Begin a serialization to a file.
@@ -200,7 +219,7 @@ Serializer::serialize(SharedPtr<ObjectModel> object) throw (std::logic_error)
SharedPtr<PatchModel> patch = PtrCast<PatchModel>(object);
if (patch) {
- serialize_patch(patch, Node(_model->world(), Node::RESOURCE, _base_uri));
+ serialize_patch(patch);
return;
}
@@ -221,11 +240,26 @@ Serializer::serialize(SharedPtr<ObjectModel> 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<PatchModel> patch, const Node& patch_id)
+Serializer::serialize_patch(SharedPtr<PatchModel> 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<PatchModel> patch, const Node& patch_id)
SharedPtr<PatchModel> patch = PtrCast<PatchModel>(n->second);
SharedPtr<NodeModel> node = PtrCast<NodeModel>(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<ObjectModel> object, const string& filename);
+ string to_string(SharedPtr<ObjectModel> object);
+
void start_to_string();
-
- void serialize(SharedPtr<ObjectModel> object) throw (std::logic_error);
+ void serialize(SharedPtr<ObjectModel> object) throw (std::logic_error);
void serialize_connection(SharedPtr<ConnectionModel> 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<PluginModel> p);
- void serialize_patch(SharedPtr<PatchModel> p, const Raul::RDF::Node& id);
+ void serialize_patch(SharedPtr<PatchModel> p);
void serialize_node(SharedPtr<NodeModel> n, const Raul::RDF::Node& id);
void serialize_port(SharedPtr<PortModel> 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<Raul::RDF::Node> NodeMap;
- Mode _mode;
- NodeMap _node_map;
- string _base_uri;
- Raul::RDF::World& _world;
- Raul::RDF::Model* _model;
+ SharedPtr<ObjectModel> _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<Node*>()),
_dependants(new Raul::List<Node*>())
{
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<PatchModel> model, const string& filename, bool recursive)
+ThreadedLoader::save_patch(SharedPtr<PatchModel> 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<PatchModel> model, const string& filename,
void
-ThreadedLoader::save_patch_event(SharedPtr<PatchModel> model, const string& filename, bool recursive)
+ThreadedLoader::save_patch_event(SharedPtr<PatchModel> 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<const string&> engine_name = optional<const string&>(),
optional<size_t> engine_poly = optional<size_t>());
- void save_patch(SharedPtr<PatchModel> model, const string& filename, bool recursive);
+ void save_patch(SharedPtr<PatchModel> model, const string& filename);
private:
- void save_patch_event(SharedPtr<PatchModel> model, const string& filename, bool recursive);
+ void save_patch_event(SharedPtr<PatchModel> model, const string& filename);
/** Returns nothing and takes no parameters (because they have all been bound) */
typedef sigc::slot<void> 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<EngineInterface> 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<EngineInterface> 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 */