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_Encoder |
|
21 |
|
22 @synopsis: default |
|
23 |
|
24 @description: default |
|
25 |
|
26 ** ----------------------------------------------------------------------- **/ |
|
27 |
|
28 #ifndef _NW_ENCODER_STRING_TABLE_HEADER_GUARD_ |
|
29 #define _NW_ENCODER_STRING_TABLE_HEADER_GUARD_ |
|
30 |
|
31 #include <xml/cxml/nw_string_string.h> |
|
32 #include <xml/cxml/nw_tinytree.h> |
|
33 #include <xml/cxml/nw_wbxml_dictionary.h> |
|
34 |
|
35 #ifdef __cplusplus |
|
36 extern "C" |
|
37 { |
|
38 #endif /* __cplusplus */ |
|
39 |
|
40 #define CXML_MAX_STRTBL_ITEMS 150 |
|
41 |
|
42 /** ----------------------------------------------------------------------- ** |
|
43 @typedef: NW_DOM_DocumentNode |
|
44 |
|
45 @synopsis: default |
|
46 |
|
47 @scope: public |
|
48 @type: NW_TinyTree_Node_t |
|
49 |
|
50 @description: default |
|
51 ** ----------------------------------------------------------------------- **/ |
|
52 typedef NW_TinyTree_Node_t NW_DOM_DocumentNode_t; |
|
53 |
|
54 |
|
55 /* |
|
56 * StringItem methods |
|
57 */ |
|
58 |
|
59 /** ----------------------------------------------------------------------- ** |
|
60 @struct: NW_Encoder_StringTable |
|
61 |
|
62 @synopsis: Container for the strings in a document. |
|
63 |
|
64 @scope: public |
|
65 @variables: |
|
66 CXML_Vector_t* vector |
|
67 Array of strings. |
|
68 |
|
69 @description: Container for the strings in a document. |
|
70 ** ----------------------------------------------------------------------- **/ |
|
71 typedef struct NW_Encoder_StringTable_s{ |
|
72 CXML_Vector_t* vector; |
|
73 }NW_Encoder_StringTable_t; |
|
74 |
|
75 |
|
76 /** ----------------------------------------------------------------------- ** |
|
77 @function: NW_Encoder_StringTable_new |
|
78 |
|
79 @synopsis: Creates a new String Table. |
|
80 |
|
81 @scope: public |
|
82 |
|
83 @description: Creates a new String Table. |
|
84 |
|
85 @returns: NW_Encoder_StringTable_t* |
|
86 POinter to string table or NULL if not successful. |
|
87 |
|
88 ** ----------------------------------------------------------------------- **/ |
|
89 IMPORT_C |
|
90 NW_Encoder_StringTable_t* |
|
91 NW_Encoder_StringTable_new(void); |
|
92 |
|
93 |
|
94 /** ----------------------------------------------------------------------- ** |
|
95 @function: NW_Encoder_StringTable_delete |
|
96 |
|
97 @synopsis: Deletes a String Table. |
|
98 |
|
99 @scope: public |
|
100 |
|
101 @parameters: |
|
102 [in-out] NW_Encoder_StringTable_t* strTable |
|
103 Table to delete. |
|
104 |
|
105 @description: Deletes a String Table |
|
106 |
|
107 ** ----------------------------------------------------------------------- **/ |
|
108 IMPORT_C void |
|
109 NW_Encoder_StringTable_delete(NW_Encoder_StringTable_t* strTable); |
|
110 |
|
111 |
|
112 /** ----------------------------------------------------------------------- ** |
|
113 @struct: NW_Encoder_StringItem |
|
114 |
|
115 @synopsis: String item structure. |
|
116 |
|
117 @scope: public |
|
118 @variables: |
|
119 NW_String_t data |
|
120 The string data. |
|
121 |
|
122 NW_Uint16 frequency |
|
123 Reference count. |
|
124 |
|
125 @description: This structures is used to count the frequency of |
|
126 string occurance. |
|
127 |
|
128 ** ----------------------------------------------------------------------- **/ |
|
129 typedef struct NW_Encoder_StringItem_s{ |
|
130 NW_String_t data; |
|
131 NW_Uint16 frequency; |
|
132 } NW_Encoder_StringItem_t; |
|
133 |
|
134 |
|
135 /** ----------------------------------------------------------------------- ** |
|
136 @struct: NW_Encoder_StringTableIterator |
|
137 |
|
138 @synopsis: Iterator for walking through the string table. |
|
139 |
|
140 @scope: public |
|
141 @variables: |
|
142 NW_Encoder_StringTable_t* strTable |
|
143 The string table. |
|
144 |
|
145 NW_Uint16 currentIndex |
|
146 Current iterator cursor. |
|
147 |
|
148 @description: Iterator for walking through the string table. |
|
149 ** ----------------------------------------------------------------------- **/ |
|
150 typedef struct NW_Encoder_StringTableIterator_s{ |
|
151 NW_Encoder_StringTable_t* strTable; |
|
152 NW_Uint16 currentIndex; |
|
153 } NW_Encoder_StringTableIterator_t; |
|
154 |
|
155 |
|
156 /** ----------------------------------------------------------------------- ** |
|
157 @function: NW_Encoder_StringTable_new |
|
158 |
|
159 @synopsis: Creates a new String Item. |
|
160 |
|
161 @scope: public |
|
162 |
|
163 @description: Creates a new String Item. |
|
164 |
|
165 @returns: NW_Encoder_StringTable_t* |
|
166 The string table or NULL if not success. |
|
167 |
|
168 ** ----------------------------------------------------------------------- **/ |
|
169 IMPORT_C |
|
170 NW_Encoder_StringTable_t* |
|
171 NW_Encoder_StringTable_new(void); |
|
172 |
|
173 |
|
174 /** ----------------------------------------------------------------------- ** |
|
175 @function: NW_Encoder_StringTable_GetSize |
|
176 |
|
177 @synopsis: Returns number of strings in the string table. |
|
178 |
|
179 @scope: public |
|
180 |
|
181 @parameters: |
|
182 [in] NW_Encoder_StringTable_t* table |
|
183 The string table. |
|
184 |
|
185 @description: Returns number of strings in the string table. |
|
186 |
|
187 @returns: CXML_Vector_Metric_t |
|
188 Number of strings in the table. |
|
189 |
|
190 ** ----------------------------------------------------------------------- **/ |
|
191 IMPORT_C CXML_Vector_Metric_t |
|
192 NW_Encoder_StringTable_GetSize(NW_Encoder_StringTable_t* table); |
|
193 |
|
194 |
|
195 /** ----------------------------------------------------------------------- ** |
|
196 @function: NW_Encoder_StringTable_append |
|
197 |
|
198 @synopsis: Appends string to list. |
|
199 |
|
200 @scope: public |
|
201 |
|
202 @parameters: |
|
203 [in] NW_Encoder_StringTable_t* table |
|
204 The string table. |
|
205 |
|
206 [in] NW_String_t* string |
|
207 String to add. |
|
208 |
|
209 [in] NW_Bool literal |
|
210 String literal. |
|
211 |
|
212 [out] NW_Uint32* extensionByteOffset |
|
213 byte offset position of inserted or found string |
|
214 in string table |
|
215 |
|
216 @description: Appends new found string in the document to the list. |
|
217 If the string was already present in the list, then it |
|
218 increases its frequency (e.g. reference count), otherwise |
|
219 it creates a new StringItem in the list. |
|
220 |
|
221 @returns: NW_Status_t |
|
222 Status of operation. |
|
223 |
|
224 [NW_STAT_SUCCESS] |
|
225 Appended or found. |
|
226 |
|
227 [NW_STAT_BAD_INPUT_PARAM] |
|
228 Required parameter is NULL. |
|
229 |
|
230 ** ----------------------------------------------------------------------- **/ |
|
231 NW_Status_t |
|
232 NW_Encoder_StringTable_append(NW_Encoder_StringTable_t* table, |
|
233 NW_String_t* string, |
|
234 NW_Bool literal, |
|
235 NW_Uint32* extensionByteOffset); |
|
236 |
|
237 |
|
238 /** ----------------------------------------------------------------------- ** |
|
239 @function: NW_Encoder_StringTable_find |
|
240 |
|
241 @synopsis: Find a string in the table. |
|
242 |
|
243 @scope: public |
|
244 |
|
245 @parameters: |
|
246 [in] NW_Encoder_StringTable_t* strTable |
|
247 The string table. |
|
248 |
|
249 [in] NW_String_t* string |
|
250 default |
|
251 |
|
252 [out] NW_Uint32* strIndex |
|
253 Index of entry. |
|
254 |
|
255 [out] NW_Uint32* byteOffset |
|
256 Offset of text into the table. |
|
257 |
|
258 @description: Finds a string in the list and returns the corresponding |
|
259 StringItem, otherwise returns NULL. |
|
260 |
|
261 @returns: NW_Encoder_StringItem_t* |
|
262 Poiter to string item or NULL if not in the list. |
|
263 |
|
264 ** ----------------------------------------------------------------------- **/ |
|
265 NW_Encoder_StringItem_t* |
|
266 NW_Encoder_StringTable_find(NW_Encoder_StringTable_t* strTable, |
|
267 NW_String_t* string, |
|
268 NW_Uint32* strIndex, |
|
269 NW_Uint32* byteOffset); |
|
270 |
|
271 |
|
272 /** ----------------------------------------------------------------------- ** |
|
273 @function: NW_Encoder_StringTable_get |
|
274 |
|
275 @synopsis: Finds the string at a given index. |
|
276 |
|
277 @scope: public |
|
278 |
|
279 @parameters: |
|
280 [in] NW_Encoder_StringTable_t* strTable |
|
281 The string table. |
|
282 |
|
283 [in] NW_Uint32 index |
|
284 Index to get from. |
|
285 |
|
286 [out] NW_String_t* string |
|
287 Returned string. Check status for validity. |
|
288 |
|
289 @description: Finds the string at a given index. |
|
290 |
|
291 @returns: NW_Status_t |
|
292 Status of operation. |
|
293 |
|
294 [NW_STAT_SUCCESS] |
|
295 String found. |
|
296 |
|
297 [NW_STAT_FAILURE] |
|
298 String not found. |
|
299 |
|
300 ** ----------------------------------------------------------------------- **/ |
|
301 IMPORT_C NW_Status_t |
|
302 NW_Encoder_StringTable_get(NW_Encoder_StringTable_t* strTable, |
|
303 NW_Uint32 index, |
|
304 NW_String_t* string); |
|
305 |
|
306 |
|
307 /** ----------------------------------------------------------------------- ** |
|
308 @function: NW_Encoder_StringTable_getItemAt |
|
309 |
|
310 @synopsis: Finds the string at a given index. |
|
311 |
|
312 @scope: public |
|
313 |
|
314 @parameters: |
|
315 [in] NW_Encoder_StringTable_t* strTable |
|
316 The string table. |
|
317 |
|
318 [in] NW_Uint32 index |
|
319 Index to get from. |
|
320 |
|
321 @description: Finds the string at a given index. |
|
322 |
|
323 @returns: NW_Encoder_StringItem_t* |
|
324 String item at index or NULL if not found. |
|
325 |
|
326 ** ----------------------------------------------------------------------- **/ |
|
327 NW_Encoder_StringItem_t* |
|
328 NW_Encoder_StringTable_getItemAt(NW_Encoder_StringTable_t* strTable, |
|
329 NW_Uint32 index); |
|
330 |
|
331 |
|
332 /** ----------------------------------------------------------------------- ** |
|
333 @function: NW_Encoder_StringTable_removeAt |
|
334 |
|
335 @synopsis: Removes a string item. |
|
336 |
|
337 @scope: public |
|
338 |
|
339 @parameters: |
|
340 [in] NW_Encoder_StringTable_t* strTable |
|
341 The string table. |
|
342 |
|
343 [in] CXML_Vector_Metric_t index |
|
344 Index to remove from. |
|
345 |
|
346 @description: Removes a string item. |
|
347 |
|
348 @returns: NW_Status_t |
|
349 Status of operation. |
|
350 |
|
351 [NW_STAT_SUCCESS] |
|
352 Item removed. |
|
353 |
|
354 [NW_STAT_FAILURE] |
|
355 Invalid index. |
|
356 |
|
357 ** ----------------------------------------------------------------------- **/ |
|
358 NW_Status_t |
|
359 NW_Encoder_StringTable_removeAt(NW_Encoder_StringTable_t* strTable, |
|
360 CXML_Vector_Metric_t index); |
|
361 |
|
362 |
|
363 /** ----------------------------------------------------------------------- ** |
|
364 @function: NW_Encoder_StringTable_getTotalBytes |
|
365 |
|
366 @synopsis: Returns the total number of bytes used for storing all |
|
367 the strings in the list. |
|
368 |
|
369 @scope: public |
|
370 |
|
371 @parameters: |
|
372 [in] NW_Encoder_StringTable_t* strTable |
|
373 The string table. |
|
374 |
|
375 @description: Returns the total number of bytes used for storing all |
|
376 the strings in the list. |
|
377 |
|
378 @returns: NW_Uint32 |
|
379 Total byte count. |
|
380 |
|
381 ** ----------------------------------------------------------------------- **/ |
|
382 IMPORT_C NW_Uint32 |
|
383 NW_Encoder_StringTable_getTotalBytes(NW_Encoder_StringTable_t* strTable); |
|
384 |
|
385 |
|
386 /** ----------------------------------------------------------------------- ** |
|
387 @function: NW_Encoder_StringTable_createFromDOM |
|
388 |
|
389 @synopsis: Creates table for a given document. |
|
390 |
|
391 @scope: public |
|
392 |
|
393 @parameters: |
|
394 [in] NW_Encoder_StringTable_t* strTable |
|
395 The string table. |
|
396 |
|
397 [in] NW_DOM_DocumentNode_t* doc |
|
398 Root node of DOM to encode. |
|
399 |
|
400 [in] NW_WBXML_Dictionary_t* dictionary |
|
401 The dictionary. |
|
402 |
|
403 @description: Creates table for a given document. |
|
404 |
|
405 @returns: NW_Status_t |
|
406 Status of operation. |
|
407 |
|
408 [NW_STAT_SUCCESS] |
|
409 Created. |
|
410 |
|
411 [NW_STAT_FAILURE] |
|
412 No bytes found. |
|
413 |
|
414 ** ----------------------------------------------------------------------- **/ |
|
415 IMPORT_C NW_Status_t |
|
416 NW_Encoder_StringTable_createFromDOM(NW_Encoder_StringTable_t* strTable, |
|
417 NW_DOM_DocumentNode_t* doc, |
|
418 NW_WBXML_Dictionary_t* dictionary); |
|
419 |
|
420 |
|
421 /** ----------------------------------------------------------------------- ** |
|
422 @function: NW_Encoder_StringTable_getStringTableOffset |
|
423 |
|
424 @synopsis: Looks for occurrence of a string with the specified content. |
|
425 |
|
426 @scope: public |
|
427 |
|
428 @parameters: |
|
429 [in] void* pStringTableObject |
|
430 The string table. |
|
431 |
|
432 [in] NW_Uint32 byteCount |
|
433 Length of text. |
|
434 |
|
435 [in] const NW_Uint8* pString |
|
436 Text. |
|
437 |
|
438 [out] NW_Bool* pFound |
|
439 True if found in table. |
|
440 |
|
441 [out] NW_Uint32* pTableOffset |
|
442 Offset if found. |
|
443 |
|
444 @description: Looks for occurrence of a string with the specified content. |
|
445 Creates a string with the specified storage and byte length. |
|
446 |
|
447 @returns: NW_Status_t |
|
448 Status of operation. |
|
449 |
|
450 [NW_STAT_SUCCESS] |
|
451 Always returns success. |
|
452 |
|
453 ** ----------------------------------------------------------------------- **/ |
|
454 IMPORT_C NW_Status_t |
|
455 NW_Encoder_StringTable_getStringTableOffset(void* pStringTableObject, |
|
456 NW_Uint32 byteCount, |
|
457 const NW_Uint8* pString, |
|
458 NW_Bool* pFound, |
|
459 NW_Uint32* pTableOffset); |
|
460 |
|
461 |
|
462 /** ----------------------------------------------------------------------- ** |
|
463 @function: NW_Encoder_StringTable_addToStringTable |
|
464 |
|
465 @synopsis: Add string to string table. |
|
466 |
|
467 @scope: public |
|
468 |
|
469 @parameters: |
|
470 [in-out] void* pStringTableObject |
|
471 The string table. |
|
472 |
|
473 [in] NW_Uint32 byteCount |
|
474 Length of text. |
|
475 |
|
476 [in] const NW_Uint8* pString |
|
477 Text to add to table. |
|
478 |
|
479 [in] NW_Uint32* pTableOffset |
|
480 Offset installed at. |
|
481 |
|
482 @description: Adds the string to the table if it is not already there. |
|
483 Otherwise it increases the reference count. |
|
484 |
|
485 @returns: NW_Status_t |
|
486 Status of operation. |
|
487 |
|
488 [NW_STAT_SUCCESS] |
|
489 Added to table. |
|
490 |
|
491 [NW_STAT_BAD_INPUT_PARAM] |
|
492 Required parameter is NULL or invalid. |
|
493 |
|
494 ** ----------------------------------------------------------------------- **/ |
|
495 IMPORT_C NW_Status_t |
|
496 NW_Encoder_StringTable_addToStringTable(void* pStringTableObject, |
|
497 NW_Uint32 byteCount, |
|
498 const NW_Uint8* pString, |
|
499 NW_Uint32* pTableOffset); |
|
500 |
|
501 |
|
502 /** ----------------------------------------------------------------------- ** |
|
503 @function: NW_Encoder_StringTable_StringTableIterateInit |
|
504 |
|
505 @synopsis: Initializes a string table iterator. |
|
506 |
|
507 @scope: public |
|
508 |
|
509 @parameters: |
|
510 [in] void* pStringTableObject |
|
511 The string table. |
|
512 |
|
513 [in-out] void* pStringTableIterator |
|
514 Initialized iterator. |
|
515 |
|
516 @description: Initializes a string table iterator. |
|
517 |
|
518 @returns: NW_Status_t |
|
519 Status of operation. |
|
520 |
|
521 [NW_STAT_SUCCESS] |
|
522 Always returns success. |
|
523 |
|
524 ** ----------------------------------------------------------------------- **/ |
|
525 IMPORT_C NW_Status_t |
|
526 NW_Encoder_StringTable_StringTableIterateInit(void* pStringTableObject, |
|
527 void* pStringTableIterator); |
|
528 |
|
529 |
|
530 /** ----------------------------------------------------------------------- ** |
|
531 @function: NW_Encoder_StringTable_StringTableIterateNext |
|
532 |
|
533 @synopsis: Iterates through the table. |
|
534 |
|
535 @scope: public |
|
536 |
|
537 @parameters: |
|
538 [in-out] void* pStringTableIterator |
|
539 The iterator. |
|
540 |
|
541 [out] NW_Uint32* pByteCount |
|
542 Byte count for returned value or 0. |
|
543 |
|
544 [out] NW_Uint8** ppBuf |
|
545 The returned text. |
|
546 |
|
547 @description: Iterates through the table. At end of string table |
|
548 return byteCount = 0. |
|
549 |
|
550 @returns: NW_Status_t |
|
551 Status of operation. |
|
552 |
|
553 [NW_STAT_WBXML_ITERATE_MORE] |
|
554 More to iterate. This value valid. |
|
555 |
|
556 [NW_STAT_WBXML_ITERATE_DONE] |
|
557 Nothing more to iterate. This value not valid. |
|
558 |
|
559 ** ----------------------------------------------------------------------- **/ |
|
560 IMPORT_C NW_Status_t |
|
561 NW_Encoder_StringTable_StringTableIterateNext(void* pStringTableIterator, |
|
562 NW_Uint32* pByteCount, |
|
563 NW_Uint8** ppBuf); |
|
564 |
|
565 |
|
566 #ifdef __cplusplus |
|
567 } /* extern "C" { */ |
|
568 #endif /* __cplusplus */ |
|
569 |
|
570 #endif |
|