aboutsummaryrefslogtreecommitdiffstats
path: root/include/lv2/atom/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/lv2/atom/util.h')
-rw-r--r--include/lv2/atom/util.h62
1 files changed, 33 insertions, 29 deletions
diff --git a/include/lv2/atom/util.h b/include/lv2/atom/util.h
index f585f82..9a3d8a3 100644
--- a/include/lv2/atom/util.h
+++ b/include/lv2/atom/util.h
@@ -1,4 +1,4 @@
-// Copyright 2008-2015 David Robillard <d@drobilla.net>
+// Copyright 2008-2024 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
#ifndef LV2_ATOM_UTIL_H
@@ -13,7 +13,7 @@
*/
/**
- @defgroup util Utilities
+ @defgroup atom_util Utilities
@ingroup atom
Utilities for working with atoms.
@@ -21,13 +21,15 @@
@{
*/
-#include "lv2/atom/atom.h"
+#include <lv2/atom/atom.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
+// NOLINTBEGIN(bugprone-macro-parentheses)
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -36,7 +38,9 @@ extern "C" {
static inline uint32_t
lv2_atom_pad_size(uint32_t size)
{
- return (size + 7U) & (~7U);
+ static const uint32_t mask = 7U;
+
+ return (size + mask) & ~mask;
}
/** Return the total size of `atom`, including the header. */
@@ -57,8 +61,7 @@ lv2_atom_is_null(const LV2_Atom* atom)
static inline bool
lv2_atom_equals(const LV2_Atom* a, const LV2_Atom* b)
{
- return (a == b) || ((a->type == b->type) && (a->size == b->size) &&
- !memcmp(a + 1, b + 1, a->size));
+ return (a == b) || !memcmp(a, b, sizeof(LV2_Atom) + a->size);
}
/**
@@ -112,14 +115,14 @@ lv2_atom_sequence_next(const LV2_Atom_Event* i)
@endcode
*/
#define LV2_ATOM_SEQUENCE_FOREACH(seq, iter) \
- for (LV2_Atom_Event * iter = lv2_atom_sequence_begin(&(seq)->body); \
+ for (LV2_Atom_Event* iter = lv2_atom_sequence_begin(&(seq)->body); \
!lv2_atom_sequence_is_end(&(seq)->body, (seq)->atom.size, (iter)); \
(iter) = lv2_atom_sequence_next(iter))
/** Like LV2_ATOM_SEQUENCE_FOREACH but for a headerless sequence body. */
-#define LV2_ATOM_SEQUENCE_BODY_FOREACH(body, size, iter) \
- for (LV2_Atom_Event * iter = lv2_atom_sequence_begin(body); \
- !lv2_atom_sequence_is_end(body, size, (iter)); \
+#define LV2_ATOM_SEQUENCE_BODY_FOREACH(body, size, iter) \
+ for (LV2_Atom_Event* iter = lv2_atom_sequence_begin(body); \
+ !lv2_atom_sequence_is_end(body, size, (iter)); \
(iter) = lv2_atom_sequence_next(iter))
/**
@@ -178,7 +181,7 @@ lv2_atom_sequence_append_event(LV2_Atom_Sequence* seq,
static inline LV2_Atom*
lv2_atom_tuple_begin(const LV2_Atom_Tuple* tup)
{
- return (LV2_Atom*)(LV2_ATOM_BODY(tup));
+ return (LV2_Atom*)tup + 1U;
}
/** Return true iff `i` has reached the end of `body`. */
@@ -210,15 +213,14 @@ lv2_atom_tuple_next(const LV2_Atom* i)
}
@endcode
*/
-#define LV2_ATOM_TUPLE_FOREACH(tuple, iter) \
- for (LV2_Atom * iter = lv2_atom_tuple_begin(tuple); \
- !lv2_atom_tuple_is_end( \
- LV2_ATOM_BODY(tuple), (tuple)->atom.size, (iter)); \
+#define LV2_ATOM_TUPLE_FOREACH(tuple, iter) \
+ for (LV2_Atom* iter = lv2_atom_tuple_begin(tuple); !lv2_atom_tuple_is_end( \
+ LV2_ATOM_BODY(tuple), (tuple)->atom.size, (iter)); \
(iter) = lv2_atom_tuple_next(iter))
/** Like LV2_ATOM_TUPLE_FOREACH but for a headerless tuple body. */
#define LV2_ATOM_TUPLE_BODY_FOREACH(body, size, iter) \
- for (LV2_Atom * iter = (LV2_Atom*)(body); \
+ for (LV2_Atom* iter = (LV2_Atom*)(body); \
!lv2_atom_tuple_is_end(body, size, (iter)); \
(iter) = lv2_atom_tuple_next(iter))
@@ -249,7 +251,7 @@ static inline LV2_Atom_Property_Body*
lv2_atom_object_next(const LV2_Atom_Property_Body* i)
{
const LV2_Atom* const value =
- (const LV2_Atom*)((const uint8_t*)i + 2 * sizeof(uint32_t));
+ (const LV2_Atom*)((const uint8_t*)i + (2 * sizeof(uint32_t)));
return (LV2_Atom_Property_Body*)((const uint8_t*)i +
lv2_atom_pad_size(
(uint32_t)sizeof(LV2_Atom_Property_Body) +
@@ -270,15 +272,15 @@ lv2_atom_object_next(const LV2_Atom_Property_Body* i)
}
@endcode
*/
-#define LV2_ATOM_OBJECT_FOREACH(obj, iter) \
- for (LV2_Atom_Property_Body * iter = lv2_atom_object_begin(&(obj)->body); \
- !lv2_atom_object_is_end(&(obj)->body, (obj)->atom.size, (iter)); \
+#define LV2_ATOM_OBJECT_FOREACH(obj, iter) \
+ for (LV2_Atom_Property_Body* iter = lv2_atom_object_begin(&(obj)->body); \
+ !lv2_atom_object_is_end(&(obj)->body, (obj)->atom.size, (iter)); \
(iter) = lv2_atom_object_next(iter))
/** Like LV2_ATOM_OBJECT_FOREACH but for a headerless object body. */
-#define LV2_ATOM_OBJECT_BODY_FOREACH(body, size, iter) \
- for (LV2_Atom_Property_Body * iter = lv2_atom_object_begin(body); \
- !lv2_atom_object_is_end(body, size, (iter)); \
+#define LV2_ATOM_OBJECT_BODY_FOREACH(body, size, iter) \
+ for (LV2_Atom_Property_Body* iter = lv2_atom_object_begin(body); \
+ !lv2_atom_object_is_end(body, size, (iter)); \
(iter) = lv2_atom_object_next(iter))
/**
@@ -357,7 +359,7 @@ lv2_atom_object_body_get(uint32_t size, const LV2_Atom_Object_Body* body, ...)
int n_queries = 0;
/* Count number of keys so we can short-circuit when done */
- va_list args;
+ va_list args; // NOLINT(cppcoreguidelines-init-variables)
va_start(args, body);
for (n_queries = 0; va_arg(args, uint32_t); ++n_queries) {
if (!va_arg(args, const LV2_Atom**)) {
@@ -370,7 +372,7 @@ lv2_atom_object_body_get(uint32_t size, const LV2_Atom_Object_Body* body, ...)
LV2_ATOM_OBJECT_BODY_FOREACH (body, size, prop) {
va_start(args, body);
for (int i = 0; i < n_queries; ++i) {
- uint32_t qkey = va_arg(args, uint32_t);
+ const uint32_t qkey = va_arg(args, uint32_t);
const LV2_Atom** qval = va_arg(args, const LV2_Atom**);
if (qkey == prop->key && !*qval) {
*qval = &prop->value;
@@ -412,7 +414,7 @@ lv2_atom_object_get(const LV2_Atom_Object* object, ...)
int n_queries = 0;
/* Count number of keys so we can short-circuit when done */
- va_list args;
+ va_list args; // NOLINT(cppcoreguidelines-init-variables)
va_start(args, object);
for (n_queries = 0; va_arg(args, uint32_t); ++n_queries) {
if (!va_arg(args, const LV2_Atom**)) {
@@ -425,7 +427,7 @@ lv2_atom_object_get(const LV2_Atom_Object* object, ...)
LV2_ATOM_OBJECT_FOREACH (object, prop) {
va_start(args, object);
for (int i = 0; i < n_queries; ++i) {
- uint32_t qkey = va_arg(args, uint32_t);
+ const uint32_t qkey = va_arg(args, uint32_t);
const LV2_Atom** qval = va_arg(args, const LV2_Atom**);
if (qkey == prop->key && !*qval) {
*qval = &prop->value;
@@ -468,7 +470,7 @@ lv2_atom_object_get_typed(const LV2_Atom_Object* object, ...)
int n_queries = 0;
/* Count number of keys so we can short-circuit when done */
- va_list args;
+ va_list args; // NOLINT(cppcoreguidelines-init-variables)
va_start(args, object);
for (n_queries = 0; va_arg(args, uint32_t); ++n_queries) {
if (!va_arg(args, const LV2_Atom**) || !va_arg(args, uint32_t)) {
@@ -502,9 +504,11 @@ lv2_atom_object_get_typed(const LV2_Atom_Object* object, ...)
} /* extern "C" */
#endif
+// NOLINTEND(bugprone-macro-parentheses)
+
/**
@}
@}
*/
-#endif /* LV2_ATOM_UTIL_H */
+#endif // LV2_ATOM_UTIL_H