videoeditorengine/h263decoder/src/list.cpp
branchRCL_3
changeset 3 e0b5df5c0969
parent 0 951a5db380a0
child 5 4c409de21d23
equal deleted inserted replaced
0:951a5db380a0 3:e0b5df5c0969
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "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 * Ixonos Plc
       
    14 *
       
    15 * Description:  
       
    16 * List handling functions.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 #include "h263dconfig.h"
       
    23 #include "list.h"
       
    24 
       
    25 #ifndef NULL
       
    26    #define NULL 0
       
    27 #endif
       
    28 
       
    29 
       
    30 /*
       
    31  * fifoClose
       
    32  *    
       
    33  *
       
    34  * Parameters:
       
    35  *    list                       a pointer to a FIFO list
       
    36  *
       
    37  * Function:
       
    38  *    This function deinitializes the given FIFO list. Notice that no dynamic
       
    39  *    allocation for the list is done. This function must be called when
       
    40  *    the list is no longer used.
       
    41  *
       
    42  * Returns:
       
    43  *    >= 0 if the function was successful
       
    44  *    < 0  indicating an error
       
    45  *
       
    46  */
       
    47 
       
    48 int fifoClose(fifo_t *list)
       
    49 {
       
    50    list->head = list->tail = NULL;
       
    51    list->numItems = 0;
       
    52 
       
    53    return 0;
       
    54 }
       
    55 
       
    56 
       
    57 /*
       
    58  * fifoGet
       
    59  *    
       
    60  *
       
    61  * Parameters:
       
    62  *    list                       a pointer to a FIFO list
       
    63  *    item                       used to return a pointer to the removed
       
    64  *                               list item
       
    65  *
       
    66  * Function:
       
    67  *    This function removes an item from the list. Notice that no copying of
       
    68  *    contents of the given item is done, i.e. only the pointer to the item
       
    69  *    is used.
       
    70  *
       
    71  *    If there are no items left in the list, NULL will be returned in
       
    72  *    the item parameter.
       
    73  *
       
    74  * Returns:
       
    75  *    >= 0 if the function was successful
       
    76  *    < 0  indicating an error
       
    77  *
       
    78  */
       
    79 
       
    80 int fifoGet(fifo_t *list, void **item)
       
    81 {
       
    82    if (list->head) {
       
    83       *item = (void *) list->head;
       
    84       list->head = (lstListItem_t *) list->head->next;
       
    85       if (list->head == NULL)
       
    86          list->tail = NULL;
       
    87       list->numItems--;
       
    88    }
       
    89 
       
    90    else
       
    91       *item = NULL;
       
    92 
       
    93    return 0;
       
    94 }
       
    95 
       
    96 
       
    97 /*
       
    98  * fifoOpen
       
    99  *    
       
   100  *
       
   101  * Parameters:
       
   102  *    list                       a pointer to a FIFO list
       
   103  *
       
   104  * Function:
       
   105  *    This function initializes the given FIFO list. Notice that no dynamic
       
   106  *    allocation for the list is done. This function must be called before
       
   107  *    the list is used.
       
   108  *
       
   109  * Returns:
       
   110  *    >= 0 if the function was successful
       
   111  *    < 0  indicating an error
       
   112  *
       
   113  */
       
   114 
       
   115 int fifoOpen(fifo_t *list)
       
   116 {
       
   117    list->head = list->tail = NULL;
       
   118    list->numItems = 0;
       
   119 
       
   120    return 0;
       
   121 }
       
   122 
       
   123 
       
   124 /*
       
   125  * fifoPeek
       
   126  *    
       
   127  *
       
   128  * Parameters:
       
   129  *    list                       a pointer to a FIFO list
       
   130  *    item                       used to return a pointer to the removed
       
   131  *                               list item
       
   132  *
       
   133  * Function:
       
   134  *    This function returns a pointer to the next in the list but does not
       
   135  *    remove the item from the list. Notice that no copying of
       
   136  *    contents of the given item is done, i.e. only the pointer to the item
       
   137  *    is used.
       
   138  *
       
   139  *    If there are no items left in the list, NULL will be returned in
       
   140  *    the item parameter.
       
   141  *
       
   142  * Returns:
       
   143  *    >= 0 if the function was successful
       
   144  *    < 0  indicating an error
       
   145  *
       
   146  */
       
   147 
       
   148 int fifoPeek(fifo_t *list, void **item)
       
   149 {
       
   150    if (list->head)
       
   151       *item = (void *) list->head;
       
   152 
       
   153    else
       
   154       *item = NULL;
       
   155 
       
   156    return 0;
       
   157 }
       
   158 
       
   159 
       
   160 /*
       
   161  * fifoPut
       
   162  *    
       
   163  *
       
   164  * Parameters:
       
   165  *    list                       a pointer to a FIFO list
       
   166  *    item                       an item to add to the list
       
   167  *
       
   168  * Function:
       
   169  *    This function adds an item into the list. Notice that no copying of
       
   170  *    contents of the given item is done, i.e. only the pointer to the item
       
   171  *    is used.
       
   172  *
       
   173  * Returns:
       
   174  *    >= 0 if the function was successful
       
   175  *    < 0  indicating an error
       
   176  *
       
   177  */
       
   178 
       
   179 int fifoPut(fifo_t *list, void *item)
       
   180 {
       
   181    ((lstListItem_t *) item)->next = NULL;
       
   182 
       
   183    if (list->tail) {
       
   184       list->tail->next = item;
       
   185       list->tail = (lstListItem_t *) (item);
       
   186    }
       
   187 
       
   188    else
       
   189       list->head = list->tail = (lstListItem_t *) item;
       
   190 
       
   191    list->numItems++;
       
   192 
       
   193    return 0;
       
   194 }
       
   195 
       
   196 
       
   197 /*
       
   198  * lifoClose
       
   199  *    
       
   200  *
       
   201  * Parameters:
       
   202  *    list                       a pointer to a LIFO list
       
   203  *
       
   204  * Function:
       
   205  *    This function deinitializes the given LIFO list. Notice that no dynamic
       
   206  *    allocation for the list is done. This function must be called when
       
   207  *    the list is no longer used.
       
   208  *
       
   209  * Returns:
       
   210  *    >= 0 if the function was successful
       
   211  *    < 0  indicating an error
       
   212  *
       
   213  */
       
   214 
       
   215 int lifoClose(lifo_t *list)
       
   216 {
       
   217    list->head = NULL;
       
   218 
       
   219    return 0;
       
   220 }
       
   221 
       
   222 
       
   223 /*
       
   224  * lifoGet
       
   225  *    
       
   226  *
       
   227  * Parameters:
       
   228  *    list                       a pointer to a LIFO list
       
   229  *    item                       used to return a pointer to the removed
       
   230  *                               list item
       
   231  *
       
   232  * Function:
       
   233  *    This function removes an item from the list. Notice that no copying of
       
   234  *    contents of the given item is done, i.e. only the pointer to the item
       
   235  *    is used.
       
   236  *
       
   237  *    If there are no items left in the list, NULL will be returned in
       
   238  *    the item parameter.
       
   239  *
       
   240  * Returns:
       
   241  *    >= 0 if the function was successful
       
   242  *    < 0  indicating an error
       
   243  *
       
   244  */
       
   245 
       
   246 int lifoGet(lifo_t *list, void **item)
       
   247 {
       
   248    if (list->head) {
       
   249       *item = list->head;
       
   250       list->head = (lstListItem_t *) list->head->next;
       
   251    }
       
   252    else
       
   253       *item = NULL;
       
   254 
       
   255    return 0;
       
   256 }
       
   257 
       
   258 
       
   259 /*
       
   260  * lifoOpen
       
   261  *    
       
   262  *
       
   263  * Parameters:
       
   264  *    list                       a pointer to a LIFO list
       
   265  *
       
   266  * Function:
       
   267  *    This function initializes the given LIFO list. Notice that no dynamic
       
   268  *    allocation for the list is done. This function must be called before
       
   269  *    the list is used.
       
   270  *
       
   271  * Returns:
       
   272  *    >= 0 if the function was successful
       
   273  *    < 0  indicating an error
       
   274  *
       
   275  */
       
   276 
       
   277 int lifoOpen(lifo_t *list)
       
   278 {
       
   279    list->head = NULL;
       
   280 
       
   281    return 0;
       
   282 }
       
   283 
       
   284 
       
   285 /*
       
   286  * lifoPut
       
   287  *    
       
   288  *
       
   289  * Parameters:
       
   290  *    list                       a pointer to a LIFO list
       
   291  *    item                       an item to add to the list
       
   292  *
       
   293  * Function:
       
   294  *    This function adds an item into the list. Notice that no copying of
       
   295  *    contents of the given item is done, i.e. only the pointer to the item
       
   296  *    is used.
       
   297  *
       
   298  * Returns:
       
   299  *    >= 0 if the function was successful
       
   300  *    < 0  indicating an error
       
   301  *
       
   302  */
       
   303 
       
   304 int lifoPut(lifo_t *list, void *item)
       
   305 {
       
   306    ((lstListItem_t *) item)->next = list->head;
       
   307    list->head = (lstListItem_t *) item;
       
   308 
       
   309    return 0;
       
   310 }
       
   311 
       
   312 
       
   313 /*
       
   314  * lstClose
       
   315  *    
       
   316  *
       
   317  * Parameters:
       
   318  *    list                       a pointer to a list
       
   319  *
       
   320  * Function:
       
   321  *    This function deinitializes the given list. Notice that no dynamic
       
   322  *    allocation for the list is done. This function must be called when
       
   323  *    the list is no longer used.
       
   324  *
       
   325  * Returns:
       
   326  *    >= 0 if the function was successful
       
   327  *    < 0  indicating an error
       
   328  *
       
   329  */
       
   330 
       
   331 int lstClose(lst_t *list)
       
   332 {
       
   333    list->head = list->prev = list->curr = NULL;
       
   334    list->numItems = 0;
       
   335 
       
   336    return 0;
       
   337 }
       
   338 
       
   339 
       
   340 /*
       
   341  * lstRemove
       
   342  *    
       
   343  *
       
   344  * Parameters:
       
   345  *    list                       a pointer to a lst list
       
   346  *    item                       used to return a pointer to the removed
       
   347  *                               list item
       
   348  *
       
   349  * Function:
       
   350  *    This function removes an item from the list. Notice that no copying of
       
   351  *    contents of the given item is done, i.e. only the pointer to the item
       
   352  *    is used.
       
   353  *
       
   354  *    If there are no items left in the list, NULL will be returned in
       
   355  *    the item parameter.
       
   356  *
       
   357  * Returns:
       
   358  *    >= 0 if the function was successful
       
   359  *    < 0  indicating an error
       
   360  *
       
   361  */
       
   362 
       
   363 int lstRemove(lst_t *list, void **item)
       
   364 {
       
   365    if (list->curr) {
       
   366       *item = (void *) list->curr;
       
   367       if (list->prev)
       
   368          list->prev->next = list->curr->next;
       
   369       else
       
   370          list->head = (lstListItem_t *) (list->curr->next);
       
   371       list->curr = (lstListItem_t *) (list->curr->next);
       
   372       ((lstListItem_t *) *item)->next = NULL;
       
   373       list->numItems--;
       
   374    }
       
   375 
       
   376    else
       
   377       *item = NULL;
       
   378 
       
   379    return 0;
       
   380 }
       
   381 
       
   382 
       
   383 /*
       
   384  * lstOpen
       
   385  *    
       
   386  *
       
   387  * Parameters:
       
   388  *    list                       a pointer to a list
       
   389  *
       
   390  * Function:
       
   391  *    This function initializes the given list. Notice that no dynamic
       
   392  *    allocation for the list is done. This function must be called before
       
   393  *    the list is used.
       
   394  *
       
   395  * Returns:
       
   396  *    >= 0 if the function was successful
       
   397  *    < 0  indicating an error
       
   398  *
       
   399  */
       
   400 
       
   401 int lstOpen(lst_t *list)
       
   402 {
       
   403    list->head = list->prev = list->curr = NULL;
       
   404    list->numItems = 0;
       
   405 
       
   406    return 0;
       
   407 }
       
   408 
       
   409 
       
   410 /*
       
   411  * lstHead
       
   412  *    
       
   413  *
       
   414  * Parameters:
       
   415  *    list                       a pointer to a lst list
       
   416  *    item                       used to return a pointer to the head item
       
   417  *                               of the list
       
   418  *
       
   419  * Function:
       
   420  *    This function sets the current access point to the head of the list and
       
   421  *    returns a pointer to the head item. Notice that no copying of
       
   422  *    contents of the given item is done, i.e. only the pointer to the item
       
   423  *    is used.
       
   424  *
       
   425  *    If there are no items left in the list, NULL will be returned in
       
   426  *    the item parameter.
       
   427  *
       
   428  * Returns:
       
   429  *    >= 0 if the function was successful
       
   430  *    < 0  indicating an error
       
   431  *
       
   432  */
       
   433 
       
   434 int lstHead(lst_t *list, void **item)
       
   435 {
       
   436    if (list->head)
       
   437       *item = (void *) list->head;
       
   438 
       
   439    else
       
   440       *item = NULL;
       
   441 
       
   442    list->curr = list->head;
       
   443    list->prev = NULL;
       
   444 
       
   445    return 0;
       
   446 }
       
   447 
       
   448 
       
   449 /*
       
   450  * lstEnd
       
   451  *    
       
   452  *
       
   453  * Parameters:
       
   454  *    list                       a pointer to a lst list
       
   455  *
       
   456  * Function:
       
   457  *    This function sets the current access point to the tail of the list
       
   458  *    enabling the item addition to the end of the list.
       
   459  *
       
   460  * Returns:
       
   461  *    >= 0 if the function was successful
       
   462  *    < 0  indicating an error
       
   463  *
       
   464  */
       
   465 
       
   466 int lstEnd(lst_t *list)
       
   467 {
       
   468    while (list->curr) {
       
   469       list->prev = list->curr;
       
   470       list->curr = (lstListItem_t *) (list->curr->next);
       
   471    }
       
   472 
       
   473    return 0;
       
   474 }
       
   475 
       
   476 
       
   477 /*
       
   478  * lstTail
       
   479  *    
       
   480  *
       
   481  * Parameters:
       
   482  *    list                       a pointer to a lst list
       
   483  *
       
   484  * Function:
       
   485  *    This function sets the current access point to the tail of the list
       
   486  *    enabling the item addition to the end of the list.
       
   487  *
       
   488  * Returns:
       
   489  *    >= 0 if the function was successful
       
   490  *    < 0  indicating an error
       
   491  *
       
   492  */
       
   493 
       
   494 int lstTail(lst_t *list, void **item)
       
   495 {
       
   496    if (!list->curr) {
       
   497       list->curr = list->head;
       
   498       list->prev = NULL;
       
   499    }
       
   500 
       
   501    if (!list->curr) {
       
   502       *item = NULL;
       
   503       return 0;
       
   504    }
       
   505 
       
   506    while (list->curr->next) {
       
   507       list->prev = list->curr;
       
   508       list->curr = (lstListItem_t *) (list->curr->next);
       
   509    }
       
   510 
       
   511    *item = list->curr;
       
   512    return 0;
       
   513 }
       
   514 
       
   515 
       
   516 /*
       
   517  * lstCurr
       
   518  *    
       
   519  *
       
   520  * Parameters:
       
   521  *    list                       a pointer to a lst list
       
   522  *    item                       used to return a pointer to the current item
       
   523  *                               of the list
       
   524  *
       
   525  * Function:
       
   526  *    This returns a pointer to the current item of the list. 
       
   527  *    Notice that no copying of contents of the given item is done, 
       
   528  *    i.e. only the pointer to the item is used.
       
   529  *
       
   530  *    If there are no items left in the list, NULL will be returned in
       
   531  *    the item parameter.
       
   532  *
       
   533  * Returns:
       
   534  *    >= 0 if the function was successful
       
   535  *    < 0  indicating an error
       
   536  *
       
   537  */
       
   538 
       
   539 int lstCurr(lst_t *list, void **item)
       
   540 {
       
   541    *item = list->curr;
       
   542    return 0;
       
   543 }
       
   544 
       
   545 
       
   546 /*
       
   547  * lstNext
       
   548  *    
       
   549  *
       
   550  * Parameters:
       
   551  *    list                       a pointer to a lst list
       
   552  *    item                       used to return a pointer to the next item
       
   553  *                               of the list
       
   554  *
       
   555  * Function:
       
   556  *    This function sets the current access point to the next item of the list
       
   557  *    and returns a pointer to the item. Notice that no copying of
       
   558  *    contents of the given item is done, i.e. only the pointer to the item
       
   559  *    is used.
       
   560  *
       
   561  *    If there are no items left in the list, NULL will be returned in
       
   562  *    the item parameter.
       
   563  *
       
   564  * Returns:
       
   565  *    >= 0 if the function was successful
       
   566  *    < 0  indicating an error
       
   567  *
       
   568  */
       
   569 
       
   570 int lstNext(lst_t *list, void **item)
       
   571 {
       
   572    if (list->curr) {
       
   573       list->prev = list->curr;
       
   574       list->curr = (lstListItem_t *) (list->curr->next);
       
   575       *item = (void *) list->curr;
       
   576    }
       
   577 
       
   578    else
       
   579       *item = NULL;
       
   580 
       
   581    return 0;
       
   582 }
       
   583 
       
   584 
       
   585 int lstNextExists(lst_t *list)
       
   586 {
       
   587    return (list->curr && list->curr->next) ? 1 : 0;
       
   588 }
       
   589 
       
   590 /*
       
   591  * lstAdd
       
   592  *    
       
   593  *
       
   594  * Parameters:
       
   595  *    list                       a pointer to a lst list
       
   596  *    item                       an item to add to the list
       
   597  *
       
   598  * Function:
       
   599  *    This function adds an item into the list. Notice that no copying of
       
   600  *    contents of the given item is done, i.e. only the pointer to the item
       
   601  *    is used.
       
   602  *
       
   603  * Returns:
       
   604  *    >= 0 if the function was successful
       
   605  *    < 0  indicating an error
       
   606  *
       
   607  */
       
   608 
       
   609 int lstAdd(lst_t *list, void *item)
       
   610 {
       
   611    ((lstListItem_t *) item)->next = list->curr;
       
   612 
       
   613    if (list->prev)
       
   614       list->prev->next = item;
       
   615 
       
   616    else
       
   617       list->head = (lstListItem_t *) item;
       
   618 
       
   619    list->curr = (lstListItem_t *) item;
       
   620 
       
   621    list->numItems++;
       
   622 
       
   623    return 0;
       
   624 }
       
   625 
       
   626 
       
   627 // End of File