diff options
author | David Robillard <d@drobilla.net> | 2018-01-21 00:41:34 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-01-21 00:56:50 +0100 |
commit | 44f7ad5222d824d81dc743045d5887418847e74e (patch) | |
tree | 1b41535ac00b8b225a25dba2873b064cb074bfa9 /ingen | |
parent | 90fca083052880479ad90d870e556f0648e32106 (diff) | |
download | ingen-44f7ad5222d824d81dc743045d5887418847e74e.tar.gz ingen-44f7ad5222d824d81dc743045d5887418847e74e.tar.bz2 ingen-44f7ad5222d824d81dc743045d5887418847e74e.zip |
Add URI class and remove use of Raul::URI
Diffstat (limited to 'ingen')
-rw-r--r-- | ingen/AtomReader.hpp | 4 | ||||
-rw-r--r-- | ingen/AtomWriter.hpp | 7 | ||||
-rw-r--r-- | ingen/ClashAvoider.hpp | 4 | ||||
-rw-r--r-- | ingen/Forge.hpp | 5 | ||||
-rw-r--r-- | ingen/Interface.hpp | 37 | ||||
-rw-r--r-- | ingen/Message.hpp | 23 | ||||
-rw-r--r-- | ingen/Node.hpp | 7 | ||||
-rw-r--r-- | ingen/Parser.hpp | 19 | ||||
-rw-r--r-- | ingen/Properties.hpp | 15 | ||||
-rw-r--r-- | ingen/Resource.hpp | 60 | ||||
-rw-r--r-- | ingen/Serialiser.hpp | 9 | ||||
-rw-r--r-- | ingen/SocketWriter.hpp | 4 | ||||
-rw-r--r-- | ingen/StreamWriter.hpp | 5 | ||||
-rw-r--r-- | ingen/Tee.hpp | 3 | ||||
-rw-r--r-- | ingen/TurtleWriter.hpp | 9 | ||||
-rw-r--r-- | ingen/URI.hpp | 149 | ||||
-rw-r--r-- | ingen/URIs.hpp | 46 | ||||
-rw-r--r-- | ingen/World.hpp | 13 | ||||
-rw-r--r-- | ingen/client/BlockModel.hpp | 6 | ||||
-rw-r--r-- | ingen/client/ClientStore.hpp | 14 | ||||
-rw-r--r-- | ingen/client/ObjectModel.hpp | 11 | ||||
-rw-r--r-- | ingen/client/PluginModel.hpp | 23 | ||||
-rw-r--r-- | ingen/client/PluginUI.hpp | 4 | ||||
-rw-r--r-- | ingen/client/PortModel.hpp | 2 | ||||
-rw-r--r-- | ingen/client/SigClientInterface.hpp | 2 | ||||
-rw-r--r-- | ingen/client/SocketClient.hpp | 4 | ||||
-rw-r--r-- | ingen/client/ThreadedSigClientInterface.hpp | 5 | ||||
-rw-r--r-- | ingen/paths.hpp | 19 |
28 files changed, 324 insertions, 185 deletions
diff --git a/ingen/AtomReader.hpp b/ingen/AtomReader.hpp index bca56022..7ea4654a 100644 --- a/ingen/AtomReader.hpp +++ b/ingen/AtomReader.hpp @@ -28,11 +28,11 @@ namespace Raul { class Path; -class URI; } namespace Ingen { +class URI; class Atom; class Interface; class Log; @@ -58,7 +58,7 @@ public: private: void get_atom(const LV2_Atom* in, Atom& out); - boost::optional<Raul::URI> atom_to_uri(const LV2_Atom* atom); + boost::optional<URI> atom_to_uri(const LV2_Atom* atom); boost::optional<Raul::Path> atom_to_path(const LV2_Atom* atom); Resource::Graph atom_to_context(const LV2_Atom* atom); diff --git a/ingen/AtomWriter.hpp b/ingen/AtomWriter.hpp index 725d4a81..5e765c75 100644 --- a/ingen/AtomWriter.hpp +++ b/ingen/AtomWriter.hpp @@ -27,7 +27,6 @@ #include "ingen/ingen.h" #include "lv2/lv2plug.in/ns/ext/atom/forge.h" #include "lv2/lv2plug.in/ns/ext/urid/urid.h" -#include "raul/URI.hpp" namespace Raul { class Path; } @@ -45,9 +44,7 @@ public: AtomWriter(URIMap& map, URIs& uris, AtomSink& sink); - Raul::URI uri() const override { - return Raul::URI("ingen:/clients/atom_writer"); - } + URI uri() const override { return URI("ingen:/clients/atom_writer"); } void message(const Message& message) override; @@ -69,7 +66,7 @@ public: void operator()(const Undo&); private: - void forge_uri(const Raul::URI& uri); + void forge_uri(const URI& uri); void forge_properties(const Properties& properties); void forge_arc(const Raul::Path& tail, const Raul::Path& head); void forge_request(LV2_Atom_Forge_Frame* frame, LV2_URID type, int32_t id); diff --git a/ingen/ClashAvoider.hpp b/ingen/ClashAvoider.hpp index a5cd3643..069c8fef 100644 --- a/ingen/ClashAvoider.hpp +++ b/ingen/ClashAvoider.hpp @@ -21,11 +21,11 @@ #include "ingen/ingen.h" #include "raul/Path.hpp" -#include "raul/URI.hpp" namespace Ingen { class Store; +class URI; /** Maps paths so they do not clash with an existing object in a store. * @@ -36,7 +36,7 @@ class INGEN_API ClashAvoider public: explicit ClashAvoider(const Store& store); - const Raul::URI map_uri(const Raul::URI& in); + const URI map_uri(const URI& in); const Raul::Path map_path(const Raul::Path& in); bool exists(const Raul::Path& path) const; diff --git a/ingen/Forge.hpp b/ingen/Forge.hpp index 3dd7bfa3..32822f89 100644 --- a/ingen/Forge.hpp +++ b/ingen/Forge.hpp @@ -25,11 +25,10 @@ #include "ingen/ingen.h" #include "lv2/lv2plug.in/ns/ext/atom/forge.h" -namespace Raul { class URI; } - namespace Ingen { class URIMap; +class URI; /** Forge for Atoms. * @ingroup IngenShared @@ -54,7 +53,7 @@ public: Atom make_urid(int32_t v) { return Atom(sizeof(int32_t), URID, &v); } - Atom make_urid(const Raul::URI& u); + Atom make_urid(const Ingen::URI& u); Atom alloc(uint32_t size, uint32_t type, const void* val) { return Atom(size, type, val); diff --git a/ingen/Interface.hpp b/ingen/Interface.hpp index 2221f8f0..a6654afe 100644 --- a/ingen/Interface.hpp +++ b/ingen/Interface.hpp @@ -33,12 +33,12 @@ namespace Raul { class Path; -class URI; } namespace Ingen { class Atom; +class URI; /** Abstract interface for Ingen servers and clients. * @@ -53,7 +53,7 @@ public: virtual ~Interface() = default; - virtual Raul::URI uri() const = 0; + virtual URI uri() const = 0; virtual SPtr<Interface> respondee() const { return SPtr<Interface>(); } @@ -67,22 +67,19 @@ public: inline void operator()(const Message& msg) { message(msg); } - inline void set_response_id(int32_t id) { - _seq = id; - } + inline void set_response_id(int32_t id) { _seq = id; } inline void bundle_begin() { message(BundleBegin{_seq++}); } + inline void bundle_end() { message(BundleEnd{_seq++}); } - inline void bundle_end() { message(BundleEnd{_seq++}); } - - inline void put(const Raul::URI& uri, + inline void put(const URI& uri, const Properties& properties, Resource::Graph ctx = Resource::Graph::DEFAULT) { message(Put{_seq++, uri, properties, ctx}); } - inline void delta(const Raul::URI& uri, + inline void delta(const URI& uri, const Properties& remove, const Properties& add, Resource::Graph ctx = Resource::Graph::DEFAULT) @@ -90,7 +87,7 @@ public: message(Delta{_seq++, uri, remove, add, ctx}); } - inline void copy(const Raul::URI& old_uri, const Raul::URI& new_uri) + inline void copy(const URI& old_uri, const URI& new_uri) { message(Copy{_seq++, old_uri, new_uri}); } @@ -100,7 +97,7 @@ public: message(Move{_seq++, old_path, new_path}); } - inline void del(const Raul::URI& uri) { message(Del{_seq++, uri}); } + inline void del(const URI& uri) { message(Del{_seq++, uri}); } inline void connect(const Raul::Path& tail, const Raul::Path& head) { @@ -117,10 +114,10 @@ public: message(DisconnectAll{_seq++, graph, path}); } - inline void set_property(const Raul::URI& subject, - const Raul::URI& predicate, - const Atom& value, - Resource::Graph ctx = Resource::Graph::DEFAULT) + inline void set_property(const URI& subject, + const URI& predicate, + const Atom& value, + Resource::Graph ctx = Resource::Graph::DEFAULT) { message(SetProperty{_seq++, subject, predicate, value, ctx}); } @@ -129,15 +126,15 @@ public: inline void redo() { message(Redo{_seq++}); } - inline void get(const Raul::URI& uri) { message(Get{_seq++, uri}); } + inline void get(const URI& uri) { message(Get{_seq++, uri}); } - inline void response(int32_t id, - Status status, - const std::string& subject) { + inline void response(int32_t id, Status status, const std::string& subject) + { message(Response{id, status, subject}); } - inline void error(const std::string& error_message) { + inline void error(const std::string& error_message) + { message(Error{_seq++, error_message}); } diff --git a/ingen/Message.hpp b/ingen/Message.hpp index 83608dae..515a2e1f 100644 --- a/ingen/Message.hpp +++ b/ingen/Message.hpp @@ -27,7 +27,6 @@ #include "ingen/Resource.hpp" #include "ingen/Status.hpp" #include "raul/Path.hpp" -#include "raul/URI.hpp" namespace Ingen { @@ -50,21 +49,21 @@ struct Connect struct Copy { - int32_t seq; - Raul::URI old_uri; - Raul::URI new_uri; + int32_t seq; + URI old_uri; + URI new_uri; }; struct Del { - int32_t seq; - Raul::URI uri; + int32_t seq; + URI uri; }; struct Delta { int32_t seq; - Raul::URI uri; + URI uri; Properties remove; Properties add; Resource::Graph ctx; @@ -92,8 +91,8 @@ struct Error struct Get { - int32_t seq; - Raul::URI subject; + int32_t seq; + URI subject; }; struct Move @@ -106,7 +105,7 @@ struct Move struct Put { int32_t seq; - Raul::URI uri; + URI uri; Properties properties; Resource::Graph ctx; }; @@ -126,8 +125,8 @@ struct Response struct SetProperty { int32_t seq; - Raul::URI subject; - Raul::URI predicate; + URI subject; + URI predicate; Atom value; Resource::Graph ctx; }; diff --git a/ingen/Node.hpp b/ingen/Node.hpp index 5b2a5ee5..e023e9e2 100644 --- a/ingen/Node.hpp +++ b/ingen/Node.hpp @@ -27,7 +27,6 @@ #include "ingen/paths.hpp" #include "ingen/types.hpp" #include "lilv/lilv.h" -#include "raul/URI.hpp" namespace Raul { class Path; @@ -83,11 +82,11 @@ public: virtual const Raul::Symbol& symbol() const = 0; virtual Node* graph_parent() const = 0; - Raul::URI base_uri() const { - if (uri()[uri().size() - 1] == '/') { + URI base_uri() const { + if (uri().string()[uri().string().size() - 1] == '/') { return uri(); } - return Raul::URI(uri() + '/'); + return URI(uri().string() + '/'); } protected: diff --git a/ingen/Parser.hpp b/ingen/Parser.hpp index 852fa0a5..ac9d8320 100644 --- a/ingen/Parser.hpp +++ b/ingen/Parser.hpp @@ -17,23 +17,25 @@ #ifndef INGEN_PARSER_HPP #define INGEN_PARSER_HPP -#include <string> #include <set> +#include <string> +#include <utility> #include <boost/optional/optional.hpp> #include "ingen/Properties.hpp" +#include "ingen/URI.hpp" #include "ingen/ingen.h" #include "raul/Path.hpp" #include "raul/Symbol.hpp" -namespace Raul { class URI; } namespace Sord { class World; } namespace Ingen { class Interface; class World; +class URI; /** Parser for reading graphs from Turtle files or strings. @@ -48,7 +50,7 @@ public: /** Record of a resource listed in a bundle manifest. */ struct ResourceRecord { - inline ResourceRecord(std::string u, std::string f) + inline ResourceRecord(URI u, std::string f) : uri(std::move(u)), filename(std::move(f)) {} @@ -56,15 +58,14 @@ public: return uri < r.uri; } - std::string uri; ///< URI of resource (e.g. a Graph) + URI uri; ///< URI of resource (e.g. a Graph) std::string filename; ///< Path of describing file (seeAlso) }; /** Find all resources of a given type listed in a manifest file. */ - virtual std::set<ResourceRecord> find_resources( - Sord::World& world, - const std::string& manifest_uri, - const Raul::URI& type_uri); + virtual std::set<ResourceRecord> find_resources(Sord::World& world, + const URI& manifest_uri, + const URI& type_uri); /** Parse a graph from RDF into a Interface (engine or client). * @@ -83,7 +84,7 @@ public: boost::optional<Raul::Symbol> symbol = boost::optional<Raul::Symbol>(), boost::optional<Properties> data = boost::optional<Properties>()); - virtual boost::optional<Raul::URI> parse_string( + virtual boost::optional<URI> parse_string( World* world, Interface* target, const std::string& str, diff --git a/ingen/Properties.hpp b/ingen/Properties.hpp index a80a00d9..e148c542 100644 --- a/ingen/Properties.hpp +++ b/ingen/Properties.hpp @@ -23,7 +23,6 @@ #include "ingen/Atom.hpp" #include "ingen/URIs.hpp" -#include "raul/URI.hpp" namespace Ingen { @@ -53,7 +52,7 @@ private: Graph _ctx; }; -class Properties : public std::multimap<Raul::URI, Property> { +class Properties : public std::multimap<URI, Property> { public: using Graph = Property::Graph; @@ -61,22 +60,22 @@ public: Properties(const Properties& copy) = default; Properties(std::initializer_list<value_type> l) - : std::multimap<Raul::URI, Property>(l) + : std::multimap<URI, Property>(l) {} - void put(const Raul::URI& key, - const Atom& value, - Graph ctx = Graph::DEFAULT) { + void put(const URI& key, + const Atom& value, + Graph ctx = Graph::DEFAULT) { emplace(key, Property(value, ctx)); } - void put(const Raul::URI& key, + void put(const URI& key, const URIs::Quark& value, Graph ctx = Graph::DEFAULT) { emplace(key, Property(value, ctx)); } - bool contains(const Raul::URI& key, const Atom& value) { + bool contains(const URI& key, const Atom& value) { for (const_iterator i = find(key); i != end() && i->first == key; ++i) { if (i->second == value) { return true; diff --git a/ingen/Resource.hpp b/ingen/Resource.hpp index 8cfdb02a..9fc854c7 100644 --- a/ingen/Resource.hpp +++ b/ingen/Resource.hpp @@ -21,10 +21,10 @@ #include <string> #include "ingen/Properties.hpp" +#include "ingen/URI.hpp" #include "ingen/URIs.hpp" #include "ingen/ingen.h" #include "raul/Deletable.hpp" -#include "raul/URI.hpp" namespace Ingen { @@ -42,7 +42,7 @@ class INGEN_API Resource : public Raul::Deletable public: using Graph = Property::Graph; - Resource(const URIs& uris, const Raul::URI& uri) + Resource(const URIs& uris, const URI& uri) : _uris(uris) , _uri(uri) {} @@ -56,15 +56,15 @@ public: return *this; } - static Raul::URI graph_to_uri(Graph g) { + static URI graph_to_uri(Graph g) { switch (g) { - case Graph::EXTERNAL: return Raul::URI(INGEN_NS "externalContext"); - case Graph::INTERNAL: return Raul::URI(INGEN_NS "internalContext"); - default: return Raul::URI(INGEN_NS "defaultContext"); + case Graph::EXTERNAL: return URI(INGEN_NS "externalContext"); + case Graph::INTERNAL: return URI(INGEN_NS "internalContext"); + default: return URI(INGEN_NS "defaultContext"); } } - static Graph uri_to_graph(const Raul::URI& uri) { + static Graph uri_to_graph(const URI& uri) { if (uri == INGEN_NS "externalContext") { return Graph::EXTERNAL; } else if (uri == INGEN_NS "internalContext") { @@ -78,27 +78,25 @@ public: * This is only useful for properties with a single value. If the * requested property has several values, the first will be returned. */ - virtual const Atom& get_property(const Raul::URI& uri) const; + virtual const Atom& get_property(const URI& uri) const; /** Set (replace) a property value. * * This will first erase any properties with the given `uri`, so after * this call exactly one property with predicate `uri` will be set. */ - virtual const Atom& set_property( - const Raul::URI& uri, - const Atom& value, - Graph ctx = Graph::DEFAULT); + virtual const Atom& set_property(const URI& uri, + const Atom& value, + Graph ctx = Graph::DEFAULT); /** Set (replace) a property value. * * This will first erase any properties with the given `uri`, so after * this call exactly one property with predicate `uri` will be set. */ - virtual const Atom& set_property( - const Raul::URI& uri, - const URIs::Quark& value, - Graph ctx = Graph::DEFAULT); + virtual const Atom& set_property(const URI& uri, + const URIs::Quark& value, + Graph ctx = Graph::DEFAULT); /** Add a property value. * @@ -108,32 +106,32 @@ public: * * @return True iff a new property was added. */ - virtual bool add_property(const Raul::URI& uri, - const Atom& value, - Graph ctx = Graph::DEFAULT); + virtual bool add_property(const URI& uri, + const Atom& value, + Graph ctx = Graph::DEFAULT); /** Remove a property. * * If `value` is patch:wildcard then any property with `uri` for a * predicate will be removed. */ - virtual void remove_property(const Raul::URI& uri, - const Atom& value); + virtual void remove_property(const URI& uri, + const Atom& value); /** Remove a property. * * If `value` is patch:wildcard then any property with `uri` for a * predicate will be removed. */ - virtual void remove_property(const Raul::URI& uri, + virtual void remove_property(const URI& uri, const URIs::Quark& value); /** Return true iff a property is set with a specific value. */ - virtual bool has_property(const Raul::URI& uri, - const Atom& value) const; + virtual bool has_property(const URI& uri, + const Atom& value) const; /** Return true iff a property is set with a specific value. */ - virtual bool has_property(const Raul::URI& uri, + virtual bool has_property(const URI& uri, const URIs::Quark& value) const; /** Set (replace) several properties at once. @@ -159,7 +157,7 @@ public: * This can be used by derived classes to implement special behaviour for * particular properties (e.g. ingen:value for ports). */ - virtual void on_property(const Raul::URI& uri, const Atom& value) {} + virtual void on_property(const URI& uri, const Atom& value) {} /** Hook called whenever a property value is removed. * @@ -168,7 +166,7 @@ public: * This can be used by derived classes to implement special behaviour for * particular properties (e.g. ingen:value for ports). */ - virtual void on_property_removed(const Raul::URI& uri, const Atom& value) {} + virtual void on_property_removed(const URI& uri, const Atom& value) {} /** Get the ingen type from a set of Properties. * @@ -182,23 +180,23 @@ public: bool& port, bool& is_output); - virtual void set_uri(const Raul::URI& uri) { _uri = uri; } + virtual void set_uri(const URI& uri) { _uri = uri; } /** Get all the properties with a given context. */ Properties properties(Resource::Graph ctx) const; const URIs& uris() const { return _uris; } - const Raul::URI& uri() const { return _uri; } + const URI& uri() const { return _uri; } const Properties& properties() const { return _properties; } Properties& properties() { return _properties; } protected: - const Atom& set_property(const Raul::URI& uri, const Atom& value) const; + const Atom& set_property(const URI& uri, const Atom& value) const; const URIs& _uris; private: - Raul::URI _uri; + URI _uri; mutable Properties _properties; }; diff --git a/ingen/Serialiser.hpp b/ingen/Serialiser.hpp index 00466350..50d4f693 100644 --- a/ingen/Serialiser.hpp +++ b/ingen/Serialiser.hpp @@ -30,6 +30,7 @@ namespace Ingen { class Arc; class Node; +class URI; class World; /** @@ -44,8 +45,8 @@ public: virtual ~Serialiser(); /** Write a graph and all its contents as a complete bundle. */ - virtual void write_bundle(SPtr<const Node> graph, - const std::string& uri); + virtual void write_bundle(SPtr<const Node> graph, + const URI& uri); /** Begin a serialization to a string. * @@ -57,8 +58,8 @@ public: * All serialized paths will have the root path chopped from their prefix * (therefore all serialized paths must be descendants of the root) */ - virtual void start_to_string(const Raul::Path& root, - const std::string& base_uri); + virtual void start_to_string(const Raul::Path& root, + const URI& base_uri); /** Begin a serialization to a file. * diff --git a/ingen/SocketWriter.hpp b/ingen/SocketWriter.hpp index bfd9b0f6..1dcc077b 100644 --- a/ingen/SocketWriter.hpp +++ b/ingen/SocketWriter.hpp @@ -25,11 +25,11 @@ namespace Raul { class Socket; -class URI; } namespace Ingen { +class URI; class URIMap; class URIs; @@ -40,7 +40,7 @@ class INGEN_API SocketWriter : public TurtleWriter public: SocketWriter(URIMap& map, URIs& uris, - const Raul::URI& uri, + const URI& uri, SPtr<Raul::Socket> sock); size_t text_sink(const void* buf, size_t len) override; diff --git a/ingen/StreamWriter.hpp b/ingen/StreamWriter.hpp index 3fe38646..66a03216 100644 --- a/ingen/StreamWriter.hpp +++ b/ingen/StreamWriter.hpp @@ -23,10 +23,9 @@ #include "ingen/ColorContext.hpp" #include "ingen/TurtleWriter.hpp" -namespace Raul { class URI; } - namespace Ingen { +class URI; class URIMap; class URIs; @@ -37,7 +36,7 @@ class INGEN_API StreamWriter : public TurtleWriter public: StreamWriter(URIMap& map, URIs& uris, - const Raul::URI& uri, + const URI& uri, FILE* stream, ColorContext::Color color); diff --git a/ingen/Tee.hpp b/ingen/Tee.hpp index b739e134..2a6f00df 100644 --- a/ingen/Tee.hpp +++ b/ingen/Tee.hpp @@ -25,7 +25,6 @@ #include "ingen/Interface.hpp" #include "ingen/Message.hpp" #include "ingen/types.hpp" -#include "raul/URI.hpp" namespace Ingen { @@ -52,7 +51,7 @@ public: } } - Raul::URI uri() const override { return Raul::URI("ingen:/tee"); } + URI uri() const override { return URI("ingen:/tee"); } private: std::mutex _sinks_mutex; diff --git a/ingen/TurtleWriter.hpp b/ingen/TurtleWriter.hpp index b11e3d37..8cf7ceb8 100644 --- a/ingen/TurtleWriter.hpp +++ b/ingen/TurtleWriter.hpp @@ -24,7 +24,6 @@ #include "ingen/AtomWriter.hpp" #include "ingen/ingen.h" #include "lv2/lv2plug.in/ns/ext/atom/atom.h" -#include "raul/URI.hpp" #include "serd/serd.h" #include "sratom/sratom.h" @@ -41,9 +40,7 @@ class URIs; class INGEN_API TurtleWriter : public AtomWriter, public AtomSink { public: - TurtleWriter(URIMap& map, - URIs& uris, - const Raul::URI& uri); + TurtleWriter(URIMap& map, URIs& uris, const URI& uri); ~TurtleWriter() override; @@ -53,7 +50,7 @@ public: /** Pure virtual text sink which receives calls serialized to Turtle. */ virtual size_t text_sink(const void* buf, size_t len) = 0; - Raul::URI uri() const override { return _uri; } + URI uri() const override { return _uri; } protected: URIMap& _map; @@ -62,7 +59,7 @@ protected: SerdURI _base_uri; SerdEnv* _env; SerdWriter* _writer; - Raul::URI _uri; + URI _uri; bool _wrote_prefixes; }; diff --git a/ingen/URI.hpp b/ingen/URI.hpp new file mode 100644 index 00000000..6b2adff4 --- /dev/null +++ b/ingen/URI.hpp @@ -0,0 +1,149 @@ +/* + This file is part of Ingen. + Copyright 2018 David Robillard <http://drobilla.net/> + + Ingen is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or any later version. + + Ingen is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU Affero General Public License for details. + + You should have received a copy of the GNU Affero General Public License + along with Ingen. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef INGEN_URI_HPP +#define INGEN_URI_HPP + +#include <iosfwd> +#include <string> + +#include <boost/utility/string_view.hpp> + +#include "ingen/ingen.h" +#include "serd/serd.h" +#include "sord/sordmm.hpp" + +namespace Ingen { + +class INGEN_API URI +{ +public: + using Chunk = boost::string_view; + + URI(); + explicit URI(const std::string& str); + explicit URI(const char* str); + URI(const std::string& str, const URI& base); + explicit URI(const Sord::Node& node); + + URI(const URI& uri); + URI& operator=(const URI& uri); + + URI(URI&& uri); + URI& operator=(URI&& uri); + + ~URI(); + + bool empty() const { return !_node.buf; } + + std::string string() const { return std::string(c_str(), _node.n_bytes); } + size_t length() const { return _node.n_bytes; } + const char* c_str() const { return (const char*)_node.buf; } + + operator std::string() const { return string(); } + + const char* begin() const { return (const char*)_node.buf; } + const char* end() const { return (const char*)_node.buf + _node.n_bytes; } + + Chunk scheme() const { return make_chunk(_uri.scheme); } + Chunk authority() const { return make_chunk(_uri.authority); } + Chunk path() const { return make_chunk(_uri.path); } + Chunk query() const { return make_chunk(_uri.query); } + Chunk fragment() const { return make_chunk(_uri.fragment); } + + static bool is_valid(const char* str) { + return serd_uri_string_has_scheme((const uint8_t*)str); + } + + static bool is_valid(const std::string& str) + { + return is_valid(str.c_str()); + } + +private: + static Chunk make_chunk(const SerdChunk& chunk) { + return Chunk((const char*)chunk.buf, chunk.len); + } + + SerdNode _node; + SerdURI _uri; +}; + +inline bool operator==(const URI& lhs, const URI& rhs) +{ + return lhs.string() == rhs.string(); +} + +inline bool operator==(const URI& lhs, const std::string& rhs) +{ + return lhs.string() == rhs; +} + +inline bool operator==(const URI& lhs, const char* rhs) +{ + return lhs.string() == rhs; +} + +inline bool operator==(const URI& lhs, const Sord::Node& rhs) +{ + return rhs.type() == Sord::Node::URI && lhs.string() == rhs.to_string(); +} + +inline bool operator==(const Sord::Node& lhs, const URI& rhs) +{ + return rhs == lhs; +} + +inline bool operator!=(const URI& lhs, const URI& rhs) +{ + return lhs.string() != rhs.string(); +} + +inline bool operator!=(const URI& lhs, const std::string& rhs) +{ + return lhs.string() != rhs; +} + +inline bool operator!=(const URI& lhs, const char* rhs) +{ + return lhs.string() != rhs; +} + +inline bool operator!=(const URI& lhs, const Sord::Node& rhs) +{ + return !(lhs == rhs); +} + +inline bool operator!=(const Sord::Node& lhs, const URI& rhs) +{ + return !(lhs == rhs); +} + +inline bool operator<(const URI& lhs, const URI& rhs) +{ + return lhs.string() < rhs.string(); +} + +template <typename Char, typename Traits> +inline std::basic_ostream<Char, Traits>& +operator<<(std::basic_ostream<Char, Traits>& os, const URI& uri) +{ + return os << uri.string(); +} + +} // namespace Ingen + +#endif // INGEN_URI_HPP diff --git a/ingen/URIs.hpp b/ingen/URIs.hpp index c718322d..71c14d14 100644 --- a/ingen/URIs.hpp +++ b/ingen/URIs.hpp @@ -18,11 +18,11 @@ #define INGEN_URIS_HPP #include "ingen/Atom.hpp" +#include "ingen/URI.hpp" #include "ingen/ingen.h" #include "lilv/lilv.h" #include "lv2/lv2plug.in/ns/ext/urid/urid.h" #include "raul/Noncopyable.hpp" -#include "raul/URI.hpp" namespace Ingen { @@ -41,7 +41,7 @@ class INGEN_API URIs : public Raul::Noncopyable { public: URIs(Ingen::Forge& forge, URIMap* map, LilvWorld* lworld); - struct Quark : public Raul::URI { + struct Quark : public URI { Quark(Ingen::Forge& forge, URIMap* map, LilvWorld* lworld, @@ -55,19 +55,6 @@ public: explicit operator Atom() const { return urid; } operator const LilvNode*() const { return lnode; } - inline bool operator==(const Atom& rhs) const { - if (rhs.type() == urid.type()) { - return rhs == urid; - } else if (rhs.type() == uri.type()) { - return rhs == uri; - } - return false; - } - - inline bool operator!=(const Atom& rhs) const { - return !operator==(rhs); - } - Atom urid; Atom uri; LilvNode* lnode; @@ -213,12 +200,33 @@ public: const Quark work_schedule; }; -inline bool operator==(const Atom& a, const URIs::Quark& b) { - return b == a; +inline bool +operator==(const URIs::Quark& lhs, const Atom& rhs) +{ + if (rhs.type() == lhs.urid.type()) { + return rhs == lhs.urid; + } else if (rhs.type() == lhs.uri.type()) { + return rhs == lhs.uri; + } + return false; +} + +inline bool +operator==(const Atom& lhs, const URIs::Quark& rhs) +{ + return rhs == lhs; +} + +inline bool +operator!=(const Atom& lhs, const URIs::Quark& rhs) +{ + return !(lhs == rhs); } -inline bool operator!=(const Atom& a, const URIs::Quark& b) { - return b != a; +inline bool +operator!=(const URIs::Quark& lhs, const Atom& rhs) +{ + return !(lhs == rhs); } } // namespace Ingen diff --git a/ingen/World.hpp b/ingen/World.hpp index 21d6c33b..13bd7001 100644 --- a/ingen/World.hpp +++ b/ingen/World.hpp @@ -28,7 +28,6 @@ typedef struct LilvWorldImpl LilvWorld; -namespace Raul { class URI; } namespace Sord { class World; } namespace Ingen { @@ -42,6 +41,7 @@ class Log; class Parser; class Serialiser; class Store; +class URI; class URIMap; class URIs; @@ -89,10 +89,9 @@ public: virtual bool run_module(const char* name); /** A function to create a new remote Interface. */ - typedef SPtr<Interface> (*InterfaceFactory)( - World* world, - const Raul::URI& engine_uri, - SPtr<Interface> respondee); + typedef SPtr<Interface> (*InterfaceFactory)(World* world, + const URI& engine_uri, + SPtr<Interface> respondee); /** Register an InterfaceFactory (for module implementations). */ virtual void add_interface_factory(const std::string& scheme, @@ -103,8 +102,8 @@ public: * @param respondee The Interface that will receive responses to commands * and broadcasts, if applicable. */ - virtual SPtr<Interface> new_interface(const Raul::URI& engine_uri, - SPtr<Interface> respondee); + virtual SPtr<Interface> new_interface(const URI& engine_uri, + SPtr<Interface> respondee); /** Run a script. */ virtual bool run(const std::string& mime_type, diff --git a/ingen/client/BlockModel.hpp b/ingen/client/BlockModel.hpp index 22613eca..38e8987e 100644 --- a/ingen/client/BlockModel.hpp +++ b/ingen/client/BlockModel.hpp @@ -58,7 +58,7 @@ public: Node* port(uint32_t index) const; - const Raul::URI& plugin_uri() const { return _plugin_uri; } + const URI& plugin_uri() const { return _plugin_uri; } const Resource* plugin() const { return _plugin.get(); } Resource* plugin() { return _plugin.get(); } SPtr<PluginModel> plugin_model() const { return _plugin; } @@ -86,7 +86,7 @@ protected: friend class ClientStore; BlockModel(URIs& uris, - const Raul::URI& plugin_uri, + const URI& plugin_uri, const Raul::Path& path); BlockModel(URIs& uris, SPtr<PluginModel> plugin, @@ -103,7 +103,7 @@ protected: virtual void clear(); Ports _ports; ///< Vector of ports - Raul::URI _plugin_uri; ///< Plugin URI (if PluginModel is unknown) + URI _plugin_uri; ///< Plugin URI (if PluginModel is unknown) SPtr<PluginModel> _plugin; ///< The plugin this block is an instance of private: diff --git a/ingen/client/ClientStore.hpp b/ingen/client/ClientStore.hpp index 8850f401..797052ef 100644 --- a/ingen/client/ClientStore.hpp +++ b/ingen/client/ClientStore.hpp @@ -58,15 +58,15 @@ public: Log& log, SPtr<SigClientInterface> emitter = SPtr<SigClientInterface>()); - Raul::URI uri() const override { return Raul::URI("ingen:/clients/store"); } + URI uri() const override { return URI("ingen:/clients/store"); } SPtr<const ObjectModel> object(const Raul::Path& path) const; - SPtr<const PluginModel> plugin(const Raul::URI& uri) const; - SPtr<const Resource> resource(const Raul::URI& uri) const; + SPtr<const PluginModel> plugin(const URI& uri) const; + SPtr<const Resource> resource(const URI& uri) const; void clear(); - typedef std::map< const Raul::URI, SPtr<PluginModel> > Plugins; + typedef std::map< const URI, SPtr<PluginModel> > Plugins; SPtr<const Plugins> plugins() const { return _plugins; } SPtr<Plugins> plugins() { return _plugins; } void set_plugins(SPtr<Plugins> p) { _plugins = p; } @@ -94,13 +94,13 @@ public: INGEN_SIGNAL(new_object, void, SPtr<ObjectModel>); INGEN_SIGNAL(new_plugin, void, SPtr<PluginModel>); - INGEN_SIGNAL(plugin_deleted, void, Raul::URI); + INGEN_SIGNAL(plugin_deleted, void, URI); private: SPtr<ObjectModel> _object(const Raul::Path& path); - SPtr<PluginModel> _plugin(const Raul::URI& uri); + SPtr<PluginModel> _plugin(const URI& uri); SPtr<PluginModel> _plugin(const Atom& uri); - SPtr<Resource> _resource(const Raul::URI& uri); + SPtr<Resource> _resource(const URI& uri); void add_object(SPtr<ObjectModel> object); SPtr<ObjectModel> remove_object(const Raul::Path& path); diff --git a/ingen/client/ObjectModel.hpp b/ingen/client/ObjectModel.hpp index 4250efc5..a5a68f1e 100644 --- a/ingen/client/ObjectModel.hpp +++ b/ingen/client/ObjectModel.hpp @@ -27,7 +27,6 @@ #include "ingen/types.hpp" #include "raul/Path.hpp" -#include "raul/URI.hpp" #include "ingen/Node.hpp" #include "ingen/Resource.hpp" @@ -58,10 +57,10 @@ class INGEN_API ObjectModel : public Node public: bool is_a(const URIs::Quark& type) const; - const Atom& get_property(const Raul::URI& key) const; + const Atom& get_property(const URI& key) const; - void on_property(const Raul::URI& uri, const Atom& value); - void on_property_removed(const Raul::URI& uri, const Atom& value); + void on_property(const URI& uri, const Atom& value); + void on_property_removed(const URI& uri, const Atom& value); const Raul::Path& path() const { return _path; } const Raul::Symbol& symbol() const { return _symbol; } @@ -73,8 +72,8 @@ public: // Signals INGEN_SIGNAL(new_child, void, SPtr<ObjectModel>); INGEN_SIGNAL(removed_child, void, SPtr<ObjectModel>); - INGEN_SIGNAL(property, void, const Raul::URI&, const Atom&); - INGEN_SIGNAL(property_removed, void, const Raul::URI&, const Atom&); + INGEN_SIGNAL(property, void, const URI&, const Atom&); + INGEN_SIGNAL(property_removed, void, const URI&, const Atom&); INGEN_SIGNAL(destroyed, void); INGEN_SIGNAL(moved, void); diff --git a/ingen/client/PluginModel.hpp b/ingen/client/PluginModel.hpp index 585ac7d7..61de0f1a 100644 --- a/ingen/client/PluginModel.hpp +++ b/ingen/client/PluginModel.hpp @@ -50,18 +50,19 @@ class INGEN_API PluginModel : public Ingen::Resource { public: PluginModel(URIs& uris, - const Raul::URI& uri, + const URI& uri, const Atom& type, const Ingen::Properties& properties); - const Atom& type() const { return _type; } - const Raul::URI type_uri() const { - return Raul::URI(_type.is_valid() - ? _uris.forge.str(_type, false) - : "http://www.w3.org/2002/07/owl#Nothing"); + const Atom& type() const { return _type; } + + const URI type_uri() const + { + return URI(_type.is_valid() ? _uris.forge.str(_type, false) + : "http://www.w3.org/2002/07/owl#Nothing"); } - virtual const Atom& get_property(const Raul::URI& key) const; + virtual const Atom& get_property(const URI& key) const; Raul::Symbol default_block_symbol() const; std::string human_name() const; @@ -70,7 +71,7 @@ public: typedef std::map<float, std::string> ScalePoints; ScalePoints port_scale_points(uint32_t i) const; - typedef std::map<Raul::URI, std::string> Presets; + typedef std::map<URI, std::string> Presets; const Presets& presets() const { return _presets; } static LilvWorld* lilv_world() { return _lilv_world; } @@ -96,8 +97,8 @@ public: // Signals INGEN_SIGNAL(changed, void); - INGEN_SIGNAL(property, void, const Raul::URI&, const Atom&); - INGEN_SIGNAL(preset, void, const Raul::URI&, const std::string&); + INGEN_SIGNAL(property, void, const URI&, const Atom&); + INGEN_SIGNAL(preset, void, const URI&, const std::string&); bool fetched() const { return _fetched; } void set_fetched(bool f) { _fetched = f; } @@ -106,7 +107,7 @@ protected: friend class ClientStore; void set(SPtr<PluginModel> p); - void add_preset(const Raul::URI& uri, const std::string& label); + void add_preset(const URI& uri, const std::string& label); private: std::string get_documentation(const LilvNode* subject, bool html) const; diff --git a/ingen/client/PluginUI.hpp b/ingen/client/PluginUI.hpp index 45475cfe..a98df61d 100644 --- a/ingen/client/PluginUI.hpp +++ b/ingen/client/PluginUI.hpp @@ -76,8 +76,8 @@ public: * engine and/or update itself as necessary. */ INGEN_SIGNAL(property_changed, void, - const Raul::URI&, // Subject - const Raul::URI&, // Predicate + const URI&, // Subject + const URI&, // Predicate const Atom&, // Object Resource::Graph); // Context diff --git a/ingen/client/PortModel.hpp b/ingen/client/PortModel.hpp index f03e5bc1..9ad37378 100644 --- a/ingen/client/PortModel.hpp +++ b/ingen/client/PortModel.hpp @@ -63,7 +63,7 @@ public: inline bool operator==(const PortModel& pm) const { return (path() == pm.path()); } - void on_property(const Raul::URI& uri, const Atom& value); + void on_property(const URI& uri, const Atom& value); // Signals INGEN_SIGNAL(value_changed, void, const Atom&); diff --git a/ingen/client/SigClientInterface.hpp b/ingen/client/SigClientInterface.hpp index 4acc903b..6e94b257 100644 --- a/ingen/client/SigClientInterface.hpp +++ b/ingen/client/SigClientInterface.hpp @@ -46,7 +46,7 @@ class INGEN_API SigClientInterface : public Ingen::Interface, public: SigClientInterface() {} - Raul::URI uri() const override { return Raul::URI("ingen:/clients/sig"); } + URI uri() const override { return URI("ingen:/clients/sig"); } INGEN_SIGNAL(message, void, Message) diff --git a/ingen/client/SocketClient.hpp b/ingen/client/SocketClient.hpp index cceba9a3..8236200b 100644 --- a/ingen/client/SocketClient.hpp +++ b/ingen/client/SocketClient.hpp @@ -30,7 +30,7 @@ class INGEN_API SocketClient : public SocketWriter { public: SocketClient(World& world, - const Raul::URI& uri, + const URI& uri, SPtr<Raul::Socket> sock, SPtr<Interface> respondee) : SocketWriter(world.uri_map(), world.uris(), uri, sock) @@ -48,7 +48,7 @@ public: static SPtr<Ingen::Interface> new_socket_interface(Ingen::World* world, - const Raul::URI& uri, + const URI& uri, SPtr<Ingen::Interface> respondee) { const Raul::Socket::Type type = (uri.scheme() == "unix" diff --git a/ingen/client/ThreadedSigClientInterface.hpp b/ingen/client/ThreadedSigClientInterface.hpp index 6457d559..751ea37b 100644 --- a/ingen/client/ThreadedSigClientInterface.hpp +++ b/ingen/client/ThreadedSigClientInterface.hpp @@ -55,9 +55,7 @@ public: : message_slot(_signal_message.make_slot()) {} - Raul::URI uri() const override { - return Raul::URI("ingen:/clients/sig_queue"); - } + URI uri() const override { return URI("ingen:/clients/sig_queue"); } void message(const Message& msg) override { std::lock_guard<std::mutex> lock(_mutex); @@ -87,7 +85,6 @@ private: using Graph = Resource::Graph; using Path = Raul::Path; - using URI = Raul::URI; sigc::slot<void, Message> message_slot; }; diff --git a/ingen/paths.hpp b/ingen/paths.hpp index 3269a2ab..e75e71e0 100644 --- a/ingen/paths.hpp +++ b/ingen/paths.hpp @@ -20,33 +20,34 @@ #include <cstddef> #include <string> -#include "raul/URI.hpp" +#include "ingen/URI.hpp" #include "raul/Path.hpp" namespace Ingen { -inline Raul::URI main_uri() { return Raul::URI("ingen:/main"); } +inline URI main_uri() { return URI("ingen:/main"); } -inline bool uri_is_path(const Raul::URI& uri) +inline bool uri_is_path(const URI& uri) { - const size_t root_len = main_uri().length(); + const size_t root_len = main_uri().string().length(); if (uri == main_uri()) { return true; } else { - return uri.substr(0, root_len + 1) == main_uri() + "/"; + return uri.string().substr(0, root_len + 1) == + main_uri().string() + "/"; } } -inline Raul::Path uri_to_path(const Raul::URI& uri) +inline Raul::Path uri_to_path(const URI& uri) { return (uri == main_uri()) ? Raul::Path("/") - : Raul::Path(uri.substr(main_uri().length())); + : Raul::Path(uri.string().substr(main_uri().string().length())); } -inline Raul::URI path_to_uri(const Raul::Path& path) +inline URI path_to_uri(const Raul::Path& path) { - return Raul::URI(main_uri() + path.c_str()); + return URI(main_uri().string() + path.c_str()); } } // namespace Ingen |