tesseract 4.1.1
Loading...
Searching...
No Matches
oldlist.h
Go to the documentation of this file.
1/* -*-C-*-
2 ********************************************************************************
3 *
4 * File: oldlist.h (Formerly list.h)
5 * Description: List processing procedures declarations.
6 * Author: Mark Seaman, SW Productivity
7 *
8 * (c) Copyright 1987, Hewlett-Packard Company.
9 ** Licensed under the Apache License, Version 2.0 (the "License");
10 ** you may not use this file except in compliance with the License.
11 ** You may obtain a copy of the License at
12 ** http://www.apache.org/licenses/LICENSE-2.0
13 ** Unless required by applicable law or agreed to in writing, software
14 ** distributed under the License is distributed on an "AS IS" BASIS,
15 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ** See the License for the specific language governing permissions and
17 ** limitations under the License.
18 *
19 ********************************************************************************
20 *
21 * This file contains the interface for a set of general purpose list
22 * manipulation routines. For the implementation of these routines see
23 * the file "list.c".
24 *
25 ********************************************************************************
26 *
27 * INDEX
28 * =======
29 *
30 * BASICS:
31 * -------
32 * first_node - Macro to return the first list node (not the cell).
33 * list_rest - Macro the return the second list cell
34 * pop - Destroy one list cell
35 * push - Create one list cell and set the node and next fields
36 *
37 * ITERATION:
38 * -----------------
39 * iterate - Macro to create a for loop to visit each cell.
40 *
41 * COPYING:
42 * -----------------
43 * reverse - (Deprecated) Creates a backwards copy of the input list.
44 *
45 * LIST CELL COUNTS:
46 * -----------------
47 * count - Returns the number of list cells in the list.
48 * last - Returns the last list cell.
49 *
50 * TRANSFORMS: (Note: These functions all modify the input list.)
51 * ----------
52 * delete_d - Removes the requested elements from the list.
53 * insert - (Deprecated) Add a new element into this spot in a list.
54 (not NIL_LIST)
55 * push_last - Add a new element onto the end of a list.
56 *
57 * SETS:
58 * -----
59 * search - Return the pointer to the list cell whose node matches.
60 *
61 * CELL OPERATIONS:
62 * -----------------
63 * destroy - Return all list cells in a list.
64 * destroy_nodes - Apply a function to each list cell and destroy the list.
65 * set_rest - Assign the next field in a list cell.
66 *
67 ***********************************************************************/
68
69#ifndef LIST_H
70#define LIST_H
71
72/*----------------------------------------------------------------------
73 T y p e s
74----------------------------------------------------------------------*/
75
76#define NIL_LIST static_cast<LIST>(nullptr)
77
78using int_compare = int (*)(void*, void*);
79using void_dest = void (*)(void*);
80
81struct list_rec {
84};
85using LIST = list_rec*;
86
87/*----------------------------------------------------------------------
88 M a c r o s
89----------------------------------------------------------------------*/
90/* Predefinitions */
91#define list_rest(l) ((l) ? (l)->next : NIL_LIST)
92#define first_node(l) ((l) ? (l)->node : NIL_LIST)
93
94/**********************************************************************
95 * i t e r a t e
96 *
97 * Visit each node in the list. Replace the old list with the list
98 * minus the head. Continue until the list is NIL_LIST.
99 **********************************************************************/
100
101#define iterate(l) for (; (l) != NIL_LIST; (l) = list_rest(l))
102
103/**********************************************************************
104 * s e t r e s t
105 *
106 * Change the "next" field of a list element to point to a desired place.
107 *
108 * #define set_rest(l,node) l->next = node;
109 **********************************************************************/
110
111#define set_rest(l, cell) ((l)->next = (cell))
112
113/*----------------------------------------------------------------------
114 Public Function Prototypes
115----------------------------------------------------------------------*/
116int count(LIST var_list);
117
118LIST delete_d(LIST list, void* key, int_compare is_equal);
119
120LIST destroy(LIST list);
121
122void destroy_nodes(LIST list, void_dest destructor);
123
124void insert(LIST list, void *node);
125
126LIST last(LIST var_list);
127
128LIST pop(LIST list);
129
130LIST push(LIST list, void* element);
131
132LIST push_last(LIST list, void* item);
133
134LIST reverse(LIST list);
135
136LIST search(LIST list, void* key, int_compare is_equal);
137
138#endif
LIST push_last(LIST list, void *item)
Definition: oldlist.cpp:227
void(*)(void *) void_dest
Definition: oldlist.h:79
void destroy_nodes(LIST list, void_dest destructor)
Definition: oldlist.cpp:157
LIST search(LIST list, void *key, int_compare is_equal)
Definition: oldlist.cpp:258
LIST delete_d(LIST list, void *key, int_compare is_equal)
Definition: oldlist.cpp:110
void insert(LIST list, void *node)
Definition: oldlist.cpp:172
LIST destroy(LIST list)
Definition: oldlist.cpp:141
LIST pop(LIST list)
Definition: oldlist.cpp:201
int(*)(void *, void *) int_compare
Definition: oldlist.h:78
LIST push(LIST list, void *element)
Definition: oldlist.cpp:213
int count(LIST var_list)
Definition: oldlist.cpp:95
LIST last(LIST var_list)
Definition: oldlist.cpp:190
LIST reverse(LIST list)
Definition: oldlist.cpp:244
#define is_equal(p1, p2)
Definition: outlines.h:105
list_rec * node
Definition: oldlist.h:82
list_rec * next
Definition: oldlist.h:83