From 684a8fd8fd54a391662e72b1113ddbda14e66612 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 30 Nov 2008 19:56:36 +0000 Subject: Some support for bundle saving. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@1831 a436a847-0d15-0410-975c-d299462d15a1 --- src/serialisation/Serialiser.cpp | 68 +++++++++++++++++++++++++++++++++++++++- src/serialisation/Serialiser.hpp | 18 ++++++++++- 2 files changed, 84 insertions(+), 2 deletions(-) (limited to 'src/serialisation') diff --git a/src/serialisation/Serialiser.cpp b/src/serialisation/Serialiser.cpp index baf8a475..0bb7b57d 100644 --- a/src/serialisation/Serialiser.cpp +++ b/src/serialisation/Serialiser.cpp @@ -27,6 +27,9 @@ #include #include // pair, make_pair #include +#include +#include +#include #include "raul/Atom.hpp" #include "raul/AtomRDF.hpp" #include "raul/Path.hpp" @@ -62,8 +65,11 @@ Serialiser::Serialiser(Shared::World& world, SharedPtr store) void -Serialiser::to_file(SharedPtr object, const string& filename) +Serialiser::to_file(const Record& record) { + SharedPtr object = record.object; + const string& filename = record.uri; + _root_path = object->path(); start_to_filename(filename); serialise(object); @@ -71,6 +77,66 @@ Serialiser::to_file(SharedPtr object, const string& filename) } +static +std::string +uri_to_symbol(const std::string& uri) +{ + string symbol = uri; + symbol = symbol.substr(symbol.find_last_of("/") + 1); + symbol = symbol.substr(0, symbol.find(".")); + symbol = Path::nameify(symbol); + return symbol; +} + + +void +Serialiser::write_manifest(const std::string& bundle_uri, + const Records& records) +{ + + cout << "WRITE MANIFEST BUNDLE URI: " << bundle_uri << endl; + const string filename = Glib::filename_from_uri(bundle_uri) + "manifest.ttl"; + cout << "FILENAME: " << filename << endl; + start_to_filename(filename); + _model->set_base_uri(bundle_uri); + for (Records::const_iterator i = records.begin(); i != records.end(); ++i) { + SharedPtr patch = PtrCast(i->object); + if (patch) { + const Redland::Node subject(_model->world(), Redland::Node::RESOURCE, + uri_to_symbol(i->uri)); + _model->add_statement(subject, "rdf:type", + Redland::Node(_model->world(), Redland::Node::RESOURCE, "ingen:Patch")); + _model->add_statement(subject, "rdf:type", + Redland::Node(_model->world(), Redland::Node::RESOURCE, "lv2:Plugin")); + _model->add_statement(subject, "rdfs:seeAlso", + Redland::Node(_model->world(), Redland::Node::RESOURCE, i->uri)); + } + } + finish(); +} + + +void +Serialiser::write_bundle(const Record& record) +{ + SharedPtr object = record.object; + string bundle_uri = record.uri; + if (bundle_uri[bundle_uri.length()-1] != '/') + bundle_uri.append("/"); + + g_mkdir_with_parents(Glib::filename_from_uri(bundle_uri).c_str(), 0744); + Records records; + + string symbol = uri_to_symbol(record.uri); + + const string root_file = bundle_uri + symbol + ".ingen.ttl"; + start_to_filename(root_file); + serialise(object); + finish(); + records.push_back(Record(object, bundle_uri + symbol + ".ingen.ttl")); + write_manifest(bundle_uri, records); +} + string Serialiser::to_string(SharedPtr object, diff --git a/src/serialisation/Serialiser.hpp b/src/serialisation/Serialiser.hpp index 4d33d771..6151bae2 100644 --- a/src/serialisation/Serialiser.hpp +++ b/src/serialisation/Serialiser.hpp @@ -58,7 +58,23 @@ class Serialiser public: Serialiser(Shared::World& world, SharedPtr store); - void to_file(SharedPtr object, const std::string& filename); + struct Record { + Record(SharedPtr o, const std::string& u) + : object(o), uri(u) + {} + + const SharedPtr object; + const std::string uri; + }; + + typedef std::list Records; + + void to_file(const Record& record); + + void write_bundle(const Record& record); + + void write_manifest(const std::string& bundle_uri, + const Records& records); std::string to_string(SharedPtr object, const std::string& base_uri, -- cgit v1.2.1