xref: /aoo41x/main/vcl/inc/list.h (revision e6b30a3d)
1*e6b30a3dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*e6b30a3dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*e6b30a3dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*e6b30a3dSAndrew Rist  * distributed with this work for additional information
6*e6b30a3dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*e6b30a3dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*e6b30a3dSAndrew Rist  * "License"); you may not use this file except in compliance
9*e6b30a3dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*e6b30a3dSAndrew Rist  *
11*e6b30a3dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*e6b30a3dSAndrew Rist  *
13*e6b30a3dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*e6b30a3dSAndrew Rist  * software distributed under the License is distributed on an
15*e6b30a3dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*e6b30a3dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*e6b30a3dSAndrew Rist  * specific language governing permissions and limitations
18*e6b30a3dSAndrew Rist  * under the License.
19*e6b30a3dSAndrew Rist  *
20*e6b30a3dSAndrew Rist  *************************************************************/
21*e6b30a3dSAndrew Rist 
22*e6b30a3dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir /*[]---------------------------------------------------[]*/
25cdf0e10cSrcweir /*|                                                     |*/
26cdf0e10cSrcweir /*|  Implementation of the list data type               |*/
27cdf0e10cSrcweir /*|                                                     |*/
28cdf0e10cSrcweir /*|                                                     |*/
29cdf0e10cSrcweir /*|  Author: Alexander Gelfenbain                       |*/
30cdf0e10cSrcweir /*[]---------------------------------------------------[]*/
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #ifndef __CLIST_H
33cdf0e10cSrcweir #define __CLIST_H
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #ifdef __cplusplus
36cdf0e10cSrcweir extern "C"
37cdf0e10cSrcweir {
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir 
40cdf0e10cSrcweir /*
41cdf0e10cSrcweir  * List of void * pointers
42cdf0e10cSrcweir  */
43cdf0e10cSrcweir 
44cdf0e10cSrcweir     typedef struct _list *list;
45cdf0e10cSrcweir     typedef void (*list_destructor)(void *);
46cdf0e10cSrcweir 
47cdf0e10cSrcweir /*- constructors and a destructor */
48cdf0e10cSrcweir     list listNewEmpty(void);
49cdf0e10cSrcweir #ifdef TEST
50cdf0e10cSrcweir     list listNewCopy(list);
51cdf0e10cSrcweir #endif
52cdf0e10cSrcweir     void listDispose(list);
53cdf0e10cSrcweir     void listSetElementDtor(list, list_destructor);                     /*- this function will be executed when the element is removed via listRemove() or listClear() */
54cdf0e10cSrcweir 
55cdf0e10cSrcweir /*- queries */
56cdf0e10cSrcweir     void * listCurrent(list);
57cdf0e10cSrcweir     int    listCount(list);
58cdf0e10cSrcweir     int    listIsEmpty(list);
59cdf0e10cSrcweir #ifdef TEST
60cdf0e10cSrcweir     int    listAtFirst(list);
61cdf0e10cSrcweir     int    listAtLast(list);
62cdf0e10cSrcweir     int    listPosition(list);                        /* Expensive! */
63cdf0e10cSrcweir #endif
64cdf0e10cSrcweir /*- search */
65cdf0e10cSrcweir     int    listFind(list, void *);                    /* Returns true/false */
66cdf0e10cSrcweir 
67cdf0e10cSrcweir /*- positioning functions */
68cdf0e10cSrcweir /*- return the number of elements by which the current position in the list changes */
69cdf0e10cSrcweir     int    listNext(list);
70cdf0e10cSrcweir     int    listSkipForward(list, int n);
71cdf0e10cSrcweir     int    listToFirst(list);
72cdf0e10cSrcweir     int    listToLast(list);
73cdf0e10cSrcweir     int    listPositionAt(list, int n);               /* Expensive! */
74cdf0e10cSrcweir 
75cdf0e10cSrcweir /*- adding and removing elements */
76cdf0e10cSrcweir     list   listAppend(list, void *);
77cdf0e10cSrcweir #ifdef TEST
78cdf0e10cSrcweir     list   listPrepend(list, void *);
79cdf0e10cSrcweir     list   listInsertAfter(list, void *);
80cdf0e10cSrcweir     list   listInsertBefore(list, void *);
81cdf0e10cSrcweir #endif
82cdf0e10cSrcweir     list   listRemove(list);                          /* removes the current element */
83cdf0e10cSrcweir     list   listClear(list);                           /* removes all elements */
84cdf0e10cSrcweir 
85cdf0e10cSrcweir #ifdef TEST
86cdf0e10cSrcweir /*- forall */
87cdf0e10cSrcweir     void   listForAll(list, void (*f)(void *));
88cdf0e10cSrcweir #endif
89cdf0e10cSrcweir 
90cdf0e10cSrcweir #ifdef __cplusplus
91cdf0e10cSrcweir }
92cdf0e10cSrcweir #endif
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 
95cdf0e10cSrcweir #endif /* __CLIST_H */
96