author | sl |
Tue, 10 Jun 2014 14:32:02 +0200 | |
changeset 1 | 260cb5ec6c19 |
permissions | -rw-r--r-- |
sl@0 | 1 |
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
sl@0 | 2 |
// All rights reserved. |
sl@0 | 3 |
// This component and the accompanying materials are made available |
sl@0 | 4 |
// under the terms of "Eclipse Public License v1.0" |
sl@0 | 5 |
// which accompanies this distribution, and is available |
sl@0 | 6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
sl@0 | 7 |
// |
sl@0 | 8 |
// Initial Contributors: |
sl@0 | 9 |
// Nokia Corporation - initial contribution. |
sl@0 | 10 |
// |
sl@0 | 11 |
// Contributors: |
sl@0 | 12 |
// |
sl@0 | 13 |
// Description: |
sl@0 | 14 |
// |
sl@0 | 15 |
|
sl@0 | 16 |
#include "mp4list.h" |
sl@0 | 17 |
#include "mp4memwrap.h" |
sl@0 | 18 |
|
sl@0 | 19 |
|
sl@0 | 20 |
|
sl@0 | 21 |
/* |
sl@0 | 22 |
* Function: |
sl@0 | 23 |
* |
sl@0 | 24 |
* list_s *listCreate() |
sl@0 | 25 |
* |
sl@0 | 26 |
* Description: |
sl@0 | 27 |
* |
sl@0 | 28 |
* Create a list. |
sl@0 | 29 |
* |
sl@0 | 30 |
* Parameters: |
sl@0 | 31 |
* |
sl@0 | 32 |
* None |
sl@0 | 33 |
* |
sl@0 | 34 |
* Return value: |
sl@0 | 35 |
* |
sl@0 | 36 |
* Pointer to the allocated list. |
sl@0 | 37 |
* |
sl@0 | 38 |
*/ |
sl@0 | 39 |
list_s *listCreate() |
sl@0 | 40 |
{ |
sl@0 | 41 |
list_s *tmpList; |
sl@0 | 42 |
|
sl@0 | 43 |
if ((tmpList = (list_s *)mp4malloc(sizeof(list_s))) == NULL) |
sl@0 | 44 |
return NULL; |
sl@0 | 45 |
|
sl@0 | 46 |
tmpList->elementsInList = 0; |
sl@0 | 47 |
tmpList->bytesInList = 0; |
sl@0 | 48 |
tmpList->cumulativeBytesInList = 0; |
sl@0 | 49 |
tmpList->first = NULL; |
sl@0 | 50 |
tmpList->last = NULL; |
sl@0 | 51 |
|
sl@0 | 52 |
return tmpList; |
sl@0 | 53 |
} |
sl@0 | 54 |
|
sl@0 | 55 |
|
sl@0 | 56 |
/* |
sl@0 | 57 |
* Function: |
sl@0 | 58 |
* |
sl@0 | 59 |
* void *listAppend(list_s *list, |
sl@0 | 60 |
* void *data, |
sl@0 | 61 |
* mp4_u32 dataSize) |
sl@0 | 62 |
* |
sl@0 | 63 |
* Description: |
sl@0 | 64 |
* |
sl@0 | 65 |
* Append an element (void *) to the end of the list. |
sl@0 | 66 |
* |
sl@0 | 67 |
* Parameters: |
sl@0 | 68 |
* |
sl@0 | 69 |
* list Pointer to a list |
sl@0 | 70 |
* data Pointer to add to the list |
sl@0 | 71 |
* dataSize Size of data pointed to by data |
sl@0 | 72 |
* |
sl@0 | 73 |
* Return value: |
sl@0 | 74 |
* |
sl@0 | 75 |
* NULL Error |
sl@0 | 76 |
* Non-NULL Success |
sl@0 | 77 |
* |
sl@0 | 78 |
*/ |
sl@0 | 79 |
void *listAppend(list_s *list, void *data, mp4_u32 dataSize) |
sl@0 | 80 |
{ |
sl@0 | 81 |
node_s *tmpNode; |
sl@0 | 82 |
|
sl@0 | 83 |
if ((tmpNode = (node_s *)mp4malloc(sizeof(node_s))) == NULL) |
sl@0 | 84 |
return NULL; |
sl@0 | 85 |
|
sl@0 | 86 |
if (list->elementsInList == 0) /* List is empty */ |
sl@0 | 87 |
list->first = tmpNode; |
sl@0 | 88 |
else |
sl@0 | 89 |
list->last->next = tmpNode; |
sl@0 | 90 |
|
sl@0 | 91 |
list->last = tmpNode; |
sl@0 | 92 |
list->elementsInList++; |
sl@0 | 93 |
list->bytesInList += dataSize; |
sl@0 | 94 |
list->cumulativeBytesInList += dataSize; |
sl@0 | 95 |
|
sl@0 | 96 |
tmpNode->next = NULL; |
sl@0 | 97 |
tmpNode->data = data; |
sl@0 | 98 |
tmpNode->dataSize = dataSize; |
sl@0 | 99 |
|
sl@0 | 100 |
return (void *)tmpNode; |
sl@0 | 101 |
} |
sl@0 | 102 |
|
sl@0 | 103 |
|
sl@0 | 104 |
/* |
sl@0 | 105 |
* Function: |
sl@0 | 106 |
* |
sl@0 | 107 |
* void listDeleteFirst(list_s *list) |
sl@0 | 108 |
* |
sl@0 | 109 |
* Description: |
sl@0 | 110 |
* |
sl@0 | 111 |
* Delete the first element in the list. |
sl@0 | 112 |
* |
sl@0 | 113 |
* Parameters: |
sl@0 | 114 |
* |
sl@0 | 115 |
* list Pointer to a list |
sl@0 | 116 |
* |
sl@0 | 117 |
* Return value: |
sl@0 | 118 |
* |
sl@0 | 119 |
* None |
sl@0 | 120 |
* |
sl@0 | 121 |
*/ |
sl@0 | 122 |
void listDeleteFirst(list_s *list) |
sl@0 | 123 |
{ |
sl@0 | 124 |
if (list->elementsInList == 1) |
sl@0 | 125 |
{ |
sl@0 | 126 |
mp4free(list->first->data); |
sl@0 | 127 |
mp4free(list->first); |
sl@0 | 128 |
list->first = NULL; |
sl@0 | 129 |
list->last = NULL; |
sl@0 | 130 |
list->elementsInList = 0; |
sl@0 | 131 |
list->bytesInList = 0; |
sl@0 | 132 |
} |
sl@0 | 133 |
|
sl@0 | 134 |
if (list->elementsInList > 1) |
sl@0 | 135 |
{ |
sl@0 | 136 |
node_s *tmpNode; |
sl@0 | 137 |
|
sl@0 | 138 |
tmpNode = list->first; |
sl@0 | 139 |
list->bytesInList -= tmpNode->dataSize; |
sl@0 | 140 |
list->first = tmpNode->next; |
sl@0 | 141 |
mp4free(tmpNode->data); |
sl@0 | 142 |
mp4free(tmpNode); |
sl@0 | 143 |
list->elementsInList--; |
sl@0 | 144 |
} |
sl@0 | 145 |
} |
sl@0 | 146 |
|
sl@0 | 147 |
|
sl@0 | 148 |
/* |
sl@0 | 149 |
* Function: |
sl@0 | 150 |
* |
sl@0 | 151 |
* void listDestroyList(list_s *list) |
sl@0 | 152 |
* |
sl@0 | 153 |
* Description: |
sl@0 | 154 |
* |
sl@0 | 155 |
* Free list and all its elements from memory. |
sl@0 | 156 |
* |
sl@0 | 157 |
* Parameters: |
sl@0 | 158 |
* |
sl@0 | 159 |
* list Pointer to a list |
sl@0 | 160 |
* |
sl@0 | 161 |
* Return value: |
sl@0 | 162 |
* |
sl@0 | 163 |
* None |
sl@0 | 164 |
* |
sl@0 | 165 |
*/ |
sl@0 | 166 |
void listDestroyList(list_s *list) |
sl@0 | 167 |
{ |
sl@0 | 168 |
while (list->elementsInList) |
sl@0 | 169 |
listDeleteFirst(list); |
sl@0 | 170 |
|
sl@0 | 171 |
mp4free(list); |
sl@0 | 172 |
} |
sl@0 | 173 |
|
sl@0 | 174 |
|
sl@0 | 175 |
/* |
sl@0 | 176 |
* Function: |
sl@0 | 177 |
* |
sl@0 | 178 |
* mp4_u32 listElementsInList(list_s *list) |
sl@0 | 179 |
* |
sl@0 | 180 |
* Description: |
sl@0 | 181 |
* |
sl@0 | 182 |
* Return the number of elements in the list. |
sl@0 | 183 |
* |
sl@0 | 184 |
* Parameters: |
sl@0 | 185 |
* |
sl@0 | 186 |
* list Pointer to a list |
sl@0 | 187 |
* |
sl@0 | 188 |
* Return value: |
sl@0 | 189 |
* |
sl@0 | 190 |
* Number of elements in the list |
sl@0 | 191 |
* |
sl@0 | 192 |
*/ |
sl@0 | 193 |
mp4_u32 listElementsInList(list_s *list) |
sl@0 | 194 |
{ |
sl@0 | 195 |
return list->elementsInList; |
sl@0 | 196 |
} |
sl@0 | 197 |
|
sl@0 | 198 |
|
sl@0 | 199 |
/* |
sl@0 | 200 |
* Function: |
sl@0 | 201 |
* |
sl@0 | 202 |
* mp4_u32 listBytesInList(list_s *list) |
sl@0 | 203 |
* |
sl@0 | 204 |
* Description: |
sl@0 | 205 |
* |
sl@0 | 206 |
* Return the number of bytes currently in list. |
sl@0 | 207 |
* |
sl@0 | 208 |
* Parameters: |
sl@0 | 209 |
* |
sl@0 | 210 |
* list Pointer to a list |
sl@0 | 211 |
* |
sl@0 | 212 |
* Return value: |
sl@0 | 213 |
* |
sl@0 | 214 |
* Number of bytes in the list |
sl@0 | 215 |
* |
sl@0 | 216 |
*/ |
sl@0 | 217 |
mp4_u32 listBytesInList(list_s *list) |
sl@0 | 218 |
{ |
sl@0 | 219 |
return list->bytesInList; |
sl@0 | 220 |
} |
sl@0 | 221 |
|
sl@0 | 222 |
|
sl@0 | 223 |
/* |
sl@0 | 224 |
* Function: |
sl@0 | 225 |
* |
sl@0 | 226 |
* mp4_u32 listCumulativeBytesInList(list_s *list) |
sl@0 | 227 |
* |
sl@0 | 228 |
* Description: |
sl@0 | 229 |
* |
sl@0 | 230 |
* Return the number of bytes that have been in the list since the list |
sl@0 | 231 |
* was created. |
sl@0 | 232 |
* |
sl@0 | 233 |
* Parameters: |
sl@0 | 234 |
* |
sl@0 | 235 |
* list Pointer to a list |
sl@0 | 236 |
* |
sl@0 | 237 |
* Return value: |
sl@0 | 238 |
* |
sl@0 | 239 |
* Number of bytes in the list from the creation |
sl@0 | 240 |
* |
sl@0 | 241 |
*/ |
sl@0 | 242 |
mp4_u32 listCumulativeBytesInList(list_s *list) |
sl@0 | 243 |
{ |
sl@0 | 244 |
return list->cumulativeBytesInList; |
sl@0 | 245 |
} |
sl@0 | 246 |
// End of File |