Rename unzip tool.
[SquirrelJME.git] / nanocoat / include / sjme / comparator.h
blob4919a3dd39a6fe6cb4c002714fe5eb4efbf2a8c0
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/nvm.h"
21 /* Anti-C++. */
22 #ifdef __cplusplus
23 #ifndef SJME_CXX_IS_EXTERNED
24 #define SJME_CXX_IS_EXTERNED
25 #define SJME_CXX_SQUIRRELJME_COMPARATOR_H
26 extern "C" {
27 #endif /* #ifdef SJME_CXX_IS_EXTERNED */
28 #endif /* #ifdef __cplusplus */
30 /*--------------------------------------------------------------------------*/
32 /**
33 * A generic comparator.
35 * @param a The first item.
36 * @param b The second item.
37 * @param elementSize The size of each element.
38 * @return The resultant comparison, will be zero, negative, or positive.
39 * @since 2024/01/03
41 typedef sjme_jint (*sjme_comparator)(sjme_cpointer a, sjme_cpointer b,
42 int elementSize);
44 /**
45 * Determines the name of a given comparator.
47 * @param type The type to use.
48 * @param numPointerStars The number of pointer stars used.
49 * @since 2024/01/03
51 #define SJME_COMPARATOR(type, numPointerStars) \
52 SJME_TOKEN_PASTE_PP(sjme_comparator_, SJME_TOKEN_PASTE_PP(type, \
53 SJME_TOKEN_SINGLE(SJME_TOKEN_STARS_C##numPointerStars)))
55 /**
56 * Determines the name of a given comparator.
58 * @param type The type to use.
59 * @param numPointerStars The number of pointer stars used.
60 * @since 2024/01/03
62 #define SJME_COMPARATOR_INSENSITIVE(type, numPointerStars) \
63 SJME_TOKEN_PASTE_PP(sjme_comparator_insensitive_, \
64 SJME_TOKEN_PASTE_PP(type, \
65 SJME_TOKEN_SINGLE(SJME_TOKEN_STARS_C##numPointerStars)))
67 /**
68 * Defines a generic comparator, using a simple subtraction.
70 * @param type The type to compare.
71 * @param numPointerStars The number of pointer stars.
72 * @since 2024/01/03
74 #define SJME_COMPARATOR_GENERIC(type, numPointerStars) \
75 static sjme_inline sjme_attrArtificial sjme_jint \
76 SJME_COMPARATOR(type, numPointerStars)( \
77 sjme_cpointer a, sjme_cpointer b, int elementSize) \
78 { \
79 return (sjme_jint)(*((const type*)b) - *((const type*)a)); \
82 /** Generic @c sjme_jbyte comparator. */
83 SJME_COMPARATOR_GENERIC(sjme_jbyte, 0)
85 /** Generic @c sjme_jubyte comparator. */
86 SJME_COMPARATOR_GENERIC(sjme_jubyte, 0)
88 /** Generic @c sjme_jshort comparator. */
89 SJME_COMPARATOR_GENERIC(sjme_jshort, 0)
91 /** Generic @c sjme_jchar comparator. */
92 SJME_COMPARATOR_GENERIC(sjme_jchar, 0)
94 /** Generic @c sjme_jint comparator. */
95 SJME_COMPARATOR_GENERIC(sjme_jint, 0)
97 /** Generic @c sjme_juint comparator. */
98 SJME_COMPARATOR_GENERIC(sjme_juint, 0)
100 /** Generic @c sjme_cchar comparator. */
101 SJME_COMPARATOR_GENERIC(sjme_cchar, 0)
104 * Compares two @c sjme_lpcstr .
106 * @param a The first item.
107 * @param b The second item.
108 * @param elementSize The size of each element.
109 * @return The resultant comparison, will be zero, negative, or positive.
110 * @since 2024/01/03
112 sjme_jint SJME_COMPARATOR(sjme_lpcstr, 0)(sjme_cpointer a, sjme_cpointer b,
113 int elementSize);
116 * Compares two @c sjme_lpcstr without regards to case.
118 * @param a The first item.
119 * @param b The second item.
120 * @param elementSize The size of each element.
121 * @return The resultant comparison, will be zero, negative, or positive.
122 * @since 2024/01/03
124 sjme_jint SJME_COMPARATOR_INSENSITIVE(sjme_lpcstr, 0)(
125 sjme_cpointer a, sjme_cpointer b, int elementSize);
127 /*--------------------------------------------------------------------------*/
129 /* Anti-C++. */
130 #ifdef __cplusplus
131 #ifdef SJME_CXX_SQUIRRELJME_COMPARATOR_H
133 #undef SJME_CXX_SQUIRRELJME_COMPARATOR_H
134 #undef SJME_CXX_IS_EXTERNED
135 #endif /* #ifdef SJME_CXX_SQUIRRELJME_COMPARATOR_H */
136 #endif /* #ifdef __cplusplus */
138 #endif /* SQUIRRELJME_COMPARATOR_H */