summaryrefslogtreecommitdiffstats
path: root/raul
diff options
context:
space:
mode:
Diffstat (limited to 'raul')
-rw-r--r--raul/AtomRedland.h (renamed from raul/AtomRaptor.h)48
-rw-r--r--raul/Makefile.am30
-rw-r--r--raul/Namespaces.h2
-rw-r--r--raul/RDFModel.h82
-rw-r--r--raul/RDFNode.h75
-rw-r--r--raul/RDFQuery.h23
-rw-r--r--raul/RDFWorld.h60
-rw-r--r--raul/RDFWriter.h85
-rw-r--r--raul/Stateful.h13
9 files changed, 277 insertions, 141 deletions
diff --git a/raul/AtomRaptor.h b/raul/AtomRedland.h
index 9b50a38..ae4e3b4 100644
--- a/raul/AtomRaptor.h
+++ b/raul/AtomRedland.h
@@ -15,13 +15,13 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef RAUL_ATOM_RAPTOR_H
-#define RAUL_ATOM_RAPTOR_H
+#ifndef RAUL_ATOM_REDLAND_H
+#define RAUL_ATOM_REDLAND_H
#include <iostream>
#include <sstream>
#include <cstring>
-#include <raptor.h>
+#include <librdf.h>
#include "raul/Atom.h"
using std::cerr; using std::endl;
@@ -30,51 +30,53 @@ using std::cerr; using std::endl;
namespace Raul {
-/** Support for serializing an Atom to/from RDF (via raptor, a part of librdf).
+/** Support for serializing an Atom to/from RDF (via librdf).
*
- * (Here to prevent a unnecessary raptor dependency for Atom).
+ * (Here to prevent a unnecessary reddland dependency for Atom).
*
* \ingroup raul
*/
-class AtomRaptor {
+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 void atom_to_triple_object(raptor_statement* triple, const Atom& atom) {
+ static librdf_node* atom_to_rdf_node(librdf_world* world,
+ const Atom& atom)
+ {
std::ostringstream os;
- triple->object_literal_language = NULL;
+ librdf_uri* type = NULL;
+ librdf_node* node = NULL;
+ std::string str;
switch (atom.type()) {
case Atom::INT:
os << atom.get_int32();
- triple->object = (unsigned char*)strdup(os.str().c_str());
- triple->object_type = RAPTOR_IDENTIFIER_TYPE_LITERAL;
- triple->object_literal_datatype = raptor_new_uri(
- U("http://www.w3.org/2001/XMLSchema#integer"));
+ str = os.str();
+ // xsd:integer -> pretty integer literals in Turtle
+ type = librdf_new_uri(world, U("http://www.w3.org/2001/XMLSchema#integer"));
break;
case Atom::FLOAT:
os << atom.get_float();
- triple->object = (unsigned char*)strdup(os.str().c_str());
- triple->object_type = RAPTOR_IDENTIFIER_TYPE_LITERAL;
- /* Use xsd:decimal so turtle abbreviation works */
- triple->object_literal_datatype = raptor_new_uri(
- U("http://www.w3.org/2001/XMLSchema#decimal"));
+ str = os.str();
+ // xsd:decimal -> pretty decimal (float) literals in Turtle
+ type = librdf_new_uri(world, U("http://www.w3.org/2001/XMLSchema#decimal"));
break;
case Atom::STRING:
- triple->object = strdup(atom.get_string());
- triple->object_type = RAPTOR_IDENTIFIER_TYPE_LITERAL;
- triple->object_literal_datatype = NULL;
+ str = atom.get_string();
break;
case Atom::BLOB:
case Atom::NIL:
default:
cerr << "WARNING: Unserializable Atom!" << endl;
- triple->object = NULL;
- triple->object_type = RAPTOR_IDENTIFIER_TYPE_UNKNOWN;
}
+
+ if (str != "")
+ node = librdf_new_node_from_typed_literal(world, U(str.c_str()), NULL, type);
+
+ return node;
}
#if 0
@@ -102,4 +104,4 @@ public:
} // namespace Raul
-#endif // RAUL_ATOM_RAPTOR_H
+#endif // RAUL_ATOM_REDLAND_H
diff --git a/raul/Makefile.am b/raul/Makefile.am
index bc22299..907a95d 100644
--- a/raul/Makefile.am
+++ b/raul/Makefile.am
@@ -1,48 +1,48 @@
raulincludedir = $(includedir)/raul
raulinclude_HEADERS = \
- types.h \
- midi_events.h \
Array.h \
Atom.h \
- AtomLiblo.h \
- AtomRaptor.h \
AtomicInt.h \
AtomicPtr.h \
- DoubleBuffer.h \
Condition.h \
Deletable.h \
+ DoubleBuffer.h \
JackDriver.h \
List.h \
+ MIDIRingBuffer.h \
+ MIDISink.h \
Maid.h \
Mutex.h \
Namespaces.h \
Path.h \
Process.h \
+ Quantizer.h \
+ RDFModel.h \
+ RDFNode.h \
RDFQuery.h \
- RDFWriter.h \
+ RDFWorld.h \
+ RingBuffer.h \
+ SMFReader.h \
+ SMFWriter.h \
SRMWQueue.h \
SRSWQueue.h \
- RingBuffer.h \
Semaphore.h \
SharedPtr.h \
Slave.h \
Stateful.h \
Thread.h \
- WeakPtr.h \
TimeSlice.h \
- Quantizer.h \
- MIDIRingBuffer.h \
- MIDISink.h \
- SMFReader.h \
- SMFWriter.h
+ WeakPtr.h \
+ midi_events.h \
+ types.h
if WITH_LIBLO
raulinclude_HEADERS += AtomLiblo.h
endif
-if WITH_RAPTOR
-raulinclude_HEADERS += AtomRaptor.h
+if WITH_REDLAND
+raulinclude_HEADERS += AtomRedland.h
endif
if WITH_LASH
diff --git a/raul/Namespaces.h b/raul/Namespaces.h
index f81b7b8..673bbd5 100644
--- a/raul/Namespaces.h
+++ b/raul/Namespaces.h
@@ -28,7 +28,7 @@ namespace Raul {
*/
class Namespaces : public std::map<std::string, std::string> {
public:
- std::string qualify(std::string uri);
+ std::string qualify(std::string uri) const;
};
diff --git a/raul/RDFModel.h b/raul/RDFModel.h
new file mode 100644
index 0000000..63cdb9d
--- /dev/null
+++ b/raul/RDFModel.h
@@ -0,0 +1,82 @@
+/* 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 RDFMODEL_H
+#define RDFMODEL_H
+
+#include <stdexcept>
+#include <string>
+#include <librdf.h>
+#include <glibmm/ustring.h>
+#include <boost/utility.hpp>
+#include "raul/Namespaces.h"
+#include "raul/Atom.h"
+#include "raul/RDFNode.h"
+
+
+namespace Raul {
+namespace RDF {
+
+class World;
+
+
+class Model : public boost::noncopyable {
+public:
+ Model(World& world);
+ Model(World& world, const Glib::ustring& uri);
+ ~Model();
+
+ void serialize_to_file_handle(FILE* fd);
+ void serialize_to_file(const std::string& file);
+ std::string serialize_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;
+ librdf_storage* _storage;
+ librdf_model* _model;
+ librdf_serializer* _serializer;
+
+ size_t _next_blank_id;
+};
+
+
+} // namespace RDF
+} // namespace Raul
+
+#endif // RDFMODEL_H
diff --git a/raul/RDFNode.h b/raul/RDFNode.h
new file mode 100644
index 0000000..cefaf42
--- /dev/null
+++ b/raul/RDFNode.h
@@ -0,0 +1,75 @@
+/* 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 RDFNODE_H
+#define RDFNODE_H
+
+#include <stdexcept>
+#include <string>
+#include <librdf.h>
+#include "raul/Atom.h"
+
+namespace Raul {
+namespace RDF {
+
+class World;
+
+
+class Node {
+public:
+ // Matches librdf_node_type
+ enum Type { UNKNOWN=0, RESOURCE, LITERAL, BLANK };
+
+ Node() : _node(NULL) {}
+
+ Node(World& world, Type t, const std::string& s);
+ Node(World& world);
+ Node(librdf_node* node);
+ Node(const Node& other);
+ ~Node();
+
+ Type type() const { return ((_node) ? (Type)librdf_node_get_type(_node) : UNKNOWN); }
+
+ librdf_node* get_node() const { return _node; }
+
+ operator bool() const { return (_node != NULL); }
+
+ const Node& operator=(const Node& other) {
+ if (_node)
+ librdf_free_node(_node);
+ _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();
+ int to_int();
+
+ bool is_float();
+ float to_float();
+
+private:
+ librdf_node* _node;
+};
+
+
+} // namespace RDF
+} // namespace Raul
+
+#endif // RDFNODE_H
diff --git a/raul/RDFQuery.h b/raul/RDFQuery.h
index 1aa1cad..eef52bd 100644
--- a/raul/RDFQuery.h
+++ b/raul/RDFQuery.h
@@ -21,25 +21,30 @@
#include <map>
#include <list>
#include <glibmm/ustring.h>
+#include "raul/RDFWorld.h"
#include "raul/Namespaces.h"
namespace Raul {
+namespace RDF {
+
+class World;
+class Model;
/** Pretty wrapper for a SPARQL query.
*
- * Automatically handles things like prepending prefixes, etc. Raul specific.
+ * Automatically handles things like prepending prefixes, etc.
*/
-class RDFQuery {
+class Query {
public:
- typedef std::map<Glib::ustring, Glib::ustring> Bindings;
- typedef std::list<Bindings> Results;
+ typedef std::map<std::string, Node> Bindings; // FIXME: order? better to use int
+ typedef std::list<Bindings> Results;
- RDFQuery(const Namespaces& prefixes, Glib::ustring query)
+ Query(const World& world, Glib::ustring query)
{
// Prepend prefix header
- for (Namespaces::const_iterator i = prefixes.begin();
- i != prefixes.end(); ++i) {
+ for (Namespaces::const_iterator i = world.prefixes().begin();
+ i != world.prefixes().end(); ++i) {
_query += "PREFIX ";
_query += i->first + ": <" + i->second + ">\n";
}
@@ -47,16 +52,16 @@ public:
_query += query;
}
- Results run(const Glib::ustring base_uri) const;
+ Results run(World& world, Model& model, const Glib::ustring base_uri="") const;
Glib::ustring string() const { return _query; };
private:
-
Glib::ustring _query;
};
+} // namespace RDF
} // namespace Raul
#endif // RAUL_RDFQUERY_H
diff --git a/raul/RDFWorld.h b/raul/RDFWorld.h
new file mode 100644
index 0000000..8bbd3d1
--- /dev/null
+++ b/raul/RDFWorld.h
@@ -0,0 +1,60 @@
+/* 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 RDFWORLD_H
+#define RDFWORLD_H
+
+#include <stdexcept>
+#include <string>
+#include <librdf.h>
+#include <boost/utility.hpp>
+#include "raul/Namespaces.h"
+#include "raul/RDFNode.h"
+
+namespace Raul {
+namespace RDF {
+
+
+class World : public boost::noncopyable {
+public:
+ World();
+ ~World();
+
+ Node blank_id();
+
+ 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; }
+
+private:
+ void setup_prefixes();
+
+ librdf_world* _world;
+ Namespaces _prefixes;
+
+ size_t _next_blank_id;
+};
+
+
+} // namespace RDF
+} // namespace Raul
+
+#endif // RDFWORLD_H
diff --git a/raul/RDFWriter.h b/raul/RDFWriter.h
deleted file mode 100644
index 81bd230..0000000
--- a/raul/RDFWriter.h
+++ /dev/null
@@ -1,85 +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 RDFWRITER_H
-#define RDFWRITER_H
-
-#include <stdexcept>
-#include <string>
-#include <raptor.h>
-#include "raul/Namespaces.h"
-#include "raul/Atom.h"
-
-namespace Raul {
-
-
-class RdfId {
-public:
- enum Type { NULL_ID, ANONYMOUS, RESOURCE };
-
- RdfId(Type t, const std::string& s) : _type(t), _string(s) {}
- RdfId() : _type(NULL_ID) {}
-
- Type type() const { return _type; }
- const std::string& to_string() const { return _string; }
-
- operator bool() const { return (_type != NULL_ID); }
-
-private:
- Type _type;
- std::string _string; ///< URI or blank node ID, depending on _type
-};
-
-
-class RDFWriter {
-public:
- RDFWriter();
-
- void add_prefix(const std::string& prefix, const std::string& uri);
- std::string expand_uri(const std::string& uri);
-
- void start_to_file_handle(FILE* fd) throw (std::logic_error);
- void start_to_filename(const std::string& filename) throw (std::logic_error);
- void start_to_string() throw (std::logic_error);
- std::string finish() throw (std::logic_error);
-
- RdfId blank_id();
-
- bool serialization_in_progress() { return (_serializer != NULL); }
-
- void write(const RdfId& subject,
- const RdfId& predicate,
- const RdfId& object);
-
- void write(const RdfId& subject,
- const RdfId& predicate,
- const Atom& object);
-
-private:
- void setup_prefixes();
-
- raptor_serializer* _serializer;
- unsigned char* _string_output;
- Namespaces _prefixes;
-
- size_t _next_blank_id;
-};
-
-
-} // namespace Raul
-
-#endif // RDFWRITER_H
diff --git a/raul/Stateful.h b/raul/Stateful.h
index 5e4626c..a366ffd 100644
--- a/raul/Stateful.h
+++ b/raul/Stateful.h
@@ -18,25 +18,22 @@
#ifndef STATEFUL_H
#define STATEFUL_H
-#include "raul/RDFWriter.h"
+#include "raul/RDFModel.h"
namespace Raul {
-class RDFWriter;
-
-
class Stateful {
public:
virtual ~Stateful() {}
- virtual void write_state(RDFWriter& writer) = 0;
+ virtual void write_state(RDF::Model& model) = 0;
- RdfId id() const { return _id; }
- void set_id(const RdfId& id) { _id = id; }
+ RDF::Node id() const { return _id; }
+ void set_id(const RDF::Node& id) { _id = id; }
protected:
- RdfId _id;
+ RDF::Node _id;
};