Update contrib.
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
17 #include "mp4memwrap.h"
24 * list_s *listCreate()
36 * Pointer to the allocated list.
43 if ((tmpList = (list_s *)mp4malloc(sizeof(list_s))) == NULL)
46 tmpList->elementsInList = 0;
47 tmpList->bytesInList = 0;
48 tmpList->cumulativeBytesInList = 0;
49 tmpList->first = NULL;
59 * void *listAppend(list_s *list,
65 * Append an element (void *) to the end of the list.
69 * list Pointer to a list
70 * data Pointer to add to the list
71 * dataSize Size of data pointed to by data
79 void *listAppend(list_s *list, void *data, mp4_u32 dataSize)
83 if ((tmpNode = (node_s *)mp4malloc(sizeof(node_s))) == NULL)
86 if (list->elementsInList == 0) /* List is empty */
87 list->first = tmpNode;
89 list->last->next = tmpNode;
92 list->elementsInList++;
93 list->bytesInList += dataSize;
94 list->cumulativeBytesInList += dataSize;
98 tmpNode->dataSize = dataSize;
100 return (void *)tmpNode;
107 * void listDeleteFirst(list_s *list)
111 * Delete the first element in the list.
115 * list Pointer to a list
122 void listDeleteFirst(list_s *list)
124 if (list->elementsInList == 1)
126 mp4free(list->first->data);
127 mp4free(list->first);
130 list->elementsInList = 0;
131 list->bytesInList = 0;
134 if (list->elementsInList > 1)
138 tmpNode = list->first;
139 list->bytesInList -= tmpNode->dataSize;
140 list->first = tmpNode->next;
141 mp4free(tmpNode->data);
143 list->elementsInList--;
151 * void listDestroyList(list_s *list)
155 * Free list and all its elements from memory.
159 * list Pointer to a list
166 void listDestroyList(list_s *list)
168 while (list->elementsInList)
169 listDeleteFirst(list);
178 * mp4_u32 listElementsInList(list_s *list)
182 * Return the number of elements in the list.
186 * list Pointer to a list
190 * Number of elements in the list
193 mp4_u32 listElementsInList(list_s *list)
195 return list->elementsInList;
202 * mp4_u32 listBytesInList(list_s *list)
206 * Return the number of bytes currently in list.
210 * list Pointer to a list
214 * Number of bytes in the list
217 mp4_u32 listBytesInList(list_s *list)
219 return list->bytesInList;
226 * mp4_u32 listCumulativeBytesInList(list_s *list)
230 * Return the number of bytes that have been in the list since the list
235 * list Pointer to a list
239 * Number of bytes in the list from the creation
242 mp4_u32 listCumulativeBytesInList(list_s *list)
244 return list->cumulativeBytesInList;