jsoncons 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +7 -0
  2. data/ext/jsoncons/extconf.rb +43 -0
  3. data/ext/jsoncons/jsoncons.cpp +161 -0
  4. data/ext/jsoncons/jsoncons.h +10 -0
  5. data/jsoncons.gemspec +44 -0
  6. data/lib/jsoncons/jsoncons/examples/input/address-book.json +13 -0
  7. data/lib/jsoncons/jsoncons/examples/input/books.json +28 -0
  8. data/lib/jsoncons/jsoncons/examples/input/countries.json +7 -0
  9. data/lib/jsoncons/jsoncons/examples/input/employees.json +30 -0
  10. data/lib/jsoncons/jsoncons/examples/input/jsonschema/name.json +15 -0
  11. data/lib/jsoncons/jsoncons/examples/input/multiple-json-objects.json +3 -0
  12. data/lib/jsoncons/jsoncons/examples/input/sales.csv +6 -0
  13. data/lib/jsoncons/jsoncons/examples/input/store.json +28 -0
  14. data/lib/jsoncons/jsoncons/examples/input/tasks.csv +6 -0
  15. data/lib/jsoncons/jsoncons/include/jsoncons/allocator_holder.hpp +38 -0
  16. data/lib/jsoncons/jsoncons/include/jsoncons/basic_json.hpp +5905 -0
  17. data/lib/jsoncons/jsoncons/include/jsoncons/bigint.hpp +1611 -0
  18. data/lib/jsoncons/jsoncons/include/jsoncons/byte_string.hpp +820 -0
  19. data/lib/jsoncons/jsoncons/include/jsoncons/config/binary_config.hpp +226 -0
  20. data/lib/jsoncons/jsoncons/include/jsoncons/config/compiler_support.hpp +375 -0
  21. data/lib/jsoncons/jsoncons/include/jsoncons/config/jsoncons_config.hpp +309 -0
  22. data/lib/jsoncons/jsoncons/include/jsoncons/config/version.hpp +40 -0
  23. data/lib/jsoncons/jsoncons/include/jsoncons/conv_error.hpp +218 -0
  24. data/lib/jsoncons/jsoncons/include/jsoncons/decode_json.hpp +209 -0
  25. data/lib/jsoncons/jsoncons/include/jsoncons/decode_traits.hpp +651 -0
  26. data/lib/jsoncons/jsoncons/include/jsoncons/detail/endian.hpp +44 -0
  27. data/lib/jsoncons/jsoncons/include/jsoncons/detail/grisu3.hpp +312 -0
  28. data/lib/jsoncons/jsoncons/include/jsoncons/detail/optional.hpp +483 -0
  29. data/lib/jsoncons/jsoncons/include/jsoncons/detail/parse_number.hpp +1133 -0
  30. data/lib/jsoncons/jsoncons/include/jsoncons/detail/span.hpp +188 -0
  31. data/lib/jsoncons/jsoncons/include/jsoncons/detail/string_view.hpp +537 -0
  32. data/lib/jsoncons/jsoncons/include/jsoncons/detail/string_wrapper.hpp +370 -0
  33. data/lib/jsoncons/jsoncons/include/jsoncons/detail/write_number.hpp +567 -0
  34. data/lib/jsoncons/jsoncons/include/jsoncons/encode_json.hpp +315 -0
  35. data/lib/jsoncons/jsoncons/include/jsoncons/encode_traits.hpp +378 -0
  36. data/lib/jsoncons/jsoncons/include/jsoncons/json.hpp +18 -0
  37. data/lib/jsoncons/jsoncons/include/jsoncons/json_array.hpp +324 -0
  38. data/lib/jsoncons/jsoncons/include/jsoncons/json_content_handler.hpp +12 -0
  39. data/lib/jsoncons/jsoncons/include/jsoncons/json_cursor.hpp +448 -0
  40. data/lib/jsoncons/jsoncons/include/jsoncons/json_decoder.hpp +420 -0
  41. data/lib/jsoncons/jsoncons/include/jsoncons/json_encoder.hpp +1587 -0
  42. data/lib/jsoncons/jsoncons/include/jsoncons/json_error.hpp +156 -0
  43. data/lib/jsoncons/jsoncons/include/jsoncons/json_exception.hpp +241 -0
  44. data/lib/jsoncons/jsoncons/include/jsoncons/json_filter.hpp +653 -0
  45. data/lib/jsoncons/jsoncons/include/jsoncons/json_fwd.hpp +23 -0
  46. data/lib/jsoncons/jsoncons/include/jsoncons/json_object.hpp +1772 -0
  47. data/lib/jsoncons/jsoncons/include/jsoncons/json_options.hpp +862 -0
  48. data/lib/jsoncons/jsoncons/include/jsoncons/json_parser.hpp +2900 -0
  49. data/lib/jsoncons/jsoncons/include/jsoncons/json_reader.hpp +731 -0
  50. data/lib/jsoncons/jsoncons/include/jsoncons/json_traits_macros.hpp +1072 -0
  51. data/lib/jsoncons/jsoncons/include/jsoncons/json_traits_macros_deprecated.hpp +144 -0
  52. data/lib/jsoncons/jsoncons/include/jsoncons/json_type.hpp +206 -0
  53. data/lib/jsoncons/jsoncons/include/jsoncons/json_type_traits.hpp +1830 -0
  54. data/lib/jsoncons/jsoncons/include/jsoncons/json_visitor.hpp +1560 -0
  55. data/lib/jsoncons/jsoncons/include/jsoncons/json_visitor2.hpp +2079 -0
  56. data/lib/jsoncons/jsoncons/include/jsoncons/pretty_print.hpp +89 -0
  57. data/lib/jsoncons/jsoncons/include/jsoncons/ser_context.hpp +62 -0
  58. data/lib/jsoncons/jsoncons/include/jsoncons/sink.hpp +289 -0
  59. data/lib/jsoncons/jsoncons/include/jsoncons/source.hpp +777 -0
  60. data/lib/jsoncons/jsoncons/include/jsoncons/source_adaptor.hpp +148 -0
  61. data/lib/jsoncons/jsoncons/include/jsoncons/staj2_cursor.hpp +1189 -0
  62. data/lib/jsoncons/jsoncons/include/jsoncons/staj_cursor.hpp +1254 -0
  63. data/lib/jsoncons/jsoncons/include/jsoncons/staj_iterator.hpp +449 -0
  64. data/lib/jsoncons/jsoncons/include/jsoncons/tag_type.hpp +245 -0
  65. data/lib/jsoncons/jsoncons/include/jsoncons/text_source_adaptor.hpp +144 -0
  66. data/lib/jsoncons/jsoncons/include/jsoncons/traits_extension.hpp +884 -0
  67. data/lib/jsoncons/jsoncons/include/jsoncons/typed_array_view.hpp +250 -0
  68. data/lib/jsoncons/jsoncons/include/jsoncons/unicode_traits.hpp +1330 -0
  69. data/lib/jsoncons/jsoncons/include/jsoncons/uri.hpp +635 -0
  70. data/lib/jsoncons/jsoncons/include/jsoncons/value_converter.hpp +340 -0
  71. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson.hpp +23 -0
  72. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_cursor.hpp +320 -0
  73. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_decimal128.hpp +865 -0
  74. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_encoder.hpp +585 -0
  75. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_error.hpp +103 -0
  76. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_oid.hpp +245 -0
  77. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_options.hpp +75 -0
  78. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_parser.hpp +645 -0
  79. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_reader.hpp +92 -0
  80. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_type.hpp +44 -0
  81. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/decode_bson.hpp +201 -0
  82. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/encode_bson.hpp +144 -0
  83. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor.hpp +26 -0
  84. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_cursor.hpp +351 -0
  85. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_cursor2.hpp +265 -0
  86. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_detail.hpp +93 -0
  87. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_encoder.hpp +1766 -0
  88. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_error.hpp +105 -0
  89. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_options.hpp +113 -0
  90. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_parser.hpp +1942 -0
  91. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_reader.hpp +116 -0
  92. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/decode_cbor.hpp +203 -0
  93. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/encode_cbor.hpp +151 -0
  94. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv.hpp +17 -0
  95. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_cursor.hpp +358 -0
  96. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_encoder.hpp +954 -0
  97. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_error.hpp +85 -0
  98. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_options.hpp +973 -0
  99. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_parser.hpp +2099 -0
  100. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_reader.hpp +348 -0
  101. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_serializer.hpp +12 -0
  102. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/decode_csv.hpp +208 -0
  103. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/encode_csv.hpp +122 -0
  104. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jmespath/jmespath.hpp +5215 -0
  105. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jmespath/jmespath_error.hpp +215 -0
  106. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpatch/jsonpatch.hpp +579 -0
  107. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpatch/jsonpatch_error.hpp +121 -0
  108. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/expression.hpp +3329 -0
  109. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/flatten.hpp +432 -0
  110. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/json_location.hpp +445 -0
  111. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/json_query.hpp +115 -0
  112. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath.hpp +13 -0
  113. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_error.hpp +240 -0
  114. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp +2612 -0
  115. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp +1322 -0
  116. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpointer/jsonpointer.hpp +1577 -0
  117. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpointer/jsonpointer_error.hpp +119 -0
  118. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/format_validator.hpp +968 -0
  119. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/json_validator.hpp +120 -0
  120. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema.hpp +13 -0
  121. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema_error.hpp +105 -0
  122. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema_version.hpp +18 -0
  123. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/keyword_validator.hpp +1745 -0
  124. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/keyword_validator_factory.hpp +556 -0
  125. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_draft7.hpp +198 -0
  126. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_location.hpp +200 -0
  127. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_version.hpp +35 -0
  128. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/subschema.hpp +144 -0
  129. data/lib/jsoncons/jsoncons/include/jsoncons_ext/mergepatch/mergepatch.hpp +103 -0
  130. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/decode_msgpack.hpp +202 -0
  131. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/encode_msgpack.hpp +142 -0
  132. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack.hpp +24 -0
  133. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_cursor.hpp +343 -0
  134. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_cursor2.hpp +259 -0
  135. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_encoder.hpp +753 -0
  136. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_error.hpp +94 -0
  137. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_options.hpp +74 -0
  138. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_parser.hpp +748 -0
  139. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_reader.hpp +116 -0
  140. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_type.hpp +63 -0
  141. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/decode_ubjson.hpp +201 -0
  142. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/encode_ubjson.hpp +142 -0
  143. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson.hpp +23 -0
  144. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_cursor.hpp +307 -0
  145. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_encoder.hpp +502 -0
  146. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_error.hpp +100 -0
  147. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_options.hpp +87 -0
  148. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_parser.hpp +880 -0
  149. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_reader.hpp +92 -0
  150. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_type.hpp +43 -0
  151. data/lib/jsoncons/version.rb +5 -0
  152. data/lib/jsoncons.rb +33 -0
  153. data/test/jsoncons_test.rb +108 -0
  154. data/test/test_helper.rb +7 -0
  155. metadata +268 -0
