API参考
载入中...
搜索中...
未找到
bsl_list.h
1/*
2 * This file is part of the openHiTLS project.
3 *
4 * openHiTLS is licensed under the Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:
7 *
8 * http://license.coscl.org.cn/MulanPSL2
9 *
10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13 * See the Mulan PSL v2 for more details.
14 */
15
21
22#ifndef BSL_LIST_H
23#define BSL_LIST_H
24
25#include <stdint.h>
26#include "bsl_errno.h"
27#include "bsl_sal.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/* for handling ASN.1 SET OF type */
34
39typedef struct BslListNode {
40 struct BslListNode *prev;
41 struct BslListNode *next;
42 void *data;
44
56
73
81typedef int32_t (*BSL_LIST_PFUNC_CMP)(const void *, const void *);
82
89typedef void (*BSL_LIST_PFUNC_FREE)(void *);
90
97typedef void *(*BSL_LIST_PFUNC_DUP)(const void *);
98
99/*
100 The following macros return the specified element of the list. They do
101 not change the current list pointer.
102 */
103/* returns the current element */
104#define BSL_LIST_CURR_ELMT(pList) ((pList) ? ((pList)->curr ? ((pList)->curr->data) : NULL) : NULL)
105
106/* returns the next element */
107#define BSL_LIST_NEXT_ELMT(pList) \
108 ((pList) ? ((pList)->curr ? ((pList)->curr->next ? ((pList)->curr->next->data) : NULL) : NULL) : NULL)
109
110/* returns the previous element */
111#define BSL_LIST_PREV_ELMT(pList) \
112 ((pList) ? ((pList)->curr ? ((pList)->curr->prev ? ((pList)->curr->prev->data) : NULL) : NULL) : NULL)
113
114/* returns the last element */
115#define BSL_LIST_LAST_ELMT(pList) ((pList) ? ((pList)->last ? ((pList)->last->data) : NULL) : NULL)
116
117/* returns the first element */
118#define BSL_LIST_FIRST_ELMT(pList) ((pList) ? ((pList)->first ? ((pList)->first->data) : NULL) : NULL)
119
120/* checks if the list is NULL */
121#define BSL_LIST_EMPTY(pList) (((pList) != NULL) ? ((pList)->count == 0) : 0)
122
123/* returns the number of nodes in the list */
124#define BSL_LIST_COUNT(pList) ((pList) ? ((pList)->count) : 0)
125
126/* checks if current node is the end */
127#define BSL_LIST_IS_END(pList) ((pList) ? (NULL == (pList)->curr) : 0)
128
129/* checks if current node is the first one */
130#define BSL_LIST_IS_START(pList) ((pList) ? ((pList)->first == (pList)->curr) : 0)
131
132/* Get the next element */
133#define BSL_LIST_GET_NEXT(pList) ((pList) ? (BSL_LIST_Next(pList) ? BSL_LIST_CURR_ELMT(pList) : NULL) : NULL)
134
135/* Get the previous element */
136#define BSL_LIST_GET_PREV(pList) ((pList) ? (BSL_LIST_Prev(pList) ? BSL_LIST_CURR_ELMT(pList) : NULL) : NULL)
137
138/* Get the first element */
139#define BSL_LIST_GET_FIRST(pList) ((pList) ? (BSL_LIST_First(pList) ? BSL_LIST_CURR_ELMT(pList) : NULL) : NULL)
140
141/* Get the last element */
142#define BSL_LIST_GET_LAST(pList) ((pList) ? (BSL_LIST_Last(pList) ? BSL_LIST_CURR_ELMT(pList) : NULL) : NULL)
143
149#define BSL_LIST_FREE(pList, pFreeFunc) \
150 do { \
151 BSL_LIST_DeleteAll((pList), pFreeFunc); \
152 if (NULL != (pList)) { \
153 BSL_SAL_Free(pList); \
154 (pList) = NULL; \
155 } \
156 } while (0)
157
158
159#define SEC_INT_ERROR (-2)
160
170int32_t BSL_LIST_SetMaxElements(int32_t iMaxElements);
171
180
194int32_t BSL_LIST_AddElement(BslList *pList, void *pData, BslListPosition enPosition);
195
205
215
227
243void *BSL_LIST_Search(BslList *pList, const void *pSearchFor, BSL_LIST_PFUNC_CMP pSearcher, int32_t *pstErr);
244
255void *BSL_LIST_GetIndexNode(uint32_t ulIndex, BslList *pList);
256
270
282
291BslList *BSL_LIST_New(int32_t dataSize);
292
303void *BSL_LIST_Curr(const BslList *pstList);
304
314void *BSL_LIST_First(BslList *pstList);
315
325void *BSL_LIST_Last(BslList *pstList);
326
338void *BSL_LIST_Next(BslList *pstList);
339
351void *BSL_LIST_Prev(BslList *pstList);
352
366int32_t BSL_LIST_GetElmtIndex(const void *elmt, BslList *pstList);
367
377BslList *BSL_LIST_Concat(BslList *pDestList, const BslList *pSrcList);
378
388
398
407int32_t BSL_LIST_SetMaxQsortCount(uint32_t uiQsortSize);
408
417
428
439
449void *BSL_LIST_GetData(const BslListNode *pstNode);
450
464BslListNode *BSL_LIST_GetNextNode(const BslList *pstList, const BslListNode *pstListNode);
465
477
487void BSL_LIST_DeleteNode(BslList *pstList, const BslListNode *pstListNode, BSL_LIST_PFUNC_FREE pfFreeFunc);
488
502void BSL_LIST_DetachNode(BslList *pstList, BslListNode **pstListNode);
503
504#ifdef __cplusplus
505}
506#endif /* __cplusplus */
507
508#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 *)
定义 bsl_list.h:81
void BSL_LIST_DetachNode(BslList *pstList, BslListNode **pstListNode)
void BSL_LIST_DetachCurrent(BslList *pList)
BslListNode * BSL_LIST_FirstNode(const BslList *list)
BslListPosition
定义 bsl_list.h:67
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 *)
定义 bsl_list.h:89
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 *)
定义 bsl_list.h:97
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)
@ BSL_LIST_POS_AFTER
定义 bsl_list.h:69
@ BSL_LIST_POS_BEGIN
定义 bsl_list.h:70
@ BSL_LIST_POS_BEFORE
定义 bsl_list.h:68
@ BSL_LIST_POS_END
定义 bsl_list.h:71
定义 bsl_list.h:39
void * data
定义 bsl_list.h:42
struct BslListNode * next
定义 bsl_list.h:41
struct BslListNode * prev
定义 bsl_list.h:40
定义 bsl_list.h:49
int32_t count
定义 bsl_list.h:53
BslListNode * first
定义 bsl_list.h:50
BslListNode * last
定义 bsl_list.h:51
BslListNode * curr
定义 bsl_list.h:52
int32_t dataSize
定义 bsl_list.h:54