Rudiments
comparatorinlines.h
1// Copyright (c) 1999-2018 David Muse
2// See the COPYING file for more information
3
4#include <rudiments/charstring.h>
5#include <rudiments/wcharstring.h>
6#include <rudiments/stdio.h>
7
8inline
10 sense(1),
11 natural(false),
12 delimiters("."),
13 wdelimiters(L".") {
14}
15
16inline
19
20inline
22 sense=(reverse)?-1:1;
23}
24
25inline
27 return sense==-1;
28}
29
30inline
31void comparator::setNatural(bool natural) {
32 this->natural=natural;
33}
34
35inline
37 return natural;
38}
39
40inline
41void comparator::setNumberDelimiters(const char *delimiters) {
42 this->delimiters=delimiters;
43}
44
45inline
47 return delimiters;
48}
49
50inline
51void comparator::setWideNumberDelimiters(const wchar_t *delimiters) {
52 this->wdelimiters=delimiters;
53}
54
55inline
57 return wdelimiters;
58}
59
60inline
61int32_t comparator::compare(char *value1, char *value2) {
62 return ((natural)?
65 sense;
66}
67
68inline
69int32_t comparator::compare(const char *value1, const char *value2) {
70 return ((natural)?
73 sense;
74}
75
76inline
77int32_t comparator::compare(wchar_t *value1, wchar_t *value2) {
78 return ((natural)?
81 sense;
82}
83
84inline
85int32_t comparator::compare(const wchar_t *value1,
86 const wchar_t *value2) {
87 return ((natural)?
90 sense;
91}
92
93inline
94int32_t comparator::compare(byte_t *value1, byte_t *value2) {
95 return ((natural)?
97 (const char *)value2,
98 delimiters):
99 charstring::compare((const char *)value1,
100 (const char *)value2))*
101 sense;
102}
103
104inline
105int32_t comparator::compare(const byte_t *value1,
106 const byte_t *value2) {
107 return ((natural)?
109 (const char *)value2,
110 delimiters):
111 charstring::compare((const char *)value1,
112 (const char *)value2))*
113 sense;
114}
115
116inline
117int32_t comparator::compare(char value1, char value2) {
118 return (((int16_t)value1)-((int16_t)value2))*sense;
119}
120
121inline
122int32_t comparator::compare(bool value1, bool value2) {
123 return (((int16_t)value1)-((int16_t)value2))*sense;
124}
125
126inline
127int32_t comparator::compare(int16_t value1, int16_t value2) {
128 return (((int32_t)value1)-((int32_t)value2))*sense;
129}
130
131inline
132int32_t comparator::compare(int32_t value1, int32_t value2) {
133 return (((int64_t)value1)-((int64_t)value2))*sense;
134}
135
136inline
137int32_t comparator::compare(int64_t value1, int64_t value2) {
138 if (value1<value2) {
139 return -1*sense;
140 } else if (value1==value2) {
141 return 0;
142 } else {
143 return 1*sense;
144 }
145}
146
147inline
148int32_t comparator::compare(byte_t value1, byte_t value2) {
149 return (((int16_t)value1)-((int16_t)value2))*sense;
150}
151
152inline
153int32_t comparator::compare(uint16_t value1, uint16_t value2) {
154 return (((int32_t)value1)-((int32_t)value2))*sense;
155}
156
157inline
158int32_t comparator::compare(uint32_t value1, uint32_t value2) {
159 return (((int64_t)value1)-((int64_t)value2))*sense;
160}
161
162inline
163int32_t comparator::compare(uint64_t value1, uint64_t value2) {
164 if (value1<value2) {
165 return -1*sense;
166 } else if (value1==value2) {
167 return 0;
168 } else {
169 return 1*sense;
170 }
171}
172
173inline
174int32_t comparator::compare(float value1, float value2) {
175 if (value1<value2) {
176 return -1*sense;
177 } else if (value1==value2) {
178 return 0;
179 } else {
180 return 1*sense;
181 }
182}
183
184inline
185int32_t comparator::compare(double value1, double value2) {
186 if (value1<value2) {
187 return -1*sense;
188 } else if (value1==value2) {
189 return 0;
190 } else {
191 return 1*sense;
192 }
193}
194
195inline
196int32_t comparator::compare(long double value1, long double value2) {
197 if (value1<value2) {
198 return -1*sense;
199 } else if (value1==value2) {
200 return 0;
201 } else {
202 return 1*sense;
203 }
204}
205
206inline
207int32_t comparator::compare(void *value1, void *value2) {
208 if (value1<value2) {
209 return -1*sense;
210 } else if (value1==value2) {
211 return 0;
212 } else {
213 return 1*sense;
214 }
215}
216
217inline
218int32_t comparator::compare(object *value1, object *value2) {
219 if (value1<value2) {
220 return -1*sense;
221 } else if (value1==value2) {
222 return 0;
223 } else {
224 return 1*sense;
225 }
226}
Definition avltree.h:11
static int32_t compare(const char *str1, const char *str2)
static int32_t compareNatural(const char *str1, const char *str2)
void setNumberDelimiters(const char *delimiters)
Definition comparatorinlines.h:41
void setReverse(bool reverse)
Definition comparatorinlines.h:21
const char * getNumberDelimiters()
Definition comparatorinlines.h:46
bool getNatural()
Definition comparatorinlines.h:36
const wchar_t * getWideNumberDelimiters()
Definition comparatorinlines.h:56
void setWideNumberDelimiters(const wchar_t *delimiters)
Definition comparatorinlines.h:51
comparator()
Definition comparatorinlines.h:9
bool getReverse()
Definition comparatorinlines.h:26
virtual ~comparator()
Definition comparatorinlines.h:17
virtual int32_t compare(char *value1, char *value2)
Definition comparatorinlines.h:61
void setNatural(bool natural)
Definition comparatorinlines.h:31
static int32_t compareNatural(const wchar_t *str1, const wchar_t *str2)
static int32_t compare(const wchar_t *str1, const wchar_t *str2)