From 1f58c5f16ab295d1649fbcdf2774fdc1e4b4ea10 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 26 Mar 2017 19:47:45 +0200 Subject: Factor out object RDF node construction --- src/Serialiser.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Serialiser.cpp b/src/Serialiser.cpp index c6d1bb59..3b8ccfbe 100644 --- a/src/Serialiser.cpp +++ b/src/Serialiser.cpp @@ -85,7 +85,9 @@ struct Serialiser::Impl { void write_bundle(SPtr graph, const std::string& uri); - Sord::Node path_rdf_node(const Raul::Path& path); + Sord::Node path_rdf_node(const Raul::Path& path) const; + + Sord::Node rdf_node(SPtr node) const; void write_manifest(const std::string& bundle_path, SPtr graph); @@ -288,7 +290,7 @@ Serialiser::Impl::finish() } Sord::Node -Serialiser::Impl::path_rdf_node(const Raul::Path& path) +Serialiser::Impl::path_rdf_node(const Raul::Path& path) const { assert(_model); assert(path == _root_path || path.is_child_of(_root_path)); @@ -297,6 +299,12 @@ Serialiser::Impl::path_rdf_node(const Raul::Path& path) _base_uri); } +Sord::Node +Serialiser::Impl::rdf_node(const SPtr node) const +{ + return path_rdf_node(node->path()); +} + void Serialiser::serialise(SPtr object) throw (std::logic_error) { @@ -305,17 +313,17 @@ Serialiser::serialise(SPtr object) throw (std::logic_error) const URIs& uris = me->_world.uris(); if (object->has_property(uris.rdf_type, uris.ingen_Graph)) { - me->serialise_graph(object, me->path_rdf_node(object->path())); + me->serialise_graph(object, me->rdf_node(object)); } else if (object->has_property(uris.rdf_type, uris.ingen_Block)) { const Sord::URI plugin_id(me->_model->world(), object->plugin()->uri()); - me->serialise_block(object, plugin_id, me->path_rdf_node(object->path())); + me->serialise_block(object, plugin_id, me->rdf_node(object)); } else if (object->has_property(uris.rdf_type, uris.lv2_InputPort) || object->has_property(uris.rdf_type, uris.lv2_OutputPort)) { me->serialise_port(object, Resource::Graph::DEFAULT, - me->path_rdf_node(object->path())); + me->rdf_node(object)); } else { - me->serialise_properties(me->path_rdf_node(object->path()), + me->serialise_properties(me->rdf_node(object), object->properties()); } } @@ -391,7 +399,7 @@ Serialiser::Impl::serialise_graph(SPtr graph, _model = my_model; // Serialise reference to graph block - const Sord::Node block_id(path_rdf_node(subgraph->path())); + const Sord::Node block_id(rdf_node(subgraph)); _model->add_statement(graph_id, Sord::URI(world, uris.ingen_block), block_id); @@ -400,7 +408,7 @@ Serialiser::Impl::serialise_graph(SPtr graph, const SPtr block = n->second; const Sord::URI class_id(world, block->plugin()->uri()); - const Sord::Node block_id(path_rdf_node(n->second->path())); + const Sord::Node block_id(rdf_node(n->second)); _model->add_statement(graph_id, Sord::URI(world, uris.ingen_block), block_id); @@ -412,7 +420,7 @@ Serialiser::Impl::serialise_graph(SPtr graph, const SPtr p = n->second; // Ensure lv2:name always exists so Graph is a valid LV2 plugin - const Sord::Node port_id(path_rdf_node(p->path())); + const Sord::Node port_id(rdf_node(p)); if (p->properties().find(uris.lv2_name) == p->properties().end()) _model->add_statement(port_id, Sord::URI(world, uris.lv2_name), @@ -477,7 +485,7 @@ Serialiser::Impl::serialise_block(SPtr block, if (n->second->has_property(uris.rdf_type, uris.lv2_InputPort) || n->second->has_property(uris.rdf_type, uris.lv2_InputPort)) { const SPtr p = n->second; - const Sord::Node port_id = path_rdf_node(p->path()); + const Sord::Node port_id = rdf_node(p); serialise_port(p, Resource::Graph::DEFAULT, port_id); _model->add_statement(block_id, Sord::URI(_model->world(), uris.lv2_port), -- cgit v1.2.1