From e9c7107df9dd2001498cae65aa6ad898fbf7d2f7 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 30 Nov 2007 07:38:42 +0000 Subject: Split redland C++ wrappers out from Raul. git-svn-id: http://svn.drobilla.net/lad/raul@927 a436a847-0d15-0410-975c-d299462d15a1 --- configure.ac | 21 ++--- raul.pc.in | 4 +- raul/Atom.hpp | 86 ++++++++++++++++- raul/AtomRedland.hpp | 108 --------------------- raul/Makefile.am | 9 -- raul/Namespaces.hpp | 37 -------- raul/RDFModel.hpp | 86 ----------------- raul/RDFNode.hpp | 87 ----------------- raul/RDFQuery.hpp | 70 -------------- raul/RDFWorld.hpp | 64 ------------- raul/Stateful.hpp | 10 +- src/Makefile.am | 6 -- src/Namespaces.cpp | 43 --------- src/RDFModel.cpp | 262 --------------------------------------------------- src/RDFNode.cpp | 187 ------------------------------------ src/RDFQuery.cpp | 89 ----------------- src/RDFWorld.cpp | 104 -------------------- tests/Makefile.am | 7 +- tests/rdf_test.cpp | 8 -- 19 files changed, 97 insertions(+), 1191 deletions(-) delete mode 100644 raul/AtomRedland.hpp delete mode 100644 raul/Namespaces.hpp delete mode 100644 raul/RDFModel.hpp delete mode 100644 raul/RDFNode.hpp delete mode 100644 raul/RDFQuery.hpp delete mode 100644 raul/RDFWorld.hpp delete mode 100644 src/Namespaces.cpp delete mode 100644 src/RDFModel.cpp delete mode 100644 src/RDFNode.cpp delete mode 100644 src/RDFQuery.cpp delete mode 100644 src/RDFWorld.cpp delete mode 100644 tests/rdf_test.cpp diff --git a/configure.ac b/configure.ac index fe8b7fb..f663a8b 100644 --- a/configure.ac +++ b/configure.ac @@ -144,22 +144,13 @@ AM_CONDITIONAL(BUILD_UNIT_TESTS, [test "$build_unit_tests" = "yes"]) ################## RAUL -# Check for Redland -#PKG_CHECK_MODULES(REDLAND, redland >= 1.0.0) -# No pkg-config?! Booo! -build_redland="no" -AC_CHECK_PROG(REDLAND_CONFIG, redland-config, redland-config) -if test "X$REDLAND_CONFIG" = X; then - AC_MSG_ERROR([RAUL requires Redland (librdf), but redland-config not found.]) -else - build_redland="yes" - REDLAND_CFLAGS=`$REDLAND_CONFIG --cflags` - REDLAND_LIBS=`$REDLAND_CONFIG --libs` - AC_SUBST(REDLAND_CFLAGS) - AC_SUBST(REDLAND_LIBS) -fi -AM_CONDITIONAL(WITH_REDLAND, [test "$build_redland" = "yes"]) +# Check for Redlandmm +build_redlandmm="no" +PKG_CHECK_MODULES([REDLANDMM], [redlandmm], [build_redlandmm="yes"]) +AM_CONDITIONAL(WITH_REDLANDMM, [test "$build_redlandmm" = "yes"]) +AC_DEFINE(HAVE_REDLANDMM, 1, [Has redlandmm]) +# Check for liblo build_liblo="yes" AC_ARG_ENABLE(liblo, [AS_HELP_STRING(--enable-liblo, [Include liblo (OSC) support (yes)])], diff --git a/raul.pc.in b/raul.pc.in index 4e51533..629362d 100644 --- a/raul.pc.in +++ b/raul.pc.in @@ -6,5 +6,5 @@ includedir=@includedir@ Name: raul Version: @VERSION@ Description: A C++ convenience library for realtime audio applications -Libs: -L${libdir} -lraul @GLIBMM_LIBS@ @GTHREAD_LIBS@ @REDLAND_LIBS@ @JACK_LIBS@ @LASH_LIBS@ -Cflags: -I${includedir} @GLIBMM_CFLAGS@ @GTHREAD_CFLAGS@ @REDLAND_CFLAGS@ @JACK_CFLAGS@ @LASH_CFLAGS@ +Libs: -L${libdir} -lraul @GLIBMM_LIBS@ @GTHREAD_LIBS@ @REDLANDMM_LIBS@ @JACK_LIBS@ @LASH_LIBS@ +Cflags: -I${includedir} @GLIBMM_CFLAGS@ @GTHREAD_CFLAGS@ @REDLANDMM_CFLAGS@ @JACK_CFLAGS@ @LASH_CFLAGS@ 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 #include #include +#include +#include + +#include CONFIG_H_PATH +#ifdef HAVE_REDLANDMM +#include +#include +#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 - * - * 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 -#include -#include -#include -#include -#include - -#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 - * - * 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 -#include - -namespace Raul { - - -/** Collection of RDF namespaces with prefixes. - */ -class Namespaces : public std::map { -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 - * - * 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 -#include -#include -#include -#include -#include -#include -#include - - -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 - * - * 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 -#include -#include -#include - -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 - * - * 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 -#include -#include -#include -#include - -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 Bindings; // FIXME: order? better to use int - typedef std::list 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 - * - * 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 -#include -#include -#include -#include -#include -#include - -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 +#include 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; }; diff --git a/src/Makefile.am b/src/Makefile.am index 95f9bdc..e3d24b1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,17 +5,11 @@ lib_LTLIBRARIES = libraul.la libraul_la_SOURCES = \ Maid.cpp \ - Namespaces.cpp \ Path.cpp \ - RDFWorld.cpp \ SMFReader.cpp \ SMFWriter.cpp \ Thread.cpp -if WITH_REDLAND -libraul_la_SOURCES += RDFModel.cpp RDFNode.cpp RDFQuery.cpp -endif - if WITH_JACK libraul_la_SOURCES += JackDriver.cpp endif diff --git a/src/Namespaces.cpp b/src/Namespaces.cpp deleted file mode 100644 index 3236824..0000000 --- a/src/Namespaces.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* This file is part of Raul. - * Copyright (C) 2007 Dave Robillard - * - * 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 - */ - -#include - -namespace Raul { - - -/** Create a prefixed qname from @a uri, if possible. - * - * If @a uri can not be qualified with the namespaces currently in this - * Namespaces, @a uri will be returned unmodified. - */ -std::string -Namespaces::qualify(std::string uri) const -{ - for (const_iterator i = begin(); i != end(); ++i) { - size_t ns_len = i->second.length(); - - if (uri.substr(0, ns_len) == i->second) - return i->first + ":" + uri.substr(ns_len); - } - - return uri; -} - - -} // namespace Raul - diff --git a/src/RDFModel.cpp b/src/RDFModel.cpp deleted file mode 100644 index 95f6d68..0000000 --- a/src/RDFModel.cpp +++ /dev/null @@ -1,262 +0,0 @@ -/* This file is part of Raul. - * Copyright (C) 2007 Dave Robillard - * - * 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 - */ - -#include -#include -#include -#include -#include - -#define U(x) ((const unsigned char*)(x)) - -using namespace std; - -namespace Raul { -namespace RDF { - - -//static const char* const RDF_LANG = "rdfxml-abbrev"; -static const char* const RDF_LANG = "turtle"; - - -/** Create an empty in-memory RDF model. - */ -Model::Model(RDF::World& world) - : _world(world) - , _serialiser(NULL) -{ - Glib::Mutex::Lock lock(world.mutex()); - _storage = librdf_new_storage(_world.world(), "hashes", NULL, "hash-type='memory'"); - _model = librdf_new_model(_world.world(), _storage, NULL); -} - - -/** Load a model from a URI (local file or remote). - */ -Model::Model(World& world, const Glib::ustring& data_uri, Glib::ustring base_uri) - : _world(world) - , _serialiser(NULL) -{ - Glib::Mutex::Lock lock(world.mutex()); - _storage = librdf_new_storage(_world.world(), "hashes", NULL, "hash-type='memory'"); - _model = librdf_new_model(_world.world(), _storage, NULL); - - set_base_uri(base_uri); - - librdf_uri* uri = librdf_new_uri(world.world(), (const unsigned char*)data_uri.c_str()); - - if (uri) { - librdf_parser* parser = librdf_new_parser(world.world(), "guess", NULL, NULL); - librdf_parser_parse_into_model(parser, uri, _base.get_uri(), _model); - librdf_free_parser(parser); - } else { - cerr << "Unable to create URI " << data_uri << endl; - } - - if (uri) - librdf_free_uri(uri); - - /*cout << endl << "Loaded model from " << data_uri << ":" << endl; - serialize_to_file_handle(stdout); - cout << endl << endl;*/ -} - - -Model::~Model() -{ - Glib::Mutex::Lock lock(_world.mutex()); - - if (_serialiser) - librdf_free_serializer(_serialiser); - - librdf_free_model(_model); - librdf_free_storage(_storage); -} - - -void -Model::set_base_uri(const Glib::ustring& uri) -{ - if (uri == "") - return; - - _base = Node(_world, Node::RESOURCE, uri); -} - - -void -Model::setup_prefixes() -{ - assert(_serialiser); - - for (Namespaces::const_iterator i = _world.prefixes().begin(); i != _world.prefixes().end(); ++i) { - librdf_serializer_set_namespace(_serialiser, - librdf_new_uri(_world.world(), U(i->second.c_str())), i->first.c_str()); - } -} - - -/** Begin a serialization to a C file handle. - * - * This must be called before any write methods. - */ -void -Model::serialise_to_file_handle(FILE* fd) -{ - Glib::Mutex::Lock lock(_world.mutex()); - - _serialiser = librdf_new_serializer(_world.world(), RDF_LANG, NULL, NULL); - setup_prefixes(); - librdf_serializer_serialize_model_to_file_handle(_serialiser, fd, NULL, _model); - librdf_free_serializer(_serialiser); - _serialiser = NULL; -} - - -/** Begin a serialization to a file. - * - * \a uri must be a local (file://) URI. - * - * This must be called before any write methods. - */ -void -Model::serialise_to_file(const Glib::ustring& uri_str) -{ - Glib::Mutex::Lock lock(_world.mutex()); - - librdf_uri* uri = librdf_new_uri(_world.world(), (const unsigned char*)uri_str.c_str()); - if (uri && librdf_uri_is_file_uri(uri)) { - _serialiser = librdf_new_serializer(_world.world(), RDF_LANG, NULL, NULL); - setup_prefixes(); - librdf_serializer_serialize_model_to_file(_serialiser, librdf_uri_to_filename(uri), uri, _model); - librdf_free_serializer(_serialiser); - _serialiser = NULL; - } - librdf_free_uri(uri); -} - - -/** Begin a serialization to a string. - * - * This must be called before any write methods. - * - * The results of the serialization will be returned by the finish() method after - * the desired objects have been serialized. - */ -string -Model::serialise_to_string() -{ - Glib::Mutex::Lock lock(_world.mutex()); - - _serialiser = librdf_new_serializer(_world.world(), RDF_LANG, NULL, NULL); - setup_prefixes(); - - unsigned char* c_str - = librdf_serializer_serialize_model_to_string(_serialiser, NULL, _model); - - string result((const char*)c_str); - free(c_str); - - librdf_free_serializer(_serialiser); - _serialiser = NULL; - - return result; -} - - -void -Model::add_statement(const Node& subject, - const Node& predicate, - const Node& object) -{ - Glib::Mutex::Lock lock(_world.mutex()); - - assert(subject.get_node()); - assert(predicate.get_node()); - assert(object.get_node()); - - librdf_statement* triple = librdf_new_statement_from_nodes(_world.world(), - subject.get_node(), predicate.get_node(), object.get_node()); - - librdf_model_add_statement(_model, triple); -} - - -void -Model::add_statement(const Node& subject, - const string& predicate_id, - const Node& object) -{ - Glib::Mutex::Lock lock(_world.mutex()); - - const string predicate_uri = _world.expand_uri(predicate_id); - librdf_node* predicate = librdf_new_node_from_uri_string(_world.world(), - (const unsigned char*)predicate_uri.c_str()); - - librdf_statement* triple = librdf_new_statement_from_nodes(_world.world(), - subject.get_node(), predicate, object.get_node()); - - librdf_model_add_statement(_model, triple); -} - - -void -Model::add_statement(const Node& subject, - const Node& predicate, - const Atom& object) -{ - Glib::Mutex::Lock lock(_world.mutex()); - - librdf_node* atom_node = AtomRedland::atom_to_rdf_node(_world.world(), object); - - if (atom_node) { - librdf_statement* triple = librdf_new_statement_from_nodes(_world.world(), - subject.get_node(), predicate.get_node(), atom_node); - librdf_model_add_statement(_model, triple); - } else { - cerr << "WARNING: Unable to add statement (unserializable Atom)" << endl; - } -} - - -void -Model::add_statement(const Node& subject, - const string& predicate_id, - const Atom& object) -{ - Glib::Mutex::Lock lock(_world.mutex()); - - const string predicate_uri = _world.expand_uri(predicate_id); - librdf_node* predicate = librdf_new_node_from_uri_string(_world.world(), - (const unsigned char*)predicate_uri.c_str()); - - librdf_node* atom_node = AtomRedland::atom_to_rdf_node(_world.world(), object); - - if (atom_node) { - librdf_statement* triple = librdf_new_statement_from_nodes(_world.world(), - subject.get_node(), predicate, atom_node); - librdf_model_add_statement(_model, triple); - } else { - cerr << "WARNING: Unable to add statement (unserializable Atom)" << endl; - } -} - - - -} // namespace RDF -} // namespace Raul - diff --git a/src/RDFNode.cpp b/src/RDFNode.cpp deleted file mode 100644 index 4bc1fbb..0000000 --- a/src/RDFNode.cpp +++ /dev/null @@ -1,187 +0,0 @@ -/* This file is part of Raul. - * Copyright (C) 2007 Dave Robillard - * - * 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 - */ - -#include -#include -#include -#include - -using namespace std; - -namespace Raul { -namespace RDF { - - -Node::Node(World& world, Type type, const std::string& s) - : _world(&world) -{ - Glib::Mutex::Lock lock(world.mutex(), Glib::TRY_LOCK); - - if (type == RESOURCE) { - const string uri = world.expand_uri(s); - _node = librdf_new_node_from_uri_string(world.world(), (const unsigned char*)uri.c_str()); - } else if (type == LITERAL) { - _node = librdf_new_node_from_literal(world.world(), (const unsigned char*)s.c_str(), NULL, 0); - } else if (type == BLANK) { - _node = librdf_new_node_from_blank_identifier(world.world(), (const unsigned char*)s.c_str()); - } else { - _node = NULL; - } - - assert(this->type() == type); - assert(_world); -} - - -Node::Node(World& world) - : _world(&world) -{ - Glib::Mutex::Lock lock(world.mutex(), Glib::TRY_LOCK); - _node = librdf_new_node(world.world()); - assert(_world); -} - - -Node::Node(World& world, librdf_node* node) - : _world(&world) -{ - Glib::Mutex::Lock lock(world.mutex(), Glib::TRY_LOCK); - _node = librdf_new_node_from_node(node); - assert(_world); -} - - -Node::Node(const Node& other) - : _world(other.world()) - , _node(NULL) -{ - if (_world) { - Glib::Mutex::Lock lock(_world->mutex(), Glib::TRY_LOCK); - _node = (other._node ? librdf_new_node_from_node(other._node) : NULL); - } - - assert(to_string() == other.to_string()); -} - - -Node::~Node() -{ - if (_world) { - Glib::Mutex::Lock lock(_world->mutex(), Glib::TRY_LOCK); - if (_node) - librdf_free_node(_node); - } -} - - -string -Node::to_string() const -{ - const Type type = this->type(); - if (type == RESOURCE) { - assert(librdf_node_get_uri(_node)); - return string((const char*)librdf_uri_as_string(librdf_node_get_uri(_node))); - } else if (type == LITERAL) { - return string((const char*)librdf_node_get_literal_value(_node)); - } else if (type == BLANK) { - return string((const char*)librdf_node_get_blank_identifier(_node)); - } else { - return ""; - } -} - - -string -Node::to_quoted_uri_string() const -{ - assert(type() == RESOURCE); - assert(librdf_node_get_uri(_node)); - string str = "<"; - str.append((const char*)librdf_uri_as_string(librdf_node_get_uri(_node))); - str.append(">"); - return str; -} - - -bool -Node::is_int() const -{ - if (_node && librdf_node_get_type(_node) == LIBRDF_NODE_TYPE_LITERAL) { - librdf_uri* datatype_uri = librdf_node_get_literal_value_datatype_uri(_node); - if (datatype_uri && !strcmp((const char*)librdf_uri_as_string(datatype_uri), - "http://www.w3.org/2001/XMLSchema#integer")) - return true; - } - return false; -} - - -int -Node::to_int() const -{ - assert(is_int()); - return strtol((const char*)librdf_node_get_literal_value(_node), NULL, 10); -} - - -bool -Node::is_float() const -{ - if (_node && librdf_node_get_type(_node) == LIBRDF_NODE_TYPE_LITERAL) { - librdf_uri* datatype_uri = librdf_node_get_literal_value_datatype_uri(_node); - if (datatype_uri && !strcmp((const char*)librdf_uri_as_string(datatype_uri), - "http://www.w3.org/2001/XMLSchema#decimal")) - return true; - } - return false; -} - - -float -Node::to_float() const -{ - assert(is_float()); - return strtod((const char*)librdf_node_get_literal_value(_node), NULL); -} - -bool -Node::is_bool() const -{ - if (_node && librdf_node_get_type(_node) == LIBRDF_NODE_TYPE_LITERAL) { - librdf_uri* datatype_uri = librdf_node_get_literal_value_datatype_uri(_node); - if (datatype_uri && !strcmp((const char*)librdf_uri_as_string(datatype_uri), - "http://www.w3.org/2001/XMLSchema#boolean")) - return true; - } - return false; -} - - -float -Node::to_bool() const -{ - assert(is_bool()); - if (!strcmp((const char*)librdf_node_get_literal_value(_node), "true")) - return true; - else - return false; -} - - -} // namespace RDF -} // namespace Raul - diff --git a/src/RDFQuery.cpp b/src/RDFQuery.cpp deleted file mode 100644 index 41aa918..0000000 --- a/src/RDFQuery.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* This file is part of Raul. - * Copyright (C) 2007 Dave Robillard - * - * 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 - */ - -#include -#include -#include -#include -#include - -using namespace std; - -namespace Raul { -namespace RDF { - - -Query::Results -Query::run(World& world, Model& model, const Glib::ustring base_uri_str) const -{ - Glib::Mutex::Lock lock(world.mutex()); - - //cout << "\n**************** QUERY *******************\n"; - //cout << _query << endl; - //cout << "******************************************\n\n"; - - Results result; - - librdf_uri* base_uri = NULL; - if (base_uri_str != "") - base_uri = librdf_new_uri(world.world(), - (const unsigned char*)base_uri_str.c_str()); - - librdf_query* q = librdf_new_query(world.world(), "sparql", - NULL, (unsigned char*)_query.c_str(), base_uri); - - if (!q) { - cerr << "Unable to create query:" << endl << _query << endl; - return result; /* Return an empty Results */ - } - - librdf_query_results* results = librdf_query_execute(q, model._model); - - if (!results) { - cerr << "Failed query:" << endl << _query << endl; - return result; /* Return an empty Results */ - } - - while (!librdf_query_results_finished(results)) { - - Bindings bindings; - - for (int i=0; i < librdf_query_results_get_bindings_count(results); i++) { - const char* name = (char*)librdf_query_results_get_binding_name(results, i); - librdf_node* value = librdf_query_results_get_binding_value(results, i); - - if (name && value) - bindings.insert(std::make_pair(std::string(name), Node(world, value))); - } - - result.push_back(bindings); - librdf_query_results_next(results); - } - - librdf_free_query_results(results); - librdf_free_query(q); - - if (base_uri) - librdf_free_uri(base_uri); - - return result; -} - - -} // namespace RDF -} // namespace Raul - diff --git a/src/RDFWorld.cpp b/src/RDFWorld.cpp deleted file mode 100644 index 5420274..0000000 --- a/src/RDFWorld.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* This file is part of Raul. - * Copyright (C) 2007 Dave Robillard - * - * 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 - */ - -#include -#include -#include -#include - -#define U(x) ((const unsigned char*)(x)) - -using namespace std; - -namespace Raul { -namespace RDF { - - -//static const char* const RDF_LANG = "rdfxml-abbrev"; -static const char* const RDF_LANG = "turtle"; - - -/** Create an empty in-memory RDF model. - */ -World::World() - : _next_blank_id(1) -{ - _world = librdf_new_world(); - assert(_world); - librdf_world_open(_world); - - add_prefix("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); -} - - -World::~World() -{ - Glib::Mutex::Lock lock(_mutex); - librdf_free_world(_world); -} - - -void -World::add_prefix(const string& prefix, const string& uri) -{ - _prefixes[prefix] = uri; -} - - -/** Expands the prefix of URI, if the prefix is registered. - */ -string -World::expand_uri(const string& uri) const -{ - if (uri.find(":") == string::npos) - return uri; - - for (Namespaces::const_iterator i = _prefixes.begin(); i != _prefixes.end(); ++i) - if (uri.substr(0, i->first.length()+1) == i->first + ":") - return i->second + uri.substr(i->first.length()+1); - - return uri; -} - - -/** Opposite of expand_uri - */ -string -World::qualify(const string& uri) const -{ - return _prefixes.qualify(uri); -} - - -Node -World::blank_id(const string base_name) -{ - std::ostringstream ss; - ss << "b" << _next_blank_id++; - - if (base_name != "") - ss << "_" << base_name; - - Node result = Node(*this, Node::BLANK, ss.str()); - assert(result.to_string() == ss.str()); - return result; -} - - -} // namespace RDF -} // namespace Raul - diff --git a/tests/Makefile.am b/tests/Makefile.am index 2823a8d..63c23bc 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,7 +1,7 @@ if BUILD_UNIT_TESTS -AM_CXXFLAGS = -I.. @REDLAND_CFLAGS@ @GLIBMM_CFLAGS@ @GTHREAD_CFLAGS@ # -DTABLE_SORT_DEBUG -ALL_LIBS = @REDLAND_LIBS@ @GLIBMM_LIBS@ @GTHREAD_LIBS@ ../src/libraul.la +AM_CXXFLAGS = -I.. @REDLANDMM_CFLAGS@ @GLIBMM_CFLAGS@ @GTHREAD_CFLAGS@ # -DTABLE_SORT_DEBUG +ALL_LIBS = @REDLANDMM_LIBS@ @GLIBMM_LIBS@ @GTHREAD_LIBS@ ../src/libraul.la noinst_PROGRAMS = \ path_test \ @@ -14,7 +14,6 @@ noinst_PROGRAMS = \ time_test \ quantize_test \ smf_test \ - rdf_test \ table_test thread_test_LDADD = $(ALL_LIBS) @@ -27,7 +26,6 @@ list_test_LDADD = $(ALL_LIBS) time_test_LDADD = $(ALL_LIBS) quantize_test_LDADD = $(ALL_LIBS) smf_test_LDADD = $(ALL_LIBS) -rdf_test_LDADD = $(ALL_LIBS) table_test_LDADD = $(ALL_LIBS) path_test_SOURCES = path_test.cpp @@ -40,7 +38,6 @@ list_test_SOURCES = list_test.cpp time_test_SOURCES = time_test.cpp quantize_test_SOURCES = quantize_test.cpp smf_test_SOURCES = smf_test.cpp -rdf_test_SOURCES = rdf_test.cpp table_test_SOURCES = table_test.cpp endif diff --git a/tests/rdf_test.cpp b/tests/rdf_test.cpp deleted file mode 100644 index afb1887..0000000 --- a/tests/rdf_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include - -int -main() -{ - return 0; -} -- cgit v1.2.1