summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2008-08-17 01:34:53 +0000
committerDavid Robillard <d@drobilla.net>2008-08-17 01:34:53 +0000
commitafe4ba241fbd9163e4fbf3156d10895f369cc903 (patch)
treea4ab8fa8f5efaba632c9afb8ec04bdf28b5747e1
parent6b76fb2295f9745a6f22b7909ac157324be2a6e5 (diff)
downloadraul-afe4ba241fbd9163e4fbf3156d10895f369cc903.tar.gz
raul-afe4ba241fbd9163e4fbf3156d10895f369cc903.tar.bz2
raul-afe4ba241fbd9163e4fbf3156d10895f369cc903.zip
Cloooser...
Bundling of OSC communication both ways (previous was just engine->client). Factor out common OSC*Sender functionality (bundling stuff). Fully type-safe and polyphony-aware port value setting/getting, from RDF through OSC through engine and back again. git-svn-id: http://svn.drobilla.net/lad/raul@1409 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--raul/Atom.hpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/raul/Atom.hpp b/raul/Atom.hpp
index 3416067..a29fe95 100644
--- a/raul/Atom.hpp
+++ b/raul/Atom.hpp
@@ -55,8 +55,13 @@ public:
Atom(const char* val) : _type(STRING), _string_val(strdup(val)) {}
Atom(const std::string& val) : _type(STRING), _string_val(strdup(val.c_str())) {}
- Atom(void* val) : _type(BLOB), _blob_size(sizeof(val)), _blob_val(malloc(_blob_size))
- { memcpy(_blob_val, val, sizeof(_blob_size)); }
+ Atom(const char* type_uri, size_t size, void* val) : _type(BLOB) {
+ _blob_type_length = strlen(type_uri);
+ _blob_size = size + _blob_type_length;
+ _blob_val = malloc(_blob_size);
+ memcpy(_blob_val, type_uri, _blob_type_length);
+ memcpy((char*)_blob_val + _blob_type_length, val, size);
+ }
~Atom() {
if (_type == STRING)
@@ -135,7 +140,7 @@ public:
return _type < other.type();
}
- inline size_t data_size() {
+ inline size_t data_size() const {
switch (_type) {
case NIL: return 0;
case INT: return sizeof(uint32_t);
@@ -144,6 +149,7 @@ public:
case STRING: return strlen(_string_val);
case BLOB: return _blob_size;
}
+ return 0;
}
inline bool is_valid() const { return (_type != NIL); }
@@ -157,18 +163,23 @@ public:
inline float get_float() const { assert(_type == FLOAT); return _float_val; }
inline bool get_bool() const { assert(_type == BOOL); return _bool_val; }
inline const char* get_string() const { assert(_type == STRING); return _string_val; }
- inline const void* get_blob() const { assert(_type == BLOB); return _blob_val; }
+
+ inline const char* get_blob_type() const { assert(_type == BLOB); return (const char*)_blob_val; }
+ inline const void* get_blob() const { assert(_type == BLOB); return (const char*)_blob_val + _blob_type_length; }
private:
Type _type;
- size_t _blob_size; ///< Always a multiple of 32
union {
int32_t _int_val;
float _float_val;
bool _bool_val;
char* _string_val;
- void* _blob_val;
+ struct {
+ size_t _blob_type_length; // length of type string (first part of buffer)
+ size_t _blob_size; // length of data after type string
+ void* _blob_val; // buffer
+ };
};
};