[388] | 1 | // Copyright (c) Microsoft. All rights reserved.
|
---|
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
---|
| 3 |
|
---|
| 4 | #ifndef SINGLYLINKEDLIST_H
|
---|
| 5 | #define SINGLYLINKEDLIST_H
|
---|
| 6 |
|
---|
| 7 | #ifdef __cplusplus
|
---|
| 8 | extern "C" {
|
---|
| 9 | #else
|
---|
| 10 | #include "stdbool.h"
|
---|
| 11 | #endif /* __cplusplus */
|
---|
| 12 |
|
---|
| 13 | #include "azure_c_shared_utility/umock_c_prod.h"
|
---|
| 14 |
|
---|
| 15 | typedef struct SINGLYLINKEDLIST_INSTANCE_TAG* SINGLYLINKEDLIST_HANDLE;
|
---|
| 16 | typedef struct LIST_ITEM_INSTANCE_TAG* LIST_ITEM_HANDLE;
|
---|
| 17 |
|
---|
| 18 | /**
|
---|
| 19 | * @brief Function passed to singlylinkedlist_find, which returns whichever first list item that matches it.
|
---|
| 20 | * @param list_item Current list node being evaluated.
|
---|
| 21 | * @param match_context Context passed to singlylinkedlist_find.
|
---|
| 22 | * @returns True to indicate that the current list node is the one to be returned, or false to continue traversing the list.
|
---|
| 23 | */
|
---|
| 24 | typedef bool (*LIST_MATCH_FUNCTION)(LIST_ITEM_HANDLE list_item, const void* match_context);
|
---|
| 25 | /**
|
---|
| 26 | * @brief Function passed to singlylinkedlist_remove_if, which is used to define if an item of the list should be removed or not.
|
---|
| 27 | * @param item Value of the current list node being evaluated for removal.
|
---|
| 28 | * @param match_context Context passed to singlylinkedlist_remove_if.
|
---|
| 29 | * @param continue_processing Indicates if singlylinkedlist_remove_if shall continue iterating through the next nodes of the list or stop.
|
---|
| 30 | * @returns True to indicate that the current list node shall be removed, or false to not to.
|
---|
| 31 | */
|
---|
| 32 | typedef bool (*LIST_CONDITION_FUNCTION)(const void* item, const void* match_context, bool* continue_processing);
|
---|
| 33 | /**
|
---|
| 34 | * @brief Function passed to singlylinkedlist_foreach, which is called for the value of each node of the list.
|
---|
| 35 | * @param item Value of the current list node being processed.
|
---|
| 36 | * @param action_context Context passed to singlylinkedlist_foreach.
|
---|
| 37 | * @param continue_processing Indicates if singlylinkedlist_foreach shall continue iterating through the next nodes of the list or stop.
|
---|
| 38 | */
|
---|
| 39 | typedef void (*LIST_ACTION_FUNCTION)(const void* item, const void* action_context, bool* continue_processing);
|
---|
| 40 |
|
---|
| 41 | MOCKABLE_FUNCTION(, SINGLYLINKEDLIST_HANDLE, singlylinkedlist_create);
|
---|
| 42 | MOCKABLE_FUNCTION(, void, singlylinkedlist_destroy, SINGLYLINKEDLIST_HANDLE, list);
|
---|
| 43 | MOCKABLE_FUNCTION(, LIST_ITEM_HANDLE, singlylinkedlist_add, SINGLYLINKEDLIST_HANDLE, list, const void*, item);
|
---|
| 44 | MOCKABLE_FUNCTION(, LIST_ITEM_HANDLE, singlylinkedlist_add_head, SINGLYLINKEDLIST_HANDLE, list, const void*, item);
|
---|
| 45 | MOCKABLE_FUNCTION(, int, singlylinkedlist_remove, SINGLYLINKEDLIST_HANDLE, list, LIST_ITEM_HANDLE, item_handle);
|
---|
| 46 | MOCKABLE_FUNCTION(, LIST_ITEM_HANDLE, singlylinkedlist_get_head_item, SINGLYLINKEDLIST_HANDLE, list);
|
---|
| 47 | MOCKABLE_FUNCTION(, LIST_ITEM_HANDLE, singlylinkedlist_get_next_item, LIST_ITEM_HANDLE, item_handle);
|
---|
| 48 | MOCKABLE_FUNCTION(, LIST_ITEM_HANDLE, singlylinkedlist_find, SINGLYLINKEDLIST_HANDLE, list, LIST_MATCH_FUNCTION, match_function, const void*, match_context);
|
---|
| 49 | MOCKABLE_FUNCTION(, const void*, singlylinkedlist_item_get_value, LIST_ITEM_HANDLE, item_handle);
|
---|
| 50 | MOCKABLE_FUNCTION(, int, singlylinkedlist_remove_if, SINGLYLINKEDLIST_HANDLE, list, LIST_CONDITION_FUNCTION, condition_function, const void*, match_context);
|
---|
| 51 | MOCKABLE_FUNCTION(, int, singlylinkedlist_foreach, SINGLYLINKEDLIST_HANDLE, list, LIST_ACTION_FUNCTION, action_function, const void*, action_context);
|
---|
| 52 |
|
---|
| 53 | #ifdef __cplusplus
|
---|
| 54 | }
|
---|
| 55 | #endif /* __cplusplus */
|
---|
| 56 |
|
---|
| 57 | #endif /* SINGLYLINKEDLIST_H */
|
---|