diff options
author | David Robillard <d@drobilla.net> | 2007-02-14 03:28:12 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-02-14 03:28:12 +0000 |
commit | fedfa21db3957ea425ef9282566ffcd5804a0e76 (patch) | |
tree | 971c554c11b53b4d0530b8548159de82cc745e48 | |
parent | 5dac076bbe695e76060811e4c767ed9d1b832cb6 (diff) | |
download | raul-fedfa21db3957ea425ef9282566ffcd5804a0e76.tar.gz raul-fedfa21db3957ea425ef9282566ffcd5804a0e76.tar.bz2 raul-fedfa21db3957ea425ef9282566ffcd5804a0e76.zip |
Serialization work on Machina.
git-svn-id: http://svn.drobilla.net/lad/raul@306 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r-- | raul/Makefile.am | 3 | ||||
-rw-r--r-- | raul/RDFWriter.h | 9 | ||||
-rw-r--r-- | raul/Stateful.h | 45 | ||||
-rw-r--r-- | src/RDFWriter.cpp | 15 |
4 files changed, 69 insertions, 3 deletions
diff --git a/raul/Makefile.am b/raul/Makefile.am index 12abee0..3c1fea1 100644 --- a/raul/Makefile.am +++ b/raul/Makefile.am @@ -20,7 +20,8 @@ raulinclude_HEADERS = \ Deletable.h \ List.h \ Array.h \ - Maid.h + Maid.h\ + Stateful.h if WITH_LIBLO raulinclude_HEADERS += AtomLiblo.h diff --git a/raul/RDFWriter.h b/raul/RDFWriter.h index fbd81a5..9a5d5b3 100644 --- a/raul/RDFWriter.h +++ b/raul/RDFWriter.h @@ -29,13 +29,16 @@ namespace Raul { class RdfId { public: - enum Type { ANONYMOUS, RESOURCE }; + 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() { return (_type != NULL_ID); } + private: Type _type; std::string _string; ///< URI or blank node ID, depending on _type @@ -53,6 +56,8 @@ public: 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, @@ -69,6 +74,8 @@ private: raptor_serializer* _serializer; unsigned char* _string_output; Namespaces _prefixes; + + size_t _next_blank_id; }; diff --git a/raul/Stateful.h b/raul/Stateful.h new file mode 100644 index 0000000..5e4626c --- /dev/null +++ b/raul/Stateful.h @@ -0,0 +1,45 @@ +/* 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 STATEFUL_H +#define STATEFUL_H + +#include "raul/RDFWriter.h" + +namespace Raul { + + +class RDFWriter; + + +class Stateful { +public: + virtual ~Stateful() {} + + virtual void write_state(RDFWriter& writer) = 0; + + RdfId id() const { return _id; } + void set_id(const RdfId& id) { _id = id; } + +protected: + RdfId _id; +}; + + +} // namespace Raul + +#endif // STATEFUL_H diff --git a/src/RDFWriter.cpp b/src/RDFWriter.cpp index b23f51a..625d1fc 100644 --- a/src/RDFWriter.cpp +++ b/src/RDFWriter.cpp @@ -15,6 +15,7 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include <sstream> #include "raul/RDFWriter.h" #include "raul/AtomRaptor.h" @@ -30,7 +31,8 @@ static const char* const RDF_LANG = "turtle"; RDFWriter::RDFWriter() : _serializer(NULL) , _string_output(NULL) -{ + , _next_blank_id(0) +{ add_prefix("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); //add_prefix("rdfs", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); } @@ -40,6 +42,9 @@ void RDFWriter::add_prefix(const string& prefix, const string& uri) { _prefixes[prefix] = uri; + if (_serializer) + raptor_serialize_set_namespace(_serializer, + raptor_new_uri(U(uri.c_str())), U(prefix.c_str())); } @@ -68,6 +73,14 @@ RDFWriter::expand_uri(const string& uri) } +RdfId +RDFWriter::blank_id() +{ + std::ostringstream ss; + ss << "n" << _next_blank_id++; + return RdfId(RdfId::ANONYMOUS, ss.str()); +} + /** Begin a serialization to a file. * |