IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ticket #160: psList.h

File psList.h, 2.9 KB (added by Paul Price, 22 years ago)

Header file for psList

Line 
1#if !defined(PS_LIST_H)
2#define PS_LIST_H
3
4/** \file psList.h
5 * \brief Support for doubly linked lists
6 * \ingroup DataGroup
7 */
8
9/** Doubly-linked list element */
10typedef struct psListElem {
11 struct psListElem *prev; ///< previous link in list
12 struct psListElem *next; ///< next link in list
13 void *data; ///< real data item
14} psListElem;
15
16/** Doubly-linked list */
17typedef struct {
18 unsigned int size; ///< number of elements on list
19 psListElem *head; ///< first element on list (may be NULL)
20 psListElem *tail; ///< last element on list (may be NULL)
21 psListElem *iter; ///< iteration cursor
22 unsigned int iterIndex; ///< the numeric position of the iteration cursor in the list
23 pthread_mutex_t lock; ///< mutex to lock a node during changes
24} psList;
25
26/** Special values of index into list */
27enum {
28 PS_LIST_HEAD = 0, ///< at head
29 PS_LIST_TAIL = -1, ///< at tail
30 PS_LIST_UNKNOWN = -2, ///< unknown position
31 PS_LIST_PREV = -3, ///< previous element
32 PS_LIST_NEXT = -4 ///< next element
33};
34
35/** Functions **************************************************************/
36/** \addtogroup DataGroup General Data Container Utilities
37 * \{
38 */
39
40/** Constructor */
41psList *psListAlloc(void *data) ///< initial data item; may be NULL
42;
43
44/**** List maintainence functions ****/
45
46/** Add to list */
47bool *psListAdd(psList *list, ///< list to add to (may be NULL)
48 int location, ///< index, PS_LIST_HEAD, or PS_LIST_TAIL
49 void *data) ///< data item to add
50;
51
52/** Remove from a list */
53bool *psListRemove(psList *list, ///< list to remove element from
54 int location, ///< index of item, or PS_LIST_UNKNOWN, PS_LIST_NEXT, PS_LIST_PREV
55 void *data) ///< data item to remove
56;
57
58/** Retrieve from a list */
59void *psListGet(const psList *list, ///< list to retrieve element from
60 int location) ///< index of item, or PS_LIST_NEXT, PS_LIST_PREV, PS_LIST_UNKNOWN
61;
62
63/** Convert doubly-linked list to an array of (void *) */
64psArray *psListToArray(psList *list) ///< List to convert
65;
66
67/** Convert array to a doubly-linked list */
68psList *psArrayToList(psArray *array) ///< array of (void *) to convert
69;
70
71/** Sort a list. */
72psList *psListSort(psList *list, ///< List to sort
73 int (*compare)(const void **a, const void **b) // Function to compare two list elements
74 );
75
76/** Set the iterator */
77void psListSetIterator(psList *list, ///< list to retrieve element from
78 int iterator, ///< the desired iterator
79 int location) ///< index, PS_LIST_HEAD, or PS_LIST_TAIL
80;
81
82/** Get next element relative to iter */
83void *psListGetNext(psList *list, ///< list to retrieve element from
84 int iterator) ///< the desired iterator
85;
86
87/** Get prev element relative to iter */
88void *psListGetPrevious(psList *list, ///< list to retrieve element from
89 int iterator) ///< the desired iterator
90;
91
92/* \} */ // End of DataGroup Functions
93
94#endif