summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2013-02-23 19:55:13 +0000
committerDavid Robillard <d@drobilla.net>2013-02-23 19:55:13 +0000
commit8c4f74f7705ba6909ffbd0d04ce8fe93c2224eab (patch)
tree83a12f522b3c340af2e21898ceea2041455312d2
parentd93b8cf9aaf8972f407c7cb6b8ef2de63be25112 (diff)
downloadraul-8c4f74f7705ba6909ffbd0d04ce8fe93c2224eab.tar.gz
raul-8c4f74f7705ba6909ffbd0d04ce8fe93c2224eab.tar.bz2
raul-8c4f74f7705ba6909ffbd0d04ce8fe93c2224eab.zip
Move Atom implementation out of Raul so it can depend on LV2.
git-svn-id: http://svn.drobilla.net/lad/trunk/raul@5076 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--raul/Atom.hpp219
-rw-r--r--raul/AtomLiblo.hpp97
-rw-r--r--test/atom_test.cpp39
-rw-r--r--wscript1
4 files changed, 0 insertions, 356 deletions
diff --git a/raul/Atom.hpp b/raul/Atom.hpp
deleted file mode 100644
index 678871a..0000000
--- a/raul/Atom.hpp
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- This file is part of Raul.
- Copyright 2007-2012 David 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 3 of the License, or 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 more details.
-
- You should have received a copy of the GNU General Public License
- along with Raul. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef RAUL_ATOM_HPP
-#define RAUL_ATOM_HPP
-
-#include <stdint.h>
-
-#include <cassert>
-#include <cstdlib>
-#include <cstring>
-#include <string>
-
-namespace Raul {
-
-class Forge;
-
-/**
- A generic typed data container.
-
- An Atom holds a value with some type and size, both specified by a uint32_t.
- Values with size less than sizeof(void*) are stored inline: no dynamic
- allocation occurs so Atoms may be created in hard real-time threads.
- Otherwise, if the size is larger than sizeof(void*), the value will be
- dynamically allocated in a separate chunk of memory.
-
- @ingroup raul
-*/
-class Atom {
-public:
- Atom() : _size(0), _type(0) { _val._blob = NULL; }
- ~Atom() { dealloc(); }
-
- typedef uint32_t TypeID;
-
- /** Contruct a raw atom.
- *
- * Typically this is not used directly, use Forge methods to make atoms.
- */
- Atom(uint32_t size, TypeID type, const void* body)
- : _size(size)
- , _type(type)
- {
- if (is_reference()) {
- _val._blob = malloc(size);
- }
- if (body) {
- memcpy(get_body(), body, size);
- }
- }
-
- Atom(const Atom& copy)
- : _size(copy._size)
- , _type(copy._type)
- {
- if (is_reference()) {
- _val._blob = malloc(_size);
- memcpy(_val._blob, copy._val._blob, _size);
- } else {
- memcpy(&_val, &copy._val, _size);
- }
- }
-
- Atom& operator=(const Atom& other) {
- if (&other == this) {
- return *this;
- }
- dealloc();
- _size = other._size;
- _type = other._type;
- if (is_reference()) {
- _val._blob = malloc(_size);
- memcpy(_val._blob, other._val._blob, _size);
- } else {
- memcpy(&_val, &other._val, _size);
- }
- return *this;
- }
-
- inline bool operator==(const Atom& other) const {
- if (_type == other.type() && _size == other.size()) {
- if (is_reference()) {
- return !memcmp(_val._blob, other._val._blob, _size);
- } else {
- return !memcmp(&_val, &other._val, _size);
- }
- }
- return false;
- }
-
- inline bool operator!=(const Atom& other) const {
- return !operator==(other);
- }
-
- inline bool operator<(const Atom& other) const {
- if (_type == other.type()) {
- if (is_reference()) {
- return memcmp(_val._blob, other._val._blob, _size) < 0;
- } else {
- return memcmp(&_val, &other._val, _size) < 0;
- }
- }
- return _type < other.type();
- }
-
- inline uint32_t size() const { return _size; }
- inline bool is_valid() const { return _type; }
- inline TypeID type() const { return _type; }
-
- inline const void* get_body() const {
- return is_reference() ? _val._blob : &_val;
- }
-
- inline void* get_body() {
- return is_reference() ? _val._blob : &_val;
- }
-
- template <typename T> const T& get() const {
- assert(size() == sizeof(T));
- return *static_cast<const T*>(get_body());
- }
-
- template <typename T> const T* ptr() const {
- return static_cast<const T*>(get_body());
- }
-
-private:
- friend class Forge;
-
- /** Free dynamically allocated value, if applicable. */
- inline void dealloc() {
- if (is_reference()) {
- free(_val._blob);
- }
- }
-
- /** Return true iff this value is dynamically allocated. */
- inline bool is_reference() const {
- return _size > sizeof(_val);
- }
-
- uint32_t _size;
- TypeID _type;
-
- union {
- intptr_t _val;
- void* _blob;
- } _val;
-};
-
-class Forge {
-public:
- Forge()
- : Int(1)
- , Float(2)
- , Bool(3)
- , URI(4)
- , URID(5)
- , String(6)
- {}
-
- virtual ~Forge() {}
-
- Atom make() { return Atom(); }
- Atom make(int32_t v) { return Atom(sizeof(v), Int, &v); }
- Atom make(float v) { return Atom(sizeof(v), Float, &v); }
- Atom make(bool v) {
- const int32_t iv = v ? 1 : 0;
- return Atom(sizeof(int32_t), Bool, &iv);
- }
-
- Atom make_urid(int32_t v) { return Atom(sizeof(int32_t), URID, &v); }
-
- Atom alloc(uint32_t size, uint32_t type, const void* val) {
- return Atom(size, type, val);
- }
-
- Atom alloc(const char* v) {
- const size_t len = strlen(v);
- return Atom(len + 1, String, v);
- }
-
- Atom alloc(const std::string& v) {
- return Atom(v.length() + 1, String, v.c_str());
- }
-
- Atom alloc_uri(const char* v) {
- const size_t len = strlen(v);
- return Atom(len + 1, URI, v);
- }
-
- Atom alloc_uri(const std::string& v) {
- return Atom(v.length() + 1, URI, v.c_str());
- }
-
- Atom::TypeID Int;
- Atom::TypeID Float;
- Atom::TypeID Bool;
- Atom::TypeID URI;
- Atom::TypeID URID;
- Atom::TypeID String;
-};
-
-} // namespace Raul
-
-#endif // RAUL_ATOM_HPP
diff --git a/raul/AtomLiblo.hpp b/raul/AtomLiblo.hpp
deleted file mode 100644
index 76d106c..0000000
--- a/raul/AtomLiblo.hpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- This file is part of Raul.
- Copyright 2007-2012 David 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 3 of the License, or 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 more details.
-
- You should have received a copy of the GNU General Public License
- along with Raul. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef RAUL_ATOM_LIBLO_HPP
-#define RAUL_ATOM_LIBLO_HPP
-
-#include <lo/lo.h>
-
-#include "raul/log.hpp"
-#include "raul/Atom.hpp"
-
-namespace Raul {
-
-/** Conversion between Raul Atoms and Liblo OSC arguments.
- * This code (in header raul/AtomLiblo.hpp) depends on liblo, only apps which
- * directly depend on both raul and liblo should include it.
- */
-namespace AtomLiblo {
-
-/** Append a Raul Atom as a parameter to a liblo message */
-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::URI:
- lo_message_add_symbol(m, atom.get_uri());
- break;
- case Atom::BOOL:
- if (atom.get_bool())
- lo_message_add_true(m);
- else
- lo_message_add_false(m);
- break;
- case Atom::BLOB:
- if (atom.data_size() > 0)
- lo_message_add_blob(
- m, lo_blob_new(atom.data_size(), atom.get_blob()));
- else
- lo_message_add_nil(m);
- break;
- case Atom::NIL:
- default:
- lo_message_add_nil(m);
- break;
- }
-}
-
-/** Convert a liblo argument to a Raul::Atom */
-inline Atom
-lo_arg_to_atom(Raul::Forge& forge, char type, lo_arg* arg)
-{
- switch (type) {
- case 'i':
- return forge.make(arg->i);
- case 'f':
- return forge.make(arg->f);
- case 's':
- return forge.make(&arg->s);
- case 'S':
- return forge.alloc(Atom::URI, &arg->S);
- case 'T':
- return forge.make((bool)true);
- case 'F':
- return forge.make((bool)false);
- default:
- warn << "Unable to convert OSC type '"
- << type << "' to Atom" << std::endl;
- return Atom();
- }
-}
-
-} // namespace AtomLiblo
-} // namespace Raul
-
-#endif // RAUL_ATOM_LIBLO_HPP
diff --git a/test/atom_test.cpp b/test/atom_test.cpp
deleted file mode 100644
index 381ebbe..0000000
--- a/test/atom_test.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- This file is part of Raul.
- Copyright 2007-2012 David 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 3 of the License, or 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 more details.
-
- You should have received a copy of the GNU General Public License
- along with Raul. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "raul/Atom.hpp"
-
-using namespace std;
-using namespace Raul;
-
-int
-main()
-{
- //static const size_t buf_size = 9;
- //char buf[buf_size] = "atomtest";
-
- Forge forge;
-
- Atom nil_atom = forge.make();
- Atom int_atom = forge.make(42);
- Atom float_atom = forge.make(42.0f);
- Atom bool_atom = forge.make(true);
- Atom string_atom = forge.alloc("hello");
- //Atom blob_atom = forge.alloc("http://example.org/atomtype", buf_size, buf);
-
- return 0;
-}
-
diff --git a/wscript b/wscript
index 8acbbbd..df2344d 100644
--- a/wscript
+++ b/wscript
@@ -73,7 +73,6 @@ def configure(conf):
print('')
tests = '''
- test/atom_test
test/double_buffer_test
test/path_test
test/queue_test