tesseract  5.0.0-alpha-619-ge9db
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 /*----------------------------------------------------------------------
66  T y p e s
67 ----------------------------------------------------------------------*/
68 
69 #define NIL_LIST static_cast<LIST>(nullptr)
70 
71 using int_compare = int (*)(void*, void*);
72 using void_dest = void (*)(void*);
73 
74 struct list_rec {
76  list_rec* next;
77 };
78 using LIST = list_rec*;
79 
80 /*----------------------------------------------------------------------
81  M a c r o s
82 ----------------------------------------------------------------------*/
83 /* Predefinitions */
84 #define list_rest(l) ((l) ? (l)->next : NIL_LIST)
85 #define first_node(l) ((l) ? (l)->node : NIL_LIST)
86 
87 /**********************************************************************
88  * i t e r a t e
89  *
90  * Visit each node in the list. Replace the old list with the list
91  * minus the head. Continue until the list is NIL_LIST.
92  **********************************************************************/
93 
94 #define iterate(l) for (; (l) != NIL_LIST; (l) = list_rest(l))
95 
96 /**********************************************************************
97  * s e t r e s t
98  *
99  * Change the "next" field of a list element to point to a desired place.
100  *
101  * #define set_rest(l,node) l->next = node;
102  **********************************************************************/
103 
104 #define set_rest(l, cell) ((l)->next = (cell))
105 
106 /*----------------------------------------------------------------------
107  Public Function Prototypes
108 ----------------------------------------------------------------------*/
109 int count(LIST var_list);
110 
111 LIST delete_d(LIST list, void* key, int_compare is_equal);
112 
113 LIST destroy(LIST list);
114 
115 void destroy_nodes(LIST list, void_dest destructor);
116 
117 LIST last(LIST var_list);
118 
119 LIST pop(LIST list);
120 
121 LIST push(LIST list, void* element);
122 
123 LIST push_last(LIST list, void* item);
124 
125 LIST search(LIST list, void* key, int_compare is_equal);
126 
127 #endif
push_last
LIST push_last(LIST list, void *item)
Definition: oldlist.cpp:185
destroy_nodes
void destroy_nodes(LIST list, void_dest destructor)
Definition: oldlist.cpp:138
list_rec::next
list_rec * next
Definition: oldlist.h:75
list_rec
Definition: oldlist.h:73
list_rec::node
list_rec * node
Definition: oldlist.h:74
int_compare
int(*)(void *, void *) int_compare
Definition: oldlist.h:70
search
LIST search(LIST list, void *key, int_compare is_equal)
Definition: oldlist.cpp:202
tesstrain_utils.int
int
Definition: tesstrain_utils.py:154
pop
LIST pop(LIST list)
Definition: oldlist.cpp:161
delete_d
LIST delete_d(LIST list, void *key, int_compare is_equal)
Definition: oldlist.cpp:93
push
LIST push(LIST list, void *element)
Definition: oldlist.cpp:172
is_equal
#define is_equal(p1, p2)
Definition: outlines.h:97
void_dest
void(*)(void *) void_dest
Definition: oldlist.h:71
last
LIST last(LIST var_list)
Definition: oldlist.cpp:151
destroy
LIST destroy(LIST list)
Definition: oldlist.cpp:123
count
int count(LIST var_list)
Definition: oldlist.cpp:79