arduino_ci 0.1.20 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +21 -19
  3. data/REFERENCE.md +625 -0
  4. data/cpp/arduino/Arduino.h +1 -2
  5. data/cpp/arduino/AvrMath.h +117 -17
  6. data/cpp/arduino/Client.h +26 -0
  7. data/cpp/arduino/EEPROM.h +64 -0
  8. data/cpp/arduino/Godmode.cpp +38 -19
  9. data/cpp/arduino/Godmode.h +88 -22
  10. data/cpp/arduino/HardwareSerial.h +9 -28
  11. data/cpp/arduino/IPAddress.h +59 -0
  12. data/cpp/arduino/MockEventQueue.h +86 -0
  13. data/cpp/arduino/PinHistory.h +64 -24
  14. data/cpp/arduino/Print.h +9 -12
  15. data/cpp/arduino/Printable.h +8 -0
  16. data/cpp/arduino/SPI.h +11 -3
  17. data/cpp/arduino/Server.h +5 -0
  18. data/cpp/arduino/Udp.h +27 -0
  19. data/cpp/arduino/Wire.h +234 -0
  20. data/cpp/arduino/avr/io.h +10 -1
  21. data/cpp/arduino/avr/pgmspace.h +76 -46
  22. data/cpp/arduino/ci/StreamTape.h +36 -0
  23. data/cpp/unittest/ArduinoUnitTests.h +1 -0
  24. data/cpp/unittest/Compare.h +91 -897
  25. data/cpp/unittest/OstreamHelpers.h +9 -0
  26. data/exe/arduino_ci.rb +401 -0
  27. data/exe/arduino_ci_remote.rb +2 -385
  28. data/lib/arduino_ci.rb +1 -0
  29. data/lib/arduino_ci/arduino_cmd.rb +13 -9
  30. data/lib/arduino_ci/arduino_downloader.rb +5 -4
  31. data/lib/arduino_ci/arduino_installation.rb +5 -5
  32. data/lib/arduino_ci/ci_config.rb +12 -0
  33. data/lib/arduino_ci/cpp_library.rb +152 -25
  34. data/lib/arduino_ci/installed_cpp_library.rb +0 -0
  35. data/lib/arduino_ci/library_properties.rb +86 -0
  36. data/lib/arduino_ci/version.rb +1 -1
  37. data/misc/default.yml +50 -3
  38. metadata +23 -13
  39. data/cpp/arduino/Arduino.h.orig +0 -143
  40. data/cpp/arduino/Nullptr.h +0 -7
  41. data/cpp/arduino/ci/Queue.h +0 -73
  42. data/exe/libasan.rb +0 -29
@@ -0,0 +1,36 @@
1
+ #pragma once
2
+
3
+ #include "../Stream.h"
4
+
5
+ /**
6
+ * Stream with godmode-controlled input and godmode-persisted output
7
+ */
8
+ class StreamTape : public Stream, public ObservableDataStream
9
+ {
10
+ protected:
11
+ String* mGodmodeDataOut;
12
+ // mGodmodeDataIn is provided by Stream
13
+
14
+ public:
15
+ StreamTape(String* dataIn, String* dataOut, unsigned long* delay): Stream(), ObservableDataStream() {
16
+ mGodmodeDataIn = dataIn;
17
+ mGodmodeDataOut = dataOut;
18
+ mGodmodeMicrosDelay = delay;
19
+ }
20
+
21
+ // virtual int available(void);
22
+ // virtual int peek(void);
23
+ // virtual int read(void);
24
+ // virtual int availableForWrite(void);
25
+ // virtual void flush(void);
26
+ virtual size_t write(uint8_t aChar) {
27
+ mGodmodeDataOut->append(String((char)aChar));
28
+ advertiseByte((unsigned char)aChar);
29
+ return 1;
30
+ }
31
+
32
+ // https://stackoverflow.com/a/4271276
33
+ using Print::write; // pull in write(str) and write(buf, size) from Print
34
+
35
+ };
36
+
@@ -1,5 +1,6 @@
1
1
  #pragma once
2
2
 
3
+ #include "OstreamHelpers.h"
3
4
  #include "Assertion.h"
4
5
  #include <iostream>
5
6
  using namespace std;
@@ -1,7 +1,6 @@
1
1
  #pragma once
2
2
  #include <avr/pgmspace.h>
3
3
  #include <WString.h>
4
- #include <Nullptr.h>
5
4
 
6
5
  template < typename A, typename B > struct Compare
