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,449 @@
1
+ // Copyright 2018 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_STAJ_ITERATOR_HPP
8
+ #define JSONCONS_STAJ_ITERATOR_HPP
9
+
10
+ #include <new> // placement new
11
+ #include <memory>
12
+ #include <string>
13
+ #include <stdexcept>
14
+ #include <system_error>
15
+ #include <ios>
16
+ #include <iterator> // std::input_iterator_tag
17
+ #include <jsoncons/json_exception.hpp>
18
+ #include <jsoncons/staj_cursor.hpp>
19
+ #include <jsoncons/basic_json.hpp>
20
+ #include <jsoncons/decode_traits.hpp>
21
+
22
+ namespace jsoncons {
23
+
24
+ template <class T, class Json>
25
+ class staj_array_view;
26
+
27
+ template<class T, class Json>
28
+ class staj_array_iterator
29
+ {
30
+ using char_type = typename Json::char_type;
31
+
32
+ staj_array_view<T, Json>* view_;
33
+ std::exception_ptr eptr_;
34
+
35
+ public:
36
+ using value_type = T;
37
+ using difference_type = std::ptrdiff_t;
38
+ using pointer = T*;
39
+ using reference = T&;
40
+ using iterator_category = std::input_iterator_tag;
41
+
42
+ staj_array_iterator() noexcept
43
+ : view_(nullptr)
44
+ {
45
+ }
46
+
47
+ staj_array_iterator(staj_array_view<T, Json>& view)
48
+ : view_(std::addressof(view))
49
+ {
50
+ if (view_->cursor_->current().event_type() == staj_event_type::begin_array)
51
+ {
52
+ next();
53
+ }
54
+ else
55
+ {
56
+ view_->cursor_ = nullptr;
57
+ }
58
+ }
59
+
60
+ staj_array_iterator(staj_array_view<T, Json>& view,
61
+ std::error_code& ec)
62
+ : view_(std::addressof(view))
63
+ {
64
+ if (view_->cursor_->current().event_type() == staj_event_type::begin_array)
65
+ {
66
+ next(ec);
67
+ if (ec) {view_ = nullptr;}
68
+ }
69
+ else
70
+ {
71
+ view_ = nullptr;
72
+ }
73
+ }
74
+
75
+ ~staj_array_iterator() noexcept
76
+ {
77
+ }
78
+
79
+ bool has_value() const
80
+ {
81
+ return !eptr_;
82
+ }
83
+
84
+ const T& operator*() const
85
+ {
86
+ if (eptr_)
87
+ {
88
+ std::rethrow_exception(eptr_);
89
+ }
90
+ else
91
+ {
92
+ return *view_->value_;
93
+ }
94
+ }
95
+
96
+ const T* operator->() const
97
+ {
98
+ if (eptr_)
99
+ {
100
+ std::rethrow_exception(eptr_);
101
+ }
102
+ else
103
+ {
104
+ return view_->value_.operator->();
105
+ }
106
+ }
107
+
108
+ staj_array_iterator& operator++()
109
+ {
110
+ next();
111
+ return *this;
112
+ }
113
+
114
+ staj_array_iterator& increment(std::error_code& ec)
115
+ {
116
+ next(ec);
117
+ if (ec) {view_ = nullptr;}
118
+ return *this;
119
+ }
120
+
121
+ staj_array_iterator operator++(int) // postfix increment
122
+ {
123
+ staj_array_iterator temp(*this);
124
+ next();
125
+ return temp;
126
+ }
127
+
128
+ friend bool operator==(const staj_array_iterator& a, const staj_array_iterator& b)
129
+ {
130
+ return (!a.view_ && !b.view_)
131
+ || (!a.view_ && b.done())
132
+ || (!b.view_ && a.done());
133
+ }
134
+
135
+ friend bool operator!=(const staj_array_iterator& a, const staj_array_iterator& b)
136
+ {
137
+ return !(a == b);
138
+ }
139
+
140
+ private:
141
+
142
+ bool done() const
143
+ {
144
+ return view_->cursor_->done() || view_->cursor_->current().event_type() == staj_event_type::end_array;
145
+ }
146
+
147
+ void next()
148
+ {
149
+ std::error_code ec;
150
+ next(ec);
151
+ if (ec)
152
+ {
153
+ JSONCONS_THROW(ser_error(ec, view_->cursor_->context().line(), view_->cursor_->context().column()));
154
+ }
155
+ }
156
+
157
+ void next(std::error_code& ec)
158
+ {
159
+ using char_type = typename Json::char_type;
160
+
161
+ if (!done())
162
+ {
163
+ view_->cursor_->next(ec);
164
+ if (ec)
165
+ {
166
+ return;
167
+ }
168
+ if (!done())
169
+ {
170
+ eptr_ = std::exception_ptr();
171
+ JSONCONS_TRY
172
+ {
173
+ view_->value_ = decode_traits<T,char_type>::decode(*view_->cursor_, view_->decoder_, ec);
174
+ }
175
+ JSONCONS_CATCH(const conv_error&)
176
+ {
177
+ eptr_ = std::current_exception();
178
+ }
179
+ }
180
+ }
181
+ }
182
+ };
183
+
184
+ template <class Key,class Json,class T=Json>
185
+ class staj_object_view;
186
+
187
+ template <class Key, class T, class Json>
188
+ class staj_object_iterator
189
+ {
190
+ using char_type = typename Json::char_type;
191
+
192
+ staj_object_view<Key, T, Json>* view_;
193
+ std::exception_ptr eptr_;
194
+ public:
195
+ using key_type = std::basic_string<char_type>;
196
+ using value_type = std::pair<key_type,T>;
197
+ using difference_type = std::ptrdiff_t;
198
+ using pointer = value_type*;
199
+ using reference = value_type&;
200
+ using iterator_category = std::input_iterator_tag;
201
+
202
+ public:
203
+
204
+ staj_object_iterator() noexcept
205
+ : view_(nullptr)
206
+ {
207
+ }
208
+
209
+ staj_object_iterator(staj_object_view<Key, T, Json>& view)
210
+ : view_(std::addressof(view))
211
+ {
212
+ if (view_->cursor_->current().event_type() == staj_event_type::begin_object)
213
+ {
214
+ next();
215
+ }
216
+ else
217
+ {
218
+ view_ = nullptr;
219
+ }
220
+ }
221
+
222
+ staj_object_iterator(staj_object_view<Key, T, Json>& view,
223
+ std::error_code& ec)
224
+ : view_(std::addressof(view))
225
+ {
226
+ if (view_->cursor_->current().event_type() == staj_event_type::begin_object)
227
+ {
228
+ next(ec);
229
+ if (ec) {view_ = nullptr;}
230
+ }
231
+ else
232
+ {
233
+ view_ = nullptr;
234
+ }
235
+ }
236
+
237
+ ~staj_object_iterator() noexcept
238
+ {
239
+ }
240
+
241
+ bool has_value() const
242
+ {
243
+ return !eptr_;
244
+ }
245
+
246
+ const value_type& operator*() const
247
+ {
248
+ if (eptr_)
249
+ {
250
+ std::rethrow_exception(eptr_);
251
+ }
252
+ else
253
+ {
254
+ return *view_->key_value_;
255
+ }
256
+ }
257
+
258
+ const value_type* operator->() const
259
+ {
260
+ if (eptr_)
261
+ {
262
+ std::rethrow_exception(eptr_);
263
+ }
264
+ else
265
+ {
266
+ return view_->key_value_.operator->();
267
+ }
268
+ }
269
+
270
+ staj_object_iterator& operator++()
271
+ {
272
+ next();
273
+ return *this;
274
+ }
275
+
276
+ staj_object_iterator& increment(std::error_code& ec)
277
+ {
278
+ next(ec);
279
+ if (ec)
280
+ {
281
+ view_ = nullptr;
282
+ }
283
+ return *this;
284
+ }
285
+
286
+ staj_object_iterator operator++(int) // postfix increment
287
+ {
288
+ staj_object_iterator temp(*this);
289
+ next();
290
+ return temp;
291
+ }
292
+
293
+ friend bool operator==(const staj_object_iterator& a, const staj_object_iterator& b)
294
+ {
295
+ return (!a.view_ && !b.view_)
296
+ || (!a.view_ && b.done())
297
+ || (!b.view_ && a.done());
298
+ }
299
+
300
+ friend bool operator!=(const staj_object_iterator& a, const staj_object_iterator& b)
301
+ {
302
+ return !(a == b);
303
+ }
304
+
305
+ private:
306
+
307
+ bool done() const
308
+ {
309
+ return view_->cursor_->done() || view_->cursor_->current().event_type() == staj_event_type::end_object;
310
+ }
311
+
312
+ void next()
313
+ {
314
+ std::error_code ec;
315
+ next(ec);
316
+ if (ec)
317
+ {
318
+ JSONCONS_THROW(ser_error(ec, view_->cursor_->context().line(), view_->cursor_->context().column()));
319
+ }
320
+ }
321
+
322
+ void next(std::error_code& ec)
323
+ {
324
+ using char_type = typename Json::char_type;
325
+
326
+ view_->cursor_->next(ec);
327
+ if (ec)
328
+ {
329
+ return;
330
+ }
331
+ if (!done())
332
+ {
333
+ JSONCONS_ASSERT(view_->cursor_->current().event_type() == staj_event_type::key);
334
+ auto key = view_->cursor_->current(). template get<key_type>();
335
+ view_->cursor_->next(ec);
336
+ if (ec)
337
+ {
338
+ return;
339
+ }
340
+ if (!done())
341
+ {
342
+ eptr_ = std::exception_ptr();
343
+ JSONCONS_TRY
344
+ {
345
+ view_->key_value_ = value_type(std::move(key),decode_traits<T,char_type>::decode(*view_->cursor_, view_->decoder_, ec));
346
+ }
347
+ JSONCONS_CATCH(const conv_error&)
348
+ {
349
+ eptr_ = std::current_exception();
350
+ }
351
+ }
352
+ }
353
+ }
354
+ };
355
+
356
+ // staj_array_view
357
+
358
+ template <class T, class Json>
359
+ class staj_array_view
360
+ {
361
+ friend class staj_array_iterator<T, Json>;
362
+ public:
363
+ using char_type = typename Json::char_type;
364
+ using iterator = staj_array_iterator<T, Json>;
365
+ private:
366
+ basic_staj_cursor<char_type>* cursor_;
367
+ json_decoder<Json> decoder_;
368
+ jsoncons::optional<T> value_;
369
+ public:
370
+ staj_array_view(basic_staj_cursor<char_type>& cursor)
371
+ : cursor_(std::addressof(cursor))
372
+ {
373
+ }
374
+
375
+ iterator begin()
376
+ {
377
+ return staj_array_iterator<T, Json>(*this);
378
+ }
379
+
380
+ iterator end()
381
+ {
382
+ return staj_array_iterator<T, Json>();
383
+ }
384
+ };
385
+
386
+ // staj_object_view
387
+
388
+ template <class Key, class T, class Json>
389
+ class staj_object_view
390
+ {
391
+ friend class staj_object_iterator<Key,T,Json>;
392
+ public:
393
+ using char_type = typename Json::char_type;
394
+ using iterator = staj_object_iterator<Key,T,Json>;
395
+ using key_type = std::basic_string<char_type>;
396
+ using value_type = std::pair<key_type,T>;
397
+ private:
398
+ basic_staj_cursor<char_type>* cursor_;
399
+ json_decoder<Json> decoder_;
400
+ jsoncons::optional<value_type> key_value_;
401
+ public:
402
+ staj_object_view(basic_staj_cursor<char_type>& cursor)
403
+ : cursor_(std::addressof(cursor))
404
+ {
405
+ }
406
+
407
+ iterator begin()
408
+ {
409
+ return staj_object_iterator<Key,T,Json>(*this);
410
+ }
411
+
412
+ iterator end()
413
+ {
414
+ return staj_object_iterator<Key,T,Json>();
415
+ }
416
+ };
417
+
418
+ template <class T, class CharT, class Json=typename std::conditional<traits_extension::is_basic_json<T>::value,T,basic_json<CharT>>::type>
419
+ staj_array_view<T, Json> staj_array(basic_staj_cursor<CharT>& cursor)
420
+ {
421
+ return staj_array_view<T, Json>(cursor);
422
+ }
423
+
424
+ template <class Key, class T, class CharT, class Json=typename std::conditional<traits_extension::is_basic_json<T>::value,T,basic_json<CharT>>::type>
425
+ staj_object_view<Key, T, Json> staj_object(basic_staj_cursor<CharT>& cursor)
426
+ {
427
+ return staj_object_view<Key, T, Json>(cursor);
428
+ }
429
+
430
+ #if !defined(JSONCONS_NO_DEPRECATED)
431
+ template <class T, class CharT, class Json=typename std::conditional<traits_extension::is_basic_json<T>::value,T,basic_json<CharT>>::type>
432
+ JSONCONS_DEPRECATED_MSG("Instead, use staj_array()")
433
+ staj_array_view<T, Json> make_array_iterator(basic_staj_cursor<CharT>& cursor)
434
+ {
435
+ return staj_array_view<T, Json>(cursor);
436
+ }
437
+
438
+ template <class T, class CharT, class Json=typename std::conditional<traits_extension::is_basic_json<T>::value,T,basic_json<CharT>>::type>
439
+ JSONCONS_DEPRECATED_MSG("Instead, use staj_object()")
440
+ staj_object_view<std::basic_string<CharT>, T, Json> make_object_iterator(basic_staj_cursor<CharT>& cursor)
441
+ {
442
+ return staj_object_view<std::basic_string<CharT>, T, Json>(cursor);
443
+ }
444
+ #endif
445
+
446
+ } // namespace jsoncons
447
+
448
+ #endif
449
+
@@ -0,0 +1,245 @@
1
+ // Copyright 2019 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_TAG_TYPE_HPP
8
+ #define JSONCONS_TAG_TYPE_HPP
9
+
10
+ #include <ostream>
11
+ #include <jsoncons/config/jsoncons_config.hpp>
12
+
13
+ namespace jsoncons {
14
+
15
+ struct null_type
16
+ {
17
+ explicit null_type() = default;
18
+ };
19
+
20
+ struct temp_allocator_arg_t
21
+ {
22
+ explicit temp_allocator_arg_t() = default;
23
+ };
24
+
25
+ constexpr temp_allocator_arg_t temp_allocator_arg{};
26
+
27
+ struct result_allocator_arg_t
28
+ {
29
+ explicit result_allocator_arg_t() = default;
30
+ };
31
+
32
+ constexpr result_allocator_arg_t result_allocator_arg{};
33
+
34
+ struct half_arg_t
35
+ {
36
+ explicit half_arg_t() = default;
37
+ };
38
+
39
+ constexpr half_arg_t half_arg{};
40
+
41
+ struct json_array_arg_t
42
+ {
43
+ explicit json_array_arg_t() = default;
44
+ };
45
+
46
+ constexpr json_array_arg_t json_array_arg{};
47
+
48
+ struct json_object_arg_t
49
+ {
50
+ explicit json_object_arg_t() = default;
51
+ };
52
+
53
+ constexpr json_object_arg_t json_object_arg{};
54
+
55
+ struct byte_string_arg_t
56
+ {
57
+ explicit byte_string_arg_t() = default;
58
+ };
59
+
60
+ constexpr byte_string_arg_t byte_string_arg{};
61
+
62
+ struct json_const_pointer_arg_t
63
+ {
64
+ explicit json_const_pointer_arg_t() = default;
65
+ };
66
+
67
+ constexpr json_const_pointer_arg_t json_const_pointer_arg{};
68
+
69
+ enum class semantic_tag : uint8_t
70
+ {
71
+ none = 0,
72
+ undefined = 0x01,
73
+ datetime = 0x02,
74
+ epoch_second = 0x03,
75
+ epoch_milli = 0x04,
76
+ epoch_nano = 0x05,
77
+ bigint = 0x06,
78
+ bigdec = 0x07,
79
+ bigfloat = 0x08,
80
+ float128 = 0x09,
81
+ base16 = 0x1a,
82
+ base64 = 0x1b,
83
+ base64url = 0x1c,
84
+ uri = 0x0d,
85
+ clamped = 0x0e,
86
+ multi_dim_row_major = 0x0f,
87
+ multi_dim_column_major = 0x10,
88
+ ext = 0x11,
89
+ id = 0x12,
90
+ regex = 0x13,
91
+ code = 0x14
92
+ #if !defined(JSONCONS_NO_DEPRECATED)
93
+ , big_integer = bigint
94
+ , big_decimal = bigdec
95
+ , big_float = bigfloat
96
+ , date_time = datetime
97
+ , timestamp = epoch_second
98
+ #endif
99
+ };
100
+
101
+ template <class CharT>
102
+ std::basic_ostream<CharT>& operator<<(std::basic_ostream<CharT>& os, semantic_tag tag)
103
+ {
104
+ static constexpr const CharT* na_name = JSONCONS_CSTRING_CONSTANT(CharT, "n/a");
105
+ static constexpr const CharT* undefined_name = JSONCONS_CSTRING_CONSTANT(CharT, "undefined");
106
+ static constexpr const CharT* datetime_name = JSONCONS_CSTRING_CONSTANT(CharT, "datetime");
107
+ static constexpr const CharT* epoch_second_name = JSONCONS_CSTRING_CONSTANT(CharT, "epoch-second");
108
+ static constexpr const CharT* epoch_milli_name = JSONCONS_CSTRING_CONSTANT(CharT, "epoch-milli");
109
+ static constexpr const CharT* epoch_nano_name = JSONCONS_CSTRING_CONSTANT(CharT, "epoch-nano");
110
+ static constexpr const CharT* bigint_name = JSONCONS_CSTRING_CONSTANT(CharT, "bigint");
111
+ static constexpr const CharT* bigdec_name = JSONCONS_CSTRING_CONSTANT(CharT, "bigdec");
112
+ static constexpr const CharT* bigfloat_name = JSONCONS_CSTRING_CONSTANT(CharT, "bigfloat");
113
+ static constexpr const CharT* base16_name = JSONCONS_CSTRING_CONSTANT(CharT, "base16");
114
+ static constexpr const CharT* base64_name = JSONCONS_CSTRING_CONSTANT(CharT, "base64");
115
+ static constexpr const CharT* base64url_name = JSONCONS_CSTRING_CONSTANT(CharT, "base64url");
116
+ static constexpr const CharT* uri_name = JSONCONS_CSTRING_CONSTANT(CharT, "uri");
117
+ static constexpr const CharT* clamped_name = JSONCONS_CSTRING_CONSTANT(CharT, "clamped");
118
+ static constexpr const CharT* multi_dim_row_major_name = JSONCONS_CSTRING_CONSTANT(CharT, "multi-dim-row-major");
119
+ static constexpr const CharT* multi_dim_column_major_name = JSONCONS_CSTRING_CONSTANT(CharT, "multi-dim-column-major");
120
+ static constexpr const CharT* ext_name = JSONCONS_CSTRING_CONSTANT(CharT, "ext");
121
+ static constexpr const CharT* id_name = JSONCONS_CSTRING_CONSTANT(CharT, "id");
122
+ static constexpr const CharT* float128_name = JSONCONS_CSTRING_CONSTANT(CharT, "float128");
123
+ static constexpr const CharT* regex_name = JSONCONS_CSTRING_CONSTANT(CharT, "regex");
124
+ static constexpr const CharT* code_name = JSONCONS_CSTRING_CONSTANT(CharT, "code");
125
+
126
+ switch (tag)
127
+ {
128
+ case semantic_tag::none:
129
+ {
130
+ os << na_name;
131
+ break;
132
+ }
133
+ case semantic_tag::undefined:
134
+ {
135
+ os << undefined_name;
136
+ break;
137
+ }
138
+ case semantic_tag::datetime:
139
+ {
140
+ os << datetime_name;
141
+ break;
142
+ }
143
+ case semantic_tag::epoch_second:
144
+ {
145
+ os << epoch_second_name;
146
+ break;
147
+ }
148
+ case semantic_tag::epoch_milli:
149
+ {
150
+ os << epoch_milli_name;
151
+ break;
152
+ }
153
+ case semantic_tag::epoch_nano:
154
+ {
155
+ os << epoch_nano_name;
156
+ break;
157
+ }
158
+ case semantic_tag::bigint:
159
+ {
160
+ os << bigint_name;
161
+ break;
162
+ }
163
+ case semantic_tag::bigdec:
164
+ {
165
+ os << bigdec_name;
166
+ break;
167
+ }
168
+ case semantic_tag::bigfloat:
169
+ {
170
+ os << bigfloat_name;
171
+ break;
172
+ }
173
+ case semantic_tag::float128:
174
+ {
175
+ os << float128_name;
176
+ break;
177
+ }
178
+ case semantic_tag::base16:
179
+ {
180
+ os << base16_name;
181
+ break;
182
+ }
183
+ case semantic_tag::base64:
184
+ {
185
+ os << base64_name;
186
+ break;
187
+ }
188
+ case semantic_tag::base64url:
189
+ {
190
+ os << base64url_name;
191
+ break;
192
+ }
193
+ case semantic_tag::uri:
194
+ {
195
+ os << uri_name;
196
+ break;
197
+ }
198
+ case semantic_tag::clamped:
199
+ {
200
+ os << clamped_name;
201
+ break;
202
+ }
203
+ case semantic_tag::multi_dim_row_major:
204
+ {
205
+ os << multi_dim_row_major_name;
206
+ break;
207
+ }
208
+ case semantic_tag::multi_dim_column_major:
209
+ {
210
+ os << multi_dim_column_major_name;
211
+ break;
212
+ }
213
+ case semantic_tag::ext:
214
+ {
215
+ os << ext_name;
216
+ break;
217
+ }
218
+ case semantic_tag::id:
219
+ {
220
+ os << id_name;
221
+ break;
222
+ }
223
+ case semantic_tag::regex:
224
+ {
225
+ os << regex_name;
226
+ break;
227
+ }
228
+ case semantic_tag::code:
229
+ {
230
+ os << code_name;
231
+ break;
232
+ }
233
+ }
234
+ return os;
235
+ }
236
+
237
+ #if !defined(JSONCONS_NO_DEPRECATED)
238
+ JSONCONS_DEPRECATED_MSG("Instead, use semantic_tag") typedef semantic_tag semantic_tag_type;
239
+ JSONCONS_DEPRECATED_MSG("Instead, use byte_string_arg_t") typedef byte_string_arg_t bstr_arg_t;
240
+ constexpr byte_string_arg_t bstr_arg{};
241
+ #endif
242
+
243
+ }
244
+
245
+ #endif