diff options
author | David Robillard <d@drobilla.net> | 2007-11-30 07:38:42 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-11-30 07:38:42 +0000 |
commit | e9c7107df9dd2001498cae65aa6ad898fbf7d2f7 (patch) | |
tree | 3f0d33555a7bc18a544b19aab99b9a4504446c92 /raul/AtomRedland.hpp | |
parent | 9988890730832ebd0a5f5a64a74eb0a2e65c1de4 (diff) | |
download | raul-e9c7107df9dd2001498cae65aa6ad898fbf7d2f7.tar.gz raul-e9c7107df9dd2001498cae65aa6ad898fbf7d2f7.tar.bz2 raul-e9c7107df9dd2001498cae65aa6ad898fbf7d2f7.zip |
Split redland C++ wrappers out from Raul.
git-svn-id: http://svn.drobilla.net/lad/raul@927 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'raul/AtomRedland.hpp')
-rw-r--r-- | raul/AtomRedland.hpp | 108 |
1 files changed, 0 insertions, 108 deletions
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 |