openHiTLS API openHiTLS 0.1.0-Alpha1
bsl_list.h
浏览该文件的文档.
1/*---------------------------------------------------------------------------------------------
2 * This file is part of the openHiTLS project.
3 * Copyright © 2023 Huawei Technologies Co.,Ltd. All rights reserved.
4 * Licensed under the openHiTLS Software license agreement 1.0. See LICENSE in the project root
5 * for license information.
6 *---------------------------------------------------------------------------------------------
7 */
8
15#ifndef BSL_LIST_H
16#define BSL_LIST_H
17
18#include <stdint.h>
19#include "bsl_errno.h"
20#include "bsl_sal.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26/* for handling ASN.1 SET OF type */
31typedef struct BslListNode {
32 struct BslListNode *prev;
33 struct BslListNode *next;
34 void *data;
36
41typedef struct BslList {
45 int32_t count;
46 int32_t dataSize;
48
59typedef enum {
65
73typedef int32_t (*BSL_LIST_PFUNC_CMP)(const void *, const void *);
74
81typedef void (*BSL_LIST_PFUNC_FREE)(void *);
82
89typedef void *(*BSL_LIST_PFUNC_DUP)(const void *);
90
91/*
92 The following macros return the specified element of the list. They do
93 not change the current list pointer.
94 */
95/* returns the current element */
96#define BSL_LIST_CURR_ELMT(pList) ((pList) ? ((pList)->curr ? ((pList)->curr->data) : NULL) : NULL)
97
98/* returns the next element */
99#define BSL_LIST_NEXT_ELMT(pList) \
100 ((pList) ? ((pList)->curr ? ((pList)->curr->next ? ((pList)->curr->next->data) : NULL) : NULL) : NULL)
101
102/* returns the previous element */
103#define BSL_LIST_PREV_ELMT(pList) \
104 ((pList) ? ((pList)->curr ? ((pList)->curr->prev ? ((pList)->curr->prev->data) : NULL) : NULL) : NULL)
105
106/* returns the last element */
107#define BSL_LIST_LAST_ELMT(pList) ((pList) ? ((pList)->last ? ((pList)->last->data) : NULL) : NULL)
108
109/* returns the first element */
110#define BSL_LIST_FIRST_ELMT(pList) ((pList) ? ((pList)->first ? ((pList)->first->data) : NULL) : NULL)
111
112/* checks if the list is NULL */
113#define BSL_LIST_EMPTY(pList) (((pList) != NULL) ? ((pList)->count == 0) : 0)
114
115/* returns the number of nodes in the list */
116#define BSL_LIST_COUNT(pList) ((pList) ? ((pList)->count) : 0)
117
118/* checks if current node is the end */
119#define BSL_LIST_IS_END(pList) ((pList) ? (NULL == (pList)->curr) : 0)
120
121/* checks if current node is the first one */
122#define BSL_LIST_IS_START(pList) ((pList) ? ((pList)->first == (pList)->curr) : 0)
123
124/* Get the next element */
125#define BSL_LIST_GET_NEXT(pList) ((pList) ? (BSL_LIST_Next(pList) ? BSL_LIST_CURR_ELMT(pList) : NULL) : NULL)
126
127/* Get the previous element */
128#define BSL_LIST_GET_PREV(pList) ((pList) ? (BSL_LIST_Prev(pList) ? BSL_LIST_CURR_ELMT(pList) : NULL) : NULL)
129
130/* Get the first element */
131#define BSL_LIST_GET_FIRST(pList) ((pList) ? (BSL_LIST_First(pList) ? BSL_LIST_CURR_ELMT(pList) : NULL) : NULL)
132
133/* Get the last element */
134#define BSL_LIST_GET_LAST(pList) ((pList) ? (BSL_LIST_Last(pList) ? BSL_LIST_CURR_ELMT(pList) : NULL) : NULL)
135
141#define BSL_LIST_FREE(pList, pFreeFunc) \
142 do { \
143 BSL_LIST_DeleteAll((pList), pFreeFunc); \
144 if (NULL != (pList)) { \
145 BSL_SAL_FREE(pList); \
146 (pList) = NULL; \
147 (void)(pList); \
148 } \
149 } while (0)
150
158#define BSL_LIST_FREE_AFTER_SORT(pList) \
159 do { \
160 BSL_LIST_DeleteAllAfterSort(pList); \
161 if (NULL != (pList)) { \
162 BSL_SAL_FREE(pList); \
163 (pList) = NULL; \
164 } \
165 } while (0)
166
167#define SEC_INT_ERROR (-2)
168
178int32_t BSL_LIST_SetMaxElements(int32_t iMaxElements);
179
188
202int32_t BSL_LIST_AddElement(BslList *pList, void *pData, BslListPosition enPosition);
203
213
223
235
251void *BSL_LIST_Search(BslList *pList, const void *pSearchFor, BSL_LIST_PFUNC_CMP pSearcher, int32_t *pstErr);
252
263void *BSL_LIST_GetIndexNode(uint32_t ulIndex, BslList *pList);
264
278
290
299BslList *BSL_LIST_New(int32_t dataSize);
300
311void *BSL_LIST_Curr(const BslList *pstList);
312
322void *BSL_LIST_First(BslList *pstList);
323
333void *BSL_LIST_Last(BslList *pstList);
334
346void *BSL_LIST_Next(BslList *pstList);
347
359void *BSL_LIST_Prev(BslList *pstList);
360
374int32_t BSL_LIST_GetElmtIndex(const void *elmt, BslList *pstList);
375
385BslList *BSL_LIST_Concat(BslList *pDestList, const BslList *pSrcList);
386
396
406
415int32_t BSL_LIST_SetMaxQsortCount(uint32_t uiQsortSize);
416
425
436
447
457void *BSL_LIST_GetData(const BslListNode *pstNode);
458
472BslListNode *BSL_LIST_GetNextNode(const BslList *pstList, const BslListNode *pstListNode);
473
485
495void BSL_LIST_DeleteNode(BslList *pstList, const BslListNode *pstListNode, BSL_LIST_PFUNC_FREE pfFreeFunc);
496
510void BSL_LIST_DetachNode(BslList *pstList, BslListNode **pstListNode);
511
512#ifdef __cplusplus
513}
514#endif /* __cplusplus */
515
516#endif // BSL_LIST_H
int32_t BSL_LIST_SetMaxElements(int32_t iMaxElements)
void * BSL_LIST_Prev(BslList *pstList)
BslList * BSL_LIST_Copy(BslList *pSrcList, BSL_LIST_PFUNC_DUP pFuncCpy, BSL_LIST_PFUNC_FREE pfFreeFunc)
void BSL_LIST_DeleteAll(BslList *pList, BSL_LIST_PFUNC_FREE pfFreeFunc)
void BSL_LIST_DeleteCurrent(BslList *pList, BSL_LIST_PFUNC_FREE pfFreeFunc)
BslListNode * BSL_LIST_GetPrevNode(const BslListNode *pstListNode)
void BSL_LIST_FreeWithoutData(BslList *pstList)
void * BSL_LIST_Curr(const BslList *pstList)
int32_t BSL_LIST_GetMaxElements(void)
uint32_t BSL_LIST_GetMaxQsortCount(void)
BslList * BSL_LIST_Sort(BslList *pList, BSL_LIST_PFUNC_CMP pfCmp)
void BSL_LIST_DeleteNode(BslList *pstList, const BslListNode *pstListNode, BSL_LIST_PFUNC_FREE pfFreeFunc)
void * BSL_LIST_Search(BslList *pList, const void *pSearchFor, BSL_LIST_PFUNC_CMP pSearcher, int32_t *pstErr)
int32_t(* BSL_LIST_PFUNC_CMP)(const void *, const void *)
Definition bsl_list.h:73
void BSL_LIST_DetachNode(BslList *pstList, BslListNode **pstListNode)
void BSL_LIST_DetachCurrent(BslList *pList)
BslListNode * BSL_LIST_FirstNode(const BslList *list)
BslListPosition
Definition bsl_list.h:59
@ BSL_LIST_POS_AFTER
Definition bsl_list.h:61
@ BSL_LIST_POS_BEGIN
Definition bsl_list.h:62
@ BSL_LIST_POS_BEFORE
Definition bsl_list.h:60
@ BSL_LIST_POS_END
Definition bsl_list.h:63
void BSL_LIST_RevList(BslList *pstList)
void * BSL_LIST_Last(BslList *pstList)
void * BSL_LIST_GetData(const BslListNode *pstNode)
void * BSL_LIST_Next(BslList *pstList)
BslList * BSL_LIST_Concat(BslList *pDestList, const BslList *pSrcList)
void BSL_LIST_DeleteAllAfterSort(BslList *pList)
void(* BSL_LIST_PFUNC_FREE)(void *)
Definition bsl_list.h:81
int32_t BSL_LIST_SetMaxQsortCount(uint32_t uiQsortSize)
void * BSL_LIST_First(BslList *pstList)
int32_t BSL_LIST_GetElmtIndex(const void *elmt, BslList *pstList)
void *(* BSL_LIST_PFUNC_DUP)(const void *)
Definition bsl_list.h:89
BslListNode * BSL_LIST_GetNextNode(const BslList *pstList, const BslListNode *pstListNode)
BslList * BSL_LIST_New(int32_t dataSize)
int32_t BSL_LIST_AddElement(BslList *pList, void *pData, BslListPosition enPosition)
void * BSL_LIST_GetIndexNode(uint32_t ulIndex, BslList *pList)
void * data
Definition bsl_list.h:34
struct BslListNode * next
Definition bsl_list.h:33
struct BslListNode * prev
Definition bsl_list.h:32
Definition bsl_list.h:31
BslListNode * first
Definition bsl_list.h:42
int32_t count
Definition bsl_list.h:45
BslListNode * last
Definition bsl_list.h:43
int32_t dataSize
Definition bsl_list.h:46
BslListNode * curr
Definition bsl_list.h:44
Definition bsl_list.h:41