diff options
Diffstat (limited to 'mbglib/common/mbgklist.h')
-rw-r--r-- | mbglib/common/mbgklist.h | 103 |
1 files changed, 91 insertions, 12 deletions
diff --git a/mbglib/common/mbgklist.h b/mbglib/common/mbgklist.h index 16f3440..88c9cac 100644 --- a/mbglib/common/mbgklist.h +++ b/mbglib/common/mbgklist.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbgklist.h 1.4 2018/09/13 05:27:28Z thomas-b REL_M $ + * $Id: mbgklist.h 1.6 2021/08/05 15:05:27Z martin REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,7 +10,14 @@ * * ----------------------------------------------------------------------- * $Log: mbgklist.h $ - * Revision 1.4 2018/09/13 05:27:28Z thomas-b + * Revision 1.6 2021/08/05 15:05:27Z martin + * New typedef MBG_KLIST_HEAD for struct mbg_klist_head. + * New functions mbg_klist_insert_after() and mbg_klist_insert_before() + * provided by Philipp. + * Added some doxygen comments. + * Revision 1.5 2019/08/15 10:33:01 thomas-b + * Start variable names in macros with '_' + * Revision 1.4 2018/09/13 05:27:28 thomas-b * Added macro to get nth item of mbgklist * Revision 1.3 2017/07/05 09:52:39 martin * Safe loop macros added by philipp. @@ -70,8 +77,8 @@ extern "C" { #define mbg_klist_nth_item(head, pos, n) \ do { \ - unsigned i; \ - for (pos = (head)->next, i = 0; i < n; pos = pos->next, ++i); \ + unsigned _i; \ + for (pos = (head)->next, _i = 0; _i < n; pos = pos->next, ++_i); \ } while ( 0 ) #define mbg_klist_entry(ptr, type, member) \ @@ -119,12 +126,12 @@ extern "C" { -struct mbg_klist_head +typedef struct mbg_klist_head { struct mbg_klist_head *prev; struct mbg_klist_head *next; -}; +} MBG_KLIST_HEAD; static __mbg_inline @@ -145,6 +152,63 @@ void __mbg_klist_add_item( struct mbg_klist_head *item, struct mbg_klist_head *p } +/** + * @brief Insert a new list item after the item at the given position. + * + * The position of the list item referenced by @p head + * is left unchanged. + * + * This function is effectively the same as ::mbg_klist_prepend_item, + * the name of which is somewhat misleading. + * + * @param[in,out] head The item at a current list position. + * @param[in] item The item to be inserted. + * + * @see ::mbg_klist_insert_before + */ +static __mbg_inline +void mbg_klist_insert_after( struct mbg_klist_head *head, struct mbg_klist_head *item ) +{ + __mbg_klist_add_item( item, head, head->next ); +} + + +/** + * @brief Insert a new list item before the item at the given position. + * + * The position of the list item referenced by @p head + * is moved behind the new item. + * + * This function is effectively the same as ::mbg_klist_append_item, + * the name of which is somewhat misleading. + * + * @param[in,out] head The item at a current list position. + * @param[in] item The item to be inserted. + * + * @see ::mbg_klist_insert_after + */ +static __mbg_inline +void mbg_klist_insert_before( struct mbg_klist_head *head, struct mbg_klist_head *item ) +{ + __mbg_klist_add_item( item, head->prev, head ); +} + + +/** + * @brief Insert a new list item after the item at the given position. + * + * The position of the list item referenced by @p head + * is left unchanged. + * + * This function is effectively the same as ::mbg_klist_insert_after, + * and its name is somewhat misleading. + * + * @param[in,out] head The item at a current list position. + * @param[in] item The item to be inserted. + * + * @see ::mbg_klist_append_item + * @see ::mbg_klist_insert_after + */ static __mbg_inline void mbg_klist_prepend_item( struct mbg_klist_head *head, struct mbg_klist_head *item ) { @@ -152,6 +216,21 @@ void mbg_klist_prepend_item( struct mbg_klist_head *head, struct mbg_klist_head } +/** + * @brief Insert a new list item before the item at the given position. + * + * The position of the list item referenced by @p head + * is moved behind the new item. + * + * This is effectively the same as ::mbg_klist_insert_before, + * and its name is somewhat misleading. + * + * @param[in,out] head The item at a current list position. + * @param[in] item The item to be inserted. + * + * @see ::mbg_klist_prepend_item + * @see ::mbg_klist_insert_before + */ static __mbg_inline void mbg_klist_append_item( struct mbg_klist_head *head, struct mbg_klist_head *item ) { @@ -240,14 +319,14 @@ int mbg_klist_is_empty( const struct mbg_klist_head *head ) static __mbg_inline void __mbg_klist_add_list( const struct mbg_klist_head *list, struct mbg_klist_head *prev, struct mbg_klist_head *next ) { - struct mbg_klist_head *first = list->next; - struct mbg_klist_head *last = list->prev; + struct mbg_klist_head *_first = list->next; + struct mbg_klist_head *_last = list->prev; - first->prev = prev; - prev->next = first; + _first->prev = prev; + prev->next = _first; - last->next = next; - next->prev = last; + _last->next = next; + next->prev = _last; } |