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