Rudiments
collectioninlines.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/character.h>
7
8inline
10 object(),
11 managevalues(false),
12 managearrayvalues(false),
13 managekeys(false),
14 managearraykeys(false),
15 compptr(&comp) {
16}
17
18inline
20 object(c),
21 managevalues(c.managevalues),
22 managearrayvalues(c.managearrayvalues),
23 managekeys(c.managekeys),
24 managearraykeys(c.managearraykeys),
25 comp(c.comp),
26 compptr(&comp) {
27}
28
29inline
31 if (this!=&c) {
32 object::operator=(c);
33 managevalues=c.managevalues;
34 managearrayvalues=c.managearrayvalues;
35 managekeys=c.managekeys;
36 managearraykeys=c.managearraykeys;
37 comp=c.comp;
38 compptr=&comp;
39 }
40 return *this;
41}
42
43inline
46
47inline
49 return compptr;
50}
51
52inline
54 if (newcomp) {
55 compptr=newcomp;
56 } else {
57 compptr=&comp;
58 }
59}
60
61inline
63 managevalues=manage;
64 managearrayvalues=false;
65}
66
67inline
69 return false;
70}
71
72inline
74 return false;
75}
76
77inline
79 return 0;
80}
81
82inline
84 return false;
85}
86
87inline
89 return managevalues;
90}
91
92inline
94 managearrayvalues=manage;
95 managevalues=false;
96}
97
98inline
100 return managearrayvalues;
101}
102
103inline
105 managekeys=manage;
106 managearraykeys=false;
107}
108
109inline
111 return managekeys;
112}
113
114inline
116 managearraykeys=manage;
117 managekeys=false;
118}
119
120inline
122 return managearraykeys;
123}
124
125inline
126ssize_t collection::writeValue(output *out, const char *value) {
127 return out->printf("%s",value);
128}
129
130inline
131ssize_t collection::writeValue(output *out, char *value) {
132 return out->printf("%s",value);
133}
134
135inline
136ssize_t collection::writeValue(output *out, const wchar_t *value) {
137 return out->printf(L"%s",value);
138}
139
140inline
141ssize_t collection::writeValue(output *out, wchar_t *value) {
142 return out->printf(L"%s",value);
143}
144
145inline
146ssize_t collection::writeValue(output *out, char value) {
147 return out->printf("%c",value);
148}
149
150inline
151ssize_t collection::writeValue(output *out, wchar_t value) {
152 return out->printf(L"%c",value);
153}
154
155inline
156ssize_t collection::writeValue(output *out, bool value) {
157 return out->printf("%s",(value)?"true":"false");
158}
159
160inline
161ssize_t collection::writeValue(output *out, int16_t value) {
162 return out->printf("%hd",value);
163}
164
165inline
166ssize_t collection::writeValue(output *out, int32_t value) {
167 return out->printf("%d",value);
168}
169
170inline
171ssize_t collection::writeValue(output *out, int64_t value) {
172 #ifdef RUDIMENTS_HAVE_LONG_LONG
173 return out->printf("%lld",(long long)value);
174 #else
175 return out->printf("%ld",(long)value);
176 #endif
177}
178
179inline
180ssize_t collection::writeValue(output *out, const byte_t *value) {
181 return out->printf("%s",value);
182}
183
184inline
185ssize_t collection::writeValue(output *out, byte_t *value) {
186 return out->printf("%s",value);
187}
188
189inline
190ssize_t collection::writeValue(output *out, byte_t value) {
191 return out->printf("%c",value);
192}
193
194inline
195ssize_t collection::writeValue(output *out, uint16_t value) {
196 return out->printf("%hd",value);
197}
198
199inline
200ssize_t collection::writeValue(output *out, uint32_t value) {
201 return out->printf("%d",value);
202}
203
204inline
205ssize_t collection::writeValue(output *out, uint64_t value) {
206 #ifdef RUDIMENTS_HAVE_LONG_LONG
207 return out->printf("%lld",(long long)value);
208 #else
209 return out->printf("%ld",(long)value);
210 #endif
211}
212
213inline
214ssize_t collection::writeValue(output *out, float value) {
215 return out->printf("%f",value);
216}
217
218inline
219ssize_t collection::writeValue(output *out, double value) {
220 return out->printf("%f",value);
221}
222
223inline
224ssize_t collection::writeValue(output *out, long double value) {
225 return out->printf("%Lf",value);
226}
227
228inline
229ssize_t collection::writeValue(output *out, const void *value) {
230 return out->printf("%08x",value);
231}
232
233inline
234ssize_t collection::writeValue(output *out, void *value) {
235 return out->printf("%08x",value);
236}
237
238inline
239ssize_t collection::writeValue(output *out, const object *value) {
240 // Why this cast to const void *? gcc 3.3.6 on openbsd 7.0 for luna88k
241 // segfaults without it, and it doesn't hurt other compilers.
242 return out->printf("%08x",(const void *)value);
243}
244
245inline
246ssize_t collection::writeValue(output *out, object *value) {
247 // Why this cast to const void *? gcc 3.3.6 on openbsd 7.0 for luna88k
248 // segfaults without it, and it doesn't hurt other compilers.
249 return out->printf("%08x",(const void *)value);
250}
251
252template <class valuetype>
253inline
254ssize_t collection::writeValue(output *out, const valuetype &value) {
255 // Why this cast to const void *? gcc 3.3.6 on openbsd 7.0 for luna88k
256 // segfaults without it, and it doesn't hurt other compilers.
257 return out->printf("%08x",(const void *)&value);
258}
259
260inline
261ssize_t collection::writeJsonValue(output *out, const char *value) {
262 if (!value) {
263 return out->write("null");
264 } else if (charstring::isNumber(value)) {
265 return out->printf("%s",value);
266 }
267 return out->printf("\"%s\"",value);
268}
269
270inline
271ssize_t collection::writeJsonValue(output *out, char *value) {
272 if (!value) {
273 return out->write("null");
274 } else if (charstring::isNumber(value)) {
275 return out->printf("%s",value);
276 }
277 return out->printf("\"%s\"",value);
278}
279
280inline
281ssize_t collection::writeJsonValue(output *out, const wchar_t *value) {
282 if (!value) {
283 return out->write("null");
284 } else if (wcharstring::isNumber(value)) {
285 return out->printf(L"%s",value);
286 }
287 return out->printf(L"\"%s\"",value);
288}
289
290inline
291ssize_t collection::writeJsonValue(output *out, wchar_t *value) {
292 if (!value) {
293 return out->write("null");
294 } else if (wcharstring::isNumber(value)) {
295 return out->printf(L"%s",value);
296 }
297 return out->printf(L"\"%s\"",value);
298}
299
300inline
301ssize_t collection::writeJsonValue(output *out, char value) {
302 if (character::isDigit(value)) {
303 return out->printf("%c",value);
304 }
305 return out->printf("\"%c\"",value);
306}
307
308inline
309ssize_t collection::writeJsonValue(output *out, wchar_t value) {
310 if (character::isDigit(value)) {
311 return out->printf(L"%c",value);
312 }
313 return out->printf(L"\"%c\"",value);
314}
315
316inline
317ssize_t collection::writeJsonValue(output *out, bool value) {
318 return out->printf("%s",(value)?"true":"false");
319}
320
321inline
322ssize_t collection::writeJsonValue(output *out, int16_t value) {
323 return out->printf("%hd",value);
324}
325
326inline
327ssize_t collection::writeJsonValue(output *out, int32_t value) {
328 return out->printf("%d",value);
329}
330
331inline
332ssize_t collection::writeJsonValue(output *out, int64_t value) {
333 #ifdef RUDIMENTS_HAVE_LONG_LONG
334 return out->printf("%lld",(long long)value);
335 #else
336 return out->printf("%ld",(long)value);
337 #endif
338}
339
340inline
341ssize_t collection::writeJsonValue(output *out, const byte_t *value) {
342 if (!value) {
343 return out->write("null");
344 } else if (charstring::isNumber((const char *)value)) {
345 return out->printf("%s",value);
346 }
347 return out->printf("\"%s\"",value);
348}
349
350inline
351ssize_t collection::writeJsonValue(output *out, byte_t *value) {
352 if (!value) {
353 return out->write("null");
354 } else if (charstring::isNumber((char *)value)) {
355 return out->printf("%s",value);
356 }
357 return out->printf("\"%s\"",value);
358}
359
360inline
361ssize_t collection::writeJsonValue(output *out, byte_t value) {
362 if (character::isDigit(value)) {
363 return out->printf("%c",value);
364 }
365 return out->printf("\"%c\"",value);
366}
367
368inline
369ssize_t collection::writeJsonValue(output *out, uint16_t value) {
370 return out->printf("%hd",value);
371}
372
373inline
374ssize_t collection::writeJsonValue(output *out, uint32_t value) {
375 return out->printf("%d",value);
376}
377
378inline
379ssize_t collection::writeJsonValue(output *out, uint64_t value) {
380 #ifdef RUDIMENTS_HAVE_LONG_LONG
381 return out->printf("%lld",(long long)value);
382 #else
383 return out->printf("%ld",(long)value);
384 #endif
385}
386
387inline
388ssize_t collection::writeJsonValue(output *out, float value) {
389 return out->printf("%f",value);
390}
391
392inline
393ssize_t collection::writeJsonValue(output *out, double value) {
394 return out->printf("%f",value);
395}
396
397inline
398ssize_t collection::writeJsonValue(output *out, long double value) {
399 return out->printf("%Lf",value);
400}
401
402inline
403ssize_t collection::writeJsonValue(output *out, const void *value) {
404 if (!value) {
405 return out->write("null");
406 }
407 return out->printf("\"%08x\"",value);
408}
409
410inline
411ssize_t collection::writeJsonValue(output *out, void *value) {
412 if (!value) {
413 return out->write("null");
414 }
415 return out->printf("\"%08x\"",value);
416}
417
418inline
419ssize_t collection::writeJsonValue(output *out, const object *value) {
420 if (!value) {
421 return out->write("null");
422 }
423 // Why this cast to const void *? gcc 3.3.6 on openbsd 7.0 for luna88k
424 // segfaults without it, and it doesn't hurt other compilers.
425 return out->printf("\"%08x\"",(const void *)value);
426}
427
428inline
429ssize_t collection::writeJsonValue(output *out, object *value) {
430 if (!value) {
431 return out->write("null");
432 }
433 // Why this cast to const void *? gcc 3.3.6 on openbsd 7.0 for luna88k
434 // segfaults without it, and it doesn't hurt other compilers.
435 return out->printf("\"%08x\"",(const void *)value);
436}
437
438template <class valuetype>
439inline
440ssize_t collection::writeJsonValue(output *out, const valuetype &value) {
441 // Why this cast to const void *? gcc 3.3.6 on openbsd 7.0 for luna88k
442 // segfaults without it, and it doesn't hurt other compilers.
443 return out->printf("\"%08x\"",(const void *)&value);
444}
Definition avltree.h:11
static bool isDigit(int32_t c)
static bool isNumber(const char *val)
Definition collection.h:11
virtual ~collection()
Definition collectioninlines.h:44
void setComparator(comparator *newcomp)
Definition collectioninlines.h:53
virtual bool getManageArrayValues()
Definition collectioninlines.h:99
collection & operator=(collection &c)
Definition collectioninlines.h:30
virtual bool getManageArrayKeys()
Definition collectioninlines.h:121
virtual bool isReadOnly()
Definition collectioninlines.h:68
virtual void setManageArrayValues(bool manage)
Definition collectioninlines.h:93
virtual void setManageValues(bool manage)
Definition collectioninlines.h:62
virtual void setManageKeys(bool manage)
Definition collectioninlines.h:104
virtual void setManageArrayKeys(bool manage)
Definition collectioninlines.h:115
virtual bool getManageValues()
Definition collectioninlines.h:88
virtual bool getManageKeys()
Definition collectioninlines.h:110
virtual uint64_t getBlockSize()
Definition collectioninlines.h:78
collection()
Definition collectioninlines.h:9
comparator * getComparator()
Definition collectioninlines.h:48
virtual bool isSequentialAccess()
Definition collectioninlines.h:83
virtual bool isBlockBased()
Definition collectioninlines.h:73
Definition comparator.h:11
Definition object.h:10
Definition output.h:11
virtual ssize_t printf(const char *format,...)
Definition outputinlines.h:25
virtual ssize_t write(const byte_t *string, size_t size)=0
static bool isNumber(const wchar_t *val)