28 #include CONFIG_H_PATH
30 #define CUC(x) ((const unsigned char*)(x))
50 Atom() : _type(NIL), _blob_val(0) {}
51 Atom(int32_t val) : _type(INT), _int_val(val) {}
52 Atom(
float val) : _type(FLOAT), _float_val(val) {}
53 Atom(
bool val) : _type(BOOL), _bool_val(val) {}
54 Atom(
const char* val) : _type(STRING), _string_val(strdup(val)) {}
55 Atom(
const std::string& val) : _type(STRING), _string_val(strdup(val.c_str())) {}
57 Atom(
const char* type_uri,
size_t size,
void* val) : _type(BLOB) {
58 _blob_type_length = strlen(type_uri) + 1;
60 _blob_val = malloc(_blob_type_length + _blob_size);
61 memcpy(_blob_val, type_uri, _blob_type_length);
62 memcpy((
char*)_blob_val + _blob_type_length, val, size);
68 else if (_type == BLOB)
78 case NIL: _blob_val = 0;
break;
79 case INT: _int_val = copy._int_val;
break;
80 case FLOAT: _float_val = copy._float_val;
break;
81 case BOOL: _bool_val = copy._bool_val;
break;
82 case STRING: _string_val = strdup(copy._string_val);
break;
83 case BLOB: _blob_size = copy._blob_size;
84 _blob_type_length = copy._blob_type_length;
85 _blob_val = malloc(_blob_type_length + _blob_size);
86 memcpy(_blob_val, copy._blob_val, _blob_type_length + _blob_size);
94 else if (_type == STRING)
100 case NIL: _blob_val = 0;
break;
101 case INT: _int_val = other._int_val;
break;
102 case FLOAT: _float_val = other._float_val;
break;
103 case BOOL: _bool_val = other._bool_val;
break;
104 case STRING: _string_val = strdup(other._string_val);
break;
105 case BLOB: _blob_size = other._blob_size;
106 _blob_type_length = other._blob_type_length;
107 _blob_val = malloc(_blob_type_length + _blob_size);
108 memcpy(_blob_val, other._blob_val, _blob_type_length + _blob_size);
114 inline bool operator==(
const Atom& other)
const {
115 if (_type == other.
type()) {
117 case NIL:
return true;
118 case INT:
return _int_val == other._int_val;
119 case FLOAT:
return _float_val == other._float_val;
120 case BOOL:
return _bool_val == other._bool_val;
121 case STRING:
return strcmp(_string_val, other._string_val) == 0;
122 case BLOB:
return _blob_val == other._blob_val;
128 inline bool operator!=(
const Atom& other)
const {
return ! operator==(other); }
130 inline bool operator<(
const Atom& other)
const {
131 if (_type == other.
type()) {
133 case NIL:
return true;
134 case INT:
return _int_val < other._int_val;
135 case FLOAT:
return _float_val < other._float_val;
136 case BOOL:
return _bool_val < other._bool_val;
137 case STRING:
return strcmp(_string_val, other._string_val) < 0;
138 case BLOB:
return _blob_val < other._blob_val;
141 return _type < other.
type();
144 inline size_t data_size()
const {
147 case INT:
return sizeof(uint32_t);
148 case FLOAT:
return sizeof(float);
149 case BOOL:
return sizeof(bool);
150 case STRING:
return strlen(_string_val);
151 case BLOB:
return _blob_size;
156 inline bool is_valid()
const {
return (_type != NIL); }
161 Type
type()
const {
return _type; }
163 inline int32_t get_int32()
const { assert(_type == INT);
return _int_val; }
164 inline float get_float()
const { assert(_type == FLOAT);
return _float_val; }
165 inline bool get_bool()
const { assert(_type == BOOL);
return _bool_val; }
166 inline const char* get_string()
const { assert(_type == STRING);
return _string_val; }
168 inline const char* get_blob_type()
const { assert(_type == BLOB);
return (
const char*)_blob_val; }
169 inline const void* get_blob()
const { assert(_type == BLOB);
return (
const char*)_blob_val + _blob_type_length; }
180 size_t _blob_type_length;
190 #endif // RAUL_ATOM_HPP
An OSC atom (fundamental data types OSC messages are composed of).
Definition: Atom.hpp:39
Type type() const
Type of this atom.
Definition: Atom.hpp:161