@@ -0,0 +1,226 @@
1
+ // Copyright 2017 Daniel Parker
2
+ // Distributed under the Boost license, Version 1.0.
3
+ // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4
+
5
+ // See https://github.com/danielaparker/jsoncons for latest version
6
+
7
+ #ifndef JSONCONS_CONFIG_BINARY_CONFIG_HPP
8
+ #define JSONCONS_CONFIG_BINARY_CONFIG_HPP
9
+
10
+ #include <cfloat>
11
+ #include <cstddef>
12
+ #include <cstdint>
13
+ #include <cstring> // std::memcpy
14
+ #include <memory>
15
+ #include <type_traits> // std::enable_if
16
+
17
+ // The definitions below follow the definitions in compiler_support_p.h, https://github.com/01org/tinycbor
18
+ // MIT license
19
+
20
+ #ifdef __F16C__
21
+ # include <immintrin.h>
22
+ #endif
23
+
24
+ #ifndef __has_builtin
25
+ # define __has_builtin(x) 0
26
+ #endif
27
+
28
+ #if defined(__GNUC__)
29
+ #if (__GNUC__ * 100 + __GNUC_MINOR__ >= 403) || (__has_builtin(__builtin_bswap64) && __has_builtin(__builtin_bswap32))
30
+ # define JSONCONS_BYTE_SWAP_64 __builtin_bswap64
31
+ # define JSONCONS_BYTE_SWAP_32 __builtin_bswap32
32
+ # ifdef __INTEL_COMPILER
33
+ # define JSONCONS_BYTE_SWAP_16 _bswap16
34
+ # elif (__GNUC__ * 100 + __GNUC_MINOR__ >= 608) || __has_builtin(__builtin_bswap16)
35
+ # define JSONCONS_BYTE_SWAP_16 __builtin_bswap16
36
+ # endif
37
+ #endif
38
+ #elif defined(__sun)
39
+ # include <sys/byteorder.h>
40
+ #elif defined(_MSC_VER)
41
+ // MSVC, which implies sizeof(long) == 4
42
+ # define JSONCONS_BYTE_SWAP_64 _byteswap_uint64
43
+ # define JSONCONS_BYTE_SWAP_32 _byteswap_ulong
44
+ # define JSONCONS_BYTE_SWAP_16 _byteswap_ushort
45
+ #endif
46
+
47
+ namespace jsoncons {
48
+ namespace binary {
49
+
50
+ struct uint128_holder
51
+ {
52
+ uint64_t lo;
53
+ uint64_t hi;
54
+ };
55
+
56
+ static inline bool add_check_overflow(std::size_t v1, std::size_t v2, std::size_t *r)
57
+ {
58
+ #if ((defined(__GNUC__) && (__GNUC__ >= 5)) && !defined(__INTEL_COMPILER)) || __has_builtin(__builtin_add_overflow)
59
+ return __builtin_add_overflow(v1, v2, r);
60
+ #else
61
+ // unsigned additions are well-defined
62
+ *r = v1 + v2;
63
+ return v1 > v1 + v2;
64
+ #endif
65
+ }
66
+
67
+ #if defined(__apple_build_version__) && ((__clang_major__ < 8) || ((__clang_major__ == 8) && (__clang_minor__ < 1)))
68
+ #define APPLE_MISSING_INTRINSICS 1
69
+ #endif
70
+
71
+ inline
72
+ uint16_t encode_half(double val)
73
+ {
74
+ #if defined(__F16C__) && !defined(APPLE_MISSING_INTRINSICS)
75
+ return _cvtss_sh((float)val, 3);
76
+ #else
77
+ uint64_t v;
78
+ std::memcpy(&v, &val, sizeof(v));
79
+ int64_t sign = static_cast<int64_t>(v >> 63 << 15);
80
+ int64_t exp = (v >> 52) & 0x7ff;
81
+ int64_t mant = v << 12 >> 12 >> (53-11); /* keep only the 11 most significant bits of the mantissa */
82
+ exp -= 1023;
83
+ if (exp == 1024) {
84
+ /* infinity or NaN */
85
+ exp = 16;
86
+ mant >>= 1;
87
+ } else if (exp >= 16) {
88
+ /* overflow, as largest number */
89
+ exp = 15;
90
+ mant = 1023;
91
+ } else if (exp >= -14) {
92
+ /* regular normal */
93
+ } else if (exp >= -24) {
94
+ /* subnormal */
95
+ mant |= 1024;
96
+ mant >>= -(exp + 14);
97
+ exp = -15;
98
+ } else {
99
+ /* underflow, make zero */
100
+ return 0;
101
+ }
102
+
103
+ /* safe cast here as bit operations above guarantee not to overflow */
104
+ return static_cast<uint16_t>(sign | ((exp + 15) << 10) | mant);
105
+ #endif
106
+ }
107
+
108
+ /* this function was copied & adapted from RFC 7049 Appendix D */
109
+ inline
110
+ double decode_half(uint16_t half)
111
+ {
112
+ #if defined(__F16C__) && !defined(APPLE_MISSING_INTRINSICS)
113
+ return _cvtsh_ss(half);
114
+ #else
115
+ int64_t exp = (half >> 10) & 0x1f;
116
+ int64_t mant = half & 0x3ff;
117
+ double val;
118
+ if (exp == 0)
119
+ {
120
+ val = ldexp(static_cast<double>(mant), -24);
121
+ }
122
+ else if (exp != 31)
123
+ {
124
+ val = ldexp(static_cast<double>(mant) + 1024.0, static_cast<int>(exp - 25));
125
+ }
126
+ else
127
+ {
128
+ val = mant == 0 ? std::numeric_limits<double>::infinity() : std::nan("");
129
+ }
130
+ return half & 0x8000 ? -val : val;
131
+ #endif
132
+ }
133
+
134
+ // byte_swap
135
+
136
+ template<class T>
137
+ typename std::enable_if<std::is_integral<T>::value && sizeof(T) == sizeof(uint8_t),T>::type
138
+ byte_swap(T val)
139
+ {
140
+ return val;
141
+ }
142
+
143
+ template<class T>
144
+ typename std::enable_if<std::is_integral<T>::value && sizeof(T) == sizeof(uint16_t),T>::type
145
+ byte_swap(T val)
146
+ {
147
+ #if defined(JSONCONS_BYTE_SWAP_16)
148
+ return JSONCONS_BYTE_SWAP_16(val);
149
+ #else
150
+ return (static_cast<uint16_t>(val) >> 8) | (static_cast<uint16_t>(val) << 8);
151
+ #endif
152
+ }
153
+
154
+ template<class T>
155
+ typename std::enable_if<std::is_integral<T>::value && sizeof(T) == sizeof(uint32_t),T>::type
156
+ byte_swap(T val)
157
+ {
158
+ #if defined(JSONCONS_BYTE_SWAP_32)
159
+ return JSONCONS_BYTE_SWAP_32(val);
160
+ #else
161
+ uint32_t tmp = ((static_cast<uint32_t>(val) << 8) & 0xff00ff00) | ((static_cast<uint32_t>(val) >> 8) & 0xff00ff);
162
+ return (tmp << 16) | (tmp >> 16);
163
+ #endif
164
+ }
165
+
166
+ template<class T>
167
+ typename std::enable_if<std::is_integral<T>::value && sizeof(T) == sizeof(uint64_t),T>::type
168
+ byte_swap(T val)
169
+ {
170
+ #if defined(JSONCONS_BYTE_SWAP_64)
171
+ return JSONCONS_BYTE_SWAP_64(val);
172
+ #else
173
+ uint64_t tmp = ((static_cast<uint64_t>(val) & 0x00000000ffffffffull) << 32) | ((static_cast<uint64_t>(val) & 0xffffffff00000000ull) >> 32);
174
+ tmp = ((tmp & 0x0000ffff0000ffffull) << 16) | ((tmp & 0xffff0000ffff0000ull) >> 16);
175
+ return ((tmp & 0x00ff00ff00ff00ffull) << 8) | ((tmp & 0xff00ff00ff00ff00ull) >> 8);
176
+ #endif
177
+ }
178
+
179
+ template<class T>
180
+ typename std::enable_if<std::is_floating_point<T>::value && sizeof(T) == sizeof(uint32_t),T>::type
181
+ byte_swap(T val)
182
+ {
183
+ uint32_t x;
184
+ std::memcpy(&x,&val,sizeof(uint32_t));
185
+ uint32_t y = byte_swap(x);
186
+ T val2;
187
+ std::memcpy(&val2,&y,sizeof(uint32_t));
188
+ return val2;
189
+ }
190
+
191
+ template<class T>
192
+ typename std::enable_if<std::is_floating_point<T>::value && sizeof(T) == sizeof(uint64_t),T>::type
193
+ byte_swap(T val)
194
+ {
195
+ uint64_t x;
196
+ std::memcpy(&x,&val,sizeof(uint64_t));
197
+ uint64_t y = byte_swap(x);
198
+ T val2;
199
+ std::memcpy(&val2,&y,sizeof(uint64_t));
200
+ return val2;
201
+ }
202
+
203
+ template<class T>
204
+ typename std::enable_if<std::is_floating_point<T>::value && sizeof(T) == 2*sizeof(uint64_t),T>::type
205
+ byte_swap(T val)
206
+ {
207
+ uint128_holder x;
208
+ uint8_t buf[2*sizeof(uint64_t)];
209
+ std::memcpy(buf,&val,2*sizeof(uint64_t));
210
+ std::memcpy(&x.lo,buf,sizeof(uint64_t));
211
+ std::memcpy(&x.hi,buf+sizeof(uint64_t),sizeof(uint64_t));
212
+
213
+ uint128_holder y;
214
+ y.lo = byte_swap(x.hi);
215
+ y.hi = byte_swap(x.lo);
216
+
217
+ T val2;
218
+ std::memcpy(&val2,&y,2*sizeof(uint64_t));
219
+
220
+ return val2;
221
+ }
222
+
223
+ } // binary
224
+ } // jsoncons
225
+
226
+ #endif
@@ -0,0 +1,375 @@
1
+ // Copyright 2013 Daniel Parker
2
+ // Distributed under the Boost license, Version 1.0.
3
+ // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4
+
5
+ // See https://github.com/danielaparker/jsoncons for latest version
6
+
7
+ #ifndef JSONCONS_COMPILER_SUPPORT_HPP
8
+ #define JSONCONS_COMPILER_SUPPORT_HPP
9
+
10
+ #include <stdexcept>
11
+ #include <string>
12
+ #include <cmath>
13
+ #include <exception>
14
+ #include <ostream>
15
+
16
+ #if defined (__clang__)
17
+ #define JSONCONS_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
18
+ #endif
19
+
20
+ // Uncomment the following line to suppress deprecated names (recommended for new code)
21
+ //#define JSONCONS_NO_DEPRECATED
22
+
23
+ // The definitions below follow the definitions in compiler_support_p.h, https://github.com/01org/tinycbor
24
+ // MIT license
25
+
26
+ // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54577
27
+ #if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ < 9
28
+ #define JSONCONS_NO_VECTOR_ERASE_TAKES_CONST_ITERATOR 1
29
+ #define JSONCONS_NO_MAP_CONS_TAKES_ALLOCATOR 1
30
+ #endif
31
+
32
+ #if defined(__clang__)
33
+ # define JSONCONS_FALLTHROUGH [[clang::fallthrough]]
34
+ #elif defined(__GNUC__) && ((__GNUC__ >= 7))
35
+ # define JSONCONS_FALLTHROUGH __attribute__((fallthrough))
36
+ #elif defined (__GNUC__)
37
+ # define JSONCONS_FALLTHROUGH // FALLTHRU
38
+ #else
39
+ # define JSONCONS_FALLTHROUGH
40
+ #endif
41
+
42
+ #if defined(__GNUC__) || defined(__clang__)
43
+ #define JSONCONS_LIKELY(x) __builtin_expect(!!(x), 1)
44
+ #define JSONCONS_UNLIKELY(x) __builtin_expect(!!(x), 0)
45
+ #define JSONCONS_UNREACHABLE() __builtin_unreachable()
46
+ #elif defined(_MSC_VER)
47
+ #define JSONCONS_LIKELY(x) x
48
+ #define JSONCONS_UNLIKELY(x) x
49
+ #define JSONCONS_UNREACHABLE() __assume(0)
50
+ #else
51
+ #define JSONCONS_LIKELY(x) x
52
+ #define JSONCONS_UNLIKELY(x) x
53
+ #define JSONCONS_UNREACHABLE() do {} while (0)
54
+ #endif
55
+
56
+ // Deprecated symbols markup
57
+ #if (defined(__cplusplus) && __cplusplus >= 201402L)
58
+ #define JSONCONS_DEPRECATED_MSG(msg) [[deprecated(msg)]]
59
+ #endif
60
+
61
+ #if !defined(JSONCONS_DEPRECATED_MSG) && defined(__GNUC__) && defined(__has_extension)
62
+ #if __has_extension(attribute_deprecated_with_message)
63
+ #define JSONCONS_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
64
+ #endif
65
+ #endif
66
+
67
+ #if !defined(JSONCONS_DEPRECATED_MSG) && defined(_MSC_VER)
68
+ #if (_MSC_VER) >= 1920
69
+ #define JSONCONS_DEPRECATED_MSG(msg) [[deprecated(msg)]]
70
+ #else
71
+ #define JSONCONS_DEPRECATED_MSG(msg) __declspec(deprecated(msg))
72
+ #endif
73
+ #endif
74
+
75
+ // Following boost/atomic/detail/config.hpp
76
+ #if !defined(JSONCONS_DEPRECATED_MSG) && (\
77
+ (defined(__GNUC__) && ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0)) >= 405) ||\
78
+ (defined(__SUNPRO_CC) && (__SUNPRO_CC + 0) >= 0x5130))
79
+ #define JSONCONS_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
80
+ #endif
81
+
82
+ #if !defined(JSONCONS_DEPRECATED_MSG) && defined(__clang__) && defined(__has_extension)
83
+ #if __has_extension(attribute_deprecated_with_message)
84
+ #define JSONCONS_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
85
+ #else
86
+ #define JSONCONS_DEPRECATED_MSG(msg) __attribute__((deprecated))
87
+ #endif
88
+ #endif
89
+
90
+ #if !defined(JSONCONS_DEPRECATED_MSG)
91
+ #define JSONCONS_DEPRECATED_MSG(msg)
92
+ #endif
93
+
94
+ #if defined(ANDROID) || defined(__ANDROID__)
95
+ #if __ANDROID_API__ >= 21
96
+ #define JSONCONS_HAS_STRTOLD_L
97
+ #else
98
+ #define JSONCONS_NO_LOCALECONV
99
+ #endif
100
+ #endif
101
+
102
+ #if defined(_MSC_VER)
103
+ #define JSONCONS_HAS_MSC_STRTOD_L
104
+ #define JSONCONS_HAS_FOPEN_S
105
+ #endif
106
+
107
+ #ifndef JSONCONS_HAS_CP14
108
+ #if defined(_MSVC_LANG)
109
+ #if _MSVC_LANG >= 201402L
110
+ #define JSONCONS_HAS_CP14
111
+ #endif
112
+ #elif __cplusplus >= 201402L
113
+ #define JSONCONS_HAS_CP14
114
+ #endif
115
+ #endif
116
+
117
+ #if defined(JSONCONS_HAS_STD_FROM_CHARS) && JSONCONS_HAS_STD_FROM_CHARS
118
+ #include <charconv>
119
+ #endif
120
+
121
+ #if !defined(JSONCONS_HAS_2017)
122
+ # if defined(__clang__)
123
+ # if (__cplusplus >= 201703)
124
+ # define JSONCONS_HAS_2017 1
125
+ # endif // (__cplusplus >= 201703)
126
+ # endif // defined(__clang__)
127
+ # if defined(__GNUC__)
128
+ # if (__GNUC__ >= 7)
129
+ # if (__cplusplus >= 201703)
130
+ # define JSONCONS_HAS_2017 1
131
+ # endif // (__cplusplus >= 201703)
132
+ # endif // (__GNUC__ >= 7)
133
+ # endif // defined(__GNUC__)
134
+ # if defined(_MSC_VER)
135
+ # if (_MSC_VER >= 1910 && _MSVC_LANG >= 201703)
136
+ # define JSONCONS_HAS_2017 1
137
+ # endif // (_MSC_VER >= 1910 && MSVC_LANG >= 201703)
138
+ # endif // defined(_MSC_VER)
139
+ #endif
140
+
141
+ #if defined(JSONCONS_HAS_2017)
142
+ #define JSONCONS_NODISCARD [[nodiscard]]
143
+ #define JSONCONS_IF_CONSTEXPR if constexpr
144
+ #else
145
+ #define JSONCONS_NODISCARD
146
+ #define JSONCONS_IF_CONSTEXPR if
147
+ #endif
148
+
149
+ #if !defined(JSONCONS_HAS_STD_STRING_VIEW)
150
+ # if (defined JSONCONS_HAS_2017)
151
+ # if defined(__clang__)
152
+ # if __has_include(<string_view>)
153
+ # define JSONCONS_HAS_STD_STRING_VIEW 1
154
+ # endif // __has_include(<string_view>)
155
+ # else
156
+ # define JSONCONS_HAS_STD_STRING_VIEW 1
157
+ # endif
158
+ # endif // defined(JSONCONS_HAS_2017)
159
+ #endif // !defined(JSONCONS_HAS_STD_STRING_VIEW)
160
+
161
+ #if !defined(JSONCONS_HAS_STD_BYTE)
162
+ # if (defined JSONCONS_HAS_2017)
163
+ # define JSONCONS_HAS_STD_BYTE 1
164
+ # endif // defined(JSONCONS_HAS_2017)
165
+ #endif // !defined(JSONCONS_HAS_STD_BYTE)
166
+
167
+ #if !defined(JSONCONS_HAS_STD_OPTIONAL)
168
+ # if (defined JSONCONS_HAS_2017)
169
+ # if defined(__clang__)
170
+ # if __has_include(<optional>)
171
+ # define JSONCONS_HAS_STD_OPTIONAL 1
172
+ # endif // __has_include(<string_view>)
173
+ # else
174
+ # define JSONCONS_HAS_STD_OPTIONAL 1
175
+ # endif
176
+ # endif // defined(JSONCONS_HAS_2017)
177
+ #endif // !defined(JSONCONS_HAS_STD_OPTIONAL)
178
+
179
+ #if !defined(JSONCONS_HAS_STD_VARIANT)
180
+ # if (defined JSONCONS_HAS_2017)
181
+ # if defined(__clang__)
182
+ # if defined(__APPLE__)
183
+ # if JSONCONS_CLANG_VERSION >= 100001
184
+ # define JSONCONS_HAS_STD_VARIANT 1
185
+ # endif
186
+ # elif __has_include(<variant>)
187
+ # define JSONCONS_HAS_STD_VARIANT 1
188
+ # endif // __has_include(<variant>)
189
+ # else
190
+ # define JSONCONS_HAS_STD_VARIANT 1
191
+ # endif
192
+ # endif // defined(JSONCONS_HAS_2017)
193
+ #endif // !defined(JSONCONS_HAS_STD_VARIANT)
194
+
195
+ #if !defined(JSONCONS_HAS_FILESYSTEM)
196
+ # if (defined JSONCONS_HAS_2017)
197
+ # if defined(__clang__)
198
+ # if __has_include(<filesystem>)
199
+ # define JSONCONS_HAS_FILESYSTEM 1
200
+ # endif // __has_include(<filesystem>)
201
+ # else
202
+ # define JSONCONS_HAS_FILESYSTEM 1
203
+ # endif
204
+ # endif // defined(JSONCONS_HAS_2017)
205
+ #endif // !defined(JSONCONS_HAS_FILESYSTEM)
206
+
207
+ #if (!defined(JSONCONS_NO_EXCEPTIONS))
208
+ // Check if exceptions are disabled.
209
+ # if defined( __cpp_exceptions) && __cpp_exceptions == 0
210
+ # define JSONCONS_NO_EXCEPTIONS 1
211
+ # endif
212
+ #endif
213
+
214
+ #if !defined(JSONCONS_NO_EXCEPTIONS)
215
+
216
+ #if defined(__GNUC__) && !__EXCEPTIONS
217
+ # define JSONCONS_NO_EXCEPTIONS 1
218
+ #elif _MSC_VER
219
+ #if defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0
220
+ # define JSONCONS_NO_EXCEPTIONS 1
221
+ #elif !defined(_CPPUNWIND)
222
+ # define JSONCONS_NO_EXCEPTIONS 1
223
+ #endif
224
+ #endif
225
+ #endif
226
+
227
+ // allow to disable exceptions
228
+ #if !defined(JSONCONS_NO_EXCEPTIONS)
229
+ #define JSONCONS_THROW(exception) throw exception
230
+ #define JSONCONS_RETHROW throw
231
+ #define JSONCONS_TRY try
232
+ #define JSONCONS_CATCH(exception) catch(exception)
233
+ #else
234
+ #define JSONCONS_THROW(exception) std::terminate()
235
+ #define JSONCONS_RETHROW std::terminate()
236
+ #define JSONCONS_TRY if (true)
237
+ #define JSONCONS_CATCH(exception) if (false)
238
+ #endif
239
+
240
+ #if !defined(JSONCONS_HAS_STD_MAKE_UNIQUE)
241
+ #if defined(__clang__) && defined(__cplusplus)
242
+ #if defined(__APPLE__)
243
+ #if __clang_major__ >= 6 && __cplusplus >= 201402L // Xcode 6
244
+ #define JSONCONS_HAS_STD_MAKE_UNIQUE
245
+ #endif
246
+ #elif ((__clang_major__*100 +__clang_minor__) >= 340) && __cplusplus >= 201402L
247
+ #define JSONCONS_HAS_STD_MAKE_UNIQUE
248
+ #endif
249
+ #elif defined(__GNUC__)
250
+ #if (__GNUC__ * 100 + __GNUC_MINOR__) >= 409 && __cplusplus > 201103L
251
+ #define JSONCONS_HAS_STD_MAKE_UNIQUE
252
+ #endif
253
+ #elif defined(_MSC_VER)
254
+ #if _MSC_VER >= 1800
255
+ #define JSONCONS_HAS_STD_MAKE_UNIQUE
256
+ #endif
257
+ #endif
258
+ #endif // !defined(JSONCONS_HAS_STD_MAKE_UNIQUE)
259
+
260
+ #ifndef JSONCONS_HAS_CP14_CONSTEXPR
261
+ #if defined(_MSC_VER)
262
+ #if _MSC_VER >= 1910
263
+ #define JSONCONS_HAS_CP14_CONSTEXPR
264
+ #endif
265
+ #elif defined(__GNUC__)
266
+ #if (__GNUC__ * 100 + __GNUC_MINOR__) >= 600 && __cplusplus >= 201402L
267
+ #define JSONCONS_HAS_CP14_CONSTEXPR
268
+ #endif
269
+ #endif
270
+ #endif
271
+
272
+ #if defined(JSONCONS_HAS_CP14_CONSTEXPR)
273
+ # define JSONCONS_CPP14_CONSTEXPR constexpr
274
+ #else
275
+ # define JSONCONS_CPP14_CONSTEXPR
276
+ #endif
277
+
278
+ // Follows boost
279
+
280
+ // gcc and clang
281
+ #if (defined(__clang__) || defined(__GNUC__)) && defined(__cplusplus)
282
+ #if defined(__SIZEOF_INT128__) && !defined(_MSC_VER)
283
+ # define JSONCONS_HAS_INT128
284
+ #endif
285
+
286
+ #if (defined(linux) || defined(__linux) || defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)) && !defined(_CRAYC)
287
+ #if (__clang_major__ >= 4) && defined(__has_include)
288
+ #if __has_include(<quadmath.h>)
289
+ # define JSONCONS_HAS_FLOAT128
290
+ #endif
291
+ #endif
292
+ #endif
293
+ #endif
294
+
295
+ #if defined(__GNUC__)
296
+ #if defined(_GLIBCXX_USE_FLOAT128)
297
+ # define JSONCONS_HAS_FLOAT128
298
+ #endif
299
+ #endif
300
+
301
+ #if defined(__clang__)
302
+ #if (defined(linux) || defined(__linux) || defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)) && !defined(_CRAYC)
303
+ #if (__clang_major__ >= 4) && defined(__has_include)
304
+ #if __has_include(<quadmath.h>)
305
+ # define JSONCONS_HAS_FLOAT128
306
+ #endif
307
+ #endif
308
+ #endif
309
+ #endif
310
+
311
+ // Follows boost config/detail/suffix.hpp
312
+ #if defined(JSONCONS_HAS_INT128) && defined(__cplusplus)
313
+ namespace jsoncons{
314
+ # ifdef __GNUC__
315
+ __extension__ typedef __int128 int128_type;
316
+ __extension__ typedef unsigned __int128 uint128_type;
317
+ # else
318
+ typedef __int128 int128_type;
319
+ typedef unsigned __int128 uint128_type;
320
+ # endif
321
+ }
322
+ #endif
323
+ #if defined(JSONCONS_HAS_FLOAT128) && defined(__cplusplus)
324
+ namespace jsoncons {
325
+ # ifdef __GNUC__
326
+ __extension__ typedef __float128 float128_type;
327
+ # else
328
+ typedef __float128 float128_type;
329
+ # endif
330
+ }
331
+ #endif
332
+
333
+ #if defined(_MSC_VER) && _MSC_VER <= 1900
334
+ #define JSONCONS_COPY(first,last,d_first) std::copy(first, last, stdext::make_checked_array_iterator(d_first, static_cast<std::size_t>(std::distance(first, last))))
335
+ #else
336
+ #define JSONCONS_COPY(first,last,d_first) std::copy(first, last, d_first)
337
+ #endif
338
+
339
+ #if defined(_MSC_VER) && _MSC_VER <= 1900
340
+ #define JSONCONS_CONSTEXPR
341
+ #else
342
+ #define JSONCONS_CONSTEXPR constexpr
343
+ #endif
344
+
345
+ namespace jsoncons {
346
+
347
+ class assertion_error : public std::runtime_error
348
+ {
349
+ public:
350
+ assertion_error(const std::string& s) noexcept
351
+ : std::runtime_error(s)
352
+ {
353
+ }
354
+ const char* what() const noexcept override
355
+ {
356
+ return std::runtime_error::what();
357
+ }
358
+ };
359
+
360
+ } // namespace jsoncons
361
+
362
+ #define JSONCONS_STR2(x) #x
363
+ #define JSONCONS_STR(x) JSONCONS_STR2(x)
364
+
365
+ #ifdef _DEBUG
366
+ #define JSONCONS_ASSERT(x) if (!(x)) { \
367
+ JSONCONS_THROW(jsoncons::assertion_error("assertion '" #x "' failed at " __FILE__ ":" \
368
+ JSONCONS_STR(__LINE__))); }
369
+ #else
370
+ #define JSONCONS_ASSERT(x) if (!(x)) { \
371
+ JSONCONS_THROW(jsoncons::assertion_error("assertion '" #x "' failed at <> :" \
372
+ JSONCONS_STR( 0 ))); }
373
+ #endif // _DEBUG
374
+
375
+ #endif // JSONCONS_COMPILER_SUPPORT_HPP