summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2013-02-02 16:58:42 +0000
committerDavid Robillard <d@drobilla.net>2013-02-02 16:58:42 +0000
commit0f6cb4950ac3415bf3896e39e7e9a5bbf54986de (patch)
tree3f255789b90c3aefe67b917fe0c82fd82fc2f79f
parentbc42da1d71c637c9fb685b8b42a3c0ec4ba89d42 (diff)
downloadraul-0f6cb4950ac3415bf3896e39e7e9a5bbf54986de.tar.gz
raul-0f6cb4950ac3415bf3896e39e7e9a5bbf54986de.tar.bz2
raul-0f6cb4950ac3415bf3896e39e7e9a5bbf54986de.zip
More generic Atom class.
git-svn-id: http://svn.drobilla.net/lad/trunk/raul@5024 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--raul/Atom.hpp29
1 files changed, 16 insertions, 13 deletions
diff --git a/raul/Atom.hpp b/raul/Atom.hpp
index 5d32c38..851ccf5 100644
--- a/raul/Atom.hpp
+++ b/raul/Atom.hpp
@@ -28,14 +28,17 @@ namespace Raul {
class Forge;
-/** A piece of data with some type.
- *
- * An Atom is either a primitive type (int, float, etc.) or a blob. Primitives
- * are contained entirely within this struct so everything is realtime safe.
- * Blob creation/copying/destruction allocates and is not realtime safe.
- *
- * \ingroup raul
- */
+/**
+ 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; }
@@ -130,21 +133,21 @@ public:
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; }
- inline const char* get_uri() const { return (const char*)get_body(); }
- inline const char* get_string() const { return (const char*)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);
}