Rudiments

nodeinlines.h
1 // Copyright (c) 1999-2018 David Muse
2 // See the COPYING file for more information
3 #ifndef RUDIMENTS_NODE_H
4 #define RUDIMENTS_NODE_H
5
6 #include <rudiments/charstring.h>
7 #include <rudiments/stdio.h>
8
9 // Ideally we'd use explicit specialization here but old enough
10 // compilers don't support it and this isn't any less efficient.
11
12 inline
13 int32_t node_compare(char *value1, char *value2) {
14 return charstring::compare(value1,value2);
15 }
16
17 inline
18 int32_t node_compare(const char *value1, const char *value2) {
19 return charstring::compare(value1,value2);
20 }
21
22 inline
23 int32_t node_compare(const unsigned char *value1,
24 const unsigned char *value2) {
25 return charstring::compare((const char *)value1,(const char *)value2);
26 }
27
28 inline
29 int32_t node_compare(unsigned char *value1, unsigned char *value2) {
30 return charstring::compare((const char *)value1,(const char *)value2);
31 }
32
33 inline
34 int32_t node_compare(char value1, char value2) {
35 if (value1<value2) {
36 return -1;
37 } else if (value1==value2) {
38 return 0;
39 } else {
40 return 1;
41 }
42 }
43
44 inline
45 int32_t node_compare(int16_t value1, int16_t value2) {
46 if (value1<value2) {
47 return -1;
48 } else if (value1==value2) {
49 return 0;
50 } else {
51 return 1;
52 }
53 }
54
55 inline
56 int32_t node_compare(int32_t value1, int32_t value2) {
57 if (value1<value2) {
58 return -1;
59 } else if (value1==value2) {
60 return 0;
61 } else {
62 return 1;
63 }
64 }
65
66 inline
67 int32_t node_compare(int64_t value1, int64_t value2) {
68 if (value1<value2) {
69 return -1;
70 } else if (value1==value2) {
71 return 0;
72 } else {
73 return 1;
74 }
75 }
76
77 inline
78 int32_t node_compare(unsigned char value1, unsigned char value2) {
79 if (value1<value2) {
80 return -1;
81 } else if (value1==value2) {
82 return 0;
83 } else {
84 return 1;
85 }
86 }
87
88 inline
89 int32_t node_compare(uint16_t value1, uint16_t value2) {
90 if (value1<value2) {
91 return -1;
92 } else if (value1==value2) {
93 return 0;
94 } else {
95 return 1;
96 }
97 }
98
99 inline
100 int32_t node_compare(uint32_t value1, uint32_t value2) {
101 if (value1<value2) {
102 return -1;
103 } else if (value1==value2) {
104 return 0;
105 } else {
106 return 1;
107 }
108 }
109
110 inline
111 int32_t node_compare(uint64_t value1, uint64_t value2) {
112 if (value1<value2) {
113 return -1;
114 } else if (value1==value2) {
115 return 0;
116 } else {
117 return 1;
118 }
119 }
120
121 inline
122 int32_t node_compare(float value1, float value2) {
123 if (value1<value2) {
124 return -1;
125 } else if (value1==value2) {
126 return 0;
127 } else {
128 return 1;
129 }
130 }
131
132 inline
133 int32_t node_compare(double value1, double value2) {
134 if (value1<value2) {
135 return -1;
136 } else if (value1==value2) {
137 return 0;
138 } else {
139 return 1;
140 }
141 }
142
143 inline
144 int32_t node_compare(long double value1, long double value2) {
145 if (value1<value2) {
146 return -1;
147 } else if (value1==value2) {
148 return 0;
149 } else {
150 return 1;
151 }
152 }
153
154 inline
155 int32_t node_compare(void *value1, void *value2) {
156 if (value1<value2) {
157 return -1;
158 } else if (value1==value2) {
159 return 0;
160 } else {
161 return 1;
162 }
163 }
164
165 inline
166 void node_print(const char *value) {
167 stdoutput.printf("%s",value);
168 }
169
170 inline
171 void node_print(char *value) {
172 stdoutput.printf("%s",value);
173 }
174
175 inline
176 void node_print(char value) {
177 stdoutput.printf("%c",value);
178 }
179
180 inline
181 void node_print(int16_t value) {
182 stdoutput.printf("%hd",value);
183 }
184
185 inline
186 void node_print(int32_t value) {
187 stdoutput.printf("%d",(int)value);
188 }
189
190 inline
191 void node_print(int64_t value) {
192 #ifdef RUDIMENTS_HAVE_LONG_LONG
193 stdoutput.printf("%lld",(long long)value);
194 #else
195 stdoutput.printf("%ld",(long)value);
196 #endif
197 }
198
199 inline
200 void node_print(unsigned const char *value) {
201 stdoutput.printf("%s",value);
202 }
203
204 inline
205 void node_print(unsigned char *value) {
206 stdoutput.printf("%s",value);
207 }
208
209 inline
210 void node_print(unsigned char value) {
211 stdoutput.printf("%c",value);
212 }
213
214 inline
215 void node_print(uint16_t value) {
216 stdoutput.printf("%hd",value);
217 }
218
219 inline
220 void node_print(uint32_t value) {
221 stdoutput.printf("%d",(unsigned int)value);
222 }
223
224 inline
225 void node_print(uint64_t value) {
226 #ifdef RUDIMENTS_HAVE_LONG_LONG
227 stdoutput.printf("%lld",(unsigned long long)value);
228 #else
229 stdoutput.printf("%ld",(unsigned long)value);
230 #endif
231 }
232
233 inline
234 void node_print(float value) {
235 stdoutput.printf("%f",value);
236 }
237
238 inline
239 void node_print(double value) {
240 stdoutput.printf("%f",value);
241 }
242
243 inline
244 void node_print(long double value) {
245 stdoutput.printf("%Lf",value);
246 }
247
248 inline
249 void node_print(void *value) {
250 stdoutput.printf("%08x",value);
251 }
252
253 #endif
charstring::compare
static int32_t compare(const char *str1, const char *str2)
filedescriptor::printf
size_t printf(const char *format,...)