-
Notifications
You must be signed in to change notification settings - Fork 2
/
ArduinoJson-v6.18.3.h
8495 lines (7330 loc) · 264 KB
/
ArduinoJson-v6.18.3.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#ifdef __cplusplus
#if __cplusplus >= 201103L
# define ARDUINOJSON_HAS_LONG_LONG 1
# define ARDUINOJSON_HAS_RVALUE_REFERENCES 1
#else
# define ARDUINOJSON_HAS_LONG_LONG 0
# define ARDUINOJSON_HAS_RVALUE_REFERENCES 0
#endif
#ifndef ARDUINOJSON_HAS_NULLPTR
# if __cplusplus >= 201103L
# define ARDUINOJSON_HAS_NULLPTR 1
# else
# define ARDUINOJSON_HAS_NULLPTR 0
# endif
#endif
#if defined(_MSC_VER) && !ARDUINOJSON_HAS_LONG_LONG
# define ARDUINOJSON_HAS_INT64 1
#else
# define ARDUINOJSON_HAS_INT64 0
#endif
#ifndef ARDUINOJSON_EMBEDDED_MODE
# if defined(ARDUINO) /* Arduino*/ \
|| defined(__IAR_SYSTEMS_ICC__) /* IAR Embedded Workbench */ \
|| defined(__XC) /* MPLAB XC compiler */ \
|| defined(__ARMCC_VERSION) /* Keil ARM Compiler */ \
|| defined(__AVR) /* Atmel AVR8/GNU C Compiler */
# define ARDUINOJSON_EMBEDDED_MODE 1
# else
# define ARDUINOJSON_EMBEDDED_MODE 0
# endif
#endif
#if !defined(ARDUINOJSON_ENABLE_STD_STREAM) && defined(__has_include)
# if __has_include(<istream>) && \
__has_include(<ostream>) && \
!defined(min) && \
!defined(max)
# define ARDUINOJSON_ENABLE_STD_STREAM 1
# else
# define ARDUINOJSON_ENABLE_STD_STREAM 0
# endif
#endif
#if !defined(ARDUINOJSON_ENABLE_STD_STRING) && defined(__has_include)
# if __has_include(<string>) && !defined(min) && !defined(max)
# define ARDUINOJSON_ENABLE_STD_STRING 1
# else
# define ARDUINOJSON_ENABLE_STD_STRING 0
# endif
#endif
#ifndef ARDUINOJSON_ENABLE_STRING_VIEW
# ifdef __has_include
# if __has_include(<string_view>) && __cplusplus >= 201703L
# define ARDUINOJSON_ENABLE_STRING_VIEW 1
# endif
# endif
#endif
#ifndef ARDUINOJSON_ENABLE_STRING_VIEW
# define ARDUINOJSON_ENABLE_STRING_VIEW 0
#endif
#if ARDUINOJSON_EMBEDDED_MODE
# ifndef ARDUINOJSON_USE_DOUBLE
# define ARDUINOJSON_USE_DOUBLE 0
# endif
# ifndef ARDUINOJSON_USE_LONG_LONG
# define ARDUINOJSON_USE_LONG_LONG 0
# endif
# ifndef ARDUINOJSON_ENABLE_STD_STRING
# define ARDUINOJSON_ENABLE_STD_STRING 0
# endif
# ifndef ARDUINOJSON_ENABLE_STD_STREAM
# define ARDUINOJSON_ENABLE_STD_STREAM 0
# endif
# ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT
# define ARDUINOJSON_DEFAULT_NESTING_LIMIT 10
# endif
# ifndef ARDUINOJSON_SLOT_OFFSET_SIZE
# if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 2
# define ARDUINOJSON_SLOT_OFFSET_SIZE 1
# else
# define ARDUINOJSON_SLOT_OFFSET_SIZE 2
# endif
# endif
#else // ARDUINOJSON_EMBEDDED_MODE
# ifndef ARDUINOJSON_USE_DOUBLE
# define ARDUINOJSON_USE_DOUBLE 1
# endif
# ifndef ARDUINOJSON_USE_LONG_LONG
# if ARDUINOJSON_HAS_LONG_LONG || ARDUINOJSON_HAS_INT64
# define ARDUINOJSON_USE_LONG_LONG 1
# else
# define ARDUINOJSON_USE_LONG_LONG 0
# endif
# endif
# ifndef ARDUINOJSON_ENABLE_STD_STRING
# define ARDUINOJSON_ENABLE_STD_STRING 1
# endif
# ifndef ARDUINOJSON_ENABLE_STD_STREAM
# define ARDUINOJSON_ENABLE_STD_STREAM 1
# endif
# ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT
# define ARDUINOJSON_DEFAULT_NESTING_LIMIT 50
# endif
# ifndef ARDUINOJSON_SLOT_OFFSET_SIZE
# define ARDUINOJSON_SLOT_OFFSET_SIZE 4
# endif
#endif // ARDUINOJSON_EMBEDDED_MODE
#ifdef ARDUINO
#include <Arduino.h>
# ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING
# define ARDUINOJSON_ENABLE_ARDUINO_STRING 1
# endif
# ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM
# define ARDUINOJSON_ENABLE_ARDUINO_STREAM 1
# endif
# ifndef ARDUINOJSON_ENABLE_ARDUINO_PRINT
# define ARDUINOJSON_ENABLE_ARDUINO_PRINT 1
# endif
#else // ARDUINO
# ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING
# define ARDUINOJSON_ENABLE_ARDUINO_STRING 0
# endif
# ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM
# define ARDUINOJSON_ENABLE_ARDUINO_STREAM 0
# endif
# ifndef ARDUINOJSON_ENABLE_ARDUINO_PRINT
# define ARDUINOJSON_ENABLE_ARDUINO_PRINT 0
# endif
#endif // ARDUINO
#ifndef ARDUINOJSON_ENABLE_PROGMEM
# if defined(PROGMEM) && defined(pgm_read_byte) && defined(pgm_read_dword) && \
defined(pgm_read_ptr) && defined(pgm_read_float)
# define ARDUINOJSON_ENABLE_PROGMEM 1
# else
# define ARDUINOJSON_ENABLE_PROGMEM 0
# endif
#endif
#ifndef ARDUINOJSON_DECODE_UNICODE
# define ARDUINOJSON_DECODE_UNICODE 1
#endif
#ifndef ARDUINOJSON_ENABLE_COMMENTS
# define ARDUINOJSON_ENABLE_COMMENTS 0
#endif
#ifndef ARDUINOJSON_ENABLE_NAN
# define ARDUINOJSON_ENABLE_NAN 0
#endif
#ifndef ARDUINOJSON_ENABLE_INFINITY
# define ARDUINOJSON_ENABLE_INFINITY 0
#endif
#ifndef ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD
# define ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD 1e7
#endif
#ifndef ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD
# define ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD 1e-5
#endif
#ifndef ARDUINOJSON_LITTLE_ENDIAN
# if defined(_MSC_VER) || \
(defined(__BYTE_ORDER__) && \
__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \
defined(__LITTLE_ENDIAN__) || defined(__i386) || defined(__x86_64)
# define ARDUINOJSON_LITTLE_ENDIAN 1
# else
# define ARDUINOJSON_LITTLE_ENDIAN 0
# endif
#endif
#ifndef ARDUINOJSON_ENABLE_ALIGNMENT
# if defined(__AVR)
# define ARDUINOJSON_ENABLE_ALIGNMENT 0
# else
# define ARDUINOJSON_ENABLE_ALIGNMENT 1
# endif
#endif
#ifndef ARDUINOJSON_TAB
# define ARDUINOJSON_TAB " "
#endif
#ifndef ARDUINOJSON_ENABLE_STRING_DEDUPLICATION
# define ARDUINOJSON_ENABLE_STRING_DEDUPLICATION 1
#endif
#ifndef ARDUINOJSON_STRING_BUFFER_SIZE
# define ARDUINOJSON_STRING_BUFFER_SIZE 32
#endif
#ifndef ARDUINOJSON_DEBUG
# ifdef __PLATFORMIO_BUILD_DEBUG__
# define ARDUINOJSON_DEBUG 1
# else
# define ARDUINOJSON_DEBUG 0
# endif
#endif
#if ARDUINOJSON_HAS_NULLPTR && defined(nullptr)
# error nullptr is defined as a macro. Remove the faulty #define or #undef nullptr
#endif
#if !ARDUINOJSON_DEBUG
# ifdef __clang__
# pragma clang system_header
# elif defined __GNUC__
# pragma GCC system_header
# endif
#endif
#define ARDUINOJSON_EXPAND6(a, b, c, d, e, f) a, b, c, d, e, f
#define ARDUINOJSON_EXPAND9(a, b, c, d, e, f, g, h, i) a, b, c, d, e, f, g, h, i
#define ARDUINOJSON_EXPAND18(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, \
q, r) \
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r
#define ARDUINOJSON_CONCAT_(A, B) A##B
#define ARDUINOJSON_CONCAT2(A, B) ARDUINOJSON_CONCAT_(A, B)
#define ARDUINOJSON_CONCAT4(A, B, C, D) \
ARDUINOJSON_CONCAT2(ARDUINOJSON_CONCAT2(A, B), ARDUINOJSON_CONCAT2(C, D))
#define ARDUINOJSON_HEX_DIGIT_0000() 0
#define ARDUINOJSON_HEX_DIGIT_0001() 1
#define ARDUINOJSON_HEX_DIGIT_0010() 2
#define ARDUINOJSON_HEX_DIGIT_0011() 3
#define ARDUINOJSON_HEX_DIGIT_0100() 4
#define ARDUINOJSON_HEX_DIGIT_0101() 5
#define ARDUINOJSON_HEX_DIGIT_0110() 6
#define ARDUINOJSON_HEX_DIGIT_0111() 7
#define ARDUINOJSON_HEX_DIGIT_1000() 8
#define ARDUINOJSON_HEX_DIGIT_1001() 9
#define ARDUINOJSON_HEX_DIGIT_1010() A
#define ARDUINOJSON_HEX_DIGIT_1011() B
#define ARDUINOJSON_HEX_DIGIT_1100() C
#define ARDUINOJSON_HEX_DIGIT_1101() D
#define ARDUINOJSON_HEX_DIGIT_1110() E
#define ARDUINOJSON_HEX_DIGIT_1111() F
#define ARDUINOJSON_HEX_DIGIT_(A, B, C, D) ARDUINOJSON_HEX_DIGIT_##A##B##C##D()
#define ARDUINOJSON_HEX_DIGIT(A, B, C, D) ARDUINOJSON_HEX_DIGIT_(A, B, C, D)
#define ARDUINOJSON_VERSION "6.18.3"
#define ARDUINOJSON_VERSION_MAJOR 6
#define ARDUINOJSON_VERSION_MINOR 18
#define ARDUINOJSON_VERSION_REVISION 3
#ifndef ARDUINOJSON_NAMESPACE
# define ARDUINOJSON_NAMESPACE \
ARDUINOJSON_CONCAT4( \
ARDUINOJSON_CONCAT4(ArduinoJson, ARDUINOJSON_VERSION_MAJOR, \
ARDUINOJSON_VERSION_MINOR, \
ARDUINOJSON_VERSION_REVISION), \
_, \
ARDUINOJSON_HEX_DIGIT( \
ARDUINOJSON_ENABLE_PROGMEM, ARDUINOJSON_USE_LONG_LONG, \
ARDUINOJSON_USE_DOUBLE, ARDUINOJSON_ENABLE_STRING_DEDUPLICATION), \
ARDUINOJSON_HEX_DIGIT( \
ARDUINOJSON_ENABLE_NAN, ARDUINOJSON_ENABLE_INFINITY, \
ARDUINOJSON_ENABLE_COMMENTS, ARDUINOJSON_DECODE_UNICODE))
#endif
#if ARDUINOJSON_DEBUG
#include <assert.h>
# define ARDUINOJSON_ASSERT(X) assert(X)
#else
# define ARDUINOJSON_ASSERT(X) ((void)0)
#endif
#include <stddef.h>
namespace ARDUINOJSON_NAMESPACE {
class MemoryPool;
class VariantData;
class VariantSlot;
class CollectionData {
VariantSlot *_head;
VariantSlot *_tail;
public:
VariantData *addElement(MemoryPool *pool);
VariantData *getElement(size_t index) const;
VariantData *getOrAddElement(size_t index, MemoryPool *pool);
void removeElement(size_t index);
bool equalsArray(const CollectionData &other) const;
template<typename TAdaptedString>
VariantData *addMember(TAdaptedString key, MemoryPool *pool);
template<typename TAdaptedString>
VariantData *getMember(TAdaptedString key) const;
template<typename TAdaptedString>
VariantData *getOrAddMember(TAdaptedString key, MemoryPool *pool);
template<typename TAdaptedString>
void removeMember(TAdaptedString key) {
removeSlot(getSlot(key));
}
template<typename TAdaptedString>
bool containsKey(const TAdaptedString &key) const;
bool equalsObject(const CollectionData &other) const;
void clear();
size_t memoryUsage() const;
size_t nesting() const;
size_t size() const;
VariantSlot *addSlot(MemoryPool *);
void removeSlot(VariantSlot *slot);
bool copyFrom(const CollectionData &src, MemoryPool *pool);
VariantSlot *head() const {
return _head;
}
void movePointers(ptrdiff_t stringDistance, ptrdiff_t variantDistance);
private:
VariantSlot *getSlot(size_t index) const;
template<typename TAdaptedString>
VariantSlot *getSlot(TAdaptedString key) const;
VariantSlot *getPreviousSlot(VariantSlot *) const;
};
inline VariantData *arrayAdd(CollectionData *arr, MemoryPool *pool) {
return arr ? arr->addElement(pool) : 0;
}
template<typename TVisitor>
inline typename TVisitor::result_type arrayAccept(const CollectionData *arr,
TVisitor &visitor) {
if (arr)
return visitor.visitArray(*arr);
else
return visitor.visitNull();
}
inline bool arrayEquals(const CollectionData *lhs, const CollectionData *rhs) {
if (lhs == rhs)
return true;
if (!lhs || !rhs)
return false;
return lhs->equalsArray(*rhs);
}
#if ARDUINOJSON_ENABLE_ALIGNMENT
inline bool isAligned(size_t value) {
const size_t mask = sizeof(void *) - 1;
size_t addr = value;
return (addr & mask) == 0;
}
inline size_t addPadding(size_t bytes) {
const size_t mask = sizeof(void *) - 1;
return (bytes + mask) & ~mask;
}
template <size_t bytes>
struct AddPadding {
static const size_t mask = sizeof(void *) - 1;
static const size_t value = (bytes + mask) & ~mask;
};
#else
inline bool isAligned(size_t) {
return true;
}
inline size_t addPadding(size_t bytes) {
return bytes;
}
template<size_t bytes>
struct AddPadding {
static const size_t value = bytes;
};
#endif
template<typename T>
inline bool isAligned(T *ptr) {
return isAligned(reinterpret_cast<size_t>(ptr));
}
template<typename T>
inline T *addPadding(T *p) {
size_t address = addPadding(reinterpret_cast<size_t>(p));
return reinterpret_cast<T *>(address);
}
template<size_t X, size_t Y, bool MaxIsX = (X > Y)>
struct Max {
};
template<size_t X, size_t Y>
struct Max<X, Y, true> {
static const size_t value = X;
};
template<size_t X, size_t Y>
struct Max<X, Y, false> {
static const size_t value = Y;
};
} // namespace ARDUINOJSON_NAMESPACE
#include <string.h>
#include <stdint.h>
namespace ARDUINOJSON_NAMESPACE {
inline int safe_strcmp(const char *a, const char *b) {
if (a == b)
return 0;
if (!a)
return -1;
if (!b)
return 1;
return strcmp(a, b);
}
inline int safe_strncmp(const char *a, const char *b, size_t n) {
if (a == b)
return 0;
if (!a)
return -1;
if (!b)
return 1;
return strncmp(a, b, n);
}
namespace storage_policies {
struct store_by_address {
};
struct store_by_copy {
};
struct decide_at_runtime {
};
} // namespace storage_policies
template<bool Condition, class TrueType, class FalseType>
struct conditional {
typedef TrueType type;
};
template<class TrueType, class FalseType>
struct conditional<false, TrueType, FalseType> {
typedef FalseType type;
};
template<bool Condition, typename T = void>
struct enable_if {
};
template<typename T>
struct enable_if<true, T> {
typedef T type;
};
template<typename T, T v>
struct integral_constant {
static const T value = v;
};
typedef integral_constant<bool, true> true_type;
typedef integral_constant<bool, false> false_type;
template<typename T>
struct is_array : false_type {
};
template<typename T>
struct is_array<T[]> : true_type {
};
template<typename T, size_t N>
struct is_array<T[N]> : true_type {
};
template<typename TBase, typename TDerived>
class is_base_of {
protected: // <- to avoid GCC's "all member functions in class are private"
typedef char Yes[1];
typedef char No[2];
static Yes &probe(const TBase *);
static No &probe(...);
public:
static const bool value =
sizeof(probe(reinterpret_cast<TDerived *>(0))) == sizeof(Yes);
};
template<typename T>
T declval();
template<typename T>
struct is_class {
protected: // <- to avoid GCC's "all member functions in class are private"
typedef char Yes[1];
typedef char No[2];
template<typename U>
static Yes &probe(void (U::*)(void));
template<typename>
static No &probe(...);
public:
static const bool value = sizeof(probe<T>(0)) == sizeof(Yes);
};
template<typename T>
struct is_const : false_type {
};
template<typename T>
struct is_const<const T> : true_type {
};
} // namespace ARDUINOJSON_NAMESPACE
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable : 4244)
#endif
#ifdef __ICCARM__
#pragma diag_suppress=Pa093
#endif
namespace ARDUINOJSON_NAMESPACE {
template<typename From, typename To>
struct is_convertible {
protected: // <- to avoid GCC's "all member functions in class are private"
typedef char Yes[1];
typedef char No[2];
static Yes &probe(To);
static No &probe(...);
public:
static const bool value = sizeof(probe(declval<From>())) == sizeof(Yes);
};
} // namespace ARDUINOJSON_NAMESPACE
#ifdef _MSC_VER
# pragma warning(pop)
#endif
#ifdef __ICCARM__
#pragma diag_default=Pa093
#endif
namespace ARDUINOJSON_NAMESPACE {
template<typename T, typename U>
struct is_same : false_type {
};
template<typename T>
struct is_same<T, T> : true_type {
};
template<typename T>
struct remove_cv {
typedef T type;
};
template<typename T>
struct remove_cv<const T> {
typedef T type;
};
template<typename T>
struct remove_cv<volatile T> {
typedef T type;
};
template<typename T>
struct remove_cv<const volatile T> {
typedef T type;
};
template<class T>
struct is_floating_point
: integral_constant<
bool, //
is_same<float, typename remove_cv<T>::type>::value ||
is_same<double, typename remove_cv<T>::type>::value> {
};
template<typename T>
struct is_integral : integral_constant<bool,
is_same<typename remove_cv<T>::type, signed char>::value ||
is_same<typename remove_cv<T>::type, unsigned char>::value ||
is_same<typename remove_cv<T>::type, signed short>::value ||
is_same<typename remove_cv<T>::type, unsigned short>::value ||
is_same<typename remove_cv<T>::type, signed int>::value ||
is_same<typename remove_cv<T>::type, unsigned int>::value ||
is_same<typename remove_cv<T>::type, signed long>::value ||
is_same<typename remove_cv<T>::type, unsigned long>::value ||
#if ARDUINOJSON_HAS_LONG_LONG
is_same<typename remove_cv<T>::type, signed long long>::value ||
is_same<typename remove_cv<T>::type, unsigned long long>::value ||
#endif
#if ARDUINOJSON_HAS_INT64
is_same<typename remove_cv<T>::type, signed __int64>::value ||
is_same<typename remove_cv<T>::type, unsigned __int64>::value ||
#endif
is_same<typename remove_cv<T>::type, char>::value ||
is_same<typename remove_cv<T>::type, bool>::value> {
};
template<typename T>
struct is_enum {
static const bool value = is_convertible<T, int>::value &&
!is_class<T>::value && !is_integral<T>::value &&
!is_floating_point<T>::value;
};
template<typename T>
struct is_pointer : false_type {
};
template<typename T>
struct is_pointer<T *> : true_type {
};
template<typename T>
struct is_signed : integral_constant<bool,
is_same<typename remove_cv<T>::type, char>::value ||
is_same<typename remove_cv<T>::type, signed char>::value ||
is_same<typename remove_cv<T>::type, signed short>::value ||
is_same<typename remove_cv<T>::type, signed int>::value ||
is_same<typename remove_cv<T>::type, signed long>::value ||
#if ARDUINOJSON_HAS_LONG_LONG
is_same<typename remove_cv<T>::type, signed long long>::value ||
#endif
#if ARDUINOJSON_HAS_INT64
is_same<typename remove_cv<T>::type, signed __int64>::value ||
#endif
is_same<typename remove_cv<T>::type, float>::value ||
is_same<typename remove_cv<T>::type, double>::value> {
};
template<typename T>
struct is_unsigned : integral_constant<bool,
is_same<typename remove_cv<T>::type, unsigned char>::value ||
is_same<typename remove_cv<T>::type, unsigned short>::value ||
is_same<typename remove_cv<T>::type, unsigned int>::value ||
is_same<typename remove_cv<T>::type, unsigned long>::value ||
#if ARDUINOJSON_HAS_INT64
is_same<typename remove_cv<T>::type, unsigned __int64>::value ||
#endif
#if ARDUINOJSON_HAS_LONG_LONG
is_same<typename remove_cv<T>::type, unsigned long long>::value ||
#endif
is_same<typename remove_cv<T>::type, bool>::value> {
};
template<typename T>
struct type_identity {
typedef T type;
};
template<typename T>
struct make_unsigned;
template<>
struct make_unsigned<char> : type_identity<unsigned char> {
};
template<>
struct make_unsigned<signed char> : type_identity<unsigned char> {
};
template<>
struct make_unsigned<unsigned char> : type_identity<unsigned char> {
};
template<>
struct make_unsigned<signed short> : type_identity<unsigned short> {
};
template<>
struct make_unsigned<unsigned short> : type_identity<unsigned short> {
};
template<>
struct make_unsigned<signed int> : type_identity<unsigned int> {
};
template<>
struct make_unsigned<unsigned int> : type_identity<unsigned int> {
};
template<>
struct make_unsigned<signed long> : type_identity<unsigned long> {
};
template<>
struct make_unsigned<unsigned long> : type_identity<unsigned long> {
};
#if ARDUINOJSON_HAS_LONG_LONG
template<>
struct make_unsigned<signed long long> : type_identity<unsigned long long> {
};
template<>
struct make_unsigned<unsigned long long> : type_identity<unsigned long long> {
};
#endif
#if ARDUINOJSON_HAS_INT64
template <>
struct make_unsigned<signed __int64> : type_identity<unsigned __int64> {};
template <>
struct make_unsigned<unsigned __int64> : type_identity<unsigned __int64> {};
#endif
template<class = void>
struct make_void {
typedef void type;
};
template<typename T>
struct remove_const {
typedef T type;
};
template<typename T>
struct remove_const<const T> {
typedef T type;
};
template<typename T>
struct remove_reference {
typedef T type;
};
template<typename T>
struct remove_reference<T &> {
typedef T type;
};
template<typename T, bool bounded = false, typename Enable = void>
class StringAdapter;
template<typename T>
inline StringAdapter<T, false> adaptString(const T &str) {
return StringAdapter<T, false>(str);
}
template<typename T>
inline StringAdapter<T, true> adaptString(const T &str, size_t sz) {
return StringAdapter<T, true>(str, sz);
}
template<typename T, typename Enable = void>
struct IsString : false_type {
};
template<typename T>
struct IsString<
T, typename make_void<typename StringAdapter<T>::storage_policy>::type>
: true_type {
};
template<>
class StringAdapter<const char *> {
public:
StringAdapter(const char *str = 0) : _str(str) {}
int compare(const char *other) const {
return safe_strcmp(_str, other);
}
bool isNull() const {
return !_str;
}
size_t size() const {
if (!_str)
return 0;
return strlen(_str);
}
const char *data() const {
return _str;
}
typedef storage_policies::store_by_address storage_policy;
protected:
const char *_str;
};
template<int N>
class StringAdapter<const char[N]> : public StringAdapter<const char *> {
public:
StringAdapter<const char[N]>(const char *s) : StringAdapter<const char *>(s) {}
};
template<typename TChar>
class StringAdapter<TChar *, false,
typename enable_if<sizeof(TChar) == 1 &&
!is_same<TChar, void>::value>::type>
: public StringAdapter<const char *> {
public:
StringAdapter(const TChar *str)
: StringAdapter<const char *>(reinterpret_cast<const char *>(str)) {}
void copyTo(char *p, size_t n) const {
memcpy(p, _str, n);
}
typedef ARDUINOJSON_NAMESPACE::storage_policies::store_by_copy storage_policy;
};
class String {
public:
String() : _data(0), _isStatic(true) {}
String(const char *data, bool isStaticData = true)
: _data(data), _isStatic(isStaticData) {}
const char *c_str() const {
return _data;
}
bool isNull() const {
return !_data;
}
bool isStatic() const {
return _isStatic;
}
friend bool operator==(String lhs, String rhs) {
if (lhs._data == rhs._data)
return true;
if (!lhs._data)
return false;
if (!rhs._data)
return false;
return strcmp(lhs._data, rhs._data) == 0;
}
friend bool operator!=(String lhs, String rhs) {
if (lhs._data == rhs._data)
return false;
if (!lhs._data)
return true;
if (!rhs._data)
return true;
return strcmp(lhs._data, rhs._data) != 0;
}
private:
const char *_data;
bool _isStatic;
};
template<>
class StringAdapter<String> : public StringAdapter<char *> {
public:
StringAdapter(const String &str)
: StringAdapter<char *>(str.c_str()), _isStatic(str.isStatic()) {}
bool isStatic() const {
return _isStatic;
}
typedef storage_policies::decide_at_runtime storage_policy;
private:
bool _isStatic;
};
template<typename TChar>
class StringAdapter<TChar *, true> {
public:
StringAdapter(const char *str, size_t n) : _str(str), _size(n) {}
int compare(const char *other) const {
return safe_strncmp(_str, other, _size);
}
bool isNull() const {
return !_str;
}
void copyTo(char *p, size_t n) const {
memcpy(p, _str, n);
}
size_t size() const {
return _size;
}
typedef storage_policies::store_by_copy storage_policy;
private:
const char *_str;
size_t _size;
};
} // namespace ARDUINOJSON_NAMESPACE
#if ARDUINOJSON_ENABLE_STD_STRING
#include <string>
namespace ARDUINOJSON_NAMESPACE {
template <typename TCharTraits, typename TAllocator>
class StringAdapter<std::basic_string<char, TCharTraits, TAllocator> > {
public:
typedef std::basic_string<char, TCharTraits, TAllocator> string_type;
StringAdapter(const string_type& str) : _str(&str) {}
void copyTo(char* p, size_t n) const {
memcpy(p, _str->c_str(), n);
}
bool isNull() const {
return false;
}
int compare(const char* other) const {
if (!other)
return 1;
return _str->compare(other);
}
size_t size() const {
return _str->size();
}
typedef storage_policies::store_by_copy storage_policy;
private:
const string_type* _str;
};
} // namespace ARDUINOJSON_NAMESPACE
#endif
#if ARDUINOJSON_ENABLE_STRING_VIEW
#include <string_view>
namespace ARDUINOJSON_NAMESPACE {
template <>
class StringAdapter<std::string_view> {
public:
StringAdapter(std::string_view str) : _str(str) {}
void copyTo(char* p, size_t n) const {
memcpy(p, _str.data(), n);
}
bool isNull() const {
return false;
}
int compare(const char* other) const {
if (!other)
return 1;
return _str.compare(other);
}
size_t size() const {
return _str.size();
}
typedef storage_policies::store_by_copy storage_policy;
private:
std::string_view _str;
};
} // namespace ARDUINOJSON_NAMESPACE
#endif
#if ARDUINOJSON_ENABLE_ARDUINO_STRING
namespace ARDUINOJSON_NAMESPACE {
template<>
class StringAdapter<::String> {
public:
StringAdapter(const ::String &str) : _str(&str) {}
void copyTo(char *p, size_t n) const {
memcpy(p, _str->c_str(), n);
}
bool isNull() const {
return !_str->c_str();
}
int compare(const char *other) const {
const char *me = _str->c_str();
return safe_strcmp(me, other);
}
size_t size() const {
return _str->length();
}
typedef storage_policies::store_by_copy storage_policy;
private:
const ::String *_str;
};
template<>
class StringAdapter<::StringSumHelper> : public StringAdapter<::String> {
public:
StringAdapter<::StringSumHelper>(const ::String &s)
: StringAdapter<::String>(s) {}
};
} // namespace ARDUINOJSON_NAMESPACE
#endif
#if ARDUINOJSON_ENABLE_PROGMEM
namespace ARDUINOJSON_NAMESPACE {
struct pgm_p {
pgm_p(const char *p) : address(p) {}
const char *address;
};
} // namespace ARDUINOJSON_NAMESPACE
#ifndef strlen_P
inline size_t strlen_P(ARDUINOJSON_NAMESPACE::pgm_p s) {
const char *p = s.address;
ARDUINOJSON_ASSERT(p != NULL);
while (pgm_read_byte(p)) p++;
return size_t(p - s.address);
}
#endif
#ifndef strncmp_P
inline int strncmp_P(const char *a, ARDUINOJSON_NAMESPACE::pgm_p b, size_t n) {
const char *s1 = a;
const char *s2 = b.address;
ARDUINOJSON_ASSERT(s1 != NULL);
ARDUINOJSON_ASSERT(s2 != NULL);
while (n-- > 0) {
char c1 = *s1++;
char c2 = static_cast<char>(pgm_read_byte(s2++));
if (c1 < c2)
return -1;
if (c1 > c2)
return 1;
if (c1 == 0 /* and c2 as well */)
return 0;
}
return 0;
}
#endif
#ifndef strcmp_P
inline int strcmp_P(const char *a, ARDUINOJSON_NAMESPACE::pgm_p b) {
const char *s1 = a;
const char *s2 = b.address;
ARDUINOJSON_ASSERT(s1 != NULL);
ARDUINOJSON_ASSERT(s2 != NULL);
for (;;) {
char c1 = *s1++;
char c2 = static_cast<char>(pgm_read_byte(s2++));
if (c1 < c2)
return -1;
if (c1 > c2)
return 1;
if (c1 == 0 /* and c2 as well */)