Nigel Rantor / azure_c_shared_utility

Fork of azure_c_shared_utility by Azure IoT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers singlylinkedlist.h Source File

singlylinkedlist.h

00001 // Copyright (c) Microsoft. All rights reserved.
00002 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
00003 
00004 #ifndef SINGLYLINKEDLIST_H
00005 #define SINGLYLINKEDLIST_H
00006 
00007 #ifdef __cplusplus
00008 extern "C" {
00009 #include <cstdbool>
00010 #else
00011 #include "stdbool.h"
00012 #endif /* __cplusplus */
00013 
00014 #include "azure_c_shared_utility/umock_c_prod.h"
00015 
00016 typedef struct SINGLYLINKEDLIST_INSTANCE_TAG* SINGLYLINKEDLIST_HANDLE;
00017 typedef struct LIST_ITEM_INSTANCE_TAG* LIST_ITEM_HANDLE;
00018 
00019 /**
00020 * @brief                        Function passed to singlylinkedlist_find, which returns whichever first list item that matches it.
00021 * @param list_item              Current list node being evaluated.
00022 * @param match_context          Context passed to singlylinkedlist_find.
00023 * @returns                      True to indicate that the current list node is the one to be returned, or false to continue traversing the list.
00024 */
00025 typedef bool (*LIST_MATCH_FUNCTION)(LIST_ITEM_HANDLE list_item, const void* match_context);
00026 /**
00027 * @brief                        Function passed to singlylinkedlist_remove_if, which is used to define if an item of the list should be removed or not.
00028 * @param item                   Value of the current list node being evaluated for removal.
00029 * @param match_context          Context passed to singlylinkedlist_remove_if.
00030 * @param continue_processing    Indicates if singlylinkedlist_remove_if shall continue iterating through the next nodes of the list or stop.
00031 * @returns                      True to indicate that the current list node shall be removed, or false to not to.
00032 */
00033 typedef bool (*LIST_CONDITION_FUNCTION)(const void* item, const void* match_context, bool* continue_processing);
00034 /**
00035 * @brief                        Function passed to singlylinkedlist_foreach, which is called for the value of each node of the list.
00036 * @param item                   Value of the current list node being processed.
00037 * @param action_context         Context passed to singlylinkedlist_foreach.
00038 * @param continue_processing    Indicates if singlylinkedlist_foreach shall continue iterating through the next nodes of the list or stop.
00039 */
00040 typedef void (*LIST_ACTION_FUNCTION)(const void* item, const void* action_context, bool* continue_processing);
00041 
00042 MOCKABLE_FUNCTION(, SINGLYLINKEDLIST_HANDLE, singlylinkedlist_create);
00043 MOCKABLE_FUNCTION(, void, singlylinkedlist_destroy, SINGLYLINKEDLIST_HANDLE, list);
00044 MOCKABLE_FUNCTION(, LIST_ITEM_HANDLE, singlylinkedlist_add, SINGLYLINKEDLIST_HANDLE, list, const void*, item);
00045 MOCKABLE_FUNCTION(, int, singlylinkedlist_remove, SINGLYLINKEDLIST_HANDLE, list, LIST_ITEM_HANDLE, item_handle);
00046 MOCKABLE_FUNCTION(, LIST_ITEM_HANDLE, singlylinkedlist_get_head_item, SINGLYLINKEDLIST_HANDLE, list);
00047 MOCKABLE_FUNCTION(, LIST_ITEM_HANDLE, singlylinkedlist_get_next_item, LIST_ITEM_HANDLE, item_handle);
00048 MOCKABLE_FUNCTION(, LIST_ITEM_HANDLE, singlylinkedlist_find, SINGLYLINKEDLIST_HANDLE, list, LIST_MATCH_FUNCTION, match_function, const void*, match_context);
00049 MOCKABLE_FUNCTION(, const void*, singlylinkedlist_item_get_value, LIST_ITEM_HANDLE, item_handle);
00050 MOCKABLE_FUNCTION(, int, singlylinkedlist_remove_if, SINGLYLINKEDLIST_HANDLE, list, LIST_CONDITION_FUNCTION, condition_function, const void*, match_context);
00051 MOCKABLE_FUNCTION(, int, singlylinkedlist_foreach, SINGLYLINKEDLIST_HANDLE, list, LIST_ACTION_FUNCTION, action_function, const void*, action_context);
00052 
00053 #ifdef __cplusplus
00054 }
00055 #endif /* __cplusplus */
00056 
00057 #endif /* SINGLYLINKEDLIST_H */