summaryrefslogtreecommitdiffstats
path: root/raul
diff options
context:
space:
mode:
Diffstat (limited to 'raul')
-rw-r--r--raul/Atom.hpp86
-rw-r--r--raul/AtomRedland.hpp108
-rw-r--r--raul/Makefile.am9
-rw-r--r--raul/Namespaces.hpp37
-rw-r--r--raul/RDFModel.hpp86
-rw-r--r--raul/RDFNode.hpp87
-rw-r--r--raul/RDFQuery.hpp70
-rw-r--r--raul/RDFWorld.hpp64
-rw-r--r--raul/Stateful.hpp10
9 files changed, 87 insertions, 470 deletions
diff --git a/raul/Atom.hpp b/raul/Atom.hpp
index 443c0ae..c030bc5 100644
--- a/raul/Atom.hpp
+++ b/raul/Atom.hpp
@@ -22,6 +22,16 @@
#include <cassert>
#include <cstring>
#include <string>
+#include <sstream>
+#include <iostream>
+
+#include CONFIG_H_PATH
+#ifdef HAVE_REDLANDMM
+#include <redlandmm/Node.hpp>
+#include <redlandmm/World.hpp>
+#endif
+
+#define CUC(x) ((const unsigned char*)(x))
namespace Raul {
@@ -33,8 +43,6 @@ namespace Raul {
class Atom {
public:
- //TODO: Add a bool type here that serialises nicely to Turtle "true" and "false"
-
enum Type {
NIL,
INT,
@@ -50,10 +58,32 @@ public:
Atom(bool val) : _type(BOOL), _bool_val(val) {}
Atom(const char* val) : _type(STRING), _string_val(strdup(val)) {}
Atom(const std::string& val) : _type(STRING), _string_val(strdup(val.c_str())) {}
-
+
Atom(void* val) : _type(BLOB), _blob_size(sizeof(val)), _blob_val(malloc(_blob_size))
{ memcpy(_blob_val, val, sizeof(_blob_size)); }
+#ifdef HAVE_REDLANDMM
+ Atom(const Redland::Node& node)
+ {
+ if (node.type() == Redland::Node::RESOURCE) {
+ _type = STRING;
+ _string_val = strdup(node.to_string().c_str());
+ } else if (node.is_float()) {
+ _type = FLOAT;
+ _float_val = node.to_float();
+ } else if (node.is_int()) {
+ _type = INT;
+ _int_val = node.to_int();
+ } else if (node.is_bool()) {
+ _type = BOOL;
+ _bool_val = node.to_bool();
+ } else {
+ _type = STRING;
+ _string_val = strdup(node.to_string().c_str());
+ }
+ }
+#endif
+
~Atom()
{
if (_type == STRING)
@@ -116,12 +146,60 @@ public:
inline int32_t get_int32() const { assert(_type == INT); return _int_val; }
inline float get_float() const { assert(_type == FLOAT); return _float_val; }
- inline bool get_bool() const { assert(_type == BOOL); return _bool_val; }
+ inline bool get_bool() const { assert(_type == BOOL); return _bool_val; }
inline const char* get_string() const { assert(_type == STRING); return _string_val; }
inline const void* get_blob() const { assert(_type == BLOB); return _blob_val; }
inline operator bool() const { return (_type != NIL); }
+
+#ifdef HAVE_REDLANDMM
+ Redland::Node to_rdf_node(Redland::World& world) const
+ {
+ std::ostringstream os;
+ std::string str;
+ librdf_uri* type = NULL;
+ librdf_node* node = NULL;
+
+ switch (_type) {
+ case Atom::INT:
+ os << get_int32();
+ str = os.str();
+ // xsd:integer -> pretty integer literals in Turtle
+ type = librdf_new_uri(world.world(), CUC("http://www.w3.org/2001/XMLSchema#integer"));
+ break;
+ case Atom::FLOAT:
+ os.precision(20);
+ os << get_float();
+ str = os.str();
+ // xsd:decimal -> pretty decimal (float) literals in Turtle
+ type = librdf_new_uri(world.world(), CUC("http://www.w3.org/2001/XMLSchema#decimal"));
+ break;
+ case Atom::BOOL:
+ // xsd:boolean -> pretty boolean literals in Turtle
+ if (get_bool())
+ str = "true";
+ else
+ str = "false";
+ type = librdf_new_uri(world.world(), CUC("http://www.w3.org/2001/XMLSchema#boolean"));
+ break;
+ case Atom::STRING:
+ str = get_string();
+ break;
+ case Atom::BLOB:
+ case Atom::NIL:
+ default:
+ std::cerr << "WARNING: Unserializable Atom!" << std::endl;
+ }
+
+ if (str != "")
+ node = librdf_new_node_from_typed_literal(world.world(), CUC(str.c_str()), NULL, type);
+
+ return Redland::Node(world, node);
+ }
+#endif
+
+
private:
Type _type;
diff --git a/raul/AtomRedland.hpp b/raul/AtomRedland.hpp
deleted file mode 100644
index 95f5d9d..0000000
--- a/raul/AtomRedland.hpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/* This file is part of Raul.
- * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
- *
- * Raul is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * Raul 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 General Public License for details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef RAUL_ATOM_REDLAND_HPP
-#define RAUL_ATOM_REDLAND_HPP
-
-#include <iostream>
-#include <sstream>
-#include <cstring>
-#include <librdf.h>
-#include <raul/Atom.hpp>
-#include <raul/RDFNode.hpp>
-
-#define CUC(x) ((const unsigned char*)(x))
-
-namespace Raul {
-
-
-/** Support for serializing an Atom to/from RDF (via librdf).
- *
- * (Here to prevent a unnecessary reddland dependency for Atom).
- *
- * \ingroup raul
- */
-class AtomRedland {
-public:
- /** Set this atom's value to the object (value) portion of an RDF triple.
- *
- * Caller is responsible for calling free(triple->object).
- */
- static librdf_node* atom_to_rdf_node(librdf_world* world,
- const Atom& atom)
- {
- std::ostringstream os;
-
- librdf_uri* type = NULL;
- librdf_node* node = NULL;
- std::string str;
-
- switch (atom.type()) {
- case Atom::INT:
- os << atom.get_int32();
- str = os.str();
- // xsd:integer -> pretty integer literals in Turtle
- type = librdf_new_uri(world, CUC("http://www.w3.org/2001/XMLSchema#integer"));
- break;
- case Atom::FLOAT:
- os.precision(20);
- os << atom.get_float();
- str = os.str();
- // xsd:decimal -> pretty decimal (float) literals in Turtle
- type = librdf_new_uri(world, CUC("http://www.w3.org/2001/XMLSchema#decimal"));
- break;
- case Atom::BOOL:
- // xsd:boolean -> pretty boolean literals in Turtle
- if (atom.get_bool())
- str = "true";
- else
- str = "false";
- type = librdf_new_uri(world, CUC("http://www.w3.org/2001/XMLSchema#boolean"));
- break;
- case Atom::STRING:
- str = atom.get_string();
- break;
- case Atom::BLOB:
- case Atom::NIL:
- default:
- std::cerr << "WARNING: Unserializable Atom!" << std::endl;
- }
-
- if (str != "")
- node = librdf_new_node_from_typed_literal(world, CUC(str.c_str()), NULL, type);
-
- return node;
- }
-
- static Atom rdf_node_to_atom(const RDF::Node& node) {
- if (node.type() == RDF::Node::RESOURCE)
- return Atom(node.to_string());
- else if (node.is_float())
- return Atom(node.to_float());
- else if (node.is_int())
- return Atom(node.to_int());
- else if (node.is_bool())
- return Atom(node.to_bool());
- else
- return Atom(node.to_string());
- }
-};
-
-
-} // namespace Raul
-
-#endif // RAUL_ATOM_REDLAND_HPP
diff --git a/raul/Makefile.am b/raul/Makefile.am
index f552f7c..ef15513 100644
--- a/raul/Makefile.am
+++ b/raul/Makefile.am
@@ -12,15 +12,10 @@ raulinclude_HEADERS = \
ListImpl.hpp \
MIDISink.hpp \
Maid.hpp \
- Namespaces.hpp \
Path.hpp \
PathTable.hpp \
Process.hpp \
Quantizer.hpp \
- RDFModel.hpp \
- RDFNode.hpp \
- RDFQuery.hpp \
- RDFWorld.hpp \
RingBuffer.hpp \
SMFReader.hpp \
SMFWriter.hpp \
@@ -43,10 +38,6 @@ if WITH_LIBLO
raulinclude_HEADERS += AtomLiblo.hpp
endif
-if WITH_REDLAND
-raulinclude_HEADERS += AtomRedland.hpp
-endif
-
if WITH_LASH
raulinclude_HEADERS += LashClient.hpp LashServerInterface.hpp LashProject.hpp
endif
diff --git a/raul/Namespaces.hpp b/raul/Namespaces.hpp
deleted file mode 100644
index abaa838..0000000
--- a/raul/Namespaces.hpp
+++ /dev/null
@@ -1,37 +0,0 @@
-/* This file is part of Raul.
- * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
- *
- * Raul is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * Raul 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 General Public License for details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef RAUL_NAMESPACES_HPP
-#define RAUL_NAMESPACES_HPP
-
-#include <map>
-#include <string>
-
-namespace Raul {
-
-
-/** Collection of RDF namespaces with prefixes.
- */
-class Namespaces : public std::map<std::string, std::string> {
-public:
- std::string qualify(std::string uri) const;
-};
-
-
-} // namespace Raul
-
-#endif // RAUL_NAMESPACES_HPP
diff --git a/raul/RDFModel.hpp b/raul/RDFModel.hpp
deleted file mode 100644
index fb7350c..0000000
--- a/raul/RDFModel.hpp
+++ /dev/null
@@ -1,86 +0,0 @@
-/* This file is part of Raul.
- * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
- *
- * Raul is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * Raul 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 General Public License for details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef RAUL_RDF_MODEL_HPP
-#define RAUL_RDF_MODEL_HPP
-
-#include <stdexcept>
-#include <string>
-#include <librdf.h>
-#include <glibmm/ustring.h>
-#include <boost/utility.hpp>
-#include <raul/Namespaces.hpp>
-#include <raul/Atom.hpp>
-#include <raul/RDFNode.hpp>
-
-
-namespace Raul {
-namespace RDF {
-
-class World;
-
-
-class Model : public boost::noncopyable {
-public:
- Model(World& world);
- Model(World& world, const Glib::ustring& uri, Glib::ustring base_uri="");
- ~Model();
-
- void set_base_uri(const Glib::ustring& uri);
- const Node& base_uri() const { return _base; }
-
- void serialise_to_file_handle(FILE* fd);
- void serialise_to_file(const Glib::ustring& uri);
- std::string serialise_to_string();
-
- void add_statement(const Node& subject,
- const Node& predicate,
- const Node& object);
-
- void add_statement(const Node& subject,
- const std::string& predicate,
- const Node& object);
-
- void add_statement(const Node& subject,
- const Node& predicate,
- const Atom& object);
-
- void add_statement(const Node& subject,
- const std::string& predicate,
- const Atom& object);
-
- World& world() const { return _world; }
-
-private:
- friend class Query;
-
- void setup_prefixes();
-
- World& _world;
- Node _base;
- librdf_storage* _storage;
- librdf_model* _model;
- librdf_serializer* _serialiser;
-
- size_t _next_blank_id;
-};
-
-
-} // namespace RDF
-} // namespace Raul
-
-#endif // RAUL_RDF_MODEL_HPP
diff --git a/raul/RDFNode.hpp b/raul/RDFNode.hpp
deleted file mode 100644
index 48e9b6d..0000000
--- a/raul/RDFNode.hpp
+++ /dev/null
@@ -1,87 +0,0 @@
-/* This file is part of Raul.
- * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
- *
- * Raul is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * Raul 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 General Public License for details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef RAUL_RDF_NODE_HPP
-#define RAUL_RDF_NODE_HPP
-
-#include <stdexcept>
-#include <string>
-#include <librdf.h>
-#include <raul/Atom.hpp>
-
-namespace Raul {
-namespace RDF {
-
-class World;
-
-
-class Node {
-public:
- enum Type {
- UNKNOWN = LIBRDF_NODE_TYPE_UNKNOWN,
- RESOURCE = LIBRDF_NODE_TYPE_RESOURCE,
- LITERAL = LIBRDF_NODE_TYPE_LITERAL,
- BLANK = LIBRDF_NODE_TYPE_BLANK
- };
-
- Node() : _world(NULL), _node(NULL) {}
-
- Node(World& world, Type t, const std::string& s);
- Node(World& world);
- Node(World& world, librdf_node* node);
- Node(const Node& other);
- ~Node();
-
- Type type() const { return ((_node) ? (Type)librdf_node_get_type(_node) : UNKNOWN); }
-
- World* world() const { return _world; }
-
- librdf_node* get_node() const { return _node; }
- librdf_uri* get_uri() const { return librdf_node_get_uri(_node); }
-
- operator bool() const { return (_world != NULL && _node != NULL); }
-
- const Node& operator=(const Node& other) {
- if (_node)
- librdf_free_node(_node);
- _world = other._world;
- _node = (other._node) ? librdf_new_node_from_node(other._node) : NULL;
- return *this;
- }
-
- std::string to_string() const;
- std::string to_quoted_uri_string() const;
-
- bool is_int() const;
- int to_int() const;
-
- bool is_float() const;
- float to_float() const;
-
- bool is_bool() const;
- float to_bool() const;
-
-private:
- World* _world;
- librdf_node* _node;
-};
-
-
-} // namespace RDF
-} // namespace Raul
-
-#endif // RAUL_RDF_NODE_HPP
diff --git a/raul/RDFQuery.hpp b/raul/RDFQuery.hpp
deleted file mode 100644
index 7d82390..0000000
--- a/raul/RDFQuery.hpp
+++ /dev/null
@@ -1,70 +0,0 @@
-/* This file is part of Raul.
- * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
- *
- * Raul is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * Raul 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 General Public License for details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef RAUL_RDF_QUERY_HPP
-#define RAUL_RDF_QUERY_HPP
-
-#include <map>
-#include <list>
-#include <glibmm/ustring.h>
-#include <raul/RDFWorld.hpp>
-#include <raul/Namespaces.hpp>
-
-namespace Raul {
-namespace RDF {
-
-class World;
-class Model;
-
-
-/** Pretty wrapper for a SPARQL query.
- *
- * Automatically handles things like prepending prefixes, etc.
- */
-class Query {
-public:
- typedef std::map<std::string, Node> Bindings; // FIXME: order? better to use int
- typedef std::list<Bindings> Results;
-
- Query(World& world, Glib::ustring query)
- {
- Glib::Mutex::Lock lock(world.mutex());
-
- // Prepend prefix header
- for (Namespaces::const_iterator i = world.prefixes().begin();
- i != world.prefixes().end(); ++i) {
- _query += "PREFIX ";
- _query += i->first + ": <" + i->second + ">\n";
- }
- _query += "\n";
- _query += query;
- }
-
- Results run(World& world, Model& model, const Glib::ustring base_uri="") const;
-
- const Glib::ustring& string() const { return _query; };
-
-private:
- Glib::ustring _query;
-};
-
-
-} // namespace RDF
-} // namespace Raul
-
-#endif // RAUL_RDF_QUERY_HPP
-
diff --git a/raul/RDFWorld.hpp b/raul/RDFWorld.hpp
deleted file mode 100644
index baad711..0000000
--- a/raul/RDFWorld.hpp
+++ /dev/null
@@ -1,64 +0,0 @@
-/* This file is part of Raul.
- * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
- *
- * Raul is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * Raul 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 General Public License for details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef RAUL_RDF_WORLD_HPP
-#define RAUL_RDF_WORLD_HPP
-
-#include <stdexcept>
-#include <string>
-#include <librdf.h>
-#include <boost/utility.hpp>
-#include <glibmm/thread.h>
-#include <raul/Namespaces.hpp>
-#include <raul/RDFNode.hpp>
-
-namespace Raul {
-namespace RDF {
-
-
-class World : public boost::noncopyable {
-public:
- World();
- ~World();
-
- Node blank_id(const std::string base_name="");
-
- void add_prefix(const std::string& prefix, const std::string& uri);
- std::string expand_uri(const std::string& uri) const;
- std::string qualify(const std::string& uri) const;
-
- const Namespaces& prefixes() const { return _prefixes; }
-
- librdf_world* world() { return _world; }
-
- Glib::Mutex& mutex() { return _mutex; }
-
-private:
- void setup_prefixes();
-
- librdf_world* _world;
- Glib::Mutex _mutex;
- Namespaces _prefixes;
-
- size_t _next_blank_id;
-};
-
-
-} // namespace RDF
-} // namespace Raul
-
-#endif // RAUL_RDF_WORLD_HPP
diff --git a/raul/Stateful.hpp b/raul/Stateful.hpp
index a5ecdb8..be1491c 100644
--- a/raul/Stateful.hpp
+++ b/raul/Stateful.hpp
@@ -18,7 +18,7 @@
#ifndef STATEFUL_H
#define STATEFUL_H
-#include <raul/RDFModel.hpp>
+#include <redlandmm/Model.hpp>
namespace Raul {
@@ -27,13 +27,13 @@ class Stateful {
public:
virtual ~Stateful() {}
- virtual void write_state(RDF::Model& model) = 0;
+ virtual void write_state(Redland::Model& model) = 0;
- RDF::Node id() const { return _id; }
- void set_id(const RDF::Node& id) { _id = id; }
+ Redland::Node id() const { return _id; }
+ void set_id(const Redland::Node& id) { _id = id; }
protected:
- RDF::Node _id;
+ Redland::Node _id;
};