source: vis_dev/glu-2.3/src/list/list.h @ 21

Last change on this file since 21 was 13, checked in by cecile, 13 years ago

library glu 2.3

File size: 4.7 KB
Line 
1/*
2 * $Id: list.h,v 1.8 2005/04/18 05:14:28 fabio Exp $
3 *
4 */
5/*
6 * List Management Package Header File
7 *
8 * David Harrison
9 * University of California, 1985
10 *
11 * This file contains public type definitions for the List Managment
12 * package implemented in list.c.  This is stand alone package.
13 */
14
15#ifndef LS_DEFINED
16#define LS_DEFINED
17
18typedef void ls_dummy;
19
20typedef ls_dummy *lsList;       /* List handle           */
21typedef ls_dummy *lsGen;        /* List generator handle */
22typedef ls_dummy *lsHandle;     /* Handle to an item     */
23typedef int lsStatus;           /* Return codes          */
24typedef void *lsGeneric;        /* Generic pointer       */
25
26#define LS_NIL          0       /* Nil for lsList       */
27
28#define LS_BADSTATE     -3      /* Bad generator state   */
29#define LS_BADPARAM     -2      /* Bad parameter value   */
30#define LS_NOMORE       -1      /* No more items         */
31
32#define LS_OK           0
33
34#define LS_BEFORE       1       /* Set spot before object */
35#define LS_AFTER        2       /* Set spot after object  */
36#define LS_STOP         3       /* Stop generating items  */
37#define LS_DELETE       4       /* Delete generated item  */
38
39/*
40 * For all those routines that take a handle,  this macro can be
41 * used when no handle is required.
42 */
43
44#define LS_NH           (lsHandle *) 0
45
46typedef lsGeneric (*LS_PFLSG)(lsGeneric);
47
48EXTERN lsList lsCreate ARGS((void));
49  /* Create a new list */
50EXTERN lsStatus lsDestroy ARGS((lsList, void (*)(lsGeneric)));
51  /* Delete a previously created list */
52EXTERN lsList lsCopy ARGS((lsList, LS_PFLSG));
53   /* Copies the contents of a list    */
54
55EXTERN lsStatus lsFirstItem ARGS((lsList, lsGeneric, lsHandle *));
56  /* Gets the first item of a list */
57EXTERN lsStatus lsLastItem ARGS((lsList, lsGeneric, lsHandle *));
58  /* Gets the last item of a list */
59
60EXTERN lsStatus lsNewBegin ARGS((lsList, lsGeneric, lsHandle *));
61  /* Add item to start of list */
62EXTERN lsStatus lsNewEnd ARGS((lsList, lsGeneric, lsHandle *));
63  /* Add item to end of list */
64
65EXTERN lsStatus lsDelBegin ARGS((lsList, lsGeneric));
66  /* Delete first item of a list */
67EXTERN lsStatus lsDelEnd ARGS((lsList, lsGeneric));
68  /* Delete last item of a list */
69
70EXTERN int lsLength ARGS((lsList));
71  /* Returns the length of the list */
72
73EXTERN lsGen lsStart ARGS((lsList));
74  /* Begin generation of items in a list */
75EXTERN lsGen lsEnd ARGS((lsList));
76  /* Begin generation at end of list */
77EXTERN lsGen lsGenHandle ARGS((lsHandle, lsGeneric, int));
78  /* Produces a generator given a handle */
79EXTERN lsStatus lsNext ARGS((lsGen, lsGeneric, lsHandle *));
80  /* Generate next item in sequence */
81EXTERN lsStatus lsPrev ARGS((lsGen, lsGeneric, lsHandle *));
82  /* Generate previous item in sequence */
83EXTERN lsStatus lsInBefore ARGS((lsGen, lsGeneric, lsHandle *));
84  /* Insert an item before the most recently generated by lsNext */
85EXTERN lsStatus lsInAfter ARGS((lsGen, lsGeneric, lsHandle *));
86  /* Insert an item after the most recently generated by lsNext  */
87EXTERN lsStatus lsDelBefore ARGS((lsGen, lsGeneric));
88  /* Delete the item before the current spot */
89EXTERN lsStatus lsDelAfter ARGS((lsGen, lsGeneric));
90  /* Delete the item after the current spot */
91EXTERN lsStatus lsFinish ARGS((lsGen));
92  /* End generation of items in a list */
93EXTERN lsStatus lsForeach ARGS((lsList list, lsStatus (*userFunc)(lsGeneric, lsGeneric), lsGeneric arg));
94  /* Generation of all items of a list from the first */
95EXTERN lsStatus lsBackeach ARGS((lsList list, lsStatus (*userFunc)(lsGeneric, lsGeneric), lsGeneric arg));
96  /* Generation of all items of a list from the last */
97
98EXTERN lsList lsQueryHandle ARGS((lsHandle));
99  /* Returns the list of a handle */
100EXTERN lsGeneric lsFetchHandle ARGS((lsHandle));
101  /* Returns data associated with handle */
102EXTERN lsStatus lsRemoveItem ARGS((lsHandle, lsGeneric));
103  /* Removes item associated with handle from list */
104
105EXTERN lsStatus lsSort ARGS((lsList, int (*)(lsGeneric, lsGeneric)));
106
107  /* Sorts a list */
108EXTERN lsStatus lsUniq ARGS((lsList, int (*)(lsGeneric, lsGeneric), void (*)(lsGeneric) ));
109  /* Removes duplicates from a sorted list */
110/*
111 * Macro to iterate the items of a list.Note the following:
112 * 1) in a for loop, the test is evaluate before the first time through the body
113 * 2) the logical OR operator guarantees left to right evaluation, and the second
114 *    operand is not evaluated if first operand evaluates to non-zero
115 * 3) the comma operator returns the value of its second argument.
116 */
117#define lsForEachItem(                                         \
118  list,  /* lsList, list to iterate */                         \
119  gen,   /* lsGen, local variable for iterator */              \
120  data   /* lsGeneric, variable to return data */              \
121)                                                              \
122  for(gen = lsStart(list);                                     \
123      (lsNext(gen, &data, LS_NH) == LS_OK)       \
124      || ((void) lsFinish(gen), 0);                            \
125      )
126
127
128#endif
Note: See TracBrowser for help on using the repository browser.