7
6
  {
@@ -10,909 +9,104 @@ template < typename A, typename B > struct Compare
10
9
  if (a<b) return -1;
11
10
  if (b<a) return 1;
12
11
  return 0;
13
- } // between
14
- inline static bool equal(const A &a,const B &b)
15
- {
16
- return (!(a<b)) && (!(b<a));
17
- } // equal
18
- inline static bool notEqual(const A &a,const B &b)
19
- {
20
- return (a<b) || (b<a);
21
- } // notEqual
22
- inline static bool less(const A &a,const B &b)
23
- {
24
- return a<b;
25
- } // less
26
- inline static bool more(const A &a,const B &b)
27
- {
28
- return b<a;
29
- } // more
30
- inline static bool lessOrEqual(const A &a,const B &b)
31
- {
32
- return !(b<a);
33
- } // lessOrEqual
34
- inline static bool moreOrEqual(const A &a,const B &b)
35
- {
36
- return !(a<b);
37
- } // moreOrEqual
38
- };
39
- template < > struct Compare<String,String>;
40
- template < > struct Compare<String,const char *>;
41
- #if defined(F)
42
- template < > struct Compare<String,const __FlashStringHelper *>;
43
- #endif
44
- template < > struct Compare<String,char *>;
45
- template < size_t M > struct Compare<String,char [M]>;
46
- template < > struct Compare<const char *,String>;
47
- template < > struct Compare<const char *,const char *>;
48
- #if defined(F)
49
- template < > struct Compare<const char *,const __FlashStringHelper *>;
50
- #endif
51
- template < > struct Compare<const char *,char *>;
52
- template < size_t M > struct Compare<const char *,char [M]>;
53
- #if defined(F)
54
- template < > struct Compare<const __FlashStringHelper *,String>;
55
- #endif
56
- #if defined(F)
57
- template < > struct Compare<const __FlashStringHelper *,const char *>;
58
- #endif
59
- #if defined(F)
60
- template < > struct Compare<const __FlashStringHelper *,const __FlashStringHelper *>;
61
- #endif
62
- #if defined(F)
63
- template < > struct Compare<const __FlashStringHelper *,char *>;
64
- #endif
65
- #if defined(F)
66
- template < size_t M > struct Compare<const __FlashStringHelper *,char [M]>;
67
- #endif
68
- template < > struct Compare<char *,String>;
69
- template < > struct Compare<char *,const char *>;
70
- #if defined(F)
71
- template < > struct Compare<char *,const __FlashStringHelper *>;
72
- #endif
73
- template < > struct Compare<char *,char *>;
74
- template < size_t M > struct Compare<char *,char [M]>;
75
- template < size_t N > struct Compare<char [N],String>;
76
- template < size_t N > struct Compare<char [N],const char *>;
77
- #if defined(F)
78
- template < size_t N > struct Compare<char [N],const __FlashStringHelper *>;
79
- #endif
80
- template < size_t N > struct Compare<char [N],char *>;
81
- template < size_t N, size_t M > struct Compare<char [N],char [M]>;
82
- template < > struct Compare<String,String>
83
- {
84
- inline static int between(const String &a,const String &b)
85
- {
86
- return a.compareTo(b);
87
- } // between
88
- inline static bool equal(const String &a,const String &b)
89
- {
90
- return between(a,b) == 0;
91
- } // equal
92
- inline static bool notEqual(const String &a,const String &b)
93
- {
94
- return between(a,b) != 0;
95
- } // notEqual
96
- inline static bool less(const String &a,const String &b)
97
- {
98
- return between(a,b) < 0;
99
- } // less
100
- inline static bool more(const String &a,const String &b)
101
- {
102
- return between(a,b) > 0;
103
- } // more
104
- inline static bool lessOrEqual(const String &a,const String &b)
105
- {
106
- return between(a,b) <= 0;
107
- } // lessOrEqual
108
- inline static bool moreOrEqual(const String &a,const String &b)
109
- {
110
- return between(a,b) >= 0;
111
- } // moreOrEqual
112
- };
113
- template < > struct Compare<String,const char *>
114
- {
115
- inline static int between(const String &a,const char * const &b)
116
- {
117
- return a.compareTo(b);
118
- } // between
119
- inline static bool equal(const String &a,const char * const &b)
120
- {
121
- return between(a,b) == 0;
122
- } // equal
123
- inline static bool notEqual(const String &a,const char * const &b)
124
- {
125
- return between(a,b) != 0;
126
- } // notEqual
127
- inline static bool less(const String &a,const char * const &b)
128
- {
129
- return between(a,b) < 0;
130
- } // less
131
- inline static bool more(const String &a,const char * const &b)
132
- {
133
- return between(a,b) > 0;
134
- } // more
135
- inline static bool lessOrEqual(const String &a,const char * const &b)
136
- {
137
- return between(a,b) <= 0;
138
- } // lessOrEqual
139
- inline static bool moreOrEqual(const String &a,const char * const &b)
140
- {
141
- return between(a,b) >= 0;
142
- } // moreOrEqual
12
+ }
13
+ inline static bool equal(const A &a,const B &b) { return (!(a < b)) && (!(b < a)); }
14
+ inline static bool notEqual(const A &a,const B &b) { return (a<b) || (b<a); }
15
+ inline static bool less(const A &a,const B &b) { return a<b; }
16
+ inline static bool more(const A &a,const B &b) { return b<a; }
17
+ inline static bool lessOrEqual(const A &a,const B &b) { return !(b<a); }
18
+ inline static bool moreOrEqual(const A &a,const B &b) { return !(a<b); }
143
19
  };
