24
|
1 |
/*
|
|
2 |
* Copyright (c) 2000 - 2001 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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
/** ----------------------------------------------------------------------- **
|
|
20 |
@package: NW_TinyTree
|
|
21 |
|
|
22 |
@synopsis: default
|
|
23 |
|
|
24 |
@description: default
|
|
25 |
|
|
26 |
** ----------------------------------------------------------------------- **/
|
|
27 |
|
|
28 |
#ifndef NW_TREE_ALLOC_H
|
|
29 |
#define NW_TREE_ALLOC_H
|
|
30 |
|
|
31 |
|
|
32 |
#ifdef __cplusplus
|
|
33 |
extern "C" {
|
|
34 |
#endif /* __cplusplus */
|
|
35 |
|
|
36 |
|
|
37 |
#define MIN_SEGMENT_SIZE 64
|
|
38 |
|
|
39 |
/* ----------------------------------------------------------------------- **
|
|
40 |
These methods are private to the tiny tree module.
|
|
41 |
** ----------------------------------------------------------------------- **/
|
|
42 |
|
|
43 |
|
|
44 |
/* ----------------------------------------------------------------------- **
|
|
45 |
Storage mananagement:
|
|
46 |
|
|
47 |
Header for a storage block. When the block is allocated by the
|
|
48 |
tree_alloc methods, the storage block will be contiguous with the
|
|
49 |
header. However, when the block was supplied externally (for
|
|
50 |
example, by the parser) the storage will be somewhere else.
|
|
51 |
** ----------------------------------------------------------------------- **/
|
|
52 |
|
|
53 |
|
|
54 |
/** ----------------------------------------------------------------------- **
|
|
55 |
@typedef: NW_TinyTree_RelativeOffset
|
|
56 |
|
|
57 |
@synopsis: Relative offset into structure.
|
|
58 |
|
|
59 |
@scope: public
|
|
60 |
@type: NW_Uint32
|
|
61 |
|
|
62 |
@description: Relative offset into structure.
|
|
63 |
** ----------------------------------------------------------------------- **/
|
|
64 |
typedef NW_Uint32 NW_TinyTree_RelativeOffset_t;
|
|
65 |
|
|
66 |
|
|
67 |
/** ----------------------------------------------------------------------- **
|
|
68 |
@struct: NW_TinyTree_SegHeader
|
|
69 |
|
|
70 |
@synopsis: Segment header.
|
|
71 |
|
|
72 |
@scope: public
|
|
73 |
@variables:
|
|
74 |
NW_TinyTree_RelativeOffset_t next
|
|
75 |
Offset into segment.
|
|
76 |
|
|
77 |
NW_TinyTree_Offset_t size
|
|
78 |
Offset.
|
|
79 |
|
|
80 |
NW_TinyTree_Offset_t free_offset
|
|
81 |
Free offset.
|
|
82 |
|
|
83 |
void* initializer NW_Byte__ptr__NW_TinyTree_Offset_t
|
|
84 |
Funcion pointer for initializer.
|
|
85 |
|
|
86 |
NW_Byte* storage
|
|
87 |
Storage.
|
|
88 |
|
|
89 |
@description: Segment header.
|
|
90 |
** ----------------------------------------------------------------------- **/
|
|
91 |
typedef struct NW_TinyTree_SegHeader_s{
|
|
92 |
NW_TinyTree_RelativeOffset_t next;
|
|
93 |
NW_TinyTree_Offset_t size;
|
|
94 |
NW_TinyTree_Offset_t free_offset;
|
|
95 |
void (*initializer) (NW_Byte*, NW_TinyTree_Offset_t);
|
|
96 |
NW_Byte* storage;
|
|
97 |
} NW_TinyTree_SegHeader_t;
|
|
98 |
|
|
99 |
|
|
100 |
/** ----------------------------------------------------------------------- **
|
|
101 |
@function: NW_TinyTree_segmentGetFreeSpace
|
|
102 |
|
|
103 |
@synopsis: Get free space.
|
|
104 |
|
|
105 |
@scope: public
|
|
106 |
|
|
107 |
@parameters:
|
|
108 |
[in] NW_TinyTree_SegHeader_t* segment
|
|
109 |
The segment header.
|
|
110 |
|
|
111 |
@description: Get free space.
|
|
112 |
|
|
113 |
@returns: NW_TinyTree_Offset_t
|
|
114 |
Free space pointer.
|
|
115 |
|
|
116 |
** ----------------------------------------------------------------------- **/
|
|
117 |
NW_TinyTree_Offset_t
|
|
118 |
NW_TinyTree_segmentGetFreeSpace(NW_TinyTree_SegHeader_t* segment);
|
|
119 |
|
|
120 |
|
|
121 |
/** ----------------------------------------------------------------------- **
|
|
122 |
@function: NW_TinyTree_getFreeStorageSpace
|
|
123 |
|
|
124 |
@synopsis: Get free storage space.
|
|
125 |
|
|
126 |
@scope: public
|
|
127 |
|
|
128 |
@parameters:
|
|
129 |
[in] NW_TinyTree_SegHeader_t* base
|
|
130 |
The segment header.
|
|
131 |
|
|
132 |
@description: Get free storage space.
|
|
133 |
|
|
134 |
@returns: NW_TinyTree_Offset_t
|
|
135 |
Free storage space pointer.
|
|
136 |
|
|
137 |
** ----------------------------------------------------------------------- **/
|
|
138 |
NW_TinyTree_Offset_t
|
|
139 |
NW_TinyTree_getFreeStorageSpace(NW_TinyTree_SegHeader_t* base);
|
|
140 |
|
|
141 |
|
|
142 |
/** ----------------------------------------------------------------------- **
|
|
143 |
@function: NW_TinyTree_addSegment
|
|
144 |
|
|
145 |
@synopsis: Add segment.
|
|
146 |
|
|
147 |
@scope: public
|
|
148 |
|
|
149 |
@parameters:
|
|
150 |
[in] NW_TinyTree_SegHeader_t* base
|
|
151 |
The segment header.
|
|
152 |
|
|
153 |
[in] NW_TinyTree_Offset_t size
|
|
154 |
Size of new segment.
|
|
155 |
|
|
156 |
@description: Add segment.
|
|
157 |
|
|
158 |
@returns: NW_TinyTree_SegHeader_t*
|
|
159 |
New header.
|
|
160 |
|
|
161 |
** ----------------------------------------------------------------------- **/
|
|
162 |
NW_TinyTree_SegHeader_t*
|
|
163 |
NW_TinyTree_addSegment(NW_TinyTree_SegHeader_t* base, NW_TinyTree_Offset_t size);
|
|
164 |
|
|
165 |
|
|
166 |
/** ----------------------------------------------------------------------- **
|
|
167 |
@function: NW_TinyTree_freeSegments
|
|
168 |
|
|
169 |
@synopsis: Free segments.
|
|
170 |
|
|
171 |
@scope: public
|
|
172 |
|
|
173 |
@parameters:
|
|
174 |
[in] NW_TinyTree_SegHeader_t* base
|
|
175 |
The segment header.
|
|
176 |
|
|
177 |
@description: Free segments.
|
|
178 |
** ----------------------------------------------------------------------- **/
|
|
179 |
void
|
|
180 |
NW_TinyTree_freeSegments(NW_TinyTree_SegHeader_t* base);
|
|
181 |
|
|
182 |
|
|
183 |
/** ----------------------------------------------------------------------- **
|
|
184 |
@function: NW_TinyTree_offsetGetSegment
|
|
185 |
|
|
186 |
@synopsis: Get segment header.
|
|
187 |
|
|
188 |
@scope: public
|
|
189 |
|
|
190 |
@parameters:
|
|
191 |
[in] NW_TinyTree_SegHeader_t* base
|
|
192 |
The segment header.
|
|
193 |
|
|
194 |
[out] NW_TinyTree_Offset_t* offset
|
|
195 |
Data offset.
|
|
196 |
|
|
197 |
@description: Get the segment header associated with an offset. This
|
|
198 |
allocates a new segment if the offset is beyond any
|
|
199 |
currently allocated segment. If a new segment is
|
|
200 |
allocated, the offset is readjusted to the beginning of
|
|
201 |
the new segment.
|
|
202 |
|
|
203 |
@returns: NW_TinyTree_SegHeader_t*
|
|
204 |
Segment header or NULL if error.
|
|
205 |
|
|
206 |
** ----------------------------------------------------------------------- **/
|
|
207 |
NW_TinyTree_SegHeader_t*
|
|
208 |
NW_TinyTree_offsetGetSegment(NW_TinyTree_SegHeader_t* base, NW_TinyTree_Offset_t* offset);
|
|
209 |
|
|
210 |
|
|
211 |
/** ----------------------------------------------------------------------- **
|
|
212 |
@function: NW_TinyTree_offsetIncrement
|
|
213 |
|
|
214 |
@synopsis: Increment.
|
|
215 |
|
|
216 |
@scope: public
|
|
217 |
|
|
218 |
@parameters:
|
|
219 |
[in] NW_TinyTree_SegHeader_t* base
|
|
220 |
The segment header.
|
|
221 |
|
|
222 |
[in] NW_TinyTree_Offset_t offset
|
|
223 |
Offset.
|
|
224 |
|
|
225 |
[in] NW_TinyTree_Offset_t delta
|
|
226 |
Delta.
|
|
227 |
|
|
228 |
@description: Increment.
|
|
229 |
|
|
230 |
@returns: NW_TinyTree_Offset_t
|
|
231 |
New offset.
|
|
232 |
|
|
233 |
** ----------------------------------------------------------------------- **/
|
|
234 |
NW_TinyTree_Offset_t
|
|
235 |
NW_TinyTree_offsetIncrement(NW_TinyTree_SegHeader_t* base,
|
|
236 |
NW_TinyTree_Offset_t offset,
|
|
237 |
NW_TinyTree_Offset_t delta);
|
|
238 |
|
|
239 |
|
|
240 |
/** ----------------------------------------------------------------------- **
|
|
241 |
@function: NW_TinyTree_addressGetSegment
|
|
242 |
|
|
243 |
@synopsis: Get segment.
|
|
244 |
|
|
245 |
@scope: public
|
|
246 |
|
|
247 |
@parameters:
|
|
248 |
[in] NW_TinyTree_SegHeader_t* base
|
|
249 |
The segment header.
|
|
250 |
|
|
251 |
[out] NW_Byte** address
|
|
252 |
Address of segment.
|
|
253 |
|
|
254 |
@description: Get the segment header associated with an offset.
|
|
255 |
This allocates a new segment if the offset is beyond
|
|
256 |
any currently allocated segment. If a new segment is
|
|
257 |
allocated, the offset is readjusted to the beginning
|
|
258 |
of the new segment.
|
|
259 |
|
|
260 |
@returns: NW_TinyTree_SegHeader_t*
|
|
261 |
The segment header.
|
|
262 |
|
|
263 |
** ----------------------------------------------------------------------- **/
|
|
264 |
NW_TinyTree_SegHeader_t*
|
|
265 |
NW_TinyTree_addressGetSegment(NW_TinyTree_SegHeader_t* base,
|
|
266 |
NW_Byte** address);
|
|
267 |
|
|
268 |
|
|
269 |
/** ----------------------------------------------------------------------- **
|
|
270 |
@function: NW_TinyTree_addressIncrement
|
|
271 |
|
|
272 |
@synopsis: Increment.
|
|
273 |
|
|
274 |
@scope: public
|
|
275 |
|
|
276 |
@parameters:
|
|
277 |
[in] NW_TinyTree_SegHeader_t* base
|
|
278 |
The segment header.
|
|
279 |
|
|
280 |
[in] NW_Byte* address
|
|
281 |
Address to increment.
|
|
282 |
|
|
283 |
[in] NW_TinyTree_Offset_t delta
|
|
284 |
Delta.
|
|
285 |
|
|
286 |
@description: Increment.
|
|
287 |
|
|
288 |
@returns: NW_Byte*
|
|
289 |
New address.
|
|
290 |
|
|
291 |
** ----------------------------------------------------------------------- **/
|
|
292 |
NW_Byte*
|
|
293 |
NW_TinyTree_addressIncrement(NW_TinyTree_SegHeader_t* base,
|
|
294 |
NW_Byte* address,
|
|
295 |
NW_TinyTree_Offset_t delta);
|
|
296 |
|
|
297 |
|
|
298 |
#ifdef __cplusplus
|
|
299 |
} // extern "C" {
|
|
300 |
#endif /* __cplusplus */
|
|
301 |
|
|
302 |
#endif /* NW_TREE_ALLOC_H */
|