tesseract  4.1.0
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 ((LIST) nullptr)
77 
78 using int_compare = int (*)(void*, void*);
79 using void_dest = void (*)(void*);
80 
81 struct list_rec {
82  struct list_rec* node;
83  struct list_rec* next;
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  * p u s h o n
105  *
106  * Add a cell onto the front of a list. The list given as an input
107  * parameter is modified.
108  **********************************************************************/
109 
110 #define push_on(list, thing) ((list) = push(list, (LIST)(thing)))
111 
112 /**********************************************************************
113  * s e t r e s t
114  *
115  * Change the "next" field of a list element to point to a desired place.
116  *
117  * #define set_rest(l,node) l->next = node;
118  **********************************************************************/
119 
120 #define set_rest(l, cell) ((l)->next = (cell))
121 
122 /*----------------------------------------------------------------------
123  Public Function Prototypes
124 ----------------------------------------------------------------------*/
125 int count(LIST var_list);
126 
127 LIST delete_d(LIST list, void* key, int_compare is_equal);
128 
129 LIST destroy(LIST list);
130 
131 void destroy_nodes(LIST list, void_dest destructor);
132 
133 void insert(LIST list, void *node);
134 
135 LIST last(LIST var_list);
136 
137 LIST pop(LIST list);
138 
139 LIST push(LIST list, void* element);
140 
141 LIST push_last(LIST list, void* item);
142 
143 LIST reverse(LIST list);
144 
145 LIST search(LIST list, void* key, int_compare is_equal);
146 
147 #endif
LIST last(LIST var_list)
Definition: oldlist.cpp:191
LIST push_last(LIST list, void *item)
Definition: oldlist.cpp:233
int count(LIST var_list)
Definition: oldlist.cpp:96
LIST push(LIST list, void *element)
Definition: oldlist.cpp:219
#define is_equal(p1, p2)
Definition: outlines.h:105
LIST destroy(LIST list)
Definition: oldlist.cpp:142
LIST search(LIST list, void *key, int_compare is_equal)
Definition: oldlist.cpp:264
struct list_rec * node
Definition: oldlist.h:82
void(*)(void *) void_dest
Definition: oldlist.h:79
LIST delete_d(LIST list, void *key, int_compare is_equal)
Definition: oldlist.cpp:111
int(*)(void *, void *) int_compare
Definition: oldlist.h:78
LIST pop(LIST list)
Definition: oldlist.cpp:202
void insert(LIST list, void *node)
Definition: oldlist.cpp:173
LIST reverse(LIST list)
Definition: oldlist.cpp:250
struct list_rec * next
Definition: oldlist.h:83
void destroy_nodes(LIST list, void_dest destructor)
Definition: oldlist.cpp:158