diff options
-rw-r--r-- | raul/Atom.hpp | 34 | ||||
-rw-r--r-- | raul/Deletable.hpp | 1 | ||||
-rw-r--r-- | raul/Disposable.hpp | 2 | ||||
-rw-r--r-- | raul/Manageable.hpp | 1 |
4 files changed, 26 insertions, 12 deletions
diff --git a/raul/Atom.hpp b/raul/Atom.hpp index b1a2485..5d32c38 100644 --- a/raul/Atom.hpp +++ b/raul/Atom.hpp @@ -19,6 +19,7 @@ #include <stdint.h> +#include <cassert> #include <cstdlib> #include <cstring> #include <string> @@ -42,6 +43,22 @@ public: 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) @@ -108,6 +125,11 @@ public: return is_reference() ? _val._blob : &_val; } + template <typename T> const T& get() const { + assert(size() == sizeof(T)); + return *static_cast<const T*>(get_body()); + } + inline int32_t get_int32() const { return _val._int; } inline float get_float() const { return _val._float; } inline bool get_bool() const { return _val._bool; } @@ -117,18 +139,6 @@ public: private: friend class Forge; - Atom(uint32_t s, TypeID t, const void* v) - : _size(s) - , _type(t) - { - if (is_reference()) { - _val._blob = malloc(s); - } - if (v) { - memcpy(get_body(), v, s); - } - } - inline void dealloc() { if (is_reference()) { free(_val._blob); diff --git a/raul/Deletable.hpp b/raul/Deletable.hpp index 408fa14..212de9c 100644 --- a/raul/Deletable.hpp +++ b/raul/Deletable.hpp @@ -1,3 +1,4 @@ + /* This file is part of Raul. Copyright 2007-2012 David Robillard <http://drobilla.net> diff --git a/raul/Disposable.hpp b/raul/Disposable.hpp index 1d91bf5..7496921 100644 --- a/raul/Disposable.hpp +++ b/raul/Disposable.hpp @@ -17,6 +17,8 @@ #ifndef RAUL_DISPOSABLE_HPP #define RAUL_DISPOSABLE_HPP +#include <stddef.h> + #include "raul/Deletable.hpp" namespace Raul { diff --git a/raul/Manageable.hpp b/raul/Manageable.hpp index b2b1f48..6b8b71f 100644 --- a/raul/Manageable.hpp +++ b/raul/Manageable.hpp @@ -17,6 +17,7 @@ #ifndef RAUL_MANAGEABLE_HPP #define RAUL_MANAGEABLE_HPP +#include "raul/Deletable.hpp" #include "raul/SharedPtr.hpp" namespace Raul { |