Zycore 1.5.2
Zyan Core Library for C
Loading...
Searching...
No Matches
Comparison.h
Go to the documentation of this file.
1/***************************************************************************************************
2
3 Zyan Core Library (Zycore-C)
4
5 Original Author : Florian Bernd
6
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24
25***************************************************************************************************/
26
31
32#ifndef ZYCORE_COMPARISON_H
33#define ZYCORE_COMPARISON_H
34
35#include <Zycore/Defines.h>
36#include <Zycore/Types.h>
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42/* ============================================================================================== */
43/* Enums and types */
44/* ============================================================================================== */
45
55typedef ZyanBool (*ZyanEqualityComparison)(const void* left, const void* right);
56
68typedef ZyanI32 (*ZyanComparison)(const void* left, const void* right);
69
70/* ============================================================================================== */
71/* Macros */
72/* ============================================================================================== */
73
74/* ---------------------------------------------------------------------------------------------- */
75/* Equality comparison functions */
76/* ---------------------------------------------------------------------------------------------- */
77
84#define ZYAN_DECLARE_EQUALITY_COMPARISON(name, type) \
85 ZyanBool name(const type* left, const type* right) \
86 { \
87 ZYAN_ASSERT(left); \
88 ZYAN_ASSERT(right); \
89 \
90 return (*left == *right) ? ZYAN_TRUE : ZYAN_FALSE; \
91 }
92
101#define ZYAN_DECLARE_EQUALITY_COMPARISON_FOR_FIELD(name, type, field_name) \
102 ZyanBool name(const type* left, const type* right) \
103 { \
104 ZYAN_ASSERT(left); \
105 ZYAN_ASSERT(right); \
106 \
107 return (left->field_name == right->field_name) ? ZYAN_TRUE : ZYAN_FALSE; \
108 }
109
110/* ---------------------------------------------------------------------------------------------- */
111/* Comparison functions */
112/* ---------------------------------------------------------------------------------------------- */
113
120#define ZYAN_DECLARE_COMPARISON(name, type) \
121 ZyanI32 name(const type* left, const type* right) \
122 { \
123 ZYAN_ASSERT(left); \
124 ZYAN_ASSERT(right); \
125 \
126 if (*left < *right) \
127 { \
128 return -1; \
129 } \
130 if (*left > *right) \
131 { \
132 return 1; \
133 } \
134 return 0; \
135 }
136
145#define ZYAN_DECLARE_COMPARISON_FOR_FIELD(name, type, field_name) \
146 ZyanI32 name(const type* left, const type* right) \
147 { \
148 ZYAN_ASSERT(left); \
149 ZYAN_ASSERT(right); \
150 \
151 if (left->field_name < right->field_name) \
152 { \
153 return -1; \
154 } \
155 if (left->field_name > right->field_name) \
156 { \
157 return 1; \
158 } \
159 return 0; \
160 }
161
162 /* ---------------------------------------------------------------------------------------------- */
163
164/* ============================================================================================== */
165/* Exported functions */
166/* ============================================================================================== */
167
168/* ---------------------------------------------------------------------------------------------- */
169/* Default equality comparison functions */
170/* ---------------------------------------------------------------------------------------------- */
171
182
183
193
204
215
226
237
238/* ---------------------------------------------------------------------------------------------- */
239/* Default comparison functions */
240/* ---------------------------------------------------------------------------------------------- */
241
252
263
274
285
296
307
308/* ---------------------------------------------------------------------------------------------- */
309
310/* ============================================================================================== */
311
312#ifdef __cplusplus
313}
314#endif
315
316#endif /* ZYCORE_COMPARISON_H */
ZYAN_INLINE ZyanBool ZyanEqualsNumeric8(const ZyanU8 *left, const ZyanU8 *right)
Defines a default equality comparison function for 8-bit numeric values.
Definition Comparison.h:203
ZYAN_INLINE ZyanI32 ZyanCompareNumeric8(const ZyanU8 *left, const ZyanU8 *right)
Defines a default comparison function for 8-bit numeric values.
Definition Comparison.h:273
ZyanI32(* ZyanComparison)(const void *left, const void *right)
Defines the ZyanComparison function prototype.
Definition Comparison.h:68
ZYAN_INLINE ZyanBool ZyanEqualsNumeric64(const ZyanU64 *left, const ZyanU64 *right)
Defines a default equality comparison function for 64-bit numeric values.
Definition Comparison.h:236
ZYAN_INLINE ZyanBool ZyanEqualsPointer(const void *const *left, const void *const *right)
Defines a default equality comparison function for pointer values.
Definition Comparison.h:181
ZYAN_INLINE ZyanI32 ZyanComparePointer(const void *const *left, const void *const *right)
Defines a default comparison function for pointer values.
Definition Comparison.h:251
ZYAN_INLINE ZyanI32 ZyanCompareNumeric64(const ZyanU64 *left, const ZyanU64 *right)
Defines a default comparison function for 64-bit numeric values.
Definition Comparison.h:306
ZYAN_INLINE ZyanBool ZyanEqualsNumeric16(const ZyanU16 *left, const ZyanU16 *right)
Defines a default equality comparison function for 16-bit numeric values.
Definition Comparison.h:214
ZYAN_INLINE ZyanI32 ZyanCompareNumeric32(const ZyanU32 *left, const ZyanU32 *right)
Defines a default comparison function for 32-bit numeric values.
Definition Comparison.h:295
ZYAN_INLINE ZyanBool ZyanEqualsNumeric32(const ZyanU32 *left, const ZyanU32 *right)
Defines a default equality comparison function for 32-bit numeric values.
Definition Comparison.h:225
ZYAN_INLINE ZyanBool ZyanEqualsBool(const ZyanBool *left, const ZyanBool *right)
Defines a default equality comparison function for ZyanBool values.
Definition Comparison.h:192
ZYAN_INLINE ZyanI32 ZyanCompareNumeric16(const ZyanU16 *left, const ZyanU16 *right)
Defines a default comparison function for 16-bit numeric values.
Definition Comparison.h:284
#define ZYAN_DECLARE_COMPARISON(name, type)
Declares a generic comparison function for an integral data-type.
Definition Comparison.h:120
ZyanBool(* ZyanEqualityComparison)(const void *left, const void *right)
Defines the ZyanEqualityComparison function prototype.
Definition Comparison.h:55
#define ZYAN_DECLARE_EQUALITY_COMPARISON(name, type)
Declares a generic equality comparison function for an integral data-type.
Definition Comparison.h:84
ZYAN_INLINE ZyanI32 ZyanCompareBool(const ZyanBool *left, const ZyanBool *right)
Defines a default comparison function for ZyanBool values.
Definition Comparison.h:262
General helper and platform detection macros.
#define ZYAN_INLINE
Definition Defines.h:356
Includes and defines some default data types.
ZyanU8 ZyanBool
Defines the ZyanBool data-type.
Definition Types.h:296
int32_t ZyanI32
Definition Types.h:222
uint16_t ZyanU16
Definition Types.h:217
uint64_t ZyanU64
Definition Types.h:219
uint8_t ZyanU8
Definition Types.h:216
uint32_t ZyanU32
Definition Types.h:218