144
- #if defined(F)
145
- template < > struct Compare<String,const __FlashStringHelper *>
20
+
21
+ // helpers for macros
22
+ inline static int arduinoCICompareBetween(const String &a,const __FlashStringHelper * const &b)
146
23
  {
147
- inline static int between(const String &a,const __FlashStringHelper * const &b)
148
- {
149
- uint8_t a_buf[4],b_buf[4];
150
- uint16_t i=0;
24
+ uint8_t a_buf[4],b_buf[4];
25
+ uint16_t i=0;
151
26
 
152
- for (;;) {
153
- uint8_t j=(i%4);
154
- if (j == 0) {
155
- a.getBytes(a_buf,4,i);
156
- memcpy_P(b_buf,((const char *)b)+i,4);
157
- }
158
- if (a_buf[j] < b_buf[j]) return -1;
159
- if (a_buf[j] > b_buf[j]) return 1;
160
- if (a_buf[j] == 0) return 0;
161
- ++i;
27
+ for (;;) {
28
+ uint8_t j=(i%4);
29
+ if (j == 0) {
30
+ a.getBytes(a_buf,4,i);
31
+ memcpy_P(b_buf,((const char *)b)+i,4);
162
32
  }
163
- } // between
164
- inline static bool equal(const String &a,const __FlashStringHelper * const &b)
165
- {
166
- return between(a,b) == 0;
167
- } // equal
168
- inline static bool notEqual(const String &a,const __FlashStringHelper * const &b)
169
- {
170
- return between(a,b) != 0;
171
- } // notEqual
172
- inline static bool less(const String &a,const __FlashStringHelper * const &b)
173
- {
174
- return between(a,b) < 0;
175
- } // less
176
- inline static bool more(const String &a,const __FlashStringHelper * const &b)
177
- {
178
- return between(a,b) > 0;
179
- } // more
180
- inline static bool lessOrEqual(const String &a,const __FlashStringHelper * const &b)
181
- {
182
- return between(a,b) <= 0;
183
- } // lessOrEqual
184
- inline static bool moreOrEqual(const String &a,const __FlashStringHelper * const &b)
185
- {
186
- return between(a,b) >= 0;
187
- } // moreOrEqual
188
- };
189
- #endif
190
- template < > struct Compare<String,char *>
191
- {
192
- inline static int between(const String &a,char * const &b)
193
- {
194
- return a.compareTo(b);
195
- } // between
196
- inline static bool equal(const String &a,char * const &b)
197
- {
198
- return between(a,b) == 0;
199
- } // equal
200
- inline static bool notEqual(const String &a,char * const &b)
201
- {
202
- return between(a,b) != 0;
203
- } // notEqual
204
- inline static bool less(const String &a,char * const &b)
205
- {
206
- return between(a,b) < 0;
207
- } // less
208
- inline static bool more(const String &a,char * const &b)
209
- {
210
- return between(a,b) > 0;
211
- } // more
212
- inline static bool lessOrEqual(const String &a,char * const &b)
213
- {
214
- return between(a,b) <= 0;
215
- } // lessOrEqual
216
- inline static bool moreOrEqual(const String &a,char * const &b)
217
- {
218
- return between(a,b) >= 0;
219
- } // moreOrEqual
220
- };
221
- template < size_t M > struct Compare<String,char [M]>
222
- {
223
- inline static int between(const String &a,const char (&b)[M])
224
- {
225
- return a.compareTo(b);
226
- } // between
227
- inline static bool equal(const String &a,const char (&b)[M])
228
- {
229
- return between(a,b) == 0;
230
- } // equal
231
- inline static bool notEqual(const String &a,const char (&b)[M])
232
- {
233
- return between(a,b) != 0;
234
- } // notEqual
235
- inline static bool less(const String &a,const char (&b)[M])
236
- {
237
- return between(a,b) < 0;
238
- } // less
239
- inline static bool more(const String &a,const char (&b)[M])
240
- {
241
- return between(a,b) > 0;
242
- } // more
243
- inline static bool lessOrEqual(const String &a,const char (&b)[M])
244
- {
245
- return between(a,b) <= 0;
246
- } // lessOrEqual
247
- inline static bool moreOrEqual(const String &a,const char (&b)[M])
248
- {
249
- return between(a,b) >= 0;
250
- } // moreOrEqual
251
- };
252
- template < > struct Compare<const char *,String>
253
- {
254
- inline static int between(const char * const &a,const String &b)
255
- {
256
- return -b.compareTo(a);
257
- } // between
258
- inline static bool equal(const char * const &a,const String &b)
259
- {
260
- return between(a,b) == 0;
261
- } // equal
262
- inline static bool notEqual(const char * const &a,const String &b)
263
- {
264
- return between(a,b) != 0;
265
- } // notEqual
266
- inline static bool less(const char * const &a,const String &b)
267
- {
268
- return between(a,b) < 0;
269
- } // less
270
- inline static bool more(const char * const &a,const String &b)
271
- {
272
- return between(a,b) > 0;
273
- } // more
274
- inline static bool lessOrEqual(const char * const &a,const String &b)
275
- {
276
- return between(a,b) <= 0;
277
- } // lessOrEqual
278
- inline static bool moreOrEqual(const char * const &a,const String &b)
279
- {
280
- return between(a,b) >= 0;
281
- } // moreOrEqual
282
- };
283
- template < > struct Compare<const char *,const char *>
284
- {
285
- inline static int between(const char * const &a,const char * const &b)
286
- {
287
- return strcmp(a,b);
288
- } // between
289
- inline static bool equal(const char * const &a,const char * const &b)
290
- {
291
- return between(a,b) == 0;
292
- } // equal
293
- inline static bool notEqual(const char * const &a,const char * const &b)
294
- {
295
- return between(a,b) != 0;
296
- } // notEqual
297
- inline static bool less(const char * const &a,const char * const &b)
298
- {
299
- return between(a,b) < 0;
300
- } // less
301
- inline static bool more(const char * const &a,const char * const &b)
302
- {
303
- return between(a,b) > 0;
304
- } // more
305
- inline static bool lessOrEqual(const char * const &a,const char * const &b)
306
- {
307
- return between(a,b) <= 0;
308
- } // lessOrEqual
309
- inline static bool moreOrEqual(const char * const &a,const char * const &b)
310
- {
311
- return between(a,b) >= 0;
312
- } // moreOrEqual
313
- };
314
- #if defined(F)
315
- template < > struct Compare<const char *,const __FlashStringHelper *>
316
- {
317
- inline static int between(const char * const &a,const __FlashStringHelper * const &b)
318
- {
319
- return strcmp_P(a,(const char *)b);
320
- } // between
321
- inline static bool equal(const char * const &a,const __FlashStringHelper * const &b)
322
- {
323
- return between(a,b) == 0;
324
- } // equal
325
- inline static bool notEqual(const char * const &a,const __FlashStringHelper * const &b)
326
- {
327
- return between(a,b) != 0;
328
- } // notEqual
329
- inline static bool less(const char * const &a,const __FlashStringHelper * const &b)
330
- {
331
- return between(a,b) < 0;
332
- } // less
333
- inline static bool more(const char * const &a,const __FlashStringHelper * const &b)
334
- {
335
- return between(a,b) > 0;
336
- } // more
337
- inline static bool lessOrEqual(const char * const &a,const __FlashStringHelper * const &b)
338
- {
339
- return between(a,b) <= 0;
340
- } // lessOrEqual
341
- inline static bool moreOrEqual(const char * const &a,const __FlashStringHelper * const &b)
342
- {
343
- return between(a,b) >= 0;
344
- } // moreOrEqual
345
- };
346
- #endif
347
- template < > struct Compare<const char *,char *>
348
- {
349
- inline static int between(const char * const &a,char * const &b)
350
- {
351
- return strcmp(a,b);
352
- } // between
353
- inline static bool equal(const char * const &a,char * const &b)
354
- {
355
- return between(a,b) == 0;
356
- } // equal
357
- inline static bool notEqual(const char * const &a,char * const &b)
358
- {
359
- return between(a,b) != 0;
360
- } // notEqual
361
- inline static bool less(const char * const &a,char * const &b)
362
- {
363
- return between(a,b) < 0;
364
- } // less
365
- inline static bool more(const char * const &a,char * const &b)
366
- {
367
- return between(a,b) > 0;
368
- } // more
369
- inline static bool lessOrEqual(const char * const &a,char * const &b)
370
- {
371
- return between(a,b) <= 0;
372
- } // lessOrEqual
373
- inline static bool moreOrEqual(const char * const &a,char * const &b)
374
- {
375
- return between(a,b) >= 0;
376
- } // moreOrEqual
377
- };
378
- template < size_t M > struct Compare<const char *,char [M]>
379
- {
380
- inline static int between(const char * const &a,const char (&b)[M])
381
- {
382
- return strcmp(a,b);
383
- } // between
384
- inline static bool equal(const char * const &a,const char (&b)[M])
385
- {
386
- return between(a,b) == 0;
387
- } // equal
388
- inline static bool notEqual(const char * const &a,const char (&b)[M])
389
- {
390
- return between(a,b) != 0;
391
- } // notEqual
392
- inline static bool less(const char * const &a,const char (&b)[M])
393
- {
394
- return between(a,b) < 0;
395
- } // less
396
- inline static bool more(const char * const &a,const char (&b)[M])
397
- {
398
- return between(a,b) > 0;
399
- } // more
400
- inline static bool lessOrEqual(const char * const &a,const char (&b)[M])
401
- {
402
- return between(a,b) <= 0;
403
- } // lessOrEqual
404
- inline static bool moreOrEqual(const char * const &a,const char (&b)[M])
405
- {
406
- return between(a,b) >= 0;
407
- } // moreOrEqual
408
- };
409
- #if defined(F)
410
- template < > struct Compare<const __FlashStringHelper *,String>
411
- {
412
- inline static int between(const __FlashStringHelper * const &a,const String &b)
413
- {
414
- return -Compare < String,const __FlashStringHelper * >::between(b,a);
415
- } // between
416
- inline static bool equal(const __FlashStringHelper * const &a,const String &b)
417
- {
418
- return between(a,b) == 0;
419
- } // equal
420
- inline static bool notEqual(const __FlashStringHelper * const &a,const String &b)
421
- {
422
- return between(a,b) != 0;
423
- } // notEqual
424
- inline static bool less(const __FlashStringHelper * const &a,const String &b)
425
- {
426
- return between(a,b) < 0;
427
- } // less
428
- inline static bool more(const __FlashStringHelper * const &a,const String &b)
429
- {
430
- return between(a,b) > 0;
431
- } // more
432
- inline static bool lessOrEqual(const __FlashStringHelper * const &a,const String &b)
433
- {
434
- return between(a,b) <= 0;
435
- } // lessOrEqual
436
- inline static bool moreOrEqual(const __FlashStringHelper * const &a,const String &b)
437
- {
438
- return between(a,b) >= 0;
439
- } // moreOrEqual
440
- };
441
- #endif
442
- #if defined(F)
443
- template < > struct Compare<const __FlashStringHelper *,const char *>
444
- {
445
- inline static int between(const __FlashStringHelper * const &a,const char * const &b)
446
- {
447
- return -strcmp_P(b,(const char *)a);
448
- } // between
449
- inline static bool equal(const __FlashStringHelper * const &a,const char * const &b)
450
- {
451
- return between(a,b) == 0;
452
- } // equal
453
- inline static bool notEqual(const __FlashStringHelper * const &a,const char * const &b)
454
- {
455
- return between(a,b) != 0;
456
- } // notEqual
457
- inline static bool less(const __FlashStringHelper * const &a,const char * const &b)
458
- {
459
- return between(a,b) < 0;
460
- } // less
461
- inline static bool more(const __FlashStringHelper * const &a,const char * const &b)
462
- {
463
- return between(a,b) > 0;
464
- } // more
465
- inline static bool lessOrEqual(const __FlashStringHelper * const &a,const char * const &b)
466
- {
467
- return between(a,b) <= 0;
468
- } // lessOrEqual
469
- inline static bool moreOrEqual(const __FlashStringHelper * const &a,const char * const &b)
470
- {
471
- return between(a,b) >= 0;
472
- } // moreOrEqual
473
- };
474
- #endif
475
- #if defined(F)
476
- template < > struct Compare<const __FlashStringHelper *,const __FlashStringHelper *>
33
+ if (a_buf[j] < b_buf[j]) return -1;
34
+ if (a_buf[j] > b_buf[j]) return 1;
35
+ if (a_buf[j] == 0) return 0;
36
+ ++i;
37
+ }
38
+ }
39
+
40
+ inline static int arduinoCICompareBetween(const __FlashStringHelper * const &a,const __FlashStringHelper * const &b)
477
41
  {
478
- inline static int between(const __FlashStringHelper * const &a,const __FlashStringHelper * const &b)
479
- {
480
- uint8_t a_buf[4],b_buf[4];
481
- uint16_t i=0;
42
+ uint8_t a_buf[4],b_buf[4];
43
+ uint16_t i=0;
482
44
 
483
- for (;;) {
484
- uint8_t j=(i%4);
485
- if (j == 0) {
486
- memcpy_P(a_buf,((const char *)a)+i,4);
487
- memcpy_P(b_buf,((const char *)b)+i,4);
488
- }
489
- if (a_buf[j] < b_buf[j]) return -1;
490
- if (a_buf[j] > b_buf[j]) return 1;
491
- if (a_buf[j] == 0) return 0;
492
- ++i;
45
+ for (;;) {
46
+ uint8_t j=(i%4);
47
+ if (j == 0) {
48
+ memcpy_P(a_buf,((const char *)a)+i,4);
49
+ memcpy_P(b_buf,((const char *)b)+i,4);
493
50
  }
494
- } // between
495
- inline static bool equal(const __FlashStringHelper * const &a,const __FlashStringHelper * const &b)
496
- {
497
- return between(a,b) == 0;
498
- } // equal
499
- inline static bool notEqual(const __FlashStringHelper * const &a,const __FlashStringHelper * const &b)
500
- {
501
- return between(a,b) != 0;
502
- } // notEqual
503
- inline static bool less(const __FlashStringHelper * const &a,const __FlashStringHelper * const &b)
504
- {
505
- return between(a,b) < 0;
506
- } // less
507
- inline static bool more(const __FlashStringHelper * const &a,const __FlashStringHelper * const &b)
508
- {
509
- return between(a,b) > 0;
510
- } // more
511
- inline static bool lessOrEqual(const __FlashStringHelper * const &a,const __FlashStringHelper * const &b)
512
- {
513
- return between(a,b) <= 0;
514
- } // lessOrEqual
515
- inline static bool moreOrEqual(const __FlashStringHelper * const &a,const __FlashStringHelper * const &b)
516
- {
517
- return between(a,b) >= 0;
518
- } // moreOrEqual
519
- };
520
- #endif
521
- #if defined(F)
522
- template < > struct Compare<const __FlashStringHelper *,char *>
523
- {
524
- inline static int between(const __FlashStringHelper * const &a,char * const &b)
525
- {
526
- return -strcmp_P(b,(const char *)a);
527
- } // between
528
- inline static bool equal(const __FlashStringHelper * const &a,char * const &b)
529
- {
530
- return between(a,b) == 0;
531
- } // equal
532
- inline static bool notEqual(const __FlashStringHelper * const &a,char * const &b)
533
- {
534
- return between(a,b) != 0;
535
- } // notEqual
536
- inline static bool less(const __FlashStringHelper * const &a,char * const &b)
537
- {
538
- return between(a,b) < 0;
539
- } // less
540
- inline static bool more(const __FlashStringHelper * const &a,char * const &b)
541
- {
542
- return between(a,b) > 0;
543
- } // more
544
- inline static bool lessOrEqual(const __FlashStringHelper * const &a,char * const &b)
545
- {
546
- return between(a,b) <= 0;
547
- } // lessOrEqual
548
- inline static bool moreOrEqual(const __FlashStringHelper * const &a,char * const &b)
549
- {
550
- return between(a,b) >= 0;
551
- } // moreOrEqual
552
- };
553
- #endif
554
- #if defined(F)
555
- template < size_t M > struct Compare<const __FlashStringHelper *,char [M]>
556
- {
557
- inline static int between(const __FlashStringHelper * const &a,const char (&b)[M])
558
- {
559
- return -strcmp_P(b,(const char *)a);
560
- } // between
561
- inline static bool equal(const __FlashStringHelper * const &a,const char (&b)[M])
562
- {
563
- return between(a,b) == 0;
564
- } // equal
565
- inline static bool notEqual(const __FlashStringHelper * const &a,const char (&b)[M])
566
- {
567
- return between(a,b) != 0;
568
- } // notEqual
569
- inline static bool less(const __FlashStringHelper * const &a,const char (&b)[M])
570
- {
571
- return between(a,b) < 0;
572
- } // less
573
- inline static bool more(const __FlashStringHelper * const &a,const char (&b)[M])
574
- {
575
- return between(a,b) > 0;
576
- } // more
577
- inline static bool lessOrEqual(const __FlashStringHelper * const &a,const char (&b)[M])
578
- {
579
- return between(a,b) <= 0;
580
- } // lessOrEqual
581
- inline static bool moreOrEqual(const __FlashStringHelper * const &a,const char (&b)[M])
582
- {
583
- return between(a,b) >= 0;
584
- } // moreOrEqual
585
- };
586
- #endif
587
- template < > struct Compare<char *,String>
588
- {
589
- inline static int between(char * const &a,const String &b)
590
- {
591
- return -b.compareTo(a);
592
- } // between
593
- inline static bool equal(char * const &a,const String &b)
594
- {
595
- return between(a,b) == 0;
596
- } // equal
597
- inline static bool notEqual(char * const &a,const String &b)
598
- {
599
- return between(a,b) != 0;
600
- } // notEqual
601
- inline static bool less(char * const &a,const String &b)
602
- {
603
- return between(a,b) < 0;
604
- } // less
605
- inline static bool more(char * const &a,const String &b)
606
- {
607
- return between(a,b) > 0;
608
- } // more
609
- inline static bool lessOrEqual(char * const &a,const String &b)
610
- {
611
- return between(a,b) <= 0;
612
- } // lessOrEqual
613
- inline static bool moreOrEqual(char * const &a,const String &b)
614
- {
615
- return between(a,b) >= 0;
616
- } // moreOrEqual
617
- };
618
- template < > struct Compare<char *,const char *>
619
- {
620
- inline static int between(char * const &a,const char * const &b)
621
- {
622
- return strcmp(a,b);
623
- } // between
624
- inline static bool equal(char * const &a,const char * const &b)
625
- {
626
- return between(a,b) == 0;
627
- } // equal
628
- inline static bool notEqual(char * const &a,const char * const &b)
629
- {
630
- return between(a,b) != 0;
631
- } // notEqual
632
- inline static bool less(char * const &a,const char * const &b)
633
- {
634
- return between(a,b) < 0;
635
- } // less
636
- inline static bool more(char * const &a,const char * const &b)
637
- {
638
- return between(a,b) > 0;
639
- } // more
640
- inline static bool lessOrEqual(char * const &a,const char * const &b)
641
- {
642
- return between(a,b) <= 0;
643
- } // lessOrEqual
644
- inline static bool moreOrEqual(char * const &a,const char * const &b)
645
- {
646
- return between(a,b) >= 0;
647
- } // moreOrEqual
648
- };
649
- #if defined(F)
650
- template < > struct Compare<char *,const __FlashStringHelper *>
651
- {
652
- inline static int between(char * const &a,const __FlashStringHelper * const &b)
653
- {
654
- return strcmp_P(a,(const char *)b);
655
- } // between
656
- inline static bool equal(char * const &a,const __FlashStringHelper * const &b)
657
- {
658
- return between(a,b) == 0;
659
- } // equal
660
- inline static bool notEqual(char * const &a,const __FlashStringHelper * const &b)
661
- {
662
- return between(a,b) != 0;
663
- } // notEqual
664
- inline static bool less(char * const &a,const __FlashStringHelper * const &b)
665
- {
666
- return between(a,b) < 0;
667
- } // less
668
- inline static bool more(char * const &a,const __FlashStringHelper * const &b)
669
- {
670
- return between(a,b) > 0;
671
- } // more
672
- inline static bool lessOrEqual(char * const &a,const __FlashStringHelper * const &b)
673
- {
674
- return between(a,b) <= 0;
675
- } // lessOrEqual
676
- inline static bool moreOrEqual(char * const &a,const __FlashStringHelper * const &b)
677
- {
678
- return between(a,b) >= 0;
679
- } // moreOrEqual
680
- };
681
- #endif
682
- template < > struct Compare<char *,char *>
683
- {
684
- inline static int between(char * const &a,char * const &b)
685
- {
686
- return strcmp(a,b);
687
- } // between
688
- inline static bool equal(char * const &a,char * const &b)
689
- {
690
- return between(a,b) == 0;
691
- } // equal
692
- inline static bool notEqual(char * const &a,char * const &b)
693
- {
694
- return between(a,b) != 0;
695
- } // notEqual
696
- inline static bool less(char * const &a,char * const &b)
697
- {
698
- return between(a,b) < 0;
699
- } // less
700
- inline static bool more(char * const &a,char * const &b)
701
- {
702
- return between(a,b) > 0;
703
- } // more
704
- inline static bool lessOrEqual(char * const &a,char * const &b)
705
- {
706
- return between(a,b) <= 0;
707
- } // lessOrEqual
708
- inline static bool moreOrEqual(char * const &a,char * const &b)
709
- {
710
- return between(a,b) >= 0;
711
- } // moreOrEqual
712
- };
713
- template < size_t M > struct Compare<char *,char [M]>
714
- {
715
- inline static int between(char * const &a,const char (&b)[M])
716
- {
717
- return strcmp(a,b);
718
- } // between
719
- inline static bool equal(char * const &a,const char (&b)[M])
720
- {
721
- return between(a,b) == 0;
722
- } // equal
723
- inline static bool notEqual(char * const &a,const char (&b)[M])
724
- {
725
- return between(a,b) != 0;
726
- } // notEqual
727
- inline static bool less(char * const &a,const char (&b)[M])
728
- {
729
- return between(a,b) < 0;
730
- } // less
731
- inline static bool more(char * const &a,const char (&b)[M])
732
- {
733
- return between(a,b) > 0;
734
- } // more
735
- inline static bool lessOrEqual(char * const &a,const char (&b)[M])
736
- {
737
- return between(a,b) <= 0;
738
- } // lessOrEqual
739
- inline static bool moreOrEqual(char * const &a,const char (&b)[M])
740
- {
741
- return between(a,b) >= 0;
742
- } // moreOrEqual
743
- };
744
- template < size_t N > struct Compare<char [N],String>
745
- {
746
- inline static int between(const char (&a)[N],const String &b)
747
- {
748
- return -b.compareTo(a);
749
- } // between
750
- inline static bool equal(const char (&a)[N],const String &b)
751
- {
752
- return between(a,b) == 0;
753
- } // equal
754
- inline static bool notEqual(const char (&a)[N],const String &b)
755
- {
756
- return between(a,b) != 0;
757
- } // notEqual
758
- inline static bool less(const char (&a)[N],const String &b)
759
- {
760
- return between(a,b) < 0;
761
- } // less
762
- inline static bool more(const char (&a)[N],const String &b)
763
- {
764
- return between(a,b) > 0;
765
- } // more
766
- inline static bool lessOrEqual(const char (&a)[N],const String &b)
767
- {
768
- return between(a,b) <= 0;
769
- } // lessOrEqual
770
- inline static bool moreOrEqual(const char (&a)[N],const String &b)
771
- {
772
- return between(a,b) >= 0;
773
- } // moreOrEqual
774
- };
775
- template < size_t N > struct Compare<char [N],const char *>
776
- {
777
- inline static int between(const char (&a)[N],const char * const &b)
778
- {
779
- return strcmp(a,b);
780
- } // between
781
- inline static bool equal(const char (&a)[N],const char * const &b)
782
- {
783
- return between(a,b) == 0;
784
- } // equal
785
- inline static bool notEqual(const char (&a)[N],const char * const &b)
786
- {
787
- return between(a,b) != 0;
788
- } // notEqual
789
- inline static bool less(const char (&a)[N],const char * const &b)
790
- {
791
- return between(a,b) < 0;
792
- } // less
793
- inline static bool more(const char (&a)[N],const char * const &b)
794
- {
795
- return between(a,b) > 0;
796
- } // more
797
- inline static bool lessOrEqual(const char (&a)[N],const char * const &b)
798
- {
799
- return between(a,b) <= 0;
800
- } // lessOrEqual
801
- inline static bool moreOrEqual(const char (&a)[N],const char * const &b)
802
- {
803
- return between(a,b) >= 0;
804
- } // moreOrEqual
805
- };
806
- #if defined(F)
807
- template < size_t N > struct Compare<char [N],const __FlashStringHelper *>
808
- {
809
- inline static int between(const char (&a)[N],const __FlashStringHelper * const &b)
810
- {
811
- return strcmp_P(a,(const char *)b);
812
- } // between
813
- inline static bool equal(const char (&a)[N],const __FlashStringHelper * const &b)
814
- {
815
- return between(a,b) == 0;
816
- } // equal
817
- inline static bool notEqual(const char (&a)[N],const __FlashStringHelper * const &b)
818
- {
819
- return between(a,b) != 0;
820
- } // notEqual
821
- inline static bool less(const char (&a)[N],const __FlashStringHelper * const &b)
822
- {
823
- return between(a,b) < 0;
824
- } // less
825
- inline static bool more(const char (&a)[N],const __FlashStringHelper * const &b)
826
- {
827
- return between(a,b) > 0;
828
- } // more
829
- inline static bool lessOrEqual(const char (&a)[N],const __FlashStringHelper * const &b)
830
- {
831
- return between(a,b) <= 0;
832
- } // lessOrEqual
833
- inline static bool moreOrEqual(const char (&a)[N],const __FlashStringHelper * const &b)
834
- {
835
- return between(a,b) >= 0;
836
- } // moreOrEqual
837
- };
838
- #endif
839
- template < size_t N > struct Compare<char [N],char *>
840
- {
841
- inline static int between(const char (&a)[N],char * const &b)
842
- {
843
- return strcmp(a,b);
844
- } // between
845
- inline static bool equal(const char (&a)[N],char * const &b)
846
- {
847
- return between(a,b) == 0;
848
- } // equal
849
- inline static bool notEqual(const char (&a)[N],char * const &b)
850
- {
851
- return between(a,b) != 0;
852
- } // notEqual
853
- inline static bool less(const char (&a)[N],char * const &b)
854
- {
855
- return between(a,b) < 0;
856
- } // less
857
- inline static bool more(const char (&a)[N],char * const &b)
858
- {
859
- return between(a,b) > 0;
860
- } // more
861
- inline static bool lessOrEqual(const char (&a)[N],char * const &b)
862
- {
863
- return between(a,b) <= 0;
864
- } // lessOrEqual
865
- inline static bool moreOrEqual(const char (&a)[N],char * const &b)
866
- {
867
- return between(a,b) >= 0;
868
- } // moreOrEqual
869
- };
870
- template < size_t N, size_t M > struct Compare<char [N],char [M]>
871
- {
872
- inline static int between(const char (&a)[N],const char (&b)[M])
873
- {
874
- return strcmp(a,b);
875
- } // between
876
- inline static bool equal(const char (&a)[N],const char (&b)[M])
877
- {
878
- return between(a,b) == 0;
879
- } // equal
880
- inline static bool notEqual(const char (&a)[N],const char (&b)[M])
881
- {
882
- return between(a,b) != 0;
883
- } // notEqual
884
- inline static bool less(const char (&a)[N],const char (&b)[M])
885
- {
886
- return between(a,b) < 0;
887
- } // less
888
- inline static bool more(const char (&a)[N],const char (&b)[M])
889
- {
890
- return between(a,b) > 0;
891
- } // more
892
- inline static bool lessOrEqual(const char (&a)[N],const char (&b)[M])
893
- {
894
- return between(a,b) <= 0;
895
- } // lessOrEqual
896
- inline static bool moreOrEqual(const char (&a)[N],const char (&b)[M])
897
- {
898
- return between(a,b) >= 0;
899
- } // moreOrEqual
900
- };
51
+ if (a_buf[j] < b_buf[j]) return -1;
52
+ if (a_buf[j] > b_buf[j]) return 1;
53
+ if (a_buf[j] == 0) return 0;
54
+ ++i;
55
+ }
56
+ }
57
+
58
+
59
+ // this macro works for all the string-based comparisons
60
+ // but just in case, https://stackoverflow.com/a/13842784/2063546
61
+ #define comparisonTemplateMacro(T1, T1m, T2, T2m, betweenImpl, ...) \
62
+ template < __VA_ARGS__ > struct Compare<T1 T1m, T2 T2m>; \
63
+ template < __VA_ARGS__ > struct Compare<T1 T1m, T2 T2m> \
64
+ { \
65
+ inline static int between( T1 const (&a)T1m, T2 const (&b)T2m) { return betweenImpl; } \
66
+ inline static bool equal( T1 const (&a)T1m, T2 const (&b)T2m) { return between(a, b) == 0; } \
67
+ inline static bool notEqual( T1 const (&a)T1m, T2 const (&b)T2m) { return between(a, b) != 0; } \
68
+ inline static bool less( T1 const (&a)T1m, T2 const (&b)T2m) { return between(a, b) < 0; } \
69
+ inline static bool more( T1 const (&a)T1m, T2 const (&b)T2m) { return between(a, b) > 0; } \
70
+ inline static bool lessOrEqual(T1 const (&a)T1m, T2 const (&b)T2m) { return between(a, b) <= 0; } \
71
+ inline static bool moreOrEqual(T1 const (&a)T1m, T2 const (&b)T2m) { return between(a, b) >= 0; } \
72
+ };
73
+
74
+ comparisonTemplateMacro(String, , String, , a.compareTo(b))
75
+ comparisonTemplateMacro(String, , const char *, , a.compareTo(b))
76
+ #if defined(F)
77
+ comparisonTemplateMacro(String, , const __FlashStringHelper *, , arduinoCICompareBetween(a, b))
78
+ comparisonTemplateMacro(const char *,, const __FlashStringHelper *, , strcmp_P(a,(const char *)b))
79
+ comparisonTemplateMacro(const __FlashStringHelper *, , String, , -arduinoCICompareBetween(b, a))
80
+ comparisonTemplateMacro(const __FlashStringHelper *, , const char *, , -strcmp_P(b,(const char *)a))
81
+ comparisonTemplateMacro(const __FlashStringHelper *, , const __FlashStringHelper *, , arduinoCICompareBetween(a, b))
82
+ comparisonTemplateMacro(const __FlashStringHelper *, , char *, , -strcmp_P(b,(const char *)a))
83
+ comparisonTemplateMacro(char *, , const __FlashStringHelper *, , strcmp_P(a,(const char *)b))
84
+ comparisonTemplateMacro(const __FlashStringHelper *, , char, [M], -strcmp_P(b,(const char *)a), size_t M)
85
+ comparisonTemplateMacro(char, [N], const __FlashStringHelper *, , strcmp_P(a,(const char *)b), size_t N)
86
+ #endif
87
+ comparisonTemplateMacro(String, , char *, , a.compareTo(b))
88
+ comparisonTemplateMacro(const char *, , String, , -b.compareTo(a))
89
+ comparisonTemplateMacro(const char *, , const char *, , strcmp(a,b))
90
+ comparisonTemplateMacro(const char *, , char *, , strcmp(a,b))
91
+ comparisonTemplateMacro(char *, , String, , -b.compareTo(a))
92
+ comparisonTemplateMacro(char *, , const char *, , strcmp(a,b))
93
+ comparisonTemplateMacro(char *, , char *, , strcmp(a,b))
94
+ comparisonTemplateMacro(String, , char, [M], a.compareTo(b), size_t M)
95
+ comparisonTemplateMacro(const char *, , char, [M], strcmp(a,b), size_t M)
96
+ comparisonTemplateMacro(char *, , char, [M], strcmp(a,b), size_t M)
97
+ comparisonTemplateMacro(char, [N], String, , -b.compareTo(a), size_t N)
98
+ comparisonTemplateMacro(char, [N], const char *, , strcmp(a,b), size_t N)
99
+ comparisonTemplateMacro(char, [N], char *, , strcmp(a,b), size_t N)
100
+ comparisonTemplateMacro(char, [N], char, [M], strcmp(a,b), size_t N, size_t M)
901
101
 
