1 /*****************************************************************************/
5 /* Collection (dynamic array) */
9 /* (C) 2000 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
45 /*****************************************************************************/
47 /*****************************************************************************/
51 /* An array of pointers that grows if needed */
52 typedef struct Collection Collection;
54 unsigned Count; /* Number of items in the list */
55 unsigned Size; /* Size of allocated array */
56 void** Items; /* Array with dynamic size */
59 /* Initializer for static collections */
60 #define STATIC_COLLECTION_INITIALIZER { 0, 0, 0 }
64 /*****************************************************************************/
66 /*****************************************************************************/
70 Collection* InitCollection (Collection* C);
71 /* Initialize a collection and return it. */
73 void DoneCollection (Collection* C);
74 /* Free the data for a collection. This will not free the data contained in
78 Collection* NewCollection (void);
79 /* Create and return a new collection */
81 void FreeCollection (Collection* C);
82 /* Free a collection */
84 unsigned CollCount (Collection* C) attribute ((const));
85 /* Return the number of items in the collection */
87 void CollInsert (Collection* C, void* Item, unsigned Index);
88 /* Insert the data at the given position in the collection */
90 void CollAppend (Collection* C, void* Item);
91 /* Append an item to the end of the collection */
93 void* CollAt (Collection* C, unsigned Index) attribute ((const));
94 /* Return the item at the given index */
96 void CollDelete (Collection* C, unsigned Index);
97 /* Remove the item with the given index from the collection. This will not
98 * free the item itself, just the pointer. All items with higher indices
99 * will get moved to a lower position.
102 void CollReplace (Collection* C, void* Item, unsigned Index);
103 /* Replace the item at the given position. The old item will not be freed,
104 * just the pointer will et replaced.
109 /* End of exprlist.h */