6 #include "opensrf/utils.h"
10 Items are stored as void*'s so it's up to the user to
11 manage the data wisely. Also, if the 'freeItem' callback is defined for the list,
12 then, it will be used on any item that needs to be freed, so don't mix data
13 types in the list if you want magic freeing */
15 struct __osrfListStruct {
16 Pvoid_t list; /* the list */
17 int size; /* how many items in the list including NULL items between non-NULL items */
18 void (*freeItem) (void* item); /* callback for freeing stored items */
20 typedef struct __osrfListStruct osrfList;
23 struct __osrfListIteratorStruct {
25 unsigned long current;
27 typedef struct __osrfListIteratorStruct osrfListIterator;
31 Creates a new list iterator with the given list
33 osrfListIterator* osrfNewListIterator( osrfList* list );
36 Returns the next non-NULL item in the list, return NULL when
37 the end of the list has been reached
39 void* osrfListIteratorNext( osrfListIterator* itr );
42 Deallocates the given list
44 void osrfListIteratorFree( osrfListIterator* itr );
46 void osrfListIteratorReset( osrfListIterator* itr );
51 @param compress If true, the list will compress empty slots on delete. If item positionality
52 is not important, then using this feature is reccomended to keep the list from growing indefinitely.
53 if item positionality is not important.
54 @return The allocated list
56 osrfList* osrfNewList();
59 Pushes an item onto the end of the list. This always finds the highest index
60 in the list and pushes the new item into the list after it.
62 @param item The item to push
63 @return 0 on success, -1 on failure
65 int osrfListPush( osrfList* list, void* item );
69 * Removes the last item in the list
70 * See osrfListRemove for details on how the removed item is handled
71 * @return The item, unless 'freeItem' exists, then returns NULL
73 void* osrfListPop( osrfList* list );
76 Puts the given item into the list at the specified position. If there
77 is already an item at the given position and the list has it's
78 "freeItem" function defined, then it will be used to free said item.
79 If no 'freeItem' callback is defined, then the displaced item will
82 @param item The item to put into the list
83 @param position The position to place the item in
84 @return NULL in successfully inserting the new item and freeing
85 any displaced items. Returns the displaced item if no "freeItem"
88 void* osrfListSet( osrfList* list, void* item, unsigned long position );
91 Returns the item at the given position
93 @param postiont the position
95 void* osrfListGetIndex( osrfList* list, unsigned long position );
98 Frees the list and all list items (if the list has a "freeItem" function defined )
101 void osrfListFree( osrfList* list );
104 Removes the list item at the given index
106 @param position The position of the item to remove
107 @return A pointer to the item removed if "freeItem" is not defined
108 for this list, returns NULL if it is.
110 void* osrfListRemove( osrfList* list, int position );
113 Finds the list item whose void* is the same as the one passed in
115 @param addr The pointer connected to the list item we're to find
116 @return the index of the item, or -1 if the item was not found
118 int osrfListFind( osrfList* list, void* addr );
121 void __osrfListSetSize( osrfList* list );
125 @return The number of non-null items in the list
127 unsigned long osrfListGetCount( osrfList* list );