Skip to content

Commit eaaf539

Browse files
committed
Add _cmp_ helper for urational attributes
1 parent 4798c26 commit eaaf539

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

include/upipe/uref_attr.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (C) 2012-2016 OpenHeadend S.A.R.L.
3+
* Copyright (C) 2026 EasyTools
34
*
45
* Authors: Christophe Massiot
56
*
@@ -2187,6 +2188,24 @@ static inline int uref_##group##_copy_##attr(struct uref *uref, \
21872188
{ \
21882189
return uref_attr_copy_rational(uref, uref_src, UDICT_TYPE_RATIONAL, \
21892190
name); \
2191+
} \
2192+
/** @This compares the desc attribute in two urefs. \
2193+
* \
2194+
* @param uref1 pointer to the first uref \
2195+
* @param uref2 pointer to the second uref \
2196+
* @return 0 if both attributes are absent or identical \
2197+
*/ \
2198+
static inline int \
2199+
uref_##group##_cmp_##attr(struct uref *uref1, struct uref *uref2) \
2200+
{ \
2201+
struct urational v1, v2; \
2202+
int err1 = uref_##group##_get_##attr(uref1, &v1); \
2203+
int err2 = uref_##group##_get_##attr(uref2, &v2); \
2204+
if (!ubase_check(err1) && !ubase_check(err2)) \
2205+
return 0; \
2206+
if (!ubase_check(err1) || !ubase_check(err2)) \
2207+
return -1; \
2208+
return urational_cmp(&v1, &v2); \
21902209
}
21912210

21922211
/* @This allows to define accessors for a shorthand rational attribute.
@@ -2238,6 +2257,24 @@ static inline int uref_##group##_copy_##attr(struct uref *uref, \
22382257
struct uref *uref_src) \
22392258
{ \
22402259
return uref_attr_copy_rational(uref, uref_src, type, NULL); \
2260+
} \
2261+
/** @This compares the desc attribute in two urefs. \
2262+
* \
2263+
* @param uref1 pointer to the first uref \
2264+
* @param uref2 pointer to the second uref \
2265+
* @return 0 if both attributes are absent or identical \
2266+
*/ \
2267+
static inline int \
2268+
uref_##group##_cmp_##attr(struct uref *uref1, struct uref *uref2) \
2269+
{ \
2270+
struct urational v1, v2; \
2271+
int err1 = uref_##group##_get_##attr(uref1, &v1); \
2272+
int err2 = uref_##group##_get_##attr(uref2, &v2); \
2273+
if (!ubase_check(err1) && !ubase_check(err2)) \
2274+
return 0; \
2275+
if (!ubase_check(err1) || !ubase_check(err2)) \
2276+
return -1; \
2277+
return urational_cmp(&v1, &v2); \
22412278
}
22422279

22432280
/* @This allows to define accessors for a rational attribute, with a name

0 commit comments

Comments
 (0)