LMMS
Loading...
Searching...
No Matches
atom-util.h
Go to the documentation of this file.
1/*
2 Copyright 2008-2015 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
30
31#ifndef LV2_ATOM_UTIL_H
32#define LV2_ATOM_UTIL_H
33
34#include <stdarg.h>
35#include <stdint.h>
36#include <string.h>
37
38#include "atom.h"
39
40#ifdef __cplusplus
41extern "C" {
42#else
43# include <stdbool.h>
44#endif
45
47static inline uint32_t
49{
50 return (size + 7U) & (~7U);
51}
52
54static inline uint32_t
56{
57 return (uint32_t)sizeof(LV2_Atom) + atom->size;
58}
59
61static inline bool
63{
64 return !atom || (atom->type == 0 && atom->size == 0);
65}
66
68static inline bool
70{
71 return (a == b) || ((a->type == b->type) &&
72 (a->size == b->size) &&
73 !memcmp(a + 1, b + 1, a->size));
74}
75
80
82static inline const LV2_Atom_Event*
84{
85 return (const LV2_Atom_Event*)(body + 1);
86}
87
89static inline const LV2_Atom_Event*
91{
92 return (const LV2_Atom_Event*)((const uint8_t*)body + lv2_atom_pad_size(size));
93}
94
96static inline LV2_Atom_Event*
101
103static inline bool
106 const LV2_Atom_Event* i)
107{
108 return (const uint8_t*)i >= ((const uint8_t*)body + size);
109}
110
112static inline const LV2_Atom_Event*
114{
115 return (const LV2_Atom_Event*)((const uint8_t*)i
116 + sizeof(LV2_Atom_Event)
117 + lv2_atom_pad_size(i->body.size));
118}
119
132#define LV2_ATOM_SEQUENCE_FOREACH(seq, iter) \
133 for (const LV2_Atom_Event* iter = lv2_atom_sequence_begin(&(seq)->body); \
134 !lv2_atom_sequence_is_end(&(seq)->body, (seq)->atom.size, (iter)); \
135 iter = lv2_atom_sequence_next(iter))
136
138#define LV2_ATOM_SEQUENCE_BODY_FOREACH(body, size, iter) \
139 for (const LV2_Atom_Event* iter = lv2_atom_sequence_begin(body); \
140 !lv2_atom_sequence_is_end(body, size, (iter)); \
141 iter = lv2_atom_sequence_next(iter))
142
148
154static inline void
159
171static inline LV2_Atom_Event*
173 uint32_t capacity,
174 const LV2_Atom_Event* event)
175{
176 const uint32_t total_size = (uint32_t)sizeof(*event) + event->body.size;
177 if (capacity - seq->atom.size < total_size) {
178 return NULL;
179 }
180
182 memcpy(e, event, total_size);
183
184 seq->atom.size += lv2_atom_pad_size(total_size);
185
186 return e;
187}
188
194
196static inline const LV2_Atom*
198{
199 return (const LV2_Atom*)(LV2_ATOM_BODY_CONST(tup));
200}
201
203static inline bool
204lv2_atom_tuple_is_end(const void* body, uint32_t size, const LV2_Atom* i)
205{
206 return (const uint8_t*)i >= ((const uint8_t*)body + size);
207}
208
210static inline const LV2_Atom*
212{
213 return (const LV2_Atom*)(
214 (const uint8_t*)i + sizeof(LV2_Atom) + lv2_atom_pad_size(i->size));
215}
216
229#define LV2_ATOM_TUPLE_FOREACH(tuple, iter) \
230 for (const LV2_Atom* iter = lv2_atom_tuple_begin(tuple); \
231 !lv2_atom_tuple_is_end(LV2_ATOM_BODY_CONST(tuple), (tuple)->atom.size, (iter)); \
232 iter = lv2_atom_tuple_next(iter))
233
235#define LV2_ATOM_TUPLE_BODY_FOREACH(body, size, iter) \
236 for (const LV2_Atom* iter = (const LV2_Atom*)body; \
237 !lv2_atom_tuple_is_end(body, size, (iter)); \
238 iter = lv2_atom_tuple_next(iter))
239
245
247static inline const LV2_Atom_Property_Body*
249{
250 return (const LV2_Atom_Property_Body*)(body + 1);
251}
252
254static inline bool
258{
259 return (const uint8_t*)i >= ((const uint8_t*)body + size);
260}
261
263static inline const LV2_Atom_Property_Body*
265{
266 const LV2_Atom* const value = (const LV2_Atom*)(
267 (const uint8_t*)i + 2 * sizeof(uint32_t));
268 return (const LV2_Atom_Property_Body*)(
269 (const uint8_t*)i + lv2_atom_pad_size(
270 (uint32_t)sizeof(LV2_Atom_Property_Body) + value->size));
271}
272
285#define LV2_ATOM_OBJECT_FOREACH(obj, iter) \
286 for (const LV2_Atom_Property_Body* iter = lv2_atom_object_begin(&(obj)->body); \
287 !lv2_atom_object_is_end(&(obj)->body, (obj)->atom.size, (iter)); \
288 iter = lv2_atom_object_next(iter))
289
291#define LV2_ATOM_OBJECT_BODY_FOREACH(body, size, iter) \
292 for (const LV2_Atom_Property_Body* iter = lv2_atom_object_begin(body); \
293 !lv2_atom_object_is_end(body, size, (iter)); \
294 iter = lv2_atom_object_next(iter))
295
301
303typedef struct {
305 const LV2_Atom** value;
307
309
335static inline int
338{
339 int matches = 0;
340 int n_queries = 0;
341
342 /* Count number of query keys so we can short-circuit when done */
343 for (LV2_Atom_Object_Query* q = query; q->key; ++q) {
344 ++n_queries;
345 }
346
347 LV2_ATOM_OBJECT_FOREACH(object, prop) {
348 for (LV2_Atom_Object_Query* q = query; q->key; ++q) {
349 if (q->key == prop->key && !*q->value) {
350 *q->value = &prop->value;
351 if (++matches == n_queries) {
352 return matches;
353 }
354 break;
355 }
356 }
357 }
358 return matches;
359}
360
364static inline int
366{
367 int matches = 0;
368 int n_queries = 0;
369
370 /* Count number of keys so we can short-circuit when done */
371 va_list args;
372 va_start(args, body);
373 for (n_queries = 0; va_arg(args, uint32_t); ++n_queries) {
374 if (!va_arg(args, const LV2_Atom**)) {
375 va_end(args);
376 return -1;
377 }
378 }
379 va_end(args);
380
382 va_start(args, body);
383 for (int i = 0; i < n_queries; ++i) {
384 uint32_t qkey = va_arg(args, uint32_t);
385 const LV2_Atom** qval = va_arg(args, const LV2_Atom**);
386 if (qkey == prop->key && !*qval) {
387 *qval = &prop->value;
388 if (++matches == n_queries) {
389 va_end(args);
390 return matches;
391 }
392 break;
393 }
394 }
395 va_end(args);
396 }
397 return matches;
398}
399
419static inline int
421{
422 int matches = 0;
423 int n_queries = 0;
424
425 /* Count number of keys so we can short-circuit when done */
426 va_list args;
427 va_start(args, object);
428 for (n_queries = 0; va_arg(args, uint32_t); ++n_queries) {
429 if (!va_arg(args, const LV2_Atom**)) {
430 return -1;
431 }
432 }
433 va_end(args);
434
435 LV2_ATOM_OBJECT_FOREACH(object, prop) {
436 va_start(args, object);
437 for (int i = 0; i < n_queries; ++i) {
438 uint32_t qkey = va_arg(args, uint32_t);
439 const LV2_Atom** qval = va_arg(args, const LV2_Atom**);
440 if (qkey == prop->key && !*qval) {
441 *qval = &prop->value;
442 if (++matches == n_queries) {
443 return matches;
444 }
445 break;
446 }
447 }
448 va_end(args);
449 }
450 return matches;
451}
452
473static inline int
475{
476 int matches = 0;
477 int n_queries = 0;
478
479 /* Count number of keys so we can short-circuit when done */
480 va_list args;
481 va_start(args, object);
482 for (n_queries = 0; va_arg(args, uint32_t); ++n_queries) {
483 if (!va_arg(args, const LV2_Atom**) ||
484 !va_arg(args, uint32_t)) {
485 return -1;
486 }
487 }
488 va_end(args);
489
490 LV2_ATOM_OBJECT_FOREACH(object, prop) {
491 va_start(args, object);
492 for (int i = 0; i < n_queries; ++i) {
493 const uint32_t qkey = va_arg(args, uint32_t);
494 const LV2_Atom** qval = va_arg(args, const LV2_Atom**);
495 const uint32_t qtype = va_arg(args, uint32_t);
496 if (!*qval && qkey == prop->key && qtype == prop->value.type) {
497 *qval = &prop->value;
498 if (++matches == n_queries) {
499 return matches;
500 }
501 break;
502 }
503 }
504 va_end(args);
505 }
506 return matches;
507}
508
513
514#ifdef __cplusplus
515} /* extern "C" */
516#endif
517
518#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_CONST(atom)
Definition atom.h:103
static PuglViewHint int value
Definition pugl.h:1708
#define LV2_ATOM_OBJECT_BODY_FOREACH(body, size, iter)
Definition atom-util.h:291
static const LV2_Atom_Event * lv2_atom_sequence_next(const LV2_Atom_Event *i)
Definition atom-util.h:113
static const LV2_Atom_Event * lv2_atom_sequence_begin(const LV2_Atom_Sequence_Body *body)
Definition atom-util.h:83
static bool lv2_atom_equals(const LV2_Atom *a, const LV2_Atom *b)
Definition atom-util.h:69
static const LV2_Atom_Property_Body * lv2_atom_object_begin(const LV2_Atom_Object_Body *body)
Definition atom-util.h:248
static bool lv2_atom_is_null(const LV2_Atom *atom)
Definition atom-util.h:62
static uint32_t lv2_atom_pad_size(uint32_t size)
Definition atom-util.h:48
static void lv2_atom_sequence_clear(LV2_Atom_Sequence *seq)
Definition atom-util.h:155
static int lv2_atom_object_body_get(uint32_t size, const LV2_Atom_Object_Body *body,...)
Definition atom-util.h:365
static bool lv2_atom_sequence_is_end(const LV2_Atom_Sequence_Body *body, uint32_t size, const LV2_Atom_Event *i)
Definition atom-util.h:104
static const LV2_Atom_Object_Query LV2_ATOM_OBJECT_QUERY_END
Definition atom-util.h:308
static LV2_Atom_Event * lv2_atom_sequence_end2(LV2_Atom_Sequence_Body *body, uint32_t size)
Definition atom-util.h:97
static bool lv2_atom_object_is_end(const LV2_Atom_Object_Body *body, uint32_t size, const LV2_Atom_Property_Body *i)
Definition atom-util.h:255
static int lv2_atom_object_get_typed(const LV2_Atom_Object *object,...)
Definition atom-util.h:474
static const LV2_Atom_Event * lv2_atom_sequence_end(const LV2_Atom_Sequence_Body *body, uint32_t size)
Definition atom-util.h:90
#define LV2_ATOM_OBJECT_FOREACH(obj, iter)
Definition atom-util.h:285
static const LV2_Atom * lv2_atom_tuple_next(const LV2_Atom *i)
Definition atom-util.h:211
static uint32_t lv2_atom_total_size(const LV2_Atom *atom)
Definition atom-util.h:55
static int lv2_atom_object_get(const LV2_Atom_Object *object,...)
Definition atom-util.h:420
static LV2_Atom_Event * lv2_atom_sequence_append_event(LV2_Atom_Sequence *seq, uint32_t capacity, const LV2_Atom_Event *event)
Definition atom-util.h:172
static int lv2_atom_object_query(const LV2_Atom_Object *object, LV2_Atom_Object_Query *query)
Definition atom-util.h:336
static const LV2_Atom_Property_Body * lv2_atom_object_next(const LV2_Atom_Property_Body *i)
Definition atom-util.h:264
static const LV2_Atom * lv2_atom_tuple_begin(const LV2_Atom_Tuple *tup)
Definition atom-util.h:197
static bool lv2_atom_tuple_is_end(const void *body, uint32_t size, const LV2_Atom *i)
Definition atom-util.h:204
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
uint32_t key
Definition atom-util.h:304
const LV2_Atom ** value
Definition atom-util.h:305
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)
b
Definition crypt.c:628
int query
Definition extract.c:1035
ulg size
Definition extract.c:2350
register uch * q
Definition fileio.c:817