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 );
68 Puts the given item into the list at the specified position. If there
69 is already an item at the given position and the list has it's
70 "freeItem" function defined, then it will be used to free said item.
71 If no 'freeItem' callback is defined, then the displaced item will
74 @param item The item to put into the list
75 @param position The position to place the item in
76 @return NULL in successfully inserting the new item and freeing
77 any displaced items. Returns the displaced item if no "freeItem"
80 void* osrfListSet( osrfList* list, void* item, unsigned long position );
83 Returns the item at the given position
85 @param postiont the position
87 void* osrfListGetIndex( osrfList* list, unsigned long position );
90 Frees the list and all list items (if the list has a "freeItem" function defined )
93 void osrfListFree( osrfList* list );
96 Removes the list item at the given index
98 @param position The position of the item to remove
99 @return A pointer to the item removed if "freeItem" is not defined
100 for this list, returns NULL if it is.
102 void* osrfListRemove( osrfList* list, int position );
105 Finds the list item whose void* is the same as the one passed in
107 @param addr The pointer connected to the list item we're to find
108 @return the index of the item, or -1 if the item was not found
110 int osrfListFind( osrfList* list, void* addr );
113 void __osrfListSetSize( osrfList* list );
116 @return The number of non-null items in the list
118 unsigned long osrfListGetCount( osrfList* list );