diff options
author | David Robillard <d@drobilla.net> | 2011-02-16 19:27:56 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-02-16 19:27:56 +0000 |
commit | 4777248a1bb15e0833d688d8c8a7c81db0bf02ac (patch) | |
tree | 9fcaf607d32f452f79286d8402348feae0cbdd66 /src | |
parent | 2c1079446f0b06559a683a9f4b0192a4f7637770 (diff) | |
download | ingen-4777248a1bb15e0833d688d8c8a7c81db0bf02ac.tar.gz ingen-4777248a1bb15e0833d688d8c8a7c81db0bf02ac.tar.bz2 ingen-4777248a1bb15e0833d688d8c8a7c81db0bf02ac.zip |
Tidy.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2962 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r-- | src/serialisation/Parser.cpp | 200 | ||||
-rw-r--r-- | src/serialisation/Parser.hpp | 121 | ||||
-rw-r--r-- | src/serialisation/Serialiser.cpp | 88 | ||||
-rw-r--r-- | src/serialisation/Serialiser.hpp | 44 |
4 files changed, 211 insertions, 242 deletions
diff --git a/src/serialisation/Parser.cpp b/src/serialisation/Parser.cpp index f1ba2ed2..2a7423b0 100644 --- a/src/serialisation/Parser.cpp +++ b/src/serialisation/Parser.cpp @@ -15,26 +15,30 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include <set> #include <locale.h> -#include <glibmm/ustring.h> -#include <glibmm/miscutils.h> -#include <glibmm/fileutils.h> + +#include <set> + #include <glibmm/convert.h> -#include "raul/log.hpp" -#include "sord/sordmm.hpp" -#include "raul/TableImpl.hpp" +#include <glibmm/fileutils.h> +#include <glibmm/miscutils.h> +#include <glibmm/ustring.h> + #include "raul/Atom.hpp" #include "raul/AtomRDF.hpp" +#include "raul/TableImpl.hpp" +#include "raul/log.hpp" + +#include "serd/serd.h" +#include "sord/sordmm.hpp" + #include "interface/EngineInterface.hpp" #include "module/World.hpp" #include "shared/LV2URIMap.hpp" + #include "Parser.hpp" #include "names.hpp" -#include "serd/serd.h" -#include "sord/sordmm.hpp" - #define LOG(s) s << "[Parser] " #define NS_INGEN "http://drobilla.net/ns/ingen#" @@ -53,7 +57,6 @@ typedef set<Sord::Node> RDFNodes; namespace Ingen { namespace Serialisation { - static Glib::ustring relative_uri(Glib::ustring base, const Glib::ustring uri, bool leading_slash) { @@ -81,7 +84,6 @@ relative_uri(Glib::ustring base, const Glib::ustring uri, bool leading_slash) return ret; } - static void normalise_uri(Glib::ustring& uri) { @@ -90,11 +92,9 @@ normalise_uri(Glib::ustring& uri) uri = uri.substr(0, dotslash) + uri.substr(dotslash + 2); } - Parser::PatchRecords -Parser::find_patches( - Ingen::Shared::World* world, - const Glib::ustring& manifest_uri) +Parser::find_patches(Ingen::Shared::World* world, + const Glib::ustring& manifest_uri) { Sord::Model model(*world->rdf_world(), manifest_uri); model.load_file(manifest_uri); @@ -122,19 +122,17 @@ Parser::find_patches( return records; } - /** Parse a patch from RDF into a CommonInterface (engine or client). * @return whether or not load was successful. */ bool -Parser::parse_document( - Ingen::Shared::World* world, - Ingen::Shared::CommonInterface* target, - Glib::ustring document_uri, - boost::optional<Raul::Path> data_path, - boost::optional<Raul::Path> parent, - boost::optional<Raul::Symbol> symbol, - boost::optional<GraphObject::Properties> data) +Parser::parse_document(Ingen::Shared::World* world, + Ingen::Shared::CommonInterface* target, + Glib::ustring document_uri, + boost::optional<Raul::Path> data_path, + boost::optional<Raul::Path> parent, + boost::optional<Raul::Symbol> symbol, + boost::optional<GraphObject::Properties> data) { normalise_uri(document_uri); @@ -148,7 +146,8 @@ Parser::parse_document( const size_t ext = filename.find(INGEN_BUNDLE_EXT); const size_t ext_len = strlen(INGEN_BUNDLE_EXT); if (ext == filename.length() - ext_len - || (ext == filename.length() - ext_len - 1 && filename[filename.length() - 1] == '/')) { + || ((ext == filename.length() - ext_len - 1) + && filename[filename.length() - 1] == '/')) { std::string basename(Glib::path_get_basename(filename)); basename = basename.substr(0, basename.find('.')); document_uri += basename + INGEN_PATCH_FILE_EXT; @@ -170,7 +169,7 @@ Parser::parse_document( if (parsed_path) { target->set_property(*parsed_path, "http://drobilla.net/ns/ingen#document", - Atom(Atom::URI, document_uri.c_str())); + Atom(Atom::URI, document_uri.c_str())); } else { LOG(warn) << "Document URI lost" << endl; } @@ -178,17 +177,15 @@ Parser::parse_document( return parsed_path; } - bool -Parser::parse_string( - Ingen::Shared::World* world, - Ingen::Shared::CommonInterface* target, - const Glib::ustring& str, - const Glib::ustring& base_uri, - boost::optional<Raul::Path> data_path, - boost::optional<Raul::Path> parent, - boost::optional<Raul::Symbol> symbol, - boost::optional<GraphObject::Properties> data) +Parser::parse_string(Ingen::Shared::World* world, + Ingen::Shared::CommonInterface* target, + const Glib::ustring& str, + const Glib::ustring& base_uri, + boost::optional<Raul::Path> data_path, + boost::optional<Raul::Path> parent, + boost::optional<Raul::Symbol> symbol, + boost::optional<GraphObject::Properties> data) { Sord::Model model(*world->rdf_world(), base_uri); model.load_string(str.c_str(), str.length(), base_uri); @@ -205,19 +202,17 @@ Parser::parse_string( return ret; } - bool -Parser::parse_update( - Ingen::Shared::World* world, - Shared::CommonInterface* target, - const Glib::ustring& str, - const Glib::ustring& base_uri, - boost::optional<Raul::Path> data_path, - boost::optional<Raul::Path> parent, - boost::optional<Raul::Symbol> symbol, - boost::optional<GraphObject::Properties> data) +Parser::parse_update(Ingen::Shared::World* world, + Shared::CommonInterface* target, + const Glib::ustring& str, + const Glib::ustring& base_uri, + boost::optional<Raul::Path> data_path, + boost::optional<Raul::Path> parent, + boost::optional<Raul::Symbol> symbol, + boost::optional<GraphObject::Properties> data) { - #if 0 +#if 0 Sord::Model model(*world->rdf_world(), str.c_str(), str.length(), base_uri); // Delete anything explicitly declared to not exist @@ -232,9 +227,9 @@ Parser::parse_update( // Properties query = Sord::Query(*world->rdf_world(), - "SELECT DISTINCT ?s ?p ?o WHERE {\n" - "?s ?p ?o .\n" - "}"); + "SELECT DISTINCT ?s ?p ?o WHERE {\n" + "?s ?p ?o .\n" + "}"); results = query.run(*world->rdf_world(), model, base_uri); for (; !results->finished(); results->next()) { @@ -250,16 +245,15 @@ Parser::parse_update( target->set_property(string("path:") + obj_uri, key, a); } - // Connections Sord::Resource subject(*world->rdf_world(), base_uri); parse_connections(world, target, model, subject, "/"); // Port values query = Sord::Query(*world->rdf_world(), - "SELECT DISTINCT ?path ?value WHERE {\n" - "?path ingen:value ?value .\n" - "}"); + "SELECT DISTINCT ?path ?value WHERE {\n" + "?path ingen:value ?value .\n" + "}"); results = query.run(*world->rdf_world(), model, base_uri); for (; !results->finished(); results->next()) { @@ -271,21 +265,19 @@ Parser::parse_update( } return parse(world, target, model, base_uri, data_path, parent, symbol, data); - #endif +#endif return false; } - boost::optional<Path> -Parser::parse( - Ingen::Shared::World* world, - Ingen::Shared::CommonInterface* target, - Sord::Model& model, - Glib::ustring document_uri, - boost::optional<Raul::Path> data_path, - boost::optional<Raul::Path> parent, - boost::optional<Raul::Symbol> symbol, - boost::optional<GraphObject::Properties> data) +Parser::parse(Ingen::Shared::World* world, + Ingen::Shared::CommonInterface* target, + Sord::Model& model, + Glib::ustring document_uri, + boost::optional<Raul::Path> data_path, + boost::optional<Raul::Path> parent, + boost::optional<Raul::Symbol> symbol, + boost::optional<GraphObject::Properties> data) { const Sord::Node::Type res = Sord::Node::RESOURCE; @@ -320,13 +312,13 @@ Parser::parse( path_str = relative_uri(document_uri, subject.to_c_string(), true); const bool is_plugin = (rdf_class == ladspa_class) - || (rdf_class == lv2_class) - || (rdf_class == internal_class); + || (rdf_class == lv2_class) + || (rdf_class == internal_class); const bool is_object = (rdf_class == patch_class) - || (rdf_class == node_class) - || (rdf_class == in_port_class) - || (rdf_class == out_port_class); + || (rdf_class == node_class) + || (rdf_class == in_port_class) + || (rdf_class == out_port_class); if (is_object) { if (path_str.empty() || path_str[0] != '/') @@ -377,16 +369,14 @@ Parser::parse( return root_path; } - boost::optional<Path> -Parser::parse_patch( - Ingen::Shared::World* world, - Ingen::Shared::CommonInterface* target, - Sord::Model& model, - const Sord::Node& subject_node, - boost::optional<Raul::Path> parent, - boost::optional<Raul::Symbol> a_symbol, - boost::optional<GraphObject::Properties> data) +Parser::parse_patch(Ingen::Shared::World* world, + Ingen::Shared::CommonInterface* target, + Sord::Model& model, + const Sord::Node& subject_node, + boost::optional<Raul::Path> parent, + boost::optional<Raul::Symbol> a_symbol, + boost::optional<GraphObject::Properties> data) { const LV2URIMap& uris = *world->uris().get(); @@ -549,9 +539,9 @@ Parser::parse_patch( #if 0 /* Enable */ query = Sord::Query(*world->rdf_world(), Glib::ustring( - "SELECT DISTINCT ?enabled WHERE {\n") - + subject + " ingen:enabled ?enabled .\n" - "}"); + "SELECT DISTINCT ?enabled WHERE {\n") + + subject + " ingen:enabled ?enabled .\n" + "}"); results = query.run(*world->rdf_world(), model, base_uri); for (; !results->finished(); results->next()) { @@ -569,15 +559,13 @@ Parser::parse_patch( return patch_path; } - boost::optional<Path> -Parser::parse_node( - Ingen::Shared::World* world, - Ingen::Shared::CommonInterface* target, - Sord::Model& model, - const Sord::Node& subject, - const Raul::Path& path, - boost::optional<GraphObject::Properties> data) +Parser::parse_node(Ingen::Shared::World* world, + Ingen::Shared::CommonInterface* target, + Sord::Model& model, + const Sord::Node& subject, + const Raul::Path& path, + boost::optional<GraphObject::Properties> data) { const LV2URIMap& uris = *world->uris().get(); @@ -607,14 +595,12 @@ Parser::parse_node( return path; } - bool -Parser::parse_connections( - Ingen::Shared::World* world, - Ingen::Shared::CommonInterface* target, - Sord::Model& model, - const Sord::Node& subject, - const Raul::Path& parent) +Parser::parse_connections(Ingen::Shared::World* world, + Ingen::Shared::CommonInterface* target, + Sord::Model& model, + const Sord::Node& subject, + const Raul::Path& parent) { Sord::Resource ingen_connection(*world->rdf_world(), NS_INGEN "connection"); Sord::Resource ingen_source(*world->rdf_world(), NS_INGEN "source"); @@ -658,15 +644,13 @@ Parser::parse_connections( return true; } - bool -Parser::parse_properties( - Ingen::Shared::World* world, - Ingen::Shared::CommonInterface* target, - Sord::Model& model, - const Sord::Node& subject, - const Raul::URI& uri, - boost::optional<GraphObject::Properties> data) +Parser::parse_properties(Ingen::Shared::World* world, + Ingen::Shared::CommonInterface* target, + Sord::Model& model, + const Sord::Node& subject, + const Raul::URI& uri, + boost::optional<GraphObject::Properties> data) { Resource::Properties properties; for (Sord::Iter i = model.find(subject, nil, nil); !i.end(); ++i) { @@ -687,15 +671,13 @@ Parser::parse_properties( return true; } - bool Parser::skip_property(const Sord::Node& predicate) { return (predicate.to_string() == "http://drobilla.net/ns/ingen#node" - || predicate.to_string() == "http://lv2plug.in/ns/lv2core#port"); + || predicate.to_string() == "http://lv2plug.in/ns/lv2core#port"); } - } // namespace Serialisation } // namespace Ingen diff --git a/src/serialisation/Parser.hpp b/src/serialisation/Parser.hpp index 06f42f14..103cd9a0 100644 --- a/src/serialisation/Parser.hpp +++ b/src/serialisation/Parser.hpp @@ -15,13 +15,16 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef INGEN_SERIALISATION_LOADER_HPP -#define INGEN_SERIALISATION_LOADER_HPP +#ifndef INGEN_SERIALISATION_PARSER_HPP +#define INGEN_SERIALISATION_PARSER_HPP #include <string> #include <list> + #include <glibmm/ustring.h> + #include <boost/optional.hpp> + #include "interface/GraphObject.hpp" namespace Raul { class Path; } @@ -34,7 +37,6 @@ namespace Shared { class World; } namespace Serialisation { - class Parser { public: virtual ~Parser() {} @@ -42,33 +44,33 @@ public: typedef Shared::GraphObject::Properties Properties; virtual bool parse_document( - Ingen::Shared::World* world, - Shared::CommonInterface* target, - Glib::ustring document_uri, - boost::optional<Raul::Path> data_path=boost::optional<Raul::Path>(), - boost::optional<Raul::Path> parent=boost::optional<Raul::Path>(), - boost::optional<Raul::Symbol> symbol=boost::optional<Raul::Symbol>(), - boost::optional<Properties> data=boost::optional<Properties>()); + Ingen::Shared::World* world, + Shared::CommonInterface* target, + Glib::ustring document_uri, + boost::optional<Raul::Path> data_path=boost::optional<Raul::Path>(), + boost::optional<Raul::Path> parent=boost::optional<Raul::Path>(), + boost::optional<Raul::Symbol> symbol=boost::optional<Raul::Symbol>(), + boost::optional<Properties> data=boost::optional<Properties>()); virtual bool parse_string( - Ingen::Shared::World* world, - Shared::CommonInterface* target, - const Glib::ustring& str, - const Glib::ustring& base_uri, - boost::optional<Raul::Path> data_path=boost::optional<Raul::Path>(), - boost::optional<Raul::Path> parent=boost::optional<Raul::Path>(), - boost::optional<Raul::Symbol> symbol=boost::optional<Raul::Symbol>(), - boost::optional<Properties> data=boost::optional<Properties>()); + Ingen::Shared::World* world, + Shared::CommonInterface* target, + const Glib::ustring& str, + const Glib::ustring& base_uri, + boost::optional<Raul::Path> data_path=boost::optional<Raul::Path>(), + boost::optional<Raul::Path> parent=boost::optional<Raul::Path>(), + boost::optional<Raul::Symbol> symbol=boost::optional<Raul::Symbol>(), + boost::optional<Properties> data=boost::optional<Properties>()); virtual bool parse_update( - Ingen::Shared::World* world, - Shared::CommonInterface* target, - const Glib::ustring& str, - const Glib::ustring& base_uri, - boost::optional<Raul::Path> data_path=boost::optional<Raul::Path>(), - boost::optional<Raul::Path> parent=boost::optional<Raul::Path>(), - boost::optional<Raul::Symbol> symbol=boost::optional<Raul::Symbol>(), - boost::optional<Properties> data=boost::optional<Properties>()); + Ingen::Shared::World* world, + Shared::CommonInterface* target, + const Glib::ustring& str, + const Glib::ustring& base_uri, + boost::optional<Raul::Path> data_path=boost::optional<Raul::Path>(), + boost::optional<Raul::Path> parent=boost::optional<Raul::Path>(), + boost::optional<Raul::Symbol> symbol=boost::optional<Raul::Symbol>(), + boost::optional<Properties> data=boost::optional<Properties>()); struct PatchRecord { PatchRecord(const Raul::URI& u, const Glib::ustring& f) : uri(u), filename(f) {} @@ -84,52 +86,51 @@ public: private: boost::optional<Raul::Path> parse( - Ingen::Shared::World* world, - Shared::CommonInterface* target, - Sord::Model& model, - Glib::ustring document_uri, - boost::optional<Raul::Path> data_path=boost::optional<Raul::Path>(), - boost::optional<Raul::Path> parent=boost::optional<Raul::Path>(), - boost::optional<Raul::Symbol> symbol=boost::optional<Raul::Symbol>(), - boost::optional<Properties> data=boost::optional<Properties>()); + Ingen::Shared::World* world, + Shared::CommonInterface* target, + Sord::Model& model, + Glib::ustring document_uri, + boost::optional<Raul::Path> data_path=boost::optional<Raul::Path>(), + boost::optional<Raul::Path> parent=boost::optional<Raul::Path>(), + boost::optional<Raul::Symbol> symbol=boost::optional<Raul::Symbol>(), + boost::optional<Properties> data=boost::optional<Properties>()); boost::optional<Raul::Path> parse_patch( - Ingen::Shared::World* world, - Ingen::Shared::CommonInterface* target, - Sord::Model& model, - const Sord::Node& subject, - boost::optional<Raul::Path> parent=boost::optional<Raul::Path>(), - boost::optional<Raul::Symbol> symbol=boost::optional<Raul::Symbol>(), - boost::optional<Properties> data=boost::optional<Properties>()); + Ingen::Shared::World* world, + Ingen::Shared::CommonInterface* target, + Sord::Model& model, + const Sord::Node& subject, + boost::optional<Raul::Path> parent=boost::optional<Raul::Path>(), + boost::optional<Raul::Symbol> symbol=boost::optional<Raul::Symbol>(), + boost::optional<Properties> data=boost::optional<Properties>()); boost::optional<Raul::Path> parse_node( - Ingen::Shared::World* world, - Ingen::Shared::CommonInterface* target, - Sord::Model& model, - const Sord::Node& subject, - const Raul::Path& path, - boost::optional<Properties> data=boost::optional<Properties>()); + Ingen::Shared::World* world, + Ingen::Shared::CommonInterface* target, + Sord::Model& model, + const Sord::Node& subject, + const Raul::Path& path, + boost::optional<Properties> data=boost::optional<Properties>()); bool parse_properties( - Ingen::Shared::World* world, - Ingen::Shared::CommonInterface* target, - Sord::Model& model, - const Sord::Node& subject, - const Raul::URI& uri, - boost::optional<Properties> data = boost::optional<Properties>()); + Ingen::Shared::World* world, + Ingen::Shared::CommonInterface* target, + Sord::Model& model, + const Sord::Node& subject, + const Raul::URI& uri, + boost::optional<Properties> data = boost::optional<Properties>()); bool parse_connections( - Ingen::Shared::World* world, - Ingen::Shared::CommonInterface* target, - Sord::Model& model, - const Sord::Node& subject, - const Raul::Path& patch); + Ingen::Shared::World* world, + Ingen::Shared::CommonInterface* target, + Sord::Model& model, + const Sord::Node& subject, + const Raul::Path& patch); bool skip_property(const Sord::Node& predicate); }; - } // namespace Serialisation } // namespace Ingen -#endif // INGEN_SERIALISATION_LOADER_HPP +#endif // INGEN_SERIALISATION_PARSER_HPP diff --git a/src/serialisation/Serialiser.cpp b/src/serialisation/Serialiser.cpp index 4c6e3f12..a3952343 100644 --- a/src/serialisation/Serialiser.cpp +++ b/src/serialisation/Serialiser.cpp @@ -15,37 +15,43 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include <locale.h> + #include <algorithm> #include <cassert> #include <cmath> -#include <cstdlib> // atof +#include <cstdlib> #include <cstring> #include <fstream> -#include <locale.h> #include <stdexcept> #include <string> -#include <utility> // pair, make_pair +#include <utility> #include <vector> + #include <glib.h> #include <glib/gstdio.h> #include <glibmm/convert.h> -#include <glibmm/miscutils.h> #include <glibmm/fileutils.h> -#include "raul/log.hpp" +#include <glibmm/miscutils.h> + #include "raul/Atom.hpp" #include "raul/AtomRDF.hpp" #include "raul/Path.hpp" #include "raul/TableImpl.hpp" +#include "raul/log.hpp" + #include "sord/sordmm.hpp" -#include "module/World.hpp" + +#include "interface/Connection.hpp" #include "interface/EngineInterface.hpp" -#include "interface/Plugin.hpp" -#include "interface/Patch.hpp" #include "interface/Node.hpp" +#include "interface/Patch.hpp" +#include "interface/Plugin.hpp" #include "interface/Port.hpp" -#include "interface/Connection.hpp" -#include "shared/ResourceImpl.hpp" +#include "module/World.hpp" #include "shared/LV2URIMap.hpp" +#include "shared/ResourceImpl.hpp" + #include "Serialiser.hpp" #include "names.hpp" @@ -60,10 +66,8 @@ using namespace Ingen::Shared; namespace Ingen { namespace Serialisation { - #define META_PREFIX "#" - Serialiser::Serialiser(Shared::World& world, SharedPtr<Shared::Store> store) : _root_path("/") , _store(store) @@ -71,7 +75,6 @@ Serialiser::Serialiser(Shared::World& world, SharedPtr<Shared::Store> store) { } - void Serialiser::to_file(const Record& record) { @@ -84,7 +87,6 @@ Serialiser::to_file(const Record& record) finish(); } - static std::string uri_to_symbol(const std::string& uri) @@ -96,7 +98,6 @@ uri_to_symbol(const std::string& uri) return symbol; } - void Serialiser::write_manifest(const std::string& bundle_uri, const Records& records) @@ -125,15 +126,14 @@ Serialiser::write_manifest(const std::string& bundle_uri, subject, Sord::Curie(_model->world(), "lv2:binary"), Sord::Resource(_model->world(), - Glib::Module::build_path("", "ingen_lv2"))); + Glib::Module::build_path("", "ingen_lv2"))); symlink(Glib::Module::build_path(INGEN_MODULE_DIR, "ingen_lv2").c_str(), - Glib::Module::build_path(bundle_path, "ingen_lv2").c_str()); + Glib::Module::build_path(bundle_path, "ingen_lv2").c_str()); } } finish(); } - void Serialiser::write_bundle(const Record& record) { @@ -155,11 +155,10 @@ Serialiser::write_bundle(const Record& record) write_manifest(bundle_uri, records); } - string Serialiser::to_string(SharedPtr<GraphObject> object, - const string& base_uri, - const GraphObject::Properties& extra_rdf) + const string& base_uri, + const GraphObject::Properties& extra_rdf) { start_to_string(object->path(), base_uri); serialise(object); @@ -179,7 +178,6 @@ Serialiser::to_string(SharedPtr<GraphObject> object, return finish(); } - /** Begin a serialization to a file. * * This must be called before any serializing methods. @@ -198,7 +196,6 @@ Serialiser::start_to_filename(const string& filename) _mode = TO_FILE; } - /** Begin a serialization to a string. * * This must be called before any serializing methods. @@ -220,7 +217,6 @@ Serialiser::start_to_string(const Raul::Path& root, const string& base_uri) _mode = TO_STRING; } - /** Finish a serialization. * * If this was a serialization to a string, the serialization output @@ -246,7 +242,6 @@ Serialiser::finish() return ret; } - Sord::Node Serialiser::instance_rdf_node(const Path& path) { @@ -255,7 +250,6 @@ Serialiser::instance_rdf_node(const Path& path) return Sord::Resource(_model->world(), path.chop_scheme().substr(1)); } - Sord::Node Serialiser::class_rdf_node(const Path& path) { @@ -264,7 +258,6 @@ Serialiser::class_rdf_node(const Path& path) return Sord::Resource(_model->world(), path.chop_scheme().substr(1)); } - void Serialiser::serialise(SharedPtr<GraphObject> object) throw (std::logic_error) { @@ -278,7 +271,7 @@ Serialiser::serialise(SharedPtr<GraphObject> object) throw (std::logic_error) serialise_patch(patch, patch_id); } else { const Sord::Resource patch_id(_model->world(), - string(META_PREFIX) + patch->path().chop_start("/")); + string(META_PREFIX) + patch->path().chop_start("/")); serialise_patch(patch, patch_id); serialise_node(patch, patch_id, instance_rdf_node(patch->path())); } @@ -299,10 +292,9 @@ Serialiser::serialise(SharedPtr<GraphObject> object) throw (std::logic_error) } LOG(warn) << "Unsupported object type, " - << object->path() << " not serialised." << endl; + << object->path() << " not serialised." << endl; } - void Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch, const Sord::Node& patch_id) { @@ -324,8 +316,8 @@ Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch, const Sord::Node& pa string symbol; GraphObject::Properties::const_iterator s = patch->properties().find(uris.lv2_symbol); if (s == patch->properties().end() - || !s->second.type() == Atom::STRING - || !Symbol::is_valid(s->second.get_string())) { + || !s->second.type() == Atom::STRING + || !Symbol::is_valid(s->second.get_string())) { symbol = Glib::path_get_basename(Glib::filename_from_uri(_model->base_uri().to_c_string())); symbol = Symbol::symbolify(symbol.substr(0, symbol.find('.'))); _model->add_statement( @@ -346,7 +338,7 @@ Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch, const Sord::Node& pa serialise_properties(patch_id, NULL, patch->meta().properties()); for (Store::const_iterator n = _store->children_begin(patch); - n != _store->children_end(patch); ++n) { + n != _store->children_end(patch); ++n) { if (n->first.parent() != patch->path()) continue; @@ -355,7 +347,7 @@ Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch, const Sord::Node& pa SharedPtr<Shared::Node> node = PtrCast<Shared::Node>(n->second); if (subpatch) { const Sord::Resource class_id(_model->world(), - string(META_PREFIX) + subpatch->path().chop_start("/")); + string(META_PREFIX) + subpatch->path().chop_start("/")); const Sord::Node node_id(instance_rdf_node(n->second->path())); _model->add_statement( patch_id, @@ -396,12 +388,11 @@ Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch, const Sord::Node& pa } for (Shared::Patch::Connections::const_iterator c = patch->connections().begin(); - c != patch->connections().end(); ++c) { + c != patch->connections().end(); ++c) { serialise_connection(patch, c->second); } } - void Serialiser::serialise_plugin(const Shared::Plugin& plugin) { @@ -415,10 +406,10 @@ Serialiser::serialise_plugin(const Shared::Plugin& plugin) Sord::Resource(_model->world(), plugin.type_uri().str())); } - void Serialiser::serialise_node(SharedPtr<Shared::Node> node, - const Sord::Node& class_id, const Sord::Node& node_id) + const Sord::Node& class_id, + const Sord::Node& node_id) { _model->add_statement( node_id, @@ -446,7 +437,6 @@ Serialiser::serialise_node(SharedPtr<Shared::Node> node, } } - /** Serialise a port on a Node */ void Serialiser::serialise_port(const Port* port, const Sord::Node& port_id) @@ -463,7 +453,7 @@ Serialiser::serialise_port(const Port* port, const Sord::Node& port_id) Sord::Curie(_model->world(), "lv2:OutputPort")); for (Port::PortTypes::const_iterator i = port->types().begin(); - i != port->types().end(); ++i) + i != port->types().end(); ++i) _model->add_statement( port_id, Sord::Curie(_model->world(), "rdf:type"), @@ -483,7 +473,6 @@ Serialiser::serialise_port(const Port* port, const Sord::Node& port_id) serialise_properties(port_id, &port->meta(), port->properties()); } - /** Serialise a port on a Patch */ void Serialiser::serialise_port_meta(const Port* port, const Sord::Node& port_id) @@ -500,7 +489,7 @@ Serialiser::serialise_port_meta(const Port* port, const Sord::Node& port_id) Sord::Curie(_model->world(), "lv2:OutputPort")); for (Port::PortTypes::const_iterator i = port->types().begin(); - i != port->types().end(); ++i) + i != port->types().end(); ++i) _model->add_statement( port_id, Sord::Curie(_model->world(), "rdf:type"), @@ -532,7 +521,6 @@ Serialiser::serialise_port_meta(const Port* port, const Sord::Node& port_id) serialise_properties(port_id, NULL, port->meta().properties()); } - void Serialiser::serialise_connection(SharedPtr<GraphObject> parent, SharedPtr<Connection> connection) throw (std::logic_error) @@ -571,14 +559,13 @@ Serialiser::serialise_connection(SharedPtr<GraphObject> parent, } } - void -Serialiser::serialise_properties( - Sord::Node subject, - const Shared::Resource* meta, - const GraphObject::Properties& properties) +Serialiser::serialise_properties(Sord::Node subject, + const Shared::Resource* meta, + const GraphObject::Properties& properties) { - for (GraphObject::Properties::const_iterator v = properties.begin(); v != properties.end(); ++v) { + for (GraphObject::Properties::const_iterator v = properties.begin(); + v != properties.end(); ++v) { if (v->second.is_valid()) { if (!meta || !meta->has_property(v->first.str(), v->second)) { const Sord::Resource key(_model->world(), v->first.str()); @@ -587,7 +574,7 @@ Serialiser::serialise_properties( _model->add_statement(subject, key, value); } else { LOG(warn) << "Can not serialise variable '" << v->first << "' :: " - << (int)v->second.type() << endl; + << (int)v->second.type() << endl; } } } else { @@ -596,6 +583,5 @@ Serialiser::serialise_properties( } } - } // namespace Serialisation } // namespace Ingen diff --git a/src/serialisation/Serialiser.hpp b/src/serialisation/Serialiser.hpp index 58fd6fc6..650e48e7 100644 --- a/src/serialisation/Serialiser.hpp +++ b/src/serialisation/Serialiser.hpp @@ -18,32 +18,34 @@ #ifndef INGEN_SERIALISATION_SERIALISER_HPP #define INGEN_SERIALISATION_SERIALISER_HPP +#include <cassert> #include <map> -#include <utility> -#include <string> #include <stdexcept> -#include <cassert> -#include "raul/SharedPtr.hpp" +#include <string> +#include <utility> + #include "raul/Path.hpp" +#include "raul/SharedPtr.hpp" + #include "sord/sordmm.hpp" + #include "interface/GraphObject.hpp" #include "shared/Store.hpp" namespace Ingen { namespace Shared { - class Plugin; - class GraphObject; - class Patch; - class Node; - class Port; - class Connection; - class World; +class Plugin; +class GraphObject; +class Patch; +class Node; +class Port; +class Connection; +class World; } namespace Serialisation { - /** Serialises Ingen objects (patches, nodes, etc) to RDF. * * \ingroup IngenClient @@ -58,7 +60,7 @@ public: struct Record { Record(SharedPtr<Shared::GraphObject> o, const std::string& u) : object(o), uri(u) - {} + {} const SharedPtr<Shared::GraphObject> object; const std::string uri; @@ -90,19 +92,18 @@ private: void start_to_filename(const std::string& filename); - void setup_prefixes(); - void serialise_patch(SharedPtr<Shared::Patch> p, const Sord::Node& id); void serialise_node(SharedPtr<Shared::Node> n, - const Sord::Node& class_id, const Sord::Node& id); + const Sord::Node& class_id, const Sord::Node& id); void serialise_port(const Shared::Port* p, const Sord::Node& id); void serialise_port_meta(const Shared::Port* p, const Sord::Node& id); - void serialise_meta_properties(Sord::Node subject, const Properties& properties); - void serialise_properties( - Sord::Node subject, - const Shared::Resource* meta, - const Properties& properties); + void serialise_meta_properties(Sord::Node subject, + const Properties& properties); + + void serialise_properties(Sord::Node subject, + const Shared::Resource* meta, + const Properties& properties); Sord::Node instance_rdf_node(const Raul::Path& path); Sord::Node class_rdf_node(const Raul::Path& path); @@ -115,7 +116,6 @@ private: Sord::Model* _model; }; - } // namespace Serialisation } // namespace Ingen |