X-Git-Url: https://git.auder.net/?p=cgds.git;a=blobdiff_plain;f=src%2FList.h;fp=src%2FList.h;h=6150d2bb466f2df365eb0832c8521efa396fb344;hp=0a36ea0177d55f0fa3056a87bd00fd78f7cd2f12;hb=e45132acdb58c076d5e06849fa51c26de9a7486d;hpb=1ff641f9960fa6c6081817a5641afb22fad91dcd diff --git a/src/List.h b/src/List.h index 0a36ea0..6150d2b 100644 --- a/src/List.h +++ b/src/List.h @@ -18,27 +18,27 @@ * @brief Cell of a double-linked list. */ typedef struct ListCell { - void* data; ///< Generic data contained in this cell. - struct ListCell* prev; ///< Pointer to previous cell in the list. - struct ListCell* next; ///< Pointer to next cell in the list. + void* data; ///< Generic data contained in this cell. + struct ListCell* prev; ///< Pointer to previous cell in the list. + struct ListCell* next; ///< Pointer to next cell in the list. } ListCell; /** * @brief Double-linked list data structure. */ typedef struct List { - UInt size; ///< Count elements in the list. - size_t dataSize; ///< Size of a list cell element in bytes. - ListCell* head; ///< Pointer to the first cell in the list. - ListCell* tail; ///< Pointer to the last cell in the list. + UInt size; ///< Count elements in the list. + size_t dataSize; ///< Size of a list cell element in bytes. + ListCell* head; ///< Pointer to the first cell in the list. + ListCell* tail; ///< Pointer to the last cell in the list. } List; /** * @brief Initialize an empty list. */ void _list_init( - List* list, ///< "this" pointer. - size_t dataSize ///< Size of a list cell elements in bytes. + List* list, ///< "this" pointer. + size_t dataSize ///< Size of a list cell elements in bytes. ); /** @@ -46,7 +46,7 @@ void _list_init( * @param dataSize Size in bytes of a list element. */ List* _list_new( - size_t dataSize ///< Size of a list cell elements in bytes. + size_t dataSize ///< Size of a list cell elements in bytes. ); /** @@ -56,34 +56,36 @@ List* _list_new( * Usage: List* list_new( type) */ #define list_new(type) \ - _list_new(sizeof(type)) +{ \ + _list_new(sizeof(type)); \ +} /** * @brief Copy constructor (shallow copy, ok for basic types). */ List* list_copy( - List* list ///< "this" pointer. + List* list ///< "this" pointer. ); /** * @brief Check if the list is empty. */ bool list_empty( - List* list ///< "this" pointer. + List* list ///< "this" pointer. ); /** * @brief return the size of current list. */ UInt list_size( - List* list ///< "this" pointer. + List* list ///< "this" pointer. ); /** * @brief Get data at the given list cell argument. */ void* _list_get( - ListCell* listCell ///< Pointer to a cell inside "this" list. + ListCell* listCell ///< Pointer to a cell inside "this" list. ); /** @@ -95,17 +97,17 @@ void* _list_get( */ #define list_get(listCell, data) \ { \ - void* pData = _list_get(listCell); \ - data = *((typeof(&data))pData); \ + void* pData = _list_get(listCell); \ + data = *((typeof(&data))pData); \ } /** * @brief Set data at the given list cell argument. */ void _list_set( - List* list, ///< "this" pointer. - ListCell* listCell, ///< Pointer to a cell inside "this" list. - void* data ///< Pointer to data to be set. + List* list, ///< "this" pointer. + ListCell* listCell, ///< Pointer to a cell inside "this" list. + void* data ///< Pointer to data to be set. ); /** @@ -118,25 +120,25 @@ void _list_set( */ #define list_set(list, listCell, data) \ { \ - typeof((data)) tmp = data; \ - _list_set(list, listCell, &tmp); \ + typeof((data)) tmp = data; \ + _list_set(list, listCell, &tmp); \ } /** * @brief Add data to the list when list is empty. */ void _list_insert_first_element( - List* list, ///< "this" pointer. - void* data ///< Pointer to data to be added + List* list, ///< "this" pointer. + void* data ///< Pointer to data to be added ); /** * @brief Add data before list cell argument. */ void _list_insert_before( - List* list, ///< "this" pointer. - ListCell* listCell, ///< Pointer to a cell inside "this" list. - void* data ///< Pointer to data to be added. + List* list, ///< "this" pointer. + ListCell* listCell, ///< Pointer to a cell inside "this" list. + void* data ///< Pointer to data to be added. ); /** @@ -149,17 +151,17 @@ void _list_insert_before( */ #define list_insert_before(list, listCell, data) \ { \ - typeof((data)) tmp = data; \ - _list_insert_before(list, listCell, &tmp); \ + typeof((data)) tmp = data; \ + _list_insert_before(list, listCell, &tmp); \ } /** * @brief Add data after list cell argument. */ void _list_insert_after( - List* list, ///< "this" pointer. - ListCell* listCell, ///< Pointer to a cell inside "this" list. - void* data ///< Pointer to data to be inserted. + List* list, ///< "this" pointer. + ListCell* listCell, ///< Pointer to a cell inside "this" list. + void* data ///< Pointer to data to be inserted. ); /** @@ -172,16 +174,16 @@ void _list_insert_after( */ #define list_insert_after(list, listCell, data) \ { \ - typeof((data)) tmp = data; \ - _list_insert_after(list, listCell, &tmp); \ + typeof((data)) tmp = data; \ + _list_insert_after(list, listCell, &tmp); \ } /** * @brief Add data at the beginning of the list. */ void _list_insert_front( - List* list, ///< "this" pointer. - void* data ///< Pointer to data to be inserted. + List* list, ///< "this" pointer. + void* data ///< Pointer to data to be inserted. ); /** @@ -193,16 +195,16 @@ void _list_insert_front( */ #define list_insert_front(list, data) \ { \ - typeof((data)) tmp = data; \ - _list_insert_front(list, &tmp); \ + typeof((data)) tmp = data; \ + _list_insert_front(list, &tmp); \ } /** * @brief Add data at the end of the list. */ void _list_insert_back( - List* list, ///< "this" pointer. - void* data ///< Pointer to data to be inserted. + List* list, ///< "this" pointer. + void* data ///< Pointer to data to be inserted. ); /** @@ -214,44 +216,44 @@ void _list_insert_back( */ #define list_insert_back(list, data) \ { \ - typeof((data)) tmp = data; \ - _list_insert_back(list, &tmp); \ + typeof((data)) tmp = data; \ + _list_insert_back(list, &tmp); \ } /** * @brief Remove data at position given by 'listCell'. */ void list_remove( - List* list, ///< "this" pointer. - ListCell* listCell ///< Pointer to a cell inside "this" list. + List* list, ///< "this" pointer. + ListCell* listCell ///< Pointer to a cell inside "this" list. ); /** * @brief Remove data at the beginning of the list. */ void list_remove_front( - List* list ///< "this" pointer. + List* list ///< "this" pointer. ); /** * @brief Remove data at the end of the list. */ void list_remove_back( - List* list ///< "this" pointer. + List* list ///< "this" pointer. ); /** * @brief Clear the entire list. */ void list_clear( - List* list ///< "this" pointer. + List* list ///< "this" pointer. ); /** * @brief Destroy the list: clear it, and free 'list' pointer. */ void list_destroy( - List* list ///< "this" pointer. + List* list ///< "this" pointer. ); //////////////////// @@ -262,36 +264,36 @@ void list_destroy( * @brief Iterator on a double-linked list. */ typedef struct ListIterator { - List* list; ///< The list to be iterate. - ListCell* current; ///< The current iterated list cell. + List* list; ///< The list to be iterate. + ListCell* current; ///< The current iterated list cell. } ListIterator; /** * @brief Obtain an iterator object, starting at list beginning. */ ListIterator* list_get_iterator( - List* list ///< Pointer to the list to be iterated over. + List* list ///< Pointer to the list to be iterated over. ); /** * @brief (Re)set current position inside list to head. */ void listI_reset_head( - ListIterator* listI ///< "this" pointer. + ListIterator* listI ///< "this" pointer. ); /** * @brief (Re)set current position inside list to tail. */ void listI_reset_tail( - ListIterator* listI ///< "this" pointer. + ListIterator* listI ///< "this" pointer. ); /** * @brief Tell if there is some data at the current index. */ bool listI_has_data( - ListIterator* listI ///< "this" pointer. + ListIterator* listI ///< "this" pointer. ); /** @@ -302,7 +304,7 @@ bool listI_has_data( * Usage: void listI_get(ListIterator* listI, void data) */ #define listI_get(listI, data) \ - list_get(listI->current, data) + list_get(listI->current, data) /** * @brief Set data at the current iterator position. @@ -312,7 +314,7 @@ bool listI_has_data( * Usage: void listI_set(ListIterator* listI, void data); */ #define listI_set(listI, data) \ - list_set(listI->list, listI->current, data) + list_set(listI->list, listI->current, data) /** * @brief Add data before current list cell. @@ -322,7 +324,7 @@ bool listI_has_data( * Usage: void listI_insert_before(ListIteratorI* listI, void data) */ #define listI_insert_before(listI, data) \ - list_insert_before(listI->list, listI->current, data) + list_insert_before(listI->list, listI->current, data) /** * @brief Add data after current list cell. @@ -332,43 +334,43 @@ bool listI_has_data( * Usage: void listI_insert_after(ListIteratorI* listI, void data) */ #define listI_insert_after(listI, data) \ - list_insert_after(listI->list, listI->current, data) + list_insert_after(listI->list, listI->current, data) /** * @brief Type to encode a direction (forward / backward). */ typedef enum { - BACKWARD = -1, ///< Move toward head. - FORWARD = 1 ///< Move toward tail. + BACKWARD = -1, ///< Move toward head. + FORWARD = 1 ///< Move toward tail. } Direction; /** * @brief Remove data at the current iterator position. */ void listI_remove( - ListIterator* listI, ///< "this" pointer. - Direction direction ///< Indicate the position of iterator after removal. + ListIterator* listI, ///< "this" pointer. + Direction direction ///< Indicate the position of iterator after removal. ); /** * @brief Move current iterator position forward (toward tail). */ void listI_move_next( - ListIterator* listI ///< "this" pointer. + ListIterator* listI ///< "this" pointer. ); /** * @brief Move current iterator position backward (toward head). */ void listI_move_prev( - ListIterator* listI ///< "this" pointer. + ListIterator* listI ///< "this" pointer. ); /** * @brief Free memory allocated for the iterator. */ void listI_destroy( - ListIterator* listI ///< "this" pointer. + ListIterator* listI ///< "this" pointer. ); #endif