|
1 /* |
|
2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Provides interfaces to data structure routines. |
|
15 * These routines support a number of different data structures. |
|
16 * |
|
17 * NW_Ds_Dar - DynamicArray of pointers. Creates an array of pointers |
|
18 * to void *. Elements are inserted and retrieved by index. |
|
19 * The array is fixed size put will automatically grow if |
|
20 * the append function is called and the array needs to grow. |
|
21 * |
|
22 */ |
|
23 |
|
24 #ifndef NWX_DATASTRUCT_H |
|
25 #define NWX_DATASTRUCT_H |
|
26 |
|
27 #ifdef __cplusplus |
|
28 extern "C" { |
|
29 #endif |
|
30 |
|
31 /* |
|
32 ** Includes |
|
33 */ |
|
34 #include "nwx_defs.h" |
|
35 #include "BrsrStatusCodes.h" |
|
36 |
|
37 /************************************************************************* |
|
38 ** Dynamic Array of Pointers Routines |
|
39 **************************************************************************/ |
|
40 |
|
41 /* |
|
42 ** Type Definitions |
|
43 */ |
|
44 |
|
45 typedef void* NW_Ds_Mem_MallocHandler(); |
|
46 typedef void NW_Ds_Mem_FreeHandler(); |
|
47 |
|
48 typedef struct { |
|
49 NW_Uint16 size; /* number of elements allocated */ |
|
50 NW_Uint16 numElements; /* number of elements in use */ |
|
51 void **elements; /* array of pointers to the elements */ |
|
52 NW_Ds_Mem_MallocHandler *mallocHandler; /* memory allocation routine */ |
|
53 NW_Ds_Mem_FreeHandler *freeHandler; /* memory deallocation routine */ |
|
54 } NW_Ds_DynamicArray_t; |
|
55 |
|
56 |
|
57 /* |
|
58 ** Global Function Declarations |
|
59 */ |
|
60 |
|
61 /* create a dynamic array on the default heap */ |
|
62 NW_Ds_DynamicArray_t *NW_Ds_DarNew_DefaultHeap(const NW_Uint16 size); |
|
63 |
|
64 /* create a dynamic array */ |
|
65 NW_Ds_DynamicArray_t *NW_Ds_DarNew(const NW_Uint16 size, |
|
66 NW_Ds_Mem_MallocHandler *alloc, |
|
67 NW_Ds_Mem_FreeHandler *free); |
|
68 |
|
69 /* deletes a dynamic array */ |
|
70 void NW_Ds_DarDelete(NW_Ds_DynamicArray_t *array); |
|
71 |
|
72 /* append pointer to new element to end of array */ |
|
73 TBrowserStatusCode NW_Ds_DarAppend(NW_Ds_DynamicArray_t *array, void *element); |
|
74 |
|
75 /* get the pointer to the specified element */ |
|
76 void *NW_Ds_DarGetElement(const NW_Ds_DynamicArray_t *array, |
|
77 const NW_Uint32 index); |
|
78 |
|
79 |
|
80 /* return count of elements */ |
|
81 NW_Uint16 NW_Ds_DarGetCount(const NW_Ds_DynamicArray_t *array); |
|
82 |
|
83 /************************************************************************* |
|
84 ** Single Linked List Routines |
|
85 **************************************************************************/ |
|
86 |
|
87 /* |
|
88 ** Type Declarations |
|
89 */ |
|
90 |
|
91 typedef struct _NW_Node_t NW_Node_t; |
|
92 struct _NW_Node_t { |
|
93 NW_Node_t *next; |
|
94 void *data; |
|
95 }; |
|
96 |
|
97 /************************************************************************* |
|
98 ** Collection Routines |
|
99 **************************************************************************/ |
|
100 |
|
101 /* |
|
102 ** Type Declarations |
|
103 */ |
|
104 |
|
105 typedef NW_Bool NW_Ds_CollectionMatcher_t (const void *key, const void *data); |
|
106 |
|
107 typedef struct _NW_Ds_Collection_t NW_Ds_Collection_t; |
|
108 |
|
109 typedef const struct { |
|
110 TBrowserStatusCode (*add)(NW_Ds_Collection_t *coll, void *value); |
|
111 void * (*lookup)(NW_Ds_Collection_t *coll, const void *key, |
|
112 NW_Ds_CollectionMatcher_t matcher); |
|
113 void * (*remove)(NW_Ds_Collection_t *coll, const void *key, |
|
114 NW_Ds_CollectionMatcher_t matcher); |
|
115 void (*reset)(NW_Ds_Collection_t *coll); |
|
116 void * (*getNext)(NW_Ds_Collection_t *coll); |
|
117 void (*free_current)(NW_Ds_Collection_t *coll); |
|
118 NW_Bool (*empty)(NW_Ds_Collection_t *coll); |
|
119 } NW_Ds_CollectionApi_t; |
|
120 |
|
121 struct _NW_Ds_Collection_t { |
|
122 NW_Ds_CollectionApi_t *api; |
|
123 void *data; |
|
124 }; |
|
125 |
|
126 |
|
127 /* |
|
128 ** Global Function Declarations |
|
129 */ |
|
130 |
|
131 #ifdef __cplusplus |
|
132 } /* extern "C" */ |
|
133 #endif |
|
134 |
|
135 |
|
136 #endif /* NWX_DATASTRUCT_H */ |
|
137 |
|
138 |