os/graphics/graphicscomposition/openwfcompositionengine/common/src/owflinkedlist.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /* Copyright (c) 2009 The Khronos Group Inc.
     2  * Portions copyright (c) 2009-2010  Nokia Corporation and/or its subsidiary(-ies)
     3  *
     4  * Permission is hereby granted, free of charge, to any person obtaining a
     5  * copy of this software and/or associated documentation files (the
     6  * "Materials"), to deal in the Materials without restriction, including
     7  * without limitation the rights to use, copy, modify, merge, publish,
     8  * distribute, sublicense, and/or sell copies of the Materials, and to
     9  * permit persons to whom the Materials are furnished to do so, subject to
    10  * the following conditions:
    11  *
    12  * The above copyright notice and this permission notice shall be included
    13  * in all copies or substantial portions of the Materials.
    14  *
    15  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    19  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    20  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    21  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
    22  */
    23 
    24 
    25 #ifdef __cplusplus
    26 extern "C"
    27 {
    28 #endif
    29 
    30 
    31 #include <string.h>
    32 #include <stdlib.h>
    33 
    34 #include "owfmemory.h"
    35 #include "owflinkedlist.h"
    36 #include "owftypes.h"
    37 #include "owfpool.h"
    38 
    39 
    40 
    41 
    42 OWF_API_CALL OWF_NODE*
    43 OWF_Node_Create(OWF_POOL* pool, void* data)
    44 {
    45     OWF_NODE*               node;
    46 
    47     node = (OWF_NODE*)OWF_Pool_GetObject(pool);
    48     if (node)
    49     {
    50         node->data = data;
    51     }
    52     return node;
    53 }
    54 
    55 OWF_API_CALL void
    56 OWF_Node_Destroy(OWF_NODE* node)
    57 {
    58     OWF_Pool_PutObject(node);
    59 }
    60 
    61 OWF_API_CALL OWF_NODE*
    62 OWF_List_Tail(OWF_NODE* root)
    63 {
    64     if (root)
    65     {
    66         while (root->next)
    67         {
    68             root = root->next;
    69         }
    70     }
    71     return root;
    72 }
    73 
    74 OWF_API_CALL OWF_NODE*
    75 OWF_List_Append(OWF_NODE* root, OWF_NODE* node)
    76 {
    77     OWF_NODE*               tail;
    78 
    79     tail = OWF_List_Tail(root);
    80     if (tail)
    81     {
    82         tail->next = node;
    83     }
    84     else
    85     {
    86         root = node;
    87     }
    88     return root;
    89 }
    90 
    91 OWF_API_CALL OWF_NODE*
    92 OWF_List_Insert(OWF_NODE* root, OWF_NODE* node)
    93 {
    94     if (root)
    95     {
    96         node->next = root;
    97     }
    98     root = node;
    99     return root;
   100 }
   101 
   102 OWF_API_CALL void
   103 OWF_List_InsertAfter(OWF_NODE* pred, OWF_NODE* succ)
   104 {
   105     if (pred && succ)
   106     {
   107         succ->next = pred->next;
   108         pred->next = succ;
   109     }
   110 }
   111 
   112 OWF_API_CALL OWF_NODE*
   113 OWF_List_Contains(OWF_NODE* root, void* data)
   114 {
   115     while (root)
   116     {
   117         if (root->data == data)
   118         {
   119             break;
   120         }
   121         root = root->next;
   122     }
   123 
   124     return root;
   125 }
   126 
   127 OWF_API_CALL OWF_NODE*
   128 OWF_List_Remove(OWF_NODE* root, OWF_NODE* node)
   129 {
   130     OWF_NODE*                iter = NULL;
   131 
   132     if (root)
   133     {
   134         if (node != root)
   135         {
   136             iter = root;
   137             while (iter)
   138             {
   139                 if (iter->next == node)
   140                 {
   141                     iter->next = node->next;
   142                     break;
   143                 }
   144                 iter = iter->next;
   145             }
   146         }
   147         else
   148         {
   149             root = root->next;
   150         }
   151     }
   152 
   153     return root;
   154 }
   155 
   156 OWF_API_CALL OWF_NODE*
   157 OWF_List_Clear(OWF_NODE* root)
   158 {
   159     OWF_NODE* next = NULL;
   160     while (root)
   161     {
   162         next = root->next;
   163         OWF_Node_Destroy(root);
   164         root = next;
   165     }
   166     return root;
   167 }
   168 
   169 #ifdef __cplusplus
   170 }
   171 #endif