diff options
author | David Robillard <d@drobilla.net> | 2007-10-08 19:36:52 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-10-08 19:36:52 +0000 |
commit | c50bee51f5c5e6a43068d2fc4c9c76586fa9fb60 (patch) | |
tree | b20e893c8280101985168be3f62014776593ae84 | |
parent | 9f975e1e8a7dd0d8d90739829dc07d1188ad51e5 (diff) | |
download | raul-c50bee51f5c5e6a43068d2fc4c9c76586fa9fb60.tar.gz raul-c50bee51f5c5e6a43068d2fc4c9c76586fa9fb60.tar.bz2 raul-c50bee51f5c5e6a43068d2fc4c9c76586fa9fb60.zip |
Update.. stuff... I hate SVN...
git-svn-id: http://svn.drobilla.net/lad/raul@855 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r-- | raul/Atom.hpp | 2 | ||||
-rw-r--r-- | raul/AtomRedland.hpp | 44 | ||||
-rw-r--r-- | raul/RDFModel.hpp | 8 | ||||
-rw-r--r-- | src/RDFModel.cpp | 42 |
4 files changed, 44 insertions, 52 deletions
diff --git a/raul/Atom.hpp b/raul/Atom.hpp index 01d783f..443c0ae 100644 --- a/raul/Atom.hpp +++ b/raul/Atom.hpp @@ -33,7 +33,7 @@ namespace Raul { class Atom { public: - //TODO: Add a bool type here that serializes nicely to Turtle "true" and "false" + //TODO: Add a bool type here that serialises nicely to Turtle "true" and "false" enum Type { NIL, diff --git a/raul/AtomRedland.hpp b/raul/AtomRedland.hpp index 0ce260b..95f5d9d 100644 --- a/raul/AtomRedland.hpp +++ b/raul/AtomRedland.hpp @@ -23,9 +23,9 @@ #include <cstring> #include <librdf.h> #include <raul/Atom.hpp> -using std::cerr; using std::endl; +#include <raul/RDFNode.hpp> -#define U(x) ((const unsigned char*)(x)) +#define CUC(x) ((const unsigned char*)(x)) namespace Raul { @@ -56,14 +56,14 @@ public: os << atom.get_int32(); str = os.str(); // xsd:integer -> pretty integer literals in Turtle - type = librdf_new_uri(world, U("http://www.w3.org/2001/XMLSchema#integer")); + 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, U("http://www.w3.org/2001/XMLSchema#decimal")); + type = librdf_new_uri(world, CUC("http://www.w3.org/2001/XMLSchema#decimal")); break; case Atom::BOOL: // xsd:boolean -> pretty boolean literals in Turtle @@ -71,7 +71,7 @@ public: str = "true"; else str = "false"; - type = librdf_new_uri(world, U("http://www.w3.org/2001/XMLSchema#boolean")); + type = librdf_new_uri(world, CUC("http://www.w3.org/2001/XMLSchema#boolean")); break; case Atom::STRING: str = atom.get_string(); @@ -79,35 +79,27 @@ public: case Atom::BLOB: case Atom::NIL: default: - cerr << "WARNING: Unserializable Atom!" << endl; + std::cerr << "WARNING: Unserializable Atom!" << std::endl; } if (str != "") - node = librdf_new_node_from_typed_literal(world, U(str.c_str()), NULL, type); + node = librdf_new_node_from_typed_literal(world, CUC(str.c_str()), NULL, type); return node; } -#if 0 - static Atom node_to_atom(librdf_node* node) { - /*switch (type) { - case 'i': - return Atom(arg->i); - case 'f': - return Atom(arg->f); - case 's': - return Atom(&arg->s); - //case 'b' - // FIXME: How to get a blob from a lo_arg? - //return Atom(arg->b); - default: - return Atom(); - }*/ - cerr << "FIXME: node_to_atom\n"; - return Atom(); + 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()); } -#endif - }; diff --git a/raul/RDFModel.hpp b/raul/RDFModel.hpp index d6f224e..40d524f 100644 --- a/raul/RDFModel.hpp +++ b/raul/RDFModel.hpp @@ -40,9 +40,9 @@ public: Model(World& world, const Glib::ustring& uri, Glib::ustring base_uri=""); ~Model(); - void serialize_to_file_handle(FILE* fd); - void serialize_to_file(const Glib::ustring& uri); - std::string serialize_to_string(); + 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, @@ -70,7 +70,7 @@ private: World& _world; librdf_storage* _storage; librdf_model* _model; - librdf_serializer* _serializer; + librdf_serializer* _serialiser; size_t _next_blank_id; }; diff --git a/src/RDFModel.cpp b/src/RDFModel.cpp index 5fdf521..5680ff1 100644 --- a/src/RDFModel.cpp +++ b/src/RDFModel.cpp @@ -37,7 +37,7 @@ static const char* const RDF_LANG = "turtle"; */ Model::Model(RDF::World& world) : _world(world) - , _serializer(NULL) + , _serialiser(NULL) { Glib::Mutex::Lock lock(world.mutex()); _storage = librdf_new_storage(_world.world(), "hashes", NULL, "hash-type='memory'"); @@ -49,7 +49,7 @@ Model::Model(RDF::World& world) */ Model::Model(World& world, const Glib::ustring& data_uri, Glib::ustring base_uri_str) : _world(world) - , _serializer(NULL) + , _serialiser(NULL) { Glib::Mutex::Lock lock(world.mutex()); _storage = librdf_new_storage(_world.world(), "hashes", NULL, "hash-type='memory'"); @@ -86,8 +86,8 @@ Model::~Model() { Glib::Mutex::Lock lock(_world.mutex()); - if (_serializer) - librdf_free_serializer(_serializer); + if (_serialiser) + librdf_free_serializer(_serialiser); librdf_free_model(_model); librdf_free_storage(_storage); @@ -97,10 +97,10 @@ Model::~Model() void Model::setup_prefixes() { - assert(_serializer); + assert(_serialiser); for (Namespaces::const_iterator i = _world.prefixes().begin(); i != _world.prefixes().end(); ++i) { - librdf_serializer_set_namespace(_serializer, + librdf_serializer_set_namespace(_serialiser, librdf_new_uri(_world.world(), U(i->second.c_str())), i->first.c_str()); } } @@ -111,15 +111,15 @@ Model::setup_prefixes() * This must be called before any write methods. */ void -Model::serialize_to_file_handle(FILE* fd) +Model::serialise_to_file_handle(FILE* fd) { Glib::Mutex::Lock lock(_world.mutex()); - _serializer = librdf_new_serializer(_world.world(), RDF_LANG, NULL, NULL); + _serialiser = librdf_new_serializer(_world.world(), RDF_LANG, NULL, NULL); setup_prefixes(); - librdf_serializer_serialize_model_to_file_handle(_serializer, fd, NULL, _model); - librdf_free_serializer(_serializer); - _serializer = NULL; + librdf_serializer_serialize_model_to_file_handle(_serialiser, fd, NULL, _model); + librdf_free_serializer(_serialiser); + _serialiser = NULL; } @@ -130,17 +130,17 @@ Model::serialize_to_file_handle(FILE* fd) * This must be called before any write methods. */ void -Model::serialize_to_file(const Glib::ustring& uri_str) +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)) { - _serializer = librdf_new_serializer(_world.world(), RDF_LANG, NULL, NULL); + _serialiser = librdf_new_serializer(_world.world(), RDF_LANG, NULL, NULL); setup_prefixes(); - librdf_serializer_serialize_model_to_file(_serializer, librdf_uri_to_filename(uri), uri, _model); - librdf_free_serializer(_serializer); - _serializer = NULL; + librdf_serializer_serialize_model_to_file(_serialiser, librdf_uri_to_filename(uri), uri, _model); + librdf_free_serializer(_serialiser); + _serialiser = NULL; } librdf_free_uri(uri); } @@ -154,21 +154,21 @@ Model::serialize_to_file(const Glib::ustring& uri_str) * the desired objects have been serialized. */ string -Model::serialize_to_string() +Model::serialise_to_string() { Glib::Mutex::Lock lock(_world.mutex()); - _serializer = librdf_new_serializer(_world.world(), RDF_LANG, NULL, NULL); + _serialiser = librdf_new_serializer(_world.world(), RDF_LANG, NULL, NULL); setup_prefixes(); unsigned char* c_str - = librdf_serializer_serialize_model_to_string(_serializer, NULL, _model); + = librdf_serializer_serialize_model_to_string(_serialiser, NULL, _model); string result((const char*)c_str); free(c_str); - librdf_free_serializer(_serializer); - _serializer = NULL; + librdf_free_serializer(_serialiser); + _serialiser = NULL; return result; } |