LMMS
Loading...
Searching...
No Matches
lv2_atom_util.h
Go to the documentation of this file.
1/*
2 Copyright 2008-2013 David Robillard <http://drobilla.net>
3
4 Permission to use, copy, modify, and/or distribute this software for any
5 purpose with or without fee is hereby granted, provided that the above
6 copyright notice and this permission notice appear in all copies.
7
8 THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*/
16
24
25#ifndef LV2_ATOM_UTIL_H
26#define LV2_ATOM_UTIL_H
27
28#include <stdarg.h>
29#include <stdint.h>
30#include <string.h>
31
32#include "lv2_atom.h"
33
34#ifdef __cplusplus
35extern "C" {
36#else
37# include <stdbool.h>
38#endif
39
41static inline uint32_t
43{
44 return (size + 7U) & (~7U);
45}
46
48static inline uint32_t
50{
51 return (uint32_t)sizeof(LV2_Atom) + atom->size;
52}
53
55static inline bool
57{
58 return !atom || (atom->type == 0 && atom->size == 0);
59}
60
62static inline bool
64{
65 return (a == b) || ((a->type == b->type) &&
66 (a->size == b->size) &&
67 !memcmp(a + 1, b + 1, a->size));
68}
69
74
76static inline LV2_Atom_Event*
78{
79 return (LV2_Atom_Event*)(body + 1);
80}
81
83static inline LV2_Atom_Event*
88
90static inline bool
93 const LV2_Atom_Event* i)
94{
95 return (const uint8_t*)i >= ((const uint8_t*)body + size);
96}
97
99static inline LV2_Atom_Event*
101{
102 return (LV2_Atom_Event*)((const uint8_t*)i
103 + sizeof(LV2_Atom_Event)
104 + lv2_atom_pad_size(i->body.size));
105}
106
119#define LV2_ATOM_SEQUENCE_FOREACH(seq, iter) \
120 for (LV2_Atom_Event* (iter) = lv2_atom_sequence_begin(&(seq)->body); \
121 !lv2_atom_sequence_is_end(&(seq)->body, (seq)->atom.size, (iter)); \
122 (iter) = lv2_atom_sequence_next(iter))
123
125#define LV2_ATOM_SEQUENCE_BODY_FOREACH(body, size, iter) \
126 for (LV2_Atom_Event* (iter) = lv2_atom_sequence_begin(body); \
127 !lv2_atom_sequence_is_end(body, size, (iter)); \
128 (iter) = lv2_atom_sequence_next(iter))
129
135
141static inline void
146
158static inline LV2_Atom_Event*
160 uint32_t capacity,
161 const LV2_Atom_Event* event)
162{
163 const uint32_t total_size = (uint32_t)sizeof(*event) + event->body.size;
164 if (capacity - seq->atom.size < total_size) {
165 return NULL;
166 }
167
169 memcpy(e, event, total_size);
170
171 seq->atom.size += lv2_atom_pad_size(total_size);
172
173 return e;
174}
175
181
183static inline LV2_Atom*
185{
186 return (LV2_Atom*)(LV2_ATOM_BODY(tup));
187}
188
190static inline bool
191lv2_atom_tuple_is_end(const void* body, uint32_t size, const LV2_Atom* i)
192{
193 return (const uint8_t*)i >= ((const uint8_t*)body + size);
194}
195
197static inline LV2_Atom*
199{
200 return (LV2_Atom*)(
201 (const uint8_t*)i + sizeof(LV2_Atom) + lv2_atom_pad_size(i->size));
202}
203
216#define LV2_ATOM_TUPLE_FOREACH(tuple, iter) \
217 for (LV2_Atom* (iter) = lv2_atom_tuple_begin(tuple); \
218 !lv2_atom_tuple_is_end(LV2_ATOM_BODY(tuple), (tuple)->size, (iter)); \
219 (iter) = lv2_atom_tuple_next(iter))
220
222#define LV2_ATOM_TUPLE_BODY_FOREACH(body, size, iter) \
223 for (LV2_Atom* (iter) = (LV2_Atom*)body; \
224 !lv2_atom_tuple_is_end(body, size, (iter)); \
225 (iter) = lv2_atom_tuple_next(iter))
226
232
234static inline LV2_Atom_Property_Body*
236{
237 return (LV2_Atom_Property_Body*)(body + 1);
238}
239
241static inline bool
245{
246 return (const uint8_t*)i >= ((const uint8_t*)body + size);
247}
248
250static inline LV2_Atom_Property_Body*
252{
253 const LV2_Atom* const value = (const LV2_Atom*)(
254 (const uint8_t*)i + 2 * sizeof(uint32_t));
255 return (LV2_Atom_Property_Body*)(
256 (const uint8_t*)i + lv2_atom_pad_size(
257 (uint32_t)sizeof(LV2_Atom_Property_Body) + value->size));
258}
259
272#define LV2_ATOM_OBJECT_FOREACH(obj, iter) \
273 for (LV2_Atom_Property_Body* (iter) = lv2_atom_object_begin(&(obj)->body); \
274 !lv2_atom_object_is_end(&(obj)->body, (obj)->atom.size, (iter)); \
275 (iter) = lv2_atom_object_next(iter))
276
278#define LV2_ATOM_OBJECT_BODY_FOREACH(body, size, iter) \
279 for (LV2_Atom_Property_Body* (iter) = lv2_atom_object_begin(body); \
280 !lv2_atom_object_is_end(body, size, (iter)); \
281 (iter) = lv2_atom_object_next(iter))
282
288
290typedef struct {
291 uint32_t key;
292 const LV2_Atom** value;
294
296
322static inline int
325{
326 int matches = 0;
327 int n_queries = 0;
328
329 /* Count number of query keys so we can short-circuit when done */
330 for (LV2_Atom_Object_Query* q = query; q->key; ++q) {
331 ++n_queries;
332 }
333
334 LV2_ATOM_OBJECT_FOREACH(object, prop) {
335 for (LV2_Atom_Object_Query* q = query; q->key; ++q) {
336 if (q->key == prop->key && !*q->value) {
337 *q->value = &prop->value;
338 if (++matches == n_queries) {
339 return matches;
340 }
341 break;
342 }
343 }
344 }
345 return matches;
346}
347
351static inline int
353{
354 int matches = 0;
355 int n_queries = 0;
356
357 /* Count number of keys so we can short-circuit when done */
358 va_list args;
359 va_start(args, body);
360 for (n_queries = 0; va_arg(args, uint32_t); ++n_queries) {
361 if (!va_arg(args, const LV2_Atom**)) {
362 return -1;
363 }
364 }
365 va_end(args);
366
368 va_start(args, body);
369 for (int i = 0; i < n_queries; ++i) {
370 uint32_t qkey = va_arg(args, uint32_t);
371 const LV2_Atom** qval = va_arg(args, const LV2_Atom**);
372 if (qkey == prop->key && !*qval) {
373 *qval = &prop->value;
374 if (++matches == n_queries) {
375 return matches;
376 }
377 break;
378 }
379 }
380 va_end(args);
381 }
382 return matches;
383}
384
404static inline int
406{
407 int matches = 0;
408 int n_queries = 0;
409
410 /* Count number of keys so we can short-circuit when done */
411 va_list args;
412 va_start(args, object);
413 for (n_queries = 0; va_arg(args, uint32_t); ++n_queries) {
414 if (!va_arg(args, const LV2_Atom**)) {
415 return -1;
416 }
417 }
418 va_end(args);
419
420 LV2_ATOM_OBJECT_FOREACH(object, prop) {
421 va_start(args, object);
422 for (int i = 0; i < n_queries; ++i) {
423 uint32_t qkey = va_arg(args, uint32_t);
424 const LV2_Atom** qval = va_arg(args, const LV2_Atom**);
425 if (qkey == prop->key && !*qval) {
426 *qval = &prop->value;
427 if (++matches == n_queries) {
428 return matches;
429 }
430 break;
431 }
432 }
433 va_end(args);
434 }
435 return matches;
436}
437
441
442#ifdef __cplusplus
443} /* extern "C" */
444#endif
445
446#endif /* LV2_ATOM_UTIL_H */
#define NULL
Definition CarlaBridgeFormat.cpp:30
uint8_t a
Definition Spc_Cpu.h:141
* e
Definition inflate.c:1404
register unsigned i
Definition inflate.c:1575
#define LV2_ATOM_BODY(atom)
Definition atom.h:98
static PuglViewHint int value
Definition pugl.h:1708
static const LV2_Atom_Object_Query LV2_ATOM_OBJECT_QUERY_END
Definition atom-util.h:308
static LV2_Atom_Event * lv2_atom_sequence_begin(const LV2_Atom_Sequence_Body *body)
Definition lv2_atom_util.h:77
#define LV2_ATOM_OBJECT_BODY_FOREACH(body, size, iter)
Definition lv2_atom_util.h:278
static bool lv2_atom_equals(const LV2_Atom *a, const LV2_Atom *b)
Definition lv2_atom_util.h:63
static bool lv2_atom_is_null(const LV2_Atom *atom)
Definition lv2_atom_util.h:56
static uint32_t lv2_atom_pad_size(uint32_t size)
Definition lv2_atom_util.h:42
static void lv2_atom_sequence_clear(LV2_Atom_Sequence *seq)
Definition lv2_atom_util.h:142
static LV2_Atom_Property_Body * lv2_atom_object_begin(const LV2_Atom_Object_Body *body)
Definition lv2_atom_util.h:235
static int lv2_atom_object_body_get(uint32_t size, const LV2_Atom_Object_Body *body,...)
Definition lv2_atom_util.h:352
static bool lv2_atom_sequence_is_end(const LV2_Atom_Sequence_Body *body, uint32_t size, const LV2_Atom_Event *i)
Definition lv2_atom_util.h:91
static bool lv2_atom_object_is_end(const LV2_Atom_Object_Body *body, uint32_t size, const LV2_Atom_Property_Body *i)
Definition lv2_atom_util.h:242
static LV2_Atom * lv2_atom_tuple_next(const LV2_Atom *i)
Definition lv2_atom_util.h:198
#define LV2_ATOM_OBJECT_FOREACH(obj, iter)
Definition lv2_atom_util.h:272
static LV2_Atom_Property_Body * lv2_atom_object_next(const LV2_Atom_Property_Body *i)
Definition lv2_atom_util.h:251
static uint32_t lv2_atom_total_size(const LV2_Atom *atom)
Definition lv2_atom_util.h:49
static int lv2_atom_object_get(const LV2_Atom_Object *object,...)
Definition lv2_atom_util.h:405
static LV2_Atom_Event * lv2_atom_sequence_append_event(LV2_Atom_Sequence *seq, uint32_t capacity, const LV2_Atom_Event *event)
Definition lv2_atom_util.h:159
static int lv2_atom_object_query(const LV2_Atom_Object *object, LV2_Atom_Object_Query *query)
Definition lv2_atom_util.h:323
static LV2_Atom * lv2_atom_tuple_begin(const LV2_Atom_Tuple *tup)
Definition lv2_atom_util.h:184
static LV2_Atom_Event * lv2_atom_sequence_end(const LV2_Atom_Sequence_Body *body, uint32_t size)
Definition lv2_atom_util.h:84
static bool lv2_atom_tuple_is_end(const void *body, uint32_t size, const LV2_Atom *i)
Definition lv2_atom_util.h:191
static LV2_Atom_Event * lv2_atom_sequence_next(const LV2_Atom_Event *i)
Definition lv2_atom_util.h:100
unsigned int uint32_t
Definition mid.cpp:100
unsigned char uint8_t
Definition mid.cpp:98
Definition atom.h:210
Definition atom.h:197
Definition atom-util.h:303
Definition atom.h:204
Definition atom.h:183
Definition atom.h:236
Definition atom.h:243
LV2_Atom atom
Definition atom.h:244
LV2_Atom_Sequence_Body body
Definition atom.h:245
Definition atom.h:164
Definition atom.h:106
uint32_t size
Definition atom.h:107
uint32_t type
Definition atom.h:108
memcpy(hh, h, RAND_HEAD_LEN)
ZCONST char * key
Definition crypt.c:587
b
Definition crypt.c:628
int query
Definition extract.c:1035
ulg size
Definition extract.c:2350
register uch * q
Definition fileio.c:817