xmlsrv_plat/cxml_library_api/inc/nw_tinytree.h
branchRCL_3
changeset 21 604ca70b6235
parent 20 889504eac4fb
equal deleted inserted replaced
20:889504eac4fb 21:604ca70b6235
     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 /** ----------------------------------------------------------------------- **
       
    21     @package:     NW_TinyTree
       
    22 
       
    23     @synopsis:    default
       
    24 
       
    25     @description: default
       
    26 
       
    27  ** ----------------------------------------------------------------------- **/
       
    28 
       
    29 #ifndef NW_TINY_TREE_H
       
    30 #define NW_TINY_TREE_H
       
    31 
       
    32 #include <xml/cxml/cxml_proj.h>
       
    33 #include <xml/cxml/nw_tinytree_treevector.h>
       
    34 #include <xml/cxml/nw_tinytree_ebuffer.h>
       
    35 
       
    36 #ifdef __cplusplus
       
    37 extern "C" {
       
    38 #endif /* __cplusplus */
       
    39 
       
    40 
       
    41 /* ----------------------------------------------------------------------- **
       
    42    Tiny tree definitions   
       
    43 ** ----------------------------------------------------------------------- **/
       
    44 
       
    45 
       
    46 
       
    47 /** ----------------------------------------------------------------------- **
       
    48     @typedef:     NW_TinyTree_Index
       
    49 
       
    50     @synopsis:    An index into the node array.
       
    51 
       
    52     @scope:       public
       
    53     @type:        CXML_Vector_Metric_t
       
    54 
       
    55     @description: An index into the node array.
       
    56  ** ----------------------------------------------------------------------- **/
       
    57 typedef CXML_Vector_Metric_t NW_TinyTree_Index_t; 
       
    58 
       
    59 
       
    60 /** ----------------------------------------------------------------------- **
       
    61     @typedef:     NW_TinyTree_Offset
       
    62 
       
    63     @synopsis:    An offset into the source buffer.
       
    64 
       
    65     @scope:       public
       
    66     @type:        NW_Uint32
       
    67 
       
    68     @description: An offset into the source buffer.
       
    69  ** ----------------------------------------------------------------------- **/
       
    70 /*
       
    71 typedef NW_Uint32 NW_TinyTree_Offset_t;
       
    72 */
       
    73 
       
    74 /*----------------------------------------------------------------------- **
       
    75    Node flags  
       
    76 ** ----------------------------------------------------------------------- **/
       
    77 
       
    78 #define TNODE_FLAG_LASTSIBLING   0x8000 /* My next_sibling points to parent */
       
    79 
       
    80 #define TNODE_FLAG_ROOT          0x4000 /* I'm the tree root */
       
    81 
       
    82 #define TNODE_FLAG_TREE          0x2000 /* I'm a special sentinel node marking
       
    83                                            the beginning of a segment */
       
    84 
       
    85 #define TNODE_FLAG_ORPHAN        0x1000 /* A node not part of a tree */
       
    86 
       
    87 #define TNODE_USR_FLAGS          0x0FFF  /* 12 bits available to tree user */
       
    88 
       
    89 
       
    90 /** ----------------------------------------------------------------------- **
       
    91     @struct:      NW_TinyTree_Node
       
    92 
       
    93     @synopsis:    Tiny tree node structure.
       
    94 
       
    95     @scope:       public
       
    96     @variables:
       
    97        NW_Uint16 flags
       
    98                   Node description flags.
       
    99 
       
   100        NW_TinyTree_Offset_t source_offset
       
   101                   Offset of node data into original buffer.
       
   102 
       
   103        NW_TinyTree_Index_t first_child
       
   104                   Index of first child of this node.
       
   105 
       
   106        NW_TinyTree_Index_t next_sibling
       
   107                   Index of next sibling of this node.
       
   108 
       
   109     @description: Tiny tree node structure.
       
   110  ** ----------------------------------------------------------------------- **/
       
   111 typedef struct NW_TinyTree_Node_s NW_TinyTree_Node_t;
       
   112 
       
   113 struct NW_TinyTree_Node_s {
       
   114   NW_Uint16 flags;
       
   115   NW_TinyTree_Offset_t source_offset;
       
   116   NW_TinyTree_Node_t* first_child;
       
   117   NW_TinyTree_Node_t* next_sibling;
       
   118   NW_TinyTree_t* tree;
       
   119   NW_Uint16 token;
       
   120 };
       
   121    
       
   122 
       
   123 /** ----------------------------------------------------------------------- **
       
   124     @struct:      NW_TinyTree_TinyTree
       
   125 
       
   126     @synopsis:    Tree structure. 
       
   127 
       
   128     @scope:       public
       
   129     @variables:
       
   130        NW_TinyTree_TreeVector_t* tree
       
   131                   Node data.
       
   132 
       
   133        NW_TinyTree_Index_t root_index
       
   134                   Node data.
       
   135 
       
   136        NW_TinyTree_EBuffer_t* ebuffer
       
   137                   Buffer data.
       
   138 
       
   139        void* context
       
   140                   Context accessible from tree (typically the parser that 
       
   141                   builds and reads the tree).
       
   142 
       
   143     @description: Tree structure. Provides access points for root 
       
   144                   and buffer data.
       
   145  ** ----------------------------------------------------------------------- **/
       
   146 typedef struct NW_TinyTree_TinyTree_s {
       
   147   /* Node data */
       
   148   NW_TinyTree_TreeVector_t* tree;
       
   149   NW_TinyTree_Index_t root_index;
       
   150   /* Buffer data */
       
   151   NW_TinyTree_EBuffer_t* ebuffer;
       
   152   /* Context accessible from tree (typically the parser that builds and reads the tree) */
       
   153   void* context;
       
   154 }NW_TinyTree_TinyTree_t;
       
   155 
       
   156 /** ----------------------------------------------------------------------- **
       
   157     @struct:      NW_TinyTree_TreeNode
       
   158 
       
   159     @synopsis:    A sentinel node that resides at the start of 
       
   160                   every tree vector segment.
       
   161 
       
   162     @scope:       public
       
   163     @variables:
       
   164        NW_Uint16 flags
       
   165                   Node description flags.
       
   166 
       
   167        NW_TinyTree_t* tree
       
   168                   The tree.
       
   169 
       
   170     @description: A special sentinel node that resides at the start of 
       
   171                   every tree vector segment, pointing to the tree itself.
       
   172                   This is used by applications like the DOM api that do 
       
   173                   not have a reference to the tree when operating on nodes.
       
   174  ** ----------------------------------------------------------------------- **/
       
   175 typedef struct NW_TinyTree_TreeNode_s{
       
   176   NW_Uint16 flags;
       
   177   NW_TinyTree_t* tree;
       
   178 }NW_TinyTree_TreeNode_t;
       
   179 
       
   180 
       
   181  /* ----------------------------------------------------------------------- ** 
       
   182     Public tiny tree API  
       
   183  ** ----------------------------------------------------------------------- **/
       
   184 
       
   185 
       
   186 
       
   187 /** ----------------------------------------------------------------------- **
       
   188     @function:    NW_TinyTree_new
       
   189 
       
   190     @synopsis:    Initialize a tree.
       
   191 
       
   192     @scope:       public
       
   193 
       
   194     @description: Initialize a tree.Allocates memory and initializes variables.
       
   195 
       
   196     @returns:     NW_TinyTree_TinyTree_t*
       
   197                   The new tree.
       
   198 
       
   199  ** ----------------------------------------------------------------------- **/
       
   200 NW_TinyTree_t*
       
   201 NW_TinyTree_new();
       
   202 
       
   203 
       
   204 /** ----------------------------------------------------------------------- **
       
   205     @function:    NW_TinyTree_construct
       
   206 
       
   207     @synopsis:    Constructor.
       
   208 
       
   209     @scope:       public
       
   210 
       
   211     @parameters:
       
   212        [in] NW_TinyTree_TinyTree_t* tree
       
   213                   The tiny tree.
       
   214 
       
   215        [in] CXML_Vector_Metric_t initialNodeCount
       
   216                   Initiali size of vector of nodes.
       
   217 
       
   218        [in] void* buffer
       
   219                   Link buffer into ebuffer.
       
   220 
       
   221        [in] NW_TinyTree_Offset_t buffsz
       
   222                   Size of block of data.
       
   223 
       
   224        [in] void* context
       
   225                   Context (i.e. parser).
       
   226 
       
   227        [in] NW_Bool freeBuff
       
   228                   Buffer deallocation flag.
       
   229 
       
   230     @description: Constructor. Adds data to the structure returned 
       
   231                   by NW_TinyTree_new.
       
   232 
       
   233     @returns:     NW_Status_t
       
   234                   Status of operation.
       
   235 
       
   236        [NW_STAT_SUCCESS]
       
   237                   Tree created.
       
   238 
       
   239        [NW_STAT_FAILURE]
       
   240                   Out of memory or general error.
       
   241 
       
   242  ** ----------------------------------------------------------------------- **/
       
   243 NW_Status_t
       
   244 NW_TinyTree_construct(NW_TinyTree_t* tree,
       
   245                       CXML_Vector_Metric_t initialNodeCount,
       
   246                       void* buffer,
       
   247                       NW_TinyTree_Offset_t buffsz,
       
   248                       void* context,
       
   249                       NW_Bool freeBuff);
       
   250 
       
   251 
       
   252 /** ----------------------------------------------------------------------- **
       
   253     @function:    NW_TinyTree_destruct
       
   254 
       
   255     @synopsis:    Clean up tree resources.
       
   256 
       
   257     @scope:       public
       
   258 
       
   259     @parameters:
       
   260        [in] NW_TinyTree_t* tree
       
   261                   default
       
   262 
       
   263     @description: Clean up tree resources.
       
   264 
       
   265  ** ----------------------------------------------------------------------- **/
       
   266 void
       
   267 NW_TinyTree_destruct(NW_TinyTree_t* tree);
       
   268 
       
   269 
       
   270 /** ----------------------------------------------------------------------- **
       
   271     @function:    NW_TinyTree_createNode
       
   272 
       
   273     @synopsis:    Create an unattached node.
       
   274 
       
   275     @scope:       public
       
   276 
       
   277     @parameters:
       
   278        [in] NW_TinyTree_t* tree
       
   279                   The tiny tree.
       
   280 
       
   281        [in] NW_TinyTree_Offset_t offset
       
   282                   Offset into buffer.
       
   283 
       
   284     @description: Create an unattached node which references the source 
       
   285                   buffer at offset.
       
   286 
       
   287     @returns:     NW_TinyTree_Node_t*
       
   288                   Node or NULL if memory could not be allocated.
       
   289 
       
   290  ** ----------------------------------------------------------------------- **/
       
   291 NW_TinyTree_Node_t*
       
   292 NW_TinyTree_createNode(NW_TinyTree_t* tree, 
       
   293                        NW_TinyTree_Offset_t offset);
       
   294 
       
   295 
       
   296 /** ----------------------------------------------------------------------- **
       
   297     @function:    NW_TinyTree_setRoot
       
   298 
       
   299     @synopsis:    Create a root node.
       
   300 
       
   301     @scope:       public
       
   302 
       
   303     @parameters:
       
   304        [in] NW_TinyTree_t* tree
       
   305                   The tiny tree.
       
   306 
       
   307        [in] NW_TinyTree_Offset_t offset
       
   308                   Offset into buffer.
       
   309 
       
   310     @description: Create a root node which references the source buffer 
       
   311                   at offset. Returns a pointer to the root node.
       
   312 
       
   313     @returns:     NW_TinyTree_Node_t*
       
   314                   Pointer to the root node.
       
   315 
       
   316  ** ----------------------------------------------------------------------- **/
       
   317 NW_TinyTree_Node_t*
       
   318 NW_TinyTree_setRoot(NW_TinyTree_t* tree, 
       
   319                     NW_TinyTree_Offset_t offset);
       
   320 
       
   321 
       
   322 /** ----------------------------------------------------------------------- **
       
   323     @function:    NW_TinyTree_getRoot
       
   324 
       
   325     @synopsis:    Get the root node of the tree.
       
   326 
       
   327     @scope:       public
       
   328 
       
   329     @parameters:
       
   330        [in] NW_TinyTree_t* tree
       
   331                   The tiny tree.
       
   332 
       
   333     @description: Get the root node of the tree.
       
   334 
       
   335     @returns:     NW_TinyTree_Node_t*
       
   336                   The root node or NULL if it is not valid.
       
   337 
       
   338  ** ----------------------------------------------------------------------- **/
       
   339 NW_TinyTree_Node_t*
       
   340 NW_TinyTree_getRoot(NW_TinyTree_t* tree);
       
   341 
       
   342 
       
   343 /** ----------------------------------------------------------------------- **
       
   344     @function:    NW_TinyTree_findNextSibling
       
   345 
       
   346     @synopsis:    Find the next sibling of a node.
       
   347 
       
   348     @scope:       public
       
   349 
       
   350     @parameters:
       
   351        [in] NW_TinyTree_t* tree
       
   352                   The tiny tree.
       
   353 
       
   354        [in] NW_TinyTree_Node_t* node
       
   355                   The reference node.
       
   356 
       
   357     @description: Find the next sibling of a node.
       
   358 
       
   359     @returns:     NW_TinyTree_Node_t*
       
   360                   The next sibling node or NULL if it is not valid.
       
   361 
       
   362  ** ----------------------------------------------------------------------- **/
       
   363 NW_TinyTree_Node_t*
       
   364 NW_TinyTree_findNextSibling(NW_TinyTree_Node_t* node);
       
   365 
       
   366 
       
   367 /** ----------------------------------------------------------------------- **
       
   368     @function:    NW_TinyTree_findLastSibling
       
   369 
       
   370     @synopsis:    Find last sibling of a node.
       
   371 
       
   372     @scope:       public
       
   373 
       
   374     @parameters:
       
   375        [in] NW_TinyTree_t* tree
       
   376                   The tiny tree.
       
   377 
       
   378        [in] NW_TinyTree_Node_t* node
       
   379                   The reference node.
       
   380 
       
   381     @description: Find last sibling of a node.
       
   382 
       
   383     @returns:     NW_TinyTree_Node_t*
       
   384                   The last sibling node or NULL if it is not valid.
       
   385 
       
   386  ** ----------------------------------------------------------------------- **/
       
   387 NW_TinyTree_Node_t*
       
   388 NW_TinyTree_findLastSibling(NW_TinyTree_Node_t* node);
       
   389 
       
   390 
       
   391 /** ----------------------------------------------------------------------- **
       
   392     @function:    NW_TinyTree_findPreviousSibling
       
   393 
       
   394     @synopsis:    Find the previous sibling of a node.
       
   395 
       
   396     @scope:       public
       
   397 
       
   398     @parameters:
       
   399        [in] NW_TinyTree_t* tree
       
   400                   The tiny tree.
       
   401 
       
   402        [in] NW_TinyTree_Node_t* node
       
   403                   The reference node.
       
   404 
       
   405     @description: Find the previous sibling of a node.
       
   406 
       
   407     @returns:     NW_TinyTree_Node_t*
       
   408                   The previous sibling node or NULL if it is not valid.
       
   409 
       
   410  ** ----------------------------------------------------------------------- **/
       
   411 NW_TinyTree_Node_t*
       
   412 NW_TinyTree_findPreviousSibling(NW_TinyTree_Node_t* node);
       
   413 
       
   414 
       
   415 /** ----------------------------------------------------------------------- **
       
   416     @function:    NW_TinyTree_findFirstChild
       
   417 
       
   418     @synopsis:    Find the first child of a node.
       
   419 
       
   420     @scope:       public
       
   421 
       
   422     @parameters:
       
   423        [in] NW_TinyTree_t* tree
       
   424                   The tiny tree.
       
   425 
       
   426        [in] NW_TinyTree_Node_t* node
       
   427                   The reference node.
       
   428 
       
   429     @description: Find the first child of a node.
       
   430 
       
   431     @returns:     NW_TinyTree_Node_t*
       
   432                   The first child node or NULL if it is not valid.
       
   433 
       
   434  ** ----------------------------------------------------------------------- **/
       
   435 NW_TinyTree_Node_t*
       
   436 NW_TinyTree_findFirstChild(NW_TinyTree_Node_t* node);
       
   437 
       
   438 
       
   439 /** ----------------------------------------------------------------------- **
       
   440     @function:    NW_TinyTree_findLastChild
       
   441 
       
   442     @synopsis:    Find a node's last child.
       
   443 
       
   444     @scope:       public
       
   445 
       
   446     @parameters:
       
   447        [in] NW_TinyTree_t* tree
       
   448                   The tiny tree.
       
   449 
       
   450        [in] NW_TinyTree_Node_t* node
       
   451                   The reference node.
       
   452 
       
   453     @description: Find a node's last child.
       
   454 
       
   455     @returns:     NW_TinyTree_Node_t*
       
   456                   The last child node or NULL if it is not valid.
       
   457 
       
   458  ** ----------------------------------------------------------------------- **/
       
   459 NW_TinyTree_Node_t*
       
   460 NW_TinyTree_findLastChild(NW_TinyTree_Node_t* node);
       
   461 
       
   462 
       
   463 /** ----------------------------------------------------------------------- **
       
   464     @function:    NW_TinyTree_findParent
       
   465 
       
   466     @synopsis:    Find a node's parent.
       
   467 
       
   468     @scope:       public
       
   469 
       
   470     @parameters:
       
   471        [in] NW_TinyTree_t* tree
       
   472                   The tiny tree.
       
   473 
       
   474        [in] NW_TinyTree_Node_t* node
       
   475                   The reference node.
       
   476 
       
   477     @description: Find a node's parent.
       
   478 
       
   479     @returns:     NW_TinyTree_Node_t*
       
   480                   The parent node of this node or NULL if it is not valid.
       
   481 
       
   482  ** ----------------------------------------------------------------------- **/
       
   483 NW_TinyTree_Node_t* 
       
   484 NW_TinyTree_findParent(NW_TinyTree_Node_t* node);
       
   485 
       
   486 
       
   487 /** ----------------------------------------------------------------------- **
       
   488     @function:    NW_TinyTree_attachAfter
       
   489 
       
   490     @synopsis:    Attach a sibling after a node.
       
   491 
       
   492     @scope:       public
       
   493 
       
   494     @parameters:
       
   495        [in] NW_TinyTree_t* tree
       
   496                   The tiny tree.
       
   497 
       
   498        [in] NW_TinyTree_Node_t* node
       
   499                   The reference node.
       
   500 
       
   501        [in] NW_TinyTree_Node_t* sibling
       
   502                   Sibling node to attach.
       
   503 
       
   504     @description: Attach a sibling after a node.
       
   505 
       
   506     @returns:     NW_Status_t
       
   507                   Status of operation.
       
   508 
       
   509        [NW_STAT_SUCCESS]
       
   510                   Always returns success.
       
   511 
       
   512  ** ----------------------------------------------------------------------- **/
       
   513 NW_Status_t 
       
   514 NW_TinyTree_attachAfter(NW_TinyTree_Node_t* node, 
       
   515                         NW_TinyTree_Node_t* sibling);
       
   516 
       
   517 
       
   518 /** ----------------------------------------------------------------------- **
       
   519     @function:    NW_TinyTree_attachBefore
       
   520 
       
   521     @synopsis:    Attach a sibling before another node.
       
   522 
       
   523     @scope:       public
       
   524 
       
   525     @parameters:
       
   526        [in] NW_TinyTree_t* tree
       
   527                   The tiny tree.
       
   528 
       
   529        [in] NW_TinyTree_Node_t* node
       
   530                   The reference node.
       
   531 
       
   532        [in] NW_TinyTree_Node_t* sibling
       
   533                   default
       
   534 
       
   535     @description: Attach a sibling before another node.
       
   536 
       
   537     @returns:     NW_Status_t
       
   538                   Status of operation.
       
   539 
       
   540        [NW_STAT_SUCCESS]
       
   541                   Node attached.
       
   542 
       
   543        [NW_STAT_FAILURE]
       
   544                   Could not attach node.
       
   545 
       
   546  ** ----------------------------------------------------------------------- **/
       
   547 NW_Status_t 
       
   548 NW_TinyTree_attachBefore(NW_TinyTree_Node_t* node, 
       
   549                          NW_TinyTree_Node_t* sibling);
       
   550 
       
   551 
       
   552 /** ----------------------------------------------------------------------- **
       
   553     @function:    NW_TinyTree_attachChild
       
   554 
       
   555     @synopsis:    Attach a child to a node.
       
   556 
       
   557     @scope:       public
       
   558 
       
   559     @parameters:
       
   560        [in] NW_TinyTree_t* tree
       
   561                   The tiny tree.
       
   562 
       
   563        [in] NW_TinyTree_Node_t* node
       
   564                   The reference node.
       
   565 
       
   566        [in] NW_TinyTree_Node_t* child
       
   567                   The child to attach.
       
   568 
       
   569     @description: Attach a child to a node as last child.
       
   570 
       
   571     @returns:     NW_Status_t
       
   572                   Status of operation.
       
   573 
       
   574        [NW_STAT_SUCCESS]
       
   575                   Node attached.
       
   576 
       
   577        [NW_STAT_FAILURE]
       
   578                   Could not attach node.
       
   579 
       
   580  ** ----------------------------------------------------------------------- **/
       
   581 NW_Status_t
       
   582 NW_TinyTree_attachChild(NW_TinyTree_Node_t* node, 
       
   583                         NW_TinyTree_Node_t* child);
       
   584 
       
   585 
       
   586 /** ----------------------------------------------------------------------- **
       
   587     @function:    NW_TinyTree_deleteNode
       
   588 
       
   589     @synopsis:    Delete a node.
       
   590 
       
   591     @scope:       public
       
   592 
       
   593     @parameters:
       
   594        [in] NW_TinyTree_t* tree
       
   595                   The tiny tree.
       
   596 
       
   597        [in] NW_TinyTree_Node_t* node
       
   598                   The node to delete.
       
   599 
       
   600     @description: Delete a node, deleting any subtree below the node as well.
       
   601 
       
   602     @returns:     NW_Status_t
       
   603                   Status of operation.
       
   604 
       
   605        [NW_STAT_SUCCESS]
       
   606                   Always returns success.
       
   607 
       
   608  ** ----------------------------------------------------------------------- **/
       
   609 NW_Status_t
       
   610 NW_TinyTree_deleteNode(NW_TinyTree_Node_t* node);
       
   611 
       
   612 
       
   613 /** ----------------------------------------------------------------------- **
       
   614     @function:    NW_TinyTree_setContext
       
   615 
       
   616     @synopsis:    Set context.
       
   617 
       
   618     @scope:       public
       
   619 
       
   620     @parameters:
       
   621        [in] NW_TinyTree_t* tree
       
   622                   The tiny tree.
       
   623 
       
   624        [in] void* context
       
   625                   Context to set.
       
   626 
       
   627     @description: Set context.
       
   628 
       
   629     @returns:     NW_Status_t
       
   630                   Status of operation.
       
   631 
       
   632        [NW_STAT_SUCCESS]
       
   633                   Always returns success.
       
   634 
       
   635  ** ----------------------------------------------------------------------- **/
       
   636 NW_Status_t
       
   637 NW_TinyTree_setContext(NW_TinyTree_t* tree, 
       
   638                        void* context);
       
   639 
       
   640 
       
   641 /** ----------------------------------------------------------------------- **
       
   642     @function:    NW_TinyTree_getContext
       
   643 
       
   644     @synopsis:    Get context.
       
   645 
       
   646     @scope:       public
       
   647 
       
   648     @parameters:
       
   649        [in] NW_TinyTree_t* tree
       
   650                   The tiny tree.
       
   651 
       
   652     @description: Get context.
       
   653 
       
   654     @returns:     void*
       
   655                   The context.
       
   656 
       
   657  ** ----------------------------------------------------------------------- **/
       
   658 void*
       
   659 NW_TinyTree_getContext(NW_TinyTree_t* tree);
       
   660 
       
   661 
       
   662 /** ----------------------------------------------------------------------- **
       
   663     @function:    NW_TinyTree_Node_getFlags
       
   664 
       
   665     @synopsis:    Get flags.
       
   666 
       
   667     @scope:       public
       
   668 
       
   669     @parameters:
       
   670        [in] NW_TinyTree_Node_t* node
       
   671                   The tiny tree.
       
   672 
       
   673     @description: Get flags.
       
   674 
       
   675     @returns:     NW_Uint16
       
   676                   The node flags.
       
   677 
       
   678  ** ----------------------------------------------------------------------- **/
       
   679 NW_Uint16 
       
   680 NW_TinyTree_Node_getFlags(NW_TinyTree_Node_t* node);
       
   681 
       
   682 
       
   683 /** ----------------------------------------------------------------------- **
       
   684     @function:    NW_TinyTree_Node_setUserFlags
       
   685 
       
   686     @synopsis:    Set user flags.
       
   687 
       
   688     @scope:       public
       
   689 
       
   690     @parameters:
       
   691        [in] NW_TinyTree_Node_t* node
       
   692                   The tiny tree.
       
   693 
       
   694        [in] NW_Uint16 flags
       
   695                   The flags.
       
   696 
       
   697     @description: Set user flags.
       
   698 
       
   699     @returns:     NW_Status_t
       
   700                   Status of operation.
       
   701 
       
   702        [NW_STAT_SUCCESS]
       
   703                   Always returns success.
       
   704 
       
   705  ** ----------------------------------------------------------------------- **/
       
   706 NW_Status_t
       
   707 NW_TinyTree_Node_setUserFlags(NW_TinyTree_Node_t* node, 
       
   708                               NW_Uint16 flags);
       
   709 
       
   710 
       
   711 /** ----------------------------------------------------------------------- **
       
   712     @function:    NW_TinyTree_Node_getSourceOffset
       
   713 
       
   714     @synopsis:    Get source offset.
       
   715 
       
   716     @scope:       public
       
   717 
       
   718     @parameters:
       
   719        [in] NW_TinyTree_Node_t* node
       
   720                   The tiny tree.
       
   721 
       
   722     @description: Get source offset.
       
   723 
       
   724     @returns:     NW_TinyTree_Offset_t
       
   725                   The offset.
       
   726 
       
   727  ** ----------------------------------------------------------------------- **/
       
   728 NW_TinyTree_Offset_t
       
   729 NW_TinyTree_Node_getSourceOffset(NW_TinyTree_Node_t* node);
       
   730 
       
   731 
       
   732 /** ----------------------------------------------------------------------- **
       
   733     @function:    NW_TinyTree_Node_getSourceAddress
       
   734 
       
   735     @synopsis:    Get source address.
       
   736 
       
   737     @scope:       public
       
   738 
       
   739     @parameters:
       
   740        [in] NW_TinyTree_t* tree
       
   741                   The tiny tree.
       
   742 
       
   743        [in] NW_TinyTree_Node_t* node
       
   744                   Reference node.
       
   745     @description: Get source address.
       
   746 
       
   747     @returns:     void*
       
   748                   The address.
       
   749 
       
   750  ** ----------------------------------------------------------------------- **/
       
   751 void*
       
   752 NW_TinyTree_Node_getSourceAddress(NW_TinyTree_t* tree, 
       
   753                                   NW_TinyTree_Node_t* node);
       
   754 
       
   755 
       
   756 /** ----------------------------------------------------------------------- **
       
   757     @function:    NW_TinyTree_Node_GetSegmentAndOffset
       
   758 
       
   759     @synopsis:    Get segment and offset.
       
   760 
       
   761     @scope:       public
       
   762 
       
   763     @parameters:
       
   764        [in] NW_TinyTree_t* tree
       
   765                   The tiny tree.
       
   766 
       
   767        [in] NW_TinyTree_Node_t* node
       
   768                   default
       
   769 
       
   770        [out] NW_Uint8** segment
       
   771                   default
       
   772 
       
   773        [out] NW_Uint32* segSize
       
   774                   default
       
   775 
       
   776        [out] NW_Uint32* offset
       
   777                   default
       
   778 
       
   779     @description: Get segment and offset.
       
   780 
       
   781     @returns:     NW_Status_t
       
   782                   Status of operation.
       
   783 
       
   784        [NW_STAT_SUCCESS]
       
   785                   Segment and offset returned.
       
   786 
       
   787        [NW_STAT_FAILURE]
       
   788                   Could not get segment and offset.
       
   789 
       
   790  ** ----------------------------------------------------------------------- **/
       
   791 NW_Status_t
       
   792 NW_TinyTree_Node_GetSegmentAndOffset(NW_TinyTree_t* tree,
       
   793                                      NW_TinyTree_Node_t* node,
       
   794                                      NW_Uint8** segment,
       
   795                                      NW_Uint32* segSize,
       
   796                                      NW_Uint32* offset);
       
   797 
       
   798 
       
   799 /** ----------------------------------------------------------------------- **
       
   800     @function:    NW_TinyTree_GetSourceOffset
       
   801 
       
   802     @synopsis:    Get source offset.
       
   803 
       
   804     @scope:       public
       
   805 
       
   806     @parameters:
       
   807        [in] NW_TinyTree_t* tree
       
   808                   The tiny tree.
       
   809 
       
   810        [in] NW_Uint8* segmentAddr
       
   811                   default
       
   812 
       
   813        [out] NW_Uint32 offset
       
   814                   Offset.
       
   815 
       
   816        [out] CXML_Vector_Metric_t* index
       
   817                   Index of segment.
       
   818 
       
   819     @description: Get source offset.
       
   820 
       
   821     @returns:     NW_Status_t
       
   822                   Status of operation.
       
   823 
       
   824        [NW_STAT_SUCCESS]
       
   825                   Offset returned.
       
   826 
       
   827        [NW_STAT_FAILURE]
       
   828                   Could not get offset.
       
   829 
       
   830  ** ----------------------------------------------------------------------- **/
       
   831 extern
       
   832 NW_Status_t
       
   833 NW_TinyTree_GetSourceOffset(NW_TinyTree_t* tree,
       
   834                             NW_Uint8* segmentAddr,         
       
   835                             NW_Uint32  offset,
       
   836                             NW_Uint32* index);
       
   837 
       
   838 
       
   839 /** ----------------------------------------------------------------------- **
       
   840     @function:    NW_TinyTree_Node_findTree
       
   841 
       
   842     @synopsis:    Find tree.
       
   843 
       
   844     @scope:       public
       
   845 
       
   846     @parameters:
       
   847        [in] NW_TinyTree_Node_t* node
       
   848                   The tree node.
       
   849 
       
   850     @description: Get a reference to the tree that owns a node. This is
       
   851                   not likely to be a very efficient call since it can 
       
   852                   only find the tree safely by doing a linear search for
       
   853                   the sentinel tree node at the beginning of the current
       
   854                   segment.
       
   855 
       
   856     @returns:     NW_TinyTree_t*
       
   857                   Tiny tree or NULL if not found.
       
   858 
       
   859  ** ----------------------------------------------------------------------- **/
       
   860 IMPORT_C NW_TinyTree_t*
       
   861 NW_TinyTree_Node_findTree(NW_TinyTree_Node_t* node);
       
   862 
       
   863 
       
   864 /** ----------------------------------------------------------------------- **
       
   865     @function:    NW_TinyTree_createChild
       
   866 
       
   867     @synopsis:    Create child node.
       
   868 
       
   869     @scope:       public
       
   870 
       
   871     @parameters:
       
   872        [in] NW_TinyTree_t* tree
       
   873                   The tiny tree.
       
   874 
       
   875        [in] NW_TinyTree_Node_t* parent
       
   876                   Parent of new child.
       
   877 
       
   878        [in] NW_TinyTree_Offset_t offset
       
   879                   Offset.
       
   880 
       
   881     @description: Create a new node as a child of an existing node. The 
       
   882                   child references the source buffer at offset. The new 
       
   883                   child node is returned.  
       
   884 
       
   885     @returns:     NW_TinyTree_Node_t*
       
   886                   The new chold node or NULL if not successful.
       
   887 
       
   888  ** ----------------------------------------------------------------------- **/
       
   889 NW_TinyTree_Node_t*
       
   890 NW_TinyTree_createChild(NW_TinyTree_t* tree, 
       
   891                         NW_TinyTree_Node_t* parent, 
       
   892                         NW_TinyTree_Offset_t offset);
       
   893 
       
   894 
       
   895 /** ----------------------------------------------------------------------- **
       
   896     @function:    NW_TinyTree_createSibling
       
   897 
       
   898     @synopsis:    Create sibling node.
       
   899 
       
   900     @scope:       public
       
   901 
       
   902     @parameters:
       
   903        [in] NW_TinyTree_t* tree
       
   904                   The tiny tree.
       
   905 
       
   906        [in] NW_TinyTree_Node_t* node
       
   907                   Sibling of new node.
       
   908 
       
   909        [in] NW_TinyTree_Offset_t offset
       
   910                   Offset.
       
   911 
       
   912     @description: Create a new node as an immediate sibling to an 
       
   913                   existing node. The child references the source buffer
       
   914                   at offset. The new child node is returned.  
       
   915 
       
   916     @returns:     NW_TinyTree_Node_t*
       
   917                   New node or NULL if not successful.
       
   918 
       
   919  ** ----------------------------------------------------------------------- **/
       
   920 NW_TinyTree_Node_t*
       
   921 NW_TinyTree_createSibling(NW_TinyTree_t* tree, 
       
   922                           NW_TinyTree_Node_t* node, 
       
   923                           NW_TinyTree_Offset_t offset);
       
   924 
       
   925 
       
   926   /* RME Documentation tools does not handle function call as parameter */
       
   927 /* * ----------------------------------------------------------------------- **
       
   928     @function:    NW_TinyTree_recurse
       
   929 
       
   930     @synopsis:    Recurse through tree using callback.
       
   931 
       
   932     @scope:       public
       
   933 
       
   934     @parameters:
       
   935        [in] NW_TinyTree_t* tree
       
   936                   The tiny tree.
       
   937 
       
   938        [in] NW_TinyTree_Node_t* start_node
       
   939                   Node to start to recurse from.
       
   940 
       
   941        [in] void (*Node_CB) (NW_TinyTree_t*, NW_TinyTree_Node_t* , void*)
       
   942                   Node handling calllback
       
   943 
       
   944        [in] void* context
       
   945                   Parser context.
       
   946 
       
   947     @description: Recurse through tree calling the callback function 
       
   948                   for each node.
       
   949 
       
   950  ** ----------------------------------------------------------------------- **/
       
   951 void
       
   952 NW_TinyTree_recurse(NW_TinyTree_t* tree,
       
   953                     NW_TinyTree_Node_t* start_node, 
       
   954                     void (*Node_CB) (NW_TinyTree_t*, NW_TinyTree_Node_t* , void*),
       
   955                     void* context);
       
   956 
       
   957 
       
   958 /* ----------------------------------------------------------------------- **
       
   959    Node iterator functions. These iterate through nodes one at a time
       
   960    returning NULL when there are no more nodes to iterate.  
       
   961 ** ----------------------------------------------------------------------- **/
       
   962   
       
   963 /** ----------------------------------------------------------------------- **
       
   964     @struct:      NW_TinyTree_NodeIterator
       
   965 
       
   966     @synopsis:    default
       
   967 
       
   968     @scope:       public
       
   969     @variables:
       
   970        NW_TinyTree_Node_t* start_node
       
   971                   The start node.
       
   972 
       
   973        NW_TinyTree_Node_t* traversal_node
       
   974                   Present node.
       
   975 
       
   976        NW_TinyTree_t* tree
       
   977                   The tree.
       
   978 
       
   979     @description: Node iterator type definition.
       
   980  ** ----------------------------------------------------------------------- **/
       
   981 typedef struct NW_TinyTree_NodeIterator_s{
       
   982   NW_TinyTree_Node_t* start_node;
       
   983   NW_TinyTree_Node_t* traversal_node;
       
   984 }NW_TinyTree_NodeIterator_t;
       
   985 
       
   986 
       
   987 /** ----------------------------------------------------------------------- **
       
   988     @function:    NW_TinyTree_NodeIterator_init
       
   989 
       
   990     @synopsis:    Initialize a node iterator with a start node.
       
   991 
       
   992     @scope:       public
       
   993 
       
   994     @parameters:
       
   995        [in] NW_TinyTree_t* tree
       
   996                   The tiny tree.
       
   997 
       
   998        [in] NW_TinyTree_Node_t* start_node
       
   999                   Iterator start point.
       
  1000 
       
  1001        [out] NW_TinyTree_NodeIterator_t* iterator
       
  1002                   Iterator structure.
       
  1003 
       
  1004     @description: Initialize a node iterator with a start node. Iterate
       
  1005                   through nodes one at a time returning NULL when there 
       
  1006                   are no more nodes to iterate.  
       
  1007  ** ----------------------------------------------------------------------- **/
       
  1008 void
       
  1009 NW_TinyTree_NodeIterator_init(NW_TinyTree_Node_t* start_node,
       
  1010                               NW_TinyTree_NodeIterator_t* iterator);
       
  1011 
       
  1012 
       
  1013 /** ----------------------------------------------------------------------- **
       
  1014     @function:    NW_TinyTree_NodeIterator_iterate
       
  1015 
       
  1016     @synopsis:    Iterate through a subtree.
       
  1017 
       
  1018     @scope:       public
       
  1019 
       
  1020     @parameters:
       
  1021        [in-out] NW_TinyTree_NodeIterator_t* iterator
       
  1022                   The iterator.
       
  1023 
       
  1024     @description: Iterate through a subtree returning each node exactly
       
  1025                   once. The algorithm follows the toplogical ordering of
       
  1026                   the tree (if there is an edge from v0 to v1, always 
       
  1027                   visit v0 before v1). It's equivalent to solving a 
       
  1028                   labyrinth by keeping your right hand on the wall!
       
  1029 
       
  1030     @returns:     NW_TinyTree_Node_t*
       
  1031                   Next node in iteration or NULL if done.
       
  1032 
       
  1033  ** ----------------------------------------------------------------------- **/
       
  1034 NW_TinyTree_Node_t*
       
  1035 NW_TinyTree_NodeIterator_iterate(NW_TinyTree_NodeIterator_t* iterator);
       
  1036 
       
  1037 
       
  1038 /** ----------------------------------------------------------------------- **
       
  1039     @function:    NW_TinyTree_NodeIterator_iterateSiblings
       
  1040 
       
  1041     @synopsis:    Iterate through the siblings of a node.
       
  1042 
       
  1043     @scope:       public
       
  1044 
       
  1045     @parameters:
       
  1046        [in-out] NW_TinyTree_NodeIterator_t* iterator
       
  1047                   The iterator.
       
  1048 
       
  1049     @description: Iterate through the siblings of a node.
       
  1050 
       
  1051     @returns:     NW_TinyTree_Node_t*
       
  1052                   Next node in iteration or NULL if done.
       
  1053 
       
  1054  ** ----------------------------------------------------------------------- **/
       
  1055 NW_TinyTree_Node_t*
       
  1056 NW_TinyTree_NodeIterator_iterateSiblings(NW_TinyTree_NodeIterator_t* iterator);
       
  1057 
       
  1058 
       
  1059 /** ----------------------------------------------------------------------- **
       
  1060     @function:    NW_TinyTree_GetWritableBlock
       
  1061 
       
  1062     @synopsis:    Get writable block.
       
  1063 
       
  1064     @scope:       public
       
  1065 
       
  1066     @parameters:
       
  1067        [in] NW_TinyTree_t* tree
       
  1068                   The tiny tree.
       
  1069 
       
  1070        [in] CXML_Vector_Metric_t size
       
  1071                   Requested size.
       
  1072 
       
  1073        [in] CXML_Vector_Metric_t* source_offset
       
  1074                   Offset.
       
  1075 
       
  1076     @description: Get writable block.
       
  1077 
       
  1078     @returns:     NW_Uint8*
       
  1079                   Writable block.
       
  1080 
       
  1081  ** ----------------------------------------------------------------------- **/
       
  1082 NW_Uint8*
       
  1083 NW_TinyTree_GetWritableBlock(NW_TinyTree_t* tree,
       
  1084                              NW_Uint32  size,
       
  1085                              NW_Uint32 *source_offset);
       
  1086 
       
  1087 
       
  1088 #ifdef __cplusplus
       
  1089 } /* extern "C" { */
       
  1090 #endif /* __cplusplus */
       
  1091 
       
  1092 #endif  /* NW_TINY_TREE_H */