1 |
/* |
2 |
* ASCEND comparison functions of various sorts. |
3 |
* by Ben Allen |
4 |
* Created 9/16/96 |
5 |
* Version: $Revision: 1.6 $ |
6 |
* Version control file: $RCSfile: cmpfunc.h,v $ |
7 |
* Date last modified: $Date: 1997/07/18 12:28:32 $ |
8 |
* Last modified by: $Author: mthomas $ |
9 |
* |
10 |
* This file is part of the Ascend Language Interpreter. |
11 |
* |
12 |
* Copyright (C) 1997 Carnegie Mellon University |
13 |
* |
14 |
* The Ascend Language Interpreter is free software; you can redistribute |
15 |
* it and/or modify it under the terms of the GNU General Public License as |
16 |
* published by the Free Software Foundation; either version 2 of the |
17 |
* License, or (at your option) any later version. |
18 |
* |
19 |
* The Ascend Language Interpreter is distributed in hope that it will be |
20 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
22 |
* General Public License for more details. |
23 |
* |
24 |
* You should have received a copy of the GNU General Public License |
25 |
* along with the program; if not, write to the Free Software Foundation, |
26 |
* Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named |
27 |
* COPYING. |
28 |
*/ |
29 |
|
30 |
/** @file |
31 |
* ASCEND comparison functions of various sorts. |
32 |
* |
33 |
* The problem with instance_types.h is that it requires |
34 |
* pulling in practically the whole compiler headers, so |
35 |
* most clients that only want this for the simpler cmp |
36 |
* functions can use it without that because of a nasty |
37 |
* ifdef down below. |
38 |
* |
39 |
* <pre> |
40 |
* When #including cmpfunc.h, make sure these files are #included first: |
41 |
* #include "utilities/ascConfig.h" |
42 |
* #include "instance_enum.h" |
43 |
* #include "compiler.h" |
44 |
* and possibly, or if CmpIntIndex is undefined, |
45 |
* #include "instance_types.h" |
46 |
* </pre> |
47 |
*/ |
48 |
|
49 |
#ifndef ASC_CMPFUNC_H |
50 |
#define ASC_CMPFUNC_H |
51 |
|
52 |
/** addtogroup compiler Compiler |
53 |
@{ |
54 |
*/ |
55 |
|
56 |
/* reminder strcmp("abc","fcd") --> -1 */ |
57 |
/* |
58 |
* When used with a sort function, these yield a list ordered in |
59 |
* increasing value. |
60 |
* if comparing symbols, use CmpSymchar for maximum speed or |
61 |
* strcmp(SCP(sc1),SCP(sc2)); |
62 |
*/ |
63 |
|
64 |
ASC_DLLSPEC int CmpSymchar(symchar *s1, symchar *s2); |
65 |
/**< |
66 |
* Compare two strings from the symbol table. |
67 |
* Regardless of the details of the symchar definition, returns |
68 |
* the result of alphabetic comparison between two items from the |
69 |
* symbol table. |
70 |
* NULL does not appear in the symbol table, |
71 |
* so it better not be given here. |
72 |
* Not necessarily implemented as strcmp. |
73 |
* @return <table><tr align="center"><td> Result </td><td> Condition </td></tr> |
74 |
* <tr align="center"><td> -1 </td><td> s1 < s2 </td></tr> |
75 |
* <tr align="center"><td> 0 </td><td> s1 == s2 </td></tr> |
76 |
* <tr align="center"><td> 1 </td><td> s1 > s2 </td></tr></table> |
77 |
*/ |
78 |
|
79 |
extern int CmpPtrs(void *p1, void *p2); |
80 |
/**< |
81 |
* <!-- CmpPtrs(p1,p2); --> |
82 |
* <!-- returns: if: --> |
83 |
* <!-- -1 p1<p2 --> |
84 |
* <!-- 0 p1==p2 --> |
85 |
* <!-- 1 p1>p2 --> |
86 |
* General pointer comparison function. |
87 |
* The comparison is for the pointers themselves, not what they point at. |
88 |
* Either pointer may be NULL. |
89 |
* @return <table><tr align="center"><td> Result </td><td> Condition </td></tr> |
90 |
* <tr align="center"><td> -1 </td><td> p1 < p2 </td></tr> |
91 |
* <tr align="center"><td> 0 </td><td> p1 == p2 </td></tr> |
92 |
* <tr align="center"><td> 1 </td><td> p1 > p2 </td></tr></table> |
93 |
* @see CmpPtrsReverse() |
94 |
*/ |
95 |
|
96 |
extern int CmpRealPtrs(void *p1, void *p2); |
97 |
/**< |
98 |
* <!-- CmpRealPtrs(p1,p2); --> |
99 |
* <!-- First asserts p1, p2 != NULL, then: --> |
100 |
* <!-- returns: if: --> |
101 |
* <!-- -1 p1<p2 --> |
102 |
* <!-- 0 p1==p2 --> |
103 |
* <!-- 1 p1>p2 --> |
104 |
* Real pointer comparison function. |
105 |
* The comparison is for the pointers themselves, not what they point at. |
106 |
* Neither pointer may be NULL (checked by assertion). |
107 |
* @return <table><tr align="center"><td> Result </td><td> Condition </td></tr> |
108 |
* <tr align="center"><td> -1 </td><td> p1 < p2 </td></tr> |
109 |
* <tr align="center"><td> 0 </td><td> p1 == p2 </td></tr> |
110 |
* <tr align="center"><td> 1 </td><td> p1 > p2 </td></tr></table> |
111 |
*/ |
112 |
|
113 |
/* |
114 |
* Comparison functions for instance pointers. |
115 |
* All rather similar, but we may decide to change the comparison |
116 |
* methods later, so each has its own function. |
117 |
*/ |
118 |
|
119 |
#ifndef NDEBUG |
120 |
#define CmpParents CmpRealPtrs |
121 |
#else |
122 |
#define CmpParents CmpParentsF |
123 |
#endif |
124 |
/**< |
125 |
* Macro for redirection of CmpParents based on debug mode. |
126 |
* @see CmpRealPtrs(), CmpParentsF() |
127 |
*/ |
128 |
extern int CmpParentsF(CONST struct Instance *i1, CONST struct Instance *i2); |
129 |
/**< |
130 |
* <!-- Comparison functions for parent instance pointers. --> |
131 |
* Parent instance pointer comparison function. |
132 |
* The comparison is for the pointers themselves, not what they point at. |
133 |
* Neither pointer may be NULL (checked by assertion). |
134 |
* @return <table><tr align="center"><td> Result </td><td> Condition </td></tr> |
135 |
* <tr align="center"><td> -1 </td><td> p1 < p2 </td></tr> |
136 |
* <tr align="center"><td> 0 </td><td> p1 == p2 </td></tr> |
137 |
* <tr align="center"><td> 1 </td><td> p1 > p2 </td></tr></table> |
138 |
*/ |
139 |
|
140 |
#ifndef NDEBUG |
141 |
#define CmpRelations CmpRealPtrs |
142 |
#else |
143 |
#define CmpRelations CmpRelationsF |
144 |
#endif |
145 |
/**< |
146 |
* Macro for redirection of CmpRelations based on debug mode. |
147 |
* @see CmpRealPtrs(), CmpRelationsF() |
148 |
*/ |
149 |
extern int CmpRelationsF(CONST struct Instance *i1, CONST struct Instance *i2); |
150 |
/**< |
151 |
* <!-- Comparison functions for relation instance pointers. --> |
152 |
* Relation instance pointer comparison function. |
153 |
* The comparison is for the pointers themselves, not what they point at. |
154 |
* Neither pointer may be NULL (checked by assertion). |
155 |
* @return <table><tr align="center"><td> Result </td><td> Condition </td></tr> |
156 |
* <tr align="center"><td> -1 </td><td> p1 < p2 </td></tr> |
157 |
* <tr align="center"><td> 0 </td><td> p1 == p2 </td></tr> |
158 |
* <tr align="center"><td> 1 </td><td> p1 > p2 </td></tr></table> |
159 |
*/ |
160 |
|
161 |
#ifndef NDEBUG |
162 |
#define CmpLogRelations CmpRealPtrs |
163 |
#else |
164 |
#define CmpLogRelations CmpLogRelationsF |
165 |
#endif |
166 |
/**< |
167 |
* Macro for redirection of CmpLogRelations based on debug mode. |
168 |
* @see CmpRealPtrs(), CmpLogRelationsF() |
169 |
*/ |
170 |
extern int CmpLogRelationsF(CONST struct Instance *i1, CONST struct Instance *i2); |
171 |
/**< |
172 |
* <!-- Comparison functions for logrelation instance pointers. --> |
173 |
* Log relation instance pointer comparison function. |
174 |
* The comparison is for the pointers themselves, not what they point at. |
175 |
* Neither pointer may be NULL (checked by assertion). |
176 |
* @return <table><tr align="center"><td> Result </td><td> Condition </td></tr> |
177 |
* <tr align="center"><td> -1 </td><td> p1 < p2 </td></tr> |
178 |
* <tr align="center"><td> 0 </td><td> p1 == p2 </td></tr> |
179 |
* <tr align="center"><td> 1 </td><td> p1 > p2 </td></tr></table> |
180 |
*/ |
181 |
|
182 |
#ifndef NDEBUG |
183 |
#define CmpWhens CmpRealPtrs |
184 |
#else |
185 |
#define CmpWhens CmpWhensF |
186 |
#endif |
187 |
/**< |
188 |
* Macro for redirection of CmpWhens based on debug mode. |
189 |
* @see CmpRealPtrs(), CmpWhensF() |
190 |
*/ |
191 |
extern int CmpWhensF(CONST struct Instance *i1, CONST struct Instance *i2); |
192 |
/**< |
193 |
* <!-- Comparison functions for when instance pointers. --> |
194 |
* When instance pointer comparison function. |
195 |
* The comparison is for the pointers themselves, not what they point at. |
196 |
* Neither pointer may be NULL (checked by assertion). |
197 |
* @return <table><tr align="center"><td> Result </td><td> Condition </td></tr> |
198 |
* <tr align="center"><td> -1 </td><td> p1 < p2 </td></tr> |
199 |
* <tr align="center"><td> 0 </td><td> p1 == p2 </td></tr> |
200 |
* <tr align="center"><td> 1 </td><td> p1 > p2 </td></tr></table> |
201 |
*/ |
202 |
|
203 |
#ifdef ASC_INSTANCE_TYPES_H |
204 |
|
205 |
extern int CmpIntIndex(CONST struct ArrayChild *a, CONST struct ArrayChild *b); |
206 |
/**< |
207 |
* Compare integer indexes of ArrayChildren a and b. |
208 |
* Both a and b must be non-NULL and are then ASSUMED to be |
209 |
* indexed by integer. |
210 |
* |
211 |
* This function requires instance_types.h be seen first or it is |
212 |
* invisible. |
213 |
* @return <table><tr align="center"><td> Result </td><td> Condition </td></tr> |
214 |
* <tr align="center"><td> -1 </td><td> a index < b index </td></tr> |
215 |
* <tr align="center"><td> 0 </td><td> a index == b index </td></tr> |
216 |
* <tr align="center"><td> 1 </td><td> a index > b index </td></tr></table> |
217 |
*/ |
218 |
extern int CmpStrIndex(CONST struct ArrayChild *a, CONST struct ArrayChild *b); |
219 |
/**< |
220 |
* <!-- CmpStrIndex(a,b),CmpIntIndex(a,b) --> |
221 |
* <!-- Comparison functions for ArrayChildren. --> |
222 |
* <!-- Both a and b must be nonNULL and are then ASSUMED to be an ar-->raychild |
223 |
* <!-- of the type appropriate for the function name. --> |
224 |
* <!-- --> |
225 |
* <!-- This function requires instance_types.h be seen first or it is --> |
226 |
* <!-- invisible. --> |
227 |
* Compare string indexes of ArrayChildren a and b. |
228 |
* Both a and b must be non-NULL and are then ASSUMED to be |
229 |
* indexed by string. |
230 |
* |
231 |
* This function requires instance_types.h be seen first or it is |
232 |
* invisible. |
233 |
* @return <table><tr align="center"><td> Result </td><td> Condition </td></tr> |
234 |
* <tr align="center"><td> -1 </td><td> a index < b index </td></tr> |
235 |
* <tr align="center"><td> 0 </td><td> a index == b index </td></tr> |
236 |
* <tr align="center"><td> 1 </td><td> a index > b index </td></tr></table> |
237 |
*/ |
238 |
|
239 |
#endif /* INSTANCE_TYPES_H_SEEN__ */ |
240 |
|
241 |
/* |
242 |
* When used with a sort function, these yield a list ordered in |
243 |
* decreasing value. |
244 |
*/ |
245 |
|
246 |
extern int CmpPtrsReverse(void *p1, void *p2); |
247 |
/**< |
248 |
* <!-- CmpPtrsReverse(p1,p2); --> |
249 |
* <!-- returns: if: --> |
250 |
* <!-- -1 p1>p2 --> |
251 |
* <!-- 0 p1==p2 --> |
252 |
* <!-- 1 p1<p2 --> |
253 |
* General pointer comparison function with reverse ordering. |
254 |
* The comparison is for the pointers themselves, not what they point at. |
255 |
* Either pointer may be NULL. |
256 |
* @return <table><tr align="center"><td> Result </td><td> Condition </td></tr> |
257 |
* <tr align="center"><td> -1 </td><td> p1 > p2 </td></tr> |
258 |
* <tr align="center"><td> 0 </td><td> p1 == p2 </td></tr> |
259 |
* <tr align="center"><td> 1 </td><td> p1 < p2 </td></tr></table> |
260 |
* @see CmpPtrs() |
261 |
*/ |
262 |
|
263 |
/* @} */ |
264 |
|
265 |
#endif /* ASC_CMPFUNC_H */ |
266 |
|