web_plat/cxml_library_api/inc/nw_tinytree_ebuffer.h
changeset 0 dd21522fd290
child 37 cb62a4f66ebe
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     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_TINYTREE_EBUFFER_H
       
    29 #define NW_TINYTREE_EBUFFER_H
       
    30 
       
    31 #include "cxml_proj.h"
       
    32 
       
    33 #ifdef __cplusplus
       
    34 extern "C" {
       
    35 #endif /* __cplusplus */
       
    36 
       
    37 /* ----------------------------------------------------------------------- **  
       
    38    EBuffers (expandable buffers) provide storage blocks of bytes that
       
    39    can be accessed by index. Tiny trees use these to store serialized
       
    40    tree data. Node source offsets are stored as ebuffer indexes. EBuffers
       
    41    are similar to segmented vectors, but with variable segment sizes so
       
    42    that continuous byte blocks of different sizes can be stored efficiently.
       
    43    Unlike vectors, EBuffers store only byte data, so alignment calculations
       
    44    are not needed. Also, EBuffers support appending, but not insertion and 
       
    45    deletion. These  simplifications make it much easier to deal with 
       
    46    variable segment sizes while guaranteeing that continuous blocks remain
       
    47    continuous.
       
    48 ** ----------------------------------------------------------------------- **/
       
    49 
       
    50 /* ------------------------------------------------------------------------- */
       
    51 
       
    52 #define NW_TINY_TREE_BLOCK_SIZE_DEFAULT    ((CXML_Vector_Metric_t) 256)
       
    53 
       
    54 
       
    55 /** ----------------------------------------------------------------------- **
       
    56     @struct:       NW_TinyTree_Segment
       
    57 
       
    58     @synopsis:    Tiny tree data segment.
       
    59 
       
    60     @scope:       public
       
    61     @variables:
       
    62        NW_Uint8* storage
       
    63                   Data storage.
       
    64 
       
    65        CXML_Vector_Metric_t segmentSize
       
    66                   Size of segment.
       
    67 
       
    68        CXML_Vector_Metric_t freeOffset
       
    69                   Free offset.
       
    70 
       
    71     @description: Tiny tree data segment.
       
    72  ** ----------------------------------------------------------------------- **/
       
    73 typedef struct NW_TinyTree_Segment_s {
       
    74   NW_Uint8* storage;
       
    75   NW_TinyTree_Offset_t segmentSize;
       
    76   NW_TinyTree_Offset_t freeOffset;
       
    77 } NW_TinyTree_Segment_t;
       
    78 
       
    79 
       
    80 /** ----------------------------------------------------------------------- **
       
    81     @struct:       NW_TinyTree_EBuffer
       
    82 
       
    83     @synopsis:    Tiny tree E buffer.
       
    84 
       
    85     @scope:       public
       
    86     @variables:
       
    87        NW_Bool ownFirstBlock
       
    88                   Ownership flag.
       
    89 
       
    90        CXML_Vector_Metric_t blockSize
       
    91                   Size of block,
       
    92 
       
    93        NW_TinyTree_Segment_t* segmentList
       
    94                   List of segments.
       
    95 
       
    96        CXML_Vector_Metric_t segmentListSize
       
    97                   Size of segment list.
       
    98 
       
    99        CXML_Vector_Metric_t numSegments
       
   100                   Number of segments.
       
   101 
       
   102     @description: EBuffers (expandable buffers) provide storage blocks
       
   103                   of bytes that can be accessed by index. Tiny trees use
       
   104                   these to store serialized tree data. Node source
       
   105                   offsets are stored as ebuffer indexes. EBuffers are
       
   106                   similar to segmented vectors, but with variable
       
   107                   segment sizes so that continuous byte blocks of
       
   108                   different sizes can be stored efficiently.  Unlike
       
   109                   vectors, EBuffers store only byte data, so alignment
       
   110                   calculations are not needed. Also, EBuffers support
       
   111                   appending, but not insertion and deletion. These
       
   112                   simplifications make it much easier to deal with
       
   113                   variable segment sizes while guaranteeing that
       
   114                   continuous blocks remain continuous.
       
   115 
       
   116  ** ----------------------------------------------------------------------- **/
       
   117 typedef struct NW_TinyTree_EBuffer_s {
       
   118   NW_Bool ownFirstBlock;
       
   119   CXML_Vector_Metric_t blockSize;
       
   120   NW_TinyTree_Segment_t* segmentList;
       
   121   CXML_Vector_Metric_t segmentListSize;
       
   122   CXML_Vector_Metric_t numSegments;
       
   123 } NW_TinyTree_EBuffer_t;
       
   124 
       
   125 /* ------------------------------------------------------------------------- *
       
   126    public methods
       
   127  * ------------------------------------------------------------------------- */
       
   128  
       
   129 NW_TinyTree_EBuffer_t*
       
   130 NW_TinyTree_EBuffer_Construct (NW_Uint8* initialBuffer,
       
   131                                NW_TinyTree_Offset_t initBuffSize,
       
   132                                NW_TinyTree_Offset_t blockSize,
       
   133                                NW_Bool freeBuff);
       
   134 
       
   135 void
       
   136 NW_TinyTree_EBuffer_Destruct (NW_TinyTree_EBuffer_t* thisObj);
       
   137 
       
   138 extern 
       
   139 NW_Uint8*
       
   140 NW_TinyTree_EBuffer_GetWritableBlock(NW_TinyTree_EBuffer_t* ebuffer,
       
   141                                      NW_TinyTree_Offset_t   size,
       
   142                                      NW_TinyTree_Offset_t*  index);
       
   143 
       
   144 
       
   145 extern
       
   146 NW_Status_t
       
   147 NW_TinyTree_EBuffer_GetSegmentAndOffset(NW_TinyTree_EBuffer_t* ebuffer,
       
   148                                         NW_TinyTree_Offset_t index,
       
   149                                         NW_Uint8** segment,              /* OUT */
       
   150                                         NW_TinyTree_Offset_t* segSize,  /* OUT */
       
   151                                         NW_TinyTree_Offset_t* offset);  /* OUT */
       
   152 
       
   153 extern
       
   154 NW_Status_t
       
   155 NW_TinyTree_EBuffer_GetIndex(NW_TinyTree_EBuffer_t* ebuffer,
       
   156                              NW_Uint8* segmentAddr,         
       
   157                              NW_TinyTree_Offset_t   offset,
       
   158                              NW_TinyTree_Offset_t * index); /* OUT */
       
   159 
       
   160 extern
       
   161 NW_Uint8*
       
   162 NW_TinyTree_EBuffer_AddressAt(NW_TinyTree_EBuffer_t* ebuffer,
       
   163                               NW_TinyTree_Offset_t index);
       
   164 
       
   165 
       
   166 #ifdef __cplusplus
       
   167 } /* extern "C" { */
       
   168 #endif /* __cplusplus */
       
   169 
       
   170 #endif /* NW_TINYTREE_EBUFFER_H */