debug.c needs dylib.h.
[SquirrelJME.git] / nanocoat / include / sjme / comparator.h
blob173a9eda1a5f50f18704c06a7119cdd57780ca2c
1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
10 /**
11 * Compares values.
13 * @since 2024/01/03
16 #ifndef SQUIRRELJME_COMPARATOR_H
17 #define SQUIRRELJME_COMPARATOR_H
19 #include "sjme/stdTypes.h"
20 #include "sjme/tokenUtils.h"
22 /* Anti-C++. */
23 #ifdef __cplusplus
24 #ifndef SJME_CXX_IS_EXTERNED
25 #define SJME_CXX_IS_EXTERNED
26 #define SJME_CXX_SQUIRRELJME_COMPARATOR_H
27 extern "C" {
28 #endif /* #ifdef SJME_CXX_IS_EXTERNED */
29 #endif /* #ifdef __cplusplus */
31 /*--------------------------------------------------------------------------*/
33 /**
34 * A generic comparator.
36 * @param a The first item.
37 * @param b The second item.
38 * @param elementSize The size of each element.
39 * @return The resultant comparison, will be zero, negative, or positive.
40 * @since 2024/01/03
42 typedef sjme_jint (*sjme_comparator)(sjme_cpointer a, sjme_cpointer b,
43 int elementSize);
45 /**
46 * Determines the name of a given comparator.
48 * @param type The type to use.
49 * @param numPointerStars The number of pointer stars used.
50 * @since 2024/01/03
52 #define SJME_COMPARATOR(type, numPointerStars) \
53 SJME_TOKEN_PASTE_PP(sjme_comparator_, SJME_TOKEN_PASTE_PP(type, \
54 SJME_TOKEN_SINGLE(SJME_TOKEN_STARS_C##numPointerStars)))
56 /**
57 * Determines the name of a given comparator.
59 * @param type The type to use.
60 * @param numPointerStars The number of pointer stars used.
61 * @since 2024/01/03
63 #define SJME_COMPARATOR_INSENSITIVE(type, numPointerStars) \
64 SJME_TOKEN_PASTE_PP(sjme_comparator_insensitive_, \
65 SJME_TOKEN_PASTE_PP(type, \
66 SJME_TOKEN_SINGLE(SJME_TOKEN_STARS_C##numPointerStars)))
68 /**
69 * Defines a generic comparator, using a simple subtraction.
71 * @param type The type to compare.
72 * @param numPointerStars The number of pointer stars.
73 * @since 2024/01/03
75 #define SJME_COMPARATOR_GENERIC(type, numPointerStars) \
76 static sjme_inline sjme_attrArtificial sjme_jint \
77 SJME_COMPARATOR(type, numPointerStars)( \
78 sjme_cpointer a, sjme_cpointer b, int elementSize) \
79 { \
80 return (sjme_jint)(*((const type*)b) - *((const type*)a)); \
83 /** Generic @c sjme_jbyte comparator. */
84 SJME_COMPARATOR_GENERIC(sjme_jbyte, 0)
86 /** Generic @c sjme_jubyte comparator. */
87 SJME_COMPARATOR_GENERIC(sjme_jubyte, 0)
89 /** Generic @c sjme_jshort comparator. */
90 SJME_COMPARATOR_GENERIC(sjme_jshort, 0)
92 /** Generic @c sjme_jchar comparator. */
93 SJME_COMPARATOR_GENERIC(sjme_jchar, 0)
95 /** Generic @c sjme_jint comparator. */
96 SJME_COMPARATOR_GENERIC(sjme_jint, 0)
98 /** Generic @c sjme_juint comparator. */
99 SJME_COMPARATOR_GENERIC(sjme_juint, 0)
101 /** Generic @c sjme_cchar comparator. */
102 SJME_COMPARATOR_GENERIC(sjme_cchar, 0)
105 * Compares two @c sjme_lpcstr .
107 * @param a The first item.
108 * @param b The second item.
109 * @param elementSize The size of each element.
110 * @return The resultant comparison, will be zero, negative, or positive.
111 * @since 2024/01/03
113 sjme_jint SJME_COMPARATOR(sjme_lpcstr, 0)(sjme_cpointer a, sjme_cpointer b,
114 int elementSize);
117 * Compares two @c sjme_lpcstr without regards to case.
119 * @param a The first item.
120 * @param b The second item.
121 * @param elementSize The size of each element.
122 * @return The resultant comparison, will be zero, negative, or positive.
123 * @since 2024/01/03
125 sjme_jint SJME_COMPARATOR_INSENSITIVE(sjme_lpcstr, 0)(
126 sjme_cpointer a, sjme_cpointer b, int elementSize);
128 /*--------------------------------------------------------------------------*/
130 /* Anti-C++. */
131 #ifdef __cplusplus
132 #ifdef SJME_CXX_SQUIRRELJME_COMPARATOR_H
134 #undef SJME_CXX_SQUIRRELJME_COMPARATOR_H
135 #undef SJME_CXX_IS_EXTERNED
136 #endif /* #ifdef SJME_CXX_SQUIRRELJME_COMPARATOR_H */
137 #endif /* #ifdef __cplusplus */
139 #endif /* SQUIRRELJME_COMPARATOR_H */