2 #include "opensrf/utils.h"
6 Items are stored as void*'s so it's up to the user to
7 manage the data wisely. Also, if the 'freeItem' callback is defined for the list,
8 then, it will be used on any item that needs to be freed, so don't mix data
9 types in the list if you want magic freeing */
11 struct __osrfListStruct {
12 Pvoid_t list; /* the list */
13 int size; /* how many items in the list including NULL items between non-NULL items */
14 void (*freeItem) (void* item); /* callback for freeing stored items */
16 typedef struct __osrfListStruct osrfList;
19 struct __osrfListIteratorStruct {
21 unsigned long current;
23 typedef struct __osrfListIteratorStruct osrfListIterator;
27 Creates a new list iterator with the given list
29 osrfListIterator* osrfNewListIterator( osrfList* list );
32 Returns the next non-NULL item in the list, return NULL when
33 the end of the list has been reached
35 void* osrfListIteratorNext( osrfListIterator* itr );
38 Deallocates the given list
40 void osrfListIteratorFree( osrfListIterator* itr );
42 void osrfListIteratorReset( osrfListIterator* itr );
47 @param compress If true, the list will compress empty slots on delete. If item positionality
48 is not important, then using this feature is reccomended to keep the list from growing indefinitely.
49 if item positionality is not important.
50 @return The allocated list
52 osrfList* osrfNewList();
55 Pushes an item onto the end of the list. This always finds the highest index
56 in the list and pushes the new item into the list after it.
58 @param item The item to push
59 @return 0 on success, -1 on failure
61 int osrfListPush( osrfList* list, void* item );
64 Puts the given item into the list at the specified position. If there
65 is already an item at the given position and the list has it's
66 "freeItem" function defined, then it will be used to free said item.
67 If no 'freeItem' callback is defined, then the displaced item will
70 @param item The item to put into the list
71 @param position The position to place the item in
72 @return NULL in successfully inserting the new item and freeing
73 any displaced items. Returns the displaced item if no "freeItem"
76 void* osrfListSet( osrfList* list, void* item, unsigned long position );
79 Returns the item at the given position
81 @param postiont the position
83 void* osrfListGetIndex( osrfList* list, unsigned long position );
86 Frees the list and all list items (if the list has a "freeItem" function defined )
89 void osrfListFree( osrfList* list );
92 Removes the list item at the given index
94 @param position The position of the item to remove
95 @return A pointer to the item removed if "freeItem" is not defined
96 for this list, returns NULL if it is.
98 void* osrfListRemove( osrfList* list, int position );
101 Finds the list item whose void* is the same as the one passed in
103 @param addr The pointer connected to the list item we're to find
104 @return the index of the item, or -1 if the item was not found
106 int osrfListFind( osrfList* list, void* addr );
109 void __osrfListSetSize( osrfList* list );
112 @return The number of non-null items in the list
114 unsigned long osrfListGetCount( osrfList* list );