902
- // null pointer comparisons
903
- template <typename B> int compareBetween( const my_nullptr_t &a, const B &b) { return Compare<my_nullptr_t,B>::between( a, b); }
904
- template <typename B> bool compareEqual( const my_nullptr_t &a, const B &b) { return Compare<my_nullptr_t,B>::equal( a, b); }
905
- template <typename B> bool compareNotEqual( const my_nullptr_t &a, const B &b) { return Compare<my_nullptr_t,B>::notEqual( a, b); }
906
- template <typename B> bool compareLess( const my_nullptr_t &a, const B &b) { return Compare<my_nullptr_t,B>::less( a, b); }
907
- template <typename B> bool compareMore( const my_nullptr_t &a, const B &b) { return Compare<my_nullptr_t,B>::more( a, b); }
908
- template <typename B> bool compareLessOrEqual(const my_nullptr_t &a, const B &b) { return Compare<my_nullptr_t,B>::lessOrEqual(a, b); }
909
- template <typename B> bool compareMoreOrEqual(const my_nullptr_t &a, const B &b) { return Compare<my_nullptr_t,B>::moreOrEqual(a, b); }
102
+ comparisonTemplateMacro(A, , std::nullptr_t, , a ? 1 : 0, typename A)
103
+ comparisonTemplateMacro(std::nullptr_t, , B, , b ? -1 : 0, typename B)
910
104
 
