From d6bd53fe5ca146398e9c3547b6cd9a06cf56d90f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 25 May 2011 00:32:23 +0000 Subject: Move sanitised serialisation headers to public include directory git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@3320 a436a847-0d15-0410-975c-d299462d15a1 --- src/serialisation/Serialiser.cpp | 167 +++++++++++++++++++++++++++------------ 1 file changed, 117 insertions(+), 50 deletions(-) (limited to 'src/serialisation/Serialiser.cpp') diff --git a/src/serialisation/Serialiser.cpp b/src/serialisation/Serialiser.cpp index 253791d2..ae1a6416 100644 --- a/src/serialisation/Serialiser.cpp +++ b/src/serialisation/Serialiser.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -49,12 +50,12 @@ #include "ingen/Patch.hpp" #include "ingen/Plugin.hpp" #include "ingen/Port.hpp" -#include "shared/World.hpp" #include "shared/LV2URIMap.hpp" #include "shared/ResourceImpl.hpp" +#include "shared/Store.hpp" +#include "shared/World.hpp" -#include "Serialiser.hpp" -#include "names.hpp" +#include "ingen/serialisation/Serialiser.hpp" #define LOG(s) s << "[Serialiser] " @@ -69,19 +70,66 @@ using namespace Ingen::Shared; namespace Ingen { namespace Serialisation { +struct Serialiser::Impl { + Impl(Shared::World& world, SharedPtr store) + : _root_path("/") + , _store(store) + , _world(world) + {} + + enum Mode { TO_FILE, TO_STRING }; + + void start_to_filename(const std::string& filename); + + void serialise_patch(SharedPtr p, + const Sord::Node& id); + + void serialise_node(SharedPtr n, + const Sord::Node& class_id, + const Sord::Node& id); + + void serialise_port(const Port* p, + Resource::Graph context, + const Sord::Node& id); + + void serialise_properties(const GraphObject* o, + Resource::Graph context, + Sord::Node id); + + void write_bundle(SharedPtr patch, + const std::string& uri); + + Sord::Node path_rdf_node(const Raul::Path& path); + + void write_manifest(const std::string& bundle_path, + SharedPtr patch, + const std::string& patch_symbol); + + void serialise_connection(const Sord::Node& parent, + SharedPtr c) + throw (std::logic_error); + + std::string finish(); + + Raul::Path _root_path; + SharedPtr _store; + Mode _mode; + std::string _base_uri; + Shared::World& _world; + Sord::Model* _model; +}; + + Serialiser::Serialiser(Shared::World& world, SharedPtr store) - : _root_path("/") - , _store(store) - , _world(world) -{ -} + : me(new Impl(world, store)) +{} void Serialiser::to_file(SharedPtr object, const std::string& filename) { - _root_path = object->path(); - start_to_filename(filename); + me->_root_path = object->path(); + me->start_to_filename(filename); serialise(object); finish(); } @@ -96,9 +144,9 @@ uri_to_symbol(const std::string& uri) } void -Serialiser::write_manifest(const std::string& bundle_path, - SharedPtr patch, - const std::string& patch_symbol) +Serialiser::Impl::write_manifest(const std::string& bundle_path, + SharedPtr patch, + const std::string& patch_symbol) { const string manifest_path(Glib::build_filename(bundle_path, "manifest.ttl")); const string binary_path(Glib::Module::build_path("", "ingen_lv2")); @@ -107,7 +155,7 @@ Serialiser::write_manifest(const std::string& bundle_path, Sord::World& world = _model->world(); - const string filename(patch_symbol + INGEN_PATCH_FILE_EXT); + const string filename(patch_symbol + ".ttl"); const Sord::URI subject(world, filename); _model->add_statement(subject, @@ -149,6 +197,13 @@ normal_bundle_uri(const std::string& uri) void Serialiser::write_bundle(SharedPtr patch, const std::string& uri) +{ + me->write_bundle(patch, uri); +} + +void +Serialiser::Impl::write_bundle(SharedPtr patch, + const std::string& uri) { Glib::ustring path = ""; try { @@ -169,7 +224,7 @@ Serialiser::write_bundle(SharedPtr patch, g_mkdir_with_parents(path.c_str(), 0744); const string symbol = uri_to_symbol(uri); - const string root_file = path + symbol + INGEN_PATCH_FILE_EXT; + const string root_file = path + symbol + ".ttl"; start_to_filename(root_file); const Path old_root_path = _root_path; @@ -189,12 +244,12 @@ Serialiser::to_string(SharedPtr object, start_to_string(object->path(), base_uri); serialise(object); - Sord::URI base_rdf_node(_model->world(), base_uri); + Sord::URI base_rdf_node(me->_model->world(), base_uri); for (GraphObject::Properties::const_iterator v = extra_rdf.begin(); v != extra_rdf.end(); ++v) { - _model->add_statement(base_rdf_node, - AtomRDF::atom_to_node(*_model, v->first), - AtomRDF::atom_to_node(*_model, v->second)); + me->_model->add_statement(base_rdf_node, + AtomRDF::atom_to_node(*me->_model, v->first), + AtomRDF::atom_to_node(*me->_model, v->second)); } return finish(); @@ -205,7 +260,7 @@ Serialiser::to_string(SharedPtr object, * This must be called before any serializing methods. */ void -Serialiser::start_to_filename(const string& filename) +Serialiser::Impl::start_to_filename(const string& filename) { setlocale(LC_NUMERIC, "C"); @@ -235,19 +290,20 @@ Serialiser::start_to_string(const Raul::Path& root, const string& base_uri) { setlocale(LC_NUMERIC, "C"); - _root_path = root; - _base_uri = base_uri; - _model = new Sord::Model(*_world.rdf_world(), base_uri); - _mode = TO_STRING; + me->_root_path = root; + me->_base_uri = base_uri; + me->_model = new Sord::Model(*me->_world.rdf_world(), base_uri); + me->_mode = Impl::TO_STRING; } -/** Finish a serialization. - * - * If this was a serialization to a string, the serialization output - * will be returned, otherwise the empty string is returned. - */ -string +std::string Serialiser::finish() +{ + return me->finish(); +} + +std::string +Serialiser::Impl::finish() { string ret = ""; if (_mode == TO_FILE) { @@ -264,7 +320,7 @@ Serialiser::finish() } Sord::Node -Serialiser::path_rdf_node(const Path& path) +Serialiser::Impl::path_rdf_node(const Path& path) { assert(_model); assert(path == _root_path || path.is_child_of(_root_path)); @@ -275,26 +331,26 @@ Serialiser::path_rdf_node(const Path& path) void Serialiser::serialise(SharedPtr object) throw (std::logic_error) { - if (!_model) + if (!me->_model) throw std::logic_error("serialise called without serialization in progress"); SharedPtr patch = PtrCast(object); if (patch) { - const Sord::URI patch_id(_model->world(), ""); - serialise_patch(patch, patch_id); + const Sord::URI patch_id(me->_model->world(), ""); + me->serialise_patch(patch, patch_id); return; } SharedPtr node = PtrCast(object); if (node) { - const Sord::URI plugin_id(_model->world(), node->plugin()->uri().str()); - serialise_node(node, plugin_id, path_rdf_node(node->path())); + const Sord::URI plugin_id(me->_model->world(), node->plugin()->uri().str()); + me->serialise_node(node, plugin_id, me->path_rdf_node(node->path())); return; } SharedPtr port = PtrCast(object); if (port) { - serialise_port(port.get(), Resource::DEFAULT, path_rdf_node(port->path())); + me->serialise_port(port.get(), Resource::DEFAULT, me->path_rdf_node(port->path())); return; } @@ -303,7 +359,8 @@ Serialiser::serialise(SharedPtr object) throw (std::logic_err } void -Serialiser::serialise_patch(SharedPtr patch, const Sord::Node& patch_id) +Serialiser::Impl::serialise_patch(SharedPtr patch, + const Sord::Node& patch_id) { assert(_model); Sord::World& world = _model->world(); @@ -413,9 +470,9 @@ Serialiser::serialise_patch(SharedPtr patch, const Sord::Node& patc } void -Serialiser::serialise_node(SharedPtr node, - const Sord::Node& class_id, - const Sord::Node& node_id) +Serialiser::Impl::serialise_node(SharedPtr node, + const Sord::Node& class_id, + const Sord::Node& node_id) { _model->add_statement(node_id, Sord::Curie(_model->world(), "rdf:type"), @@ -440,9 +497,9 @@ Serialiser::serialise_node(SharedPtr node, } void -Serialiser::serialise_port(const Port* port, - Resource::Graph context, - const Sord::Node& port_id) +Serialiser::Impl::serialise_port(const Port* port, + Resource::Graph context, + const Sord::Node& port_id) { Sord::World& world = _model->world(); @@ -491,15 +548,25 @@ Serialiser::serialise_port(const Port* port, } void -Serialiser::serialise_connection(const Sord::Node& parent, - SharedPtr connection) throw (std::logic_error) +Serialiser::serialise_connection(const Sord::Node& parent, + SharedPtr connection) + throw (std::logic_error) { - Sord::World& world = _model->world(); + return me->serialise_connection(parent, connection); +} +void +Serialiser::Impl::serialise_connection(const Sord::Node& parent, + SharedPtr connection) + throw (std::logic_error) +{ if (!_model) throw std::logic_error( "serialise_connection called without serialization in progress"); + + Sord::World& world = _model->world(); + const Sord::Node src = path_rdf_node(connection->src_port_path()); const Sord::Node dst = path_rdf_node(connection->dst_port_path()); const Sord::Node connection_id = Sord::Node::blank_id(*_world.rdf_world()); @@ -522,9 +589,9 @@ skip_property(const Sord::Node& predicate) } void -Serialiser::serialise_properties(const GraphObject* o, - Ingen::Resource::Graph context, - Sord::Node id) +Serialiser::Impl::serialise_properties(const GraphObject* o, + Ingen::Resource::Graph context, + Sord::Node id) { const GraphObject::Properties props = o->properties(context); -- cgit v1.2.1