diff options
author | David Robillard <d@drobilla.net> | 2008-01-06 21:55:17 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2008-01-06 21:55:17 +0000 |
commit | 966dbecf3e8dd13bd8af6de129a0af5b8dc83b8f (patch) | |
tree | b6f015589464b7dad703595ea0555ba1233504d6 /raul | |
parent | 2747087c382445ad7c1b891993679fb299a73151 (diff) | |
download | raul-966dbecf3e8dd13bd8af6de129a0af5b8dc83b8f.tar.gz raul-966dbecf3e8dd13bd8af6de129a0af5b8dc83b8f.tar.bz2 raul-966dbecf3e8dd13bd8af6de129a0af5b8dc83b8f.zip |
Remove raul dependency on liblo and redlandmm.
git-svn-id: http://svn.drobilla.net/lad/raul@1025 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'raul')
-rw-r--r-- | raul/Atom.hpp | 80 | ||||
-rw-r--r-- | raul/AtomLiblo.hpp | 91 | ||||
-rw-r--r-- | raul/AtomRDF.hpp | 106 | ||||
-rw-r--r-- | raul/Makefile.am | 6 |
4 files changed, 156 insertions, 127 deletions
diff --git a/raul/Atom.hpp b/raul/Atom.hpp index c1ca366..b9d81ec 100644 --- a/raul/Atom.hpp +++ b/raul/Atom.hpp @@ -26,10 +26,6 @@ #include <iostream> #include CONFIG_H_PATH -#ifdef HAVE_REDLANDMM -#include <redlandmm/Node.hpp> -#include <redlandmm/World.hpp> -#endif #define CUC(x) ((const unsigned char*)(x)) @@ -62,30 +58,7 @@ public: 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_c_string()); - } 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_c_string()); - } - } -#endif - - ~Atom() - { + ~Atom() { if (_type == STRING) free(_string_val); else if (_type == BLOB) @@ -113,8 +86,7 @@ public: } } - Atom& operator=(const Atom& other) - { + Atom& operator=(const Atom& other) { if (_type == BLOB) free(_blob_val); else if (_type == STRING) @@ -152,54 +124,6 @@ public: 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/AtomLiblo.hpp b/raul/AtomLiblo.hpp index e21e6c3..3491b3a 100644 --- a/raul/AtomLiblo.hpp +++ b/raul/AtomLiblo.hpp @@ -15,6 +15,11 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +/** @file Conversion from Raul Atom to Liblo OSC arguments and vice-versa. + * This header depends on liblo, only apps which directly depend on + * both raul and liblo should include it. + */ + #ifndef RAUL_ATOM_LIBLO_HPP #define RAUL_ATOM_LIBLO_HPP @@ -22,57 +27,53 @@ #include <raul/Atom.hpp> namespace Raul { +namespace AtomLiblo { - -/** Support for serializing an Atom to/from liblo messages. - * - * (Here to prevent a unnecessary liblo dependency for Atom). - * - * \ingroup raul - */ -class AtomLiblo { -public: - static void lo_message_add_atom(lo_message m, const Atom& atom) { - switch (atom.type()) { - case Atom::INT: - lo_message_add_int32(m, atom.get_int32()); - break; - case Atom::FLOAT: - lo_message_add_float(m, atom.get_float()); - break; - case Atom::STRING: - lo_message_add_string(m, atom.get_string()); - break; - case Atom::BLOB: - // FIXME: is this okay? what does liblo do? - lo_message_add_blob(m, const_cast<void*>(atom.get_blob())); - break; - case Atom::NIL: - default: - lo_message_add_nil(m); - break; - } +inline void +lo_message_add_atom(lo_message m, const Atom& atom) +{ + switch (atom.type()) { + case Atom::INT: + lo_message_add_int32(m, atom.get_int32()); + break; + case Atom::FLOAT: + lo_message_add_float(m, atom.get_float()); + break; + case Atom::STRING: + lo_message_add_string(m, atom.get_string()); + break; + case Atom::BLOB: + // FIXME: is this okay? what does liblo do? + lo_message_add_blob(m, const_cast<void*>(atom.get_blob())); + break; + case Atom::NIL: + default: + lo_message_add_nil(m); + break; } +} - static Atom lo_arg_to_atom(char type, lo_arg* arg) { - 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(); - } - } -}; +inline Atom +lo_arg_to_atom(char type, lo_arg* arg) +{ + 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(); + } +} +} // namespace AtomLiblo } // namespace Raul #endif // RAUL_ATOM_LIBLO_HPP diff --git a/raul/AtomRDF.hpp b/raul/AtomRDF.hpp new file mode 100644 index 0000000..2934a2a --- /dev/null +++ b/raul/AtomRDF.hpp @@ -0,0 +1,106 @@ +/* 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 + */ + +/** @file Conversion from Raul Atom to Redlandmm RDF Node and vice-versa. + * This header depends on redlandmm, only apps which directly depend on + * both raul and redlandmm should include it. + */ + +#ifndef RAUL_ATOM_RDF_HPP +#define RAUL_ATOM_RDF_HPP + +#include <cstring> +#include <string> +#include <sstream> + +#include CONFIG_H_PATH + +#include <redlandmm/Node.hpp> +#include <redlandmm/World.hpp> + +#define CUC(x) ((const unsigned char*)(x)) + +namespace Raul { +namespace AtomRDF { + +inline Atom +node_to_atom(const Redland::Node& node) +{ + if (node.type() == Redland::Node::RESOURCE) + return Atom(node.to_c_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_c_string()); +} + + +inline Redland::Node +atom_to_node(Redland::World& world, const Atom& atom) +{ + std::ostringstream os; + std::string str; + librdf_uri* type = NULL; + librdf_node* node = NULL; + + 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.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.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.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.world(), CUC(str.c_str()), NULL, type); + + return Redland::Node(world, node); +} + + +} // namespace AtomRDF +} // namespace Raul + +#endif // RAUL_ATOM_RDF_HPP + diff --git a/raul/Makefile.am b/raul/Makefile.am index c8f25a2..eeeb792 100644 --- a/raul/Makefile.am +++ b/raul/Makefile.am @@ -3,6 +3,8 @@ raulincludedir = $(includedir)/raul raulinclude_HEADERS = \ Array.hpp \ Atom.hpp \ + AtomLiblo.hpp \ + AtomRDF.hpp \ AtomicInt.hpp \ AtomicPtr.hpp \ Command.hpp \ @@ -35,10 +37,6 @@ raulinclude_HEADERS = \ midi_events.h \ types.hpp -if WITH_LIBLO -raulinclude_HEADERS += AtomLiblo.hpp -endif - if WITH_LASH raulinclude_HEADERS += LashClient.hpp LashServerInterface.hpp LashProject.hpp endif |