911
105
  // super general comparisons
912
- template <typename A, typename B> int compareBetween( const A &a, const B &b) { return Compare<A,B>::between( a, b); }
913
- template <typename A, typename B> bool compareEqual( const A &a, const B &b) { return Compare<A,B>::equal( a, b); }
914
- template <typename A, typename B> bool compareNotEqual( const A &a, const B &b) { return Compare<A,B>::notEqual( a, b); }
915
- template <typename A, typename B> bool compareLess( const A &a, const B &b) { return Compare<A,B>::less( a, b); }
916
- template <typename A, typename B> bool compareMore( const A &a, const B &b) { return Compare<A,B>::more( a, b); }
917
- template <typename A, typename B> bool compareLessOrEqual(const A &a, const B &b) { return Compare<A,B>::lessOrEqual(a, b); }
918
- template <typename A, typename B> bool compareMoreOrEqual(const A &a, const B &b) { return Compare<A,B>::moreOrEqual(a, b); }
106
+ template <typename A, typename B> int compareBetween( const A &a, const B &b) { return Compare<A, B>::between( a, b); }
107
+ template <typename A, typename B> bool compareEqual( const A &a, const B &b) { return Compare<A, B>::equal( a, b); }
108
+ template <typename A, typename B> bool compareNotEqual( const A &a, const B &b) { return Compare<A, B>::notEqual( a, b); }
109
+ template <typename A, typename B> bool compareLess( const A &a, const B &b) { return Compare<A, B>::less( a, b); }
110
+ template <typename A, typename B> bool compareMore( const A &a, const B &b) { return Compare<A, B>::more( a, b); }
111
+ template <typename A, typename B> bool compareLessOrEqual(const A &a, const B &b) { return Compare<A, B>::lessOrEqual(a, b); }
112
+ template <typename A, typename B> bool compareMoreOrEqual(const A &a, const B &b) { return Compare<A, B>::moreOrEqual(a, b); }