tesseract  4.1.1
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 
78 using int_compare = int (*)(void*, void*);
79 using void_dest = void (*)(void*);
80 
81 struct list_rec {
84 };
85 using 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 ----------------------------------------------------------------------*/
116 int count(LIST var_list);
117 
118 LIST delete_d(LIST list, void* key, int_compare is_equal);
119 
120 LIST destroy(LIST list);
121 
122 void destroy_nodes(LIST list, void_dest destructor);
123 
124 void insert(LIST list, void *node);
125 
126 LIST last(LIST var_list);
127 
128 LIST pop(LIST list);
129 
130 LIST push(LIST list, void* element);
131 
132 LIST push_last(LIST list, void* item);
133 
134 LIST reverse(LIST list);
135 
136 LIST search(LIST list, void* key, int_compare is_equal);
137 
138 #endif
list_rec::next
list_rec * next
Definition: oldlist.h:83
delete_d
LIST delete_d(LIST list, void *key, int_compare is_equal)
Definition: oldlist.cpp:110
push
LIST push(LIST list, void *element)
Definition: oldlist.cpp:213
push_last
LIST push_last(LIST list, void *item)
Definition: oldlist.cpp:227
insert
void insert(LIST list, void *node)
Definition: oldlist.cpp:172
reverse
LIST reverse(LIST list)
Definition: oldlist.cpp:244
tesstrain_utils.int
int
Definition: tesstrain_utils.py:154
void_dest
void(*)(void *) void_dest
Definition: oldlist.h:79
last
LIST last(LIST var_list)
Definition: oldlist.cpp:190
list_rec::node
list_rec * node
Definition: oldlist.h:82
destroy
LIST destroy(LIST list)
Definition: oldlist.cpp:141
search
LIST search(LIST list, void *key, int_compare is_equal)
Definition: oldlist.cpp:258
int_compare
int(*)(void *, void *) int_compare
Definition: oldlist.h:78
count
int count(LIST var_list)
Definition: oldlist.cpp:95
pop
LIST pop(LIST list)
Definition: oldlist.cpp:201
is_equal
#define is_equal(p1, p2)
Definition: outlines.h:105
destroy_nodes
void destroy_nodes(LIST list, void_dest destructor)
Definition: oldlist.cpp:157
list_rec
Definition: oldlist.h:81