diff options
Diffstat (limited to 'include/ingen/Atom.hpp')
-rw-r--r-- | include/ingen/Atom.hpp | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/include/ingen/Atom.hpp b/include/ingen/Atom.hpp index 3fb8f091..8d9cbe7f 100644 --- a/include/ingen/Atom.hpp +++ b/include/ingen/Atom.hpp @@ -17,9 +17,9 @@ #ifndef INGEN_ATOM_HPP #define INGEN_ATOM_HPP -#include "ingen/ingen.h" -#include "lv2/atom/atom.h" -#include "lv2/urid/urid.h" +#include <ingen/ingen.h> +#include <lv2/atom/atom.h> +#include <lv2/urid/urid.h> #include <algorithm> #include <cassert> @@ -41,7 +41,8 @@ namespace ingen { In either case, the data is stored in a binary compatible format to LV2_Atom (i.e., if the value is dynamically allocated, the header is repeated there). */ -class INGEN_API Atom { +class INGEN_API Atom +{ public: Atom() noexcept = default; @@ -93,21 +94,22 @@ public: return *this; } - inline bool operator==(const Atom& other) const { + bool operator==(const Atom& other) const { if (_atom.type != other._atom.type || _atom.size != other._atom.size) { return false; } + return is_reference() ? !memcmp(_body.ptr, other._body.ptr, sizeof(LV2_Atom) + _atom.size) : _body.val == other._body.val; } - inline bool operator!=(const Atom& other) const { + bool operator!=(const Atom& other) const { return !operator==(other); } - inline bool operator<(const Atom& other) const { + bool operator<(const Atom& other) const { if (_atom.type == other._atom.type) { const uint32_t min_size = std::min(_atom.size, other._atom.size); const int cmp = is_reference() @@ -115,6 +117,7 @@ public: : memcmp(&_body.val, &other._body.val, min_size); return cmp < 0 || (cmp == 0 && _atom.size < other._atom.size); } + return type() < other.type(); } @@ -122,25 +125,25 @@ public: * Always real-time safe. * @return true iff set succeeded. */ - inline bool set_rt(const Atom& other) { + bool set_rt(const Atom& other) { if (is_reference()) { return false; - } else { - _atom = other._atom; - _body.val = other._body.val; - return true; } + + _atom = other._atom; + _body.val = other._body.val; + return true; } - inline uint32_t size() const { return _atom.size; } - inline LV2_URID type() const { return _atom.type; } - inline bool is_valid() const { return _atom.type; } + uint32_t size() const { return _atom.size; } + LV2_URID type() const { return _atom.type; } + bool is_valid() const { return _atom.type; } - inline const void* get_body() const { + const void* get_body() const { return is_reference() ? static_cast<void*>(_body.ptr + 1) : &_body.val; } - inline void* get_body() { + void* get_body() { return is_reference() ? static_cast<void*>(_body.ptr + 1) : &_body.val; } @@ -159,14 +162,14 @@ public: private: /** Free dynamically allocated value, if applicable. */ - inline void dealloc() { + void dealloc() { if (is_reference()) { free(_body.ptr); } } /** Return true iff this value is dynamically allocated. */ - inline bool is_reference() const { + bool is_reference() const { return _atom.size > sizeof(_body.val); } |