mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-04 13:30:08 -05:00
control: add snd_ctl_elem_id_compare_numid() function
Idea for the function prototype by Takashi Sakamoto. Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
6f4b96ecc9
commit
83e4c1ab77
2 changed files with 27 additions and 0 deletions
|
|
@ -424,6 +424,7 @@ int snd_ctl_elem_id_malloc(snd_ctl_elem_id_t **ptr);
|
||||||
void snd_ctl_elem_id_free(snd_ctl_elem_id_t *obj);
|
void snd_ctl_elem_id_free(snd_ctl_elem_id_t *obj);
|
||||||
void snd_ctl_elem_id_clear(snd_ctl_elem_id_t *obj);
|
void snd_ctl_elem_id_clear(snd_ctl_elem_id_t *obj);
|
||||||
void snd_ctl_elem_id_copy(snd_ctl_elem_id_t *dst, const snd_ctl_elem_id_t *src);
|
void snd_ctl_elem_id_copy(snd_ctl_elem_id_t *dst, const snd_ctl_elem_id_t *src);
|
||||||
|
int snd_ctl_elem_id_compare_numid(const snd_ctl_elem_id_t *id1, const snd_ctl_elem_id_t *id2);
|
||||||
int snd_ctl_elem_id_compare_set(const snd_ctl_elem_id_t *id1, const snd_ctl_elem_id_t *id2);
|
int snd_ctl_elem_id_compare_set(const snd_ctl_elem_id_t *id1, const snd_ctl_elem_id_t *id2);
|
||||||
unsigned int snd_ctl_elem_id_get_numid(const snd_ctl_elem_id_t *obj);
|
unsigned int snd_ctl_elem_id_get_numid(const snd_ctl_elem_id_t *obj);
|
||||||
snd_ctl_elem_iface_t snd_ctl_elem_id_get_interface(const snd_ctl_elem_id_t *obj);
|
snd_ctl_elem_iface_t snd_ctl_elem_id_get_interface(const snd_ctl_elem_id_t *obj);
|
||||||
|
|
|
||||||
|
|
@ -1819,6 +1819,32 @@ void snd_ctl_elem_id_copy(snd_ctl_elem_id_t *dst, const snd_ctl_elem_id_t *src)
|
||||||
*dst = *src;
|
*dst = *src;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief compare one #snd_ctl_elem_id_t to another using numid
|
||||||
|
* \param id1 pointer to first id
|
||||||
|
* \param id2 pointer to second id
|
||||||
|
* \retval zero when values are identical, other value on a difference (like strcmp)
|
||||||
|
*
|
||||||
|
* This comparison ignores the set of fields part.
|
||||||
|
*
|
||||||
|
* The return value can be used for sorting like qsort(). It gives persistent
|
||||||
|
* results.
|
||||||
|
*/
|
||||||
|
int snd_ctl_elem_id_compare_numid(const snd_ctl_elem_id_t *id1, const snd_ctl_elem_id_t *id2)
|
||||||
|
{
|
||||||
|
int64_t d;
|
||||||
|
|
||||||
|
assert(id1 && id2);
|
||||||
|
d = (int64_t)id1->numid - (int64_t)id2->numid;
|
||||||
|
if (d & ((int64_t)INT_MAX + 1)) { /* fast path */
|
||||||
|
if (d > INT_MAX)
|
||||||
|
d = INT_MAX;
|
||||||
|
else if (d < INT_MIN)
|
||||||
|
d = INT_MIN;
|
||||||
|
}
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief compare one #snd_ctl_elem_id_t to another
|
* \brief compare one #snd_ctl_elem_id_t to another
|
||||||
* \param id1 pointer to first id
|
* \param id1 pointer to first id
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue