jsoncons 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ext/jsoncons/extconf.rb +43 -0
- data/ext/jsoncons/jsoncons.cpp +161 -0
- data/ext/jsoncons/jsoncons.h +10 -0
- data/jsoncons.gemspec +44 -0
- data/lib/jsoncons/jsoncons/examples/input/address-book.json +13 -0
- data/lib/jsoncons/jsoncons/examples/input/books.json +28 -0
- data/lib/jsoncons/jsoncons/examples/input/countries.json +7 -0
- data/lib/jsoncons/jsoncons/examples/input/employees.json +30 -0
- data/lib/jsoncons/jsoncons/examples/input/jsonschema/name.json +15 -0
- data/lib/jsoncons/jsoncons/examples/input/multiple-json-objects.json +3 -0
- data/lib/jsoncons/jsoncons/examples/input/sales.csv +6 -0
- data/lib/jsoncons/jsoncons/examples/input/store.json +28 -0
- data/lib/jsoncons/jsoncons/examples/input/tasks.csv +6 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/allocator_holder.hpp +38 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/basic_json.hpp +5905 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/bigint.hpp +1611 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/byte_string.hpp +820 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/binary_config.hpp +226 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/compiler_support.hpp +375 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/jsoncons_config.hpp +309 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/version.hpp +40 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/conv_error.hpp +218 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/decode_json.hpp +209 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/decode_traits.hpp +651 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/endian.hpp +44 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/grisu3.hpp +312 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/optional.hpp +483 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/parse_number.hpp +1133 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/span.hpp +188 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/string_view.hpp +537 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/string_wrapper.hpp +370 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/write_number.hpp +567 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/encode_json.hpp +315 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/encode_traits.hpp +378 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json.hpp +18 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_array.hpp +324 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_content_handler.hpp +12 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_cursor.hpp +448 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_decoder.hpp +420 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_encoder.hpp +1587 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_error.hpp +156 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_exception.hpp +241 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_filter.hpp +653 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_fwd.hpp +23 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_object.hpp +1772 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_options.hpp +862 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_parser.hpp +2900 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_reader.hpp +731 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_traits_macros.hpp +1072 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_traits_macros_deprecated.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_type.hpp +206 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_type_traits.hpp +1830 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_visitor.hpp +1560 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_visitor2.hpp +2079 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/pretty_print.hpp +89 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/ser_context.hpp +62 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/sink.hpp +289 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/source.hpp +777 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/source_adaptor.hpp +148 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/staj2_cursor.hpp +1189 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/staj_cursor.hpp +1254 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/staj_iterator.hpp +449 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/tag_type.hpp +245 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/text_source_adaptor.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/traits_extension.hpp +884 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/typed_array_view.hpp +250 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/unicode_traits.hpp +1330 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/uri.hpp +635 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/value_converter.hpp +340 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson.hpp +23 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_cursor.hpp +320 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_decimal128.hpp +865 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_encoder.hpp +585 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_error.hpp +103 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_oid.hpp +245 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_options.hpp +75 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_parser.hpp +645 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_reader.hpp +92 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_type.hpp +44 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/decode_bson.hpp +201 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/encode_bson.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor.hpp +26 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_cursor.hpp +351 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_cursor2.hpp +265 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_detail.hpp +93 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_encoder.hpp +1766 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_error.hpp +105 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_options.hpp +113 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_parser.hpp +1942 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_reader.hpp +116 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/decode_cbor.hpp +203 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/encode_cbor.hpp +151 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv.hpp +17 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_cursor.hpp +358 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_encoder.hpp +954 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_error.hpp +85 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_options.hpp +973 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_parser.hpp +2099 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_reader.hpp +348 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_serializer.hpp +12 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/decode_csv.hpp +208 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/encode_csv.hpp +122 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jmespath/jmespath.hpp +5215 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jmespath/jmespath_error.hpp +215 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpatch/jsonpatch.hpp +579 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpatch/jsonpatch_error.hpp +121 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/expression.hpp +3329 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/flatten.hpp +432 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/json_location.hpp +445 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/json_query.hpp +115 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath.hpp +13 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_error.hpp +240 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp +2612 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp +1322 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpointer/jsonpointer.hpp +1577 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpointer/jsonpointer_error.hpp +119 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/format_validator.hpp +968 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/json_validator.hpp +120 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema.hpp +13 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema_error.hpp +105 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema_version.hpp +18 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/keyword_validator.hpp +1745 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/keyword_validator_factory.hpp +556 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_draft7.hpp +198 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_location.hpp +200 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_version.hpp +35 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/subschema.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/mergepatch/mergepatch.hpp +103 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/decode_msgpack.hpp +202 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/encode_msgpack.hpp +142 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack.hpp +24 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_cursor.hpp +343 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_cursor2.hpp +259 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_encoder.hpp +753 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_error.hpp +94 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_options.hpp +74 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_parser.hpp +748 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_reader.hpp +116 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_type.hpp +63 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/decode_ubjson.hpp +201 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/encode_ubjson.hpp +142 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson.hpp +23 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_cursor.hpp +307 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_encoder.hpp +502 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_error.hpp +100 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_options.hpp +87 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_parser.hpp +880 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_reader.hpp +92 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_type.hpp +43 -0
- data/lib/jsoncons/version.rb +5 -0
- data/lib/jsoncons.rb +33 -0
- data/test/jsoncons_test.rb +108 -0
- data/test/test_helper.rb +7 -0
- metadata +268 -0
|
@@ -0,0 +1,1189 @@
|
|
|
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_STAJ2_CURSOR_HPP
|
|
8
|
+
#define JSONCONS_STAJ2_CURSOR_HPP
|
|
9
|
+
|
|
10
|
+
#include <memory> // std::allocator
|
|
11
|
+
#include <string>
|
|
12
|
+
#include <stdexcept>
|
|
13
|
+
#include <system_error>
|
|
14
|
+
#include <ios>
|
|
15
|
+
#include <type_traits> // std::enable_if
|
|
16
|
+
#include <array> // std::array
|
|
17
|
+
#include <functional> // std::function
|
|
18
|
+
#include <jsoncons/json_exception.hpp>
|
|
19
|
+
#include <jsoncons/json_visitor2.hpp>
|
|
20
|
+
#include <jsoncons/bigint.hpp>
|
|
21
|
+
#include <jsoncons/json_parser.hpp>
|
|
22
|
+
#include <jsoncons/ser_context.hpp>
|
|
23
|
+
#include <jsoncons/sink.hpp>
|
|
24
|
+
#include <jsoncons/detail/write_number.hpp>
|
|
25
|
+
#include <jsoncons/json_type_traits.hpp>
|
|
26
|
+
#include <jsoncons/typed_array_view.hpp>
|
|
27
|
+
#include <jsoncons/value_converter.hpp>
|
|
28
|
+
|
|
29
|
+
namespace jsoncons {
|
|
30
|
+
|
|
31
|
+
enum class staj2_event_type
|
|
32
|
+
{
|
|
33
|
+
begin_array,
|
|
34
|
+
end_array,
|
|
35
|
+
begin_object,
|
|
36
|
+
end_object,
|
|
37
|
+
string_value,
|
|
38
|
+
byte_string_value,
|
|
39
|
+
null_value,
|
|
40
|
+
bool_value,
|
|
41
|
+
int64_value,
|
|
42
|
+
uint64_value,
|
|
43
|
+
half_value,
|
|
44
|
+
double_value
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
template <class CharT>
|
|
48
|
+
std::basic_ostream<CharT>& operator<<(std::basic_ostream<CharT>& os, staj2_event_type tag)
|
|
49
|
+
{
|
|
50
|
+
static constexpr const CharT* begin_array_name = JSONCONS_CSTRING_CONSTANT(CharT, "begin_array");
|
|
51
|
+
static constexpr const CharT* end_array_name = JSONCONS_CSTRING_CONSTANT(CharT, "end_array");
|
|
52
|
+
static constexpr const CharT* begin_object_name = JSONCONS_CSTRING_CONSTANT(CharT, "begin_object");
|
|
53
|
+
static constexpr const CharT* end_object_name = JSONCONS_CSTRING_CONSTANT(CharT, "end_object");
|
|
54
|
+
static constexpr const CharT* string_value_name = JSONCONS_CSTRING_CONSTANT(CharT, "string_value");
|
|
55
|
+
static constexpr const CharT* byte_string_value_name = JSONCONS_CSTRING_CONSTANT(CharT, "byte_string_value");
|
|
56
|
+
static constexpr const CharT* null_value_name = JSONCONS_CSTRING_CONSTANT(CharT, "null_value");
|
|
57
|
+
static constexpr const CharT* bool_value_name = JSONCONS_CSTRING_CONSTANT(CharT, "bool_value");
|
|
58
|
+
static constexpr const CharT* uint64_value_name = JSONCONS_CSTRING_CONSTANT(CharT, "uint64_value");
|
|
59
|
+
static constexpr const CharT* int64_value_name = JSONCONS_CSTRING_CONSTANT(CharT, "int64_value");
|
|
60
|
+
static constexpr const CharT* half_value_name = JSONCONS_CSTRING_CONSTANT(CharT, "half_value");
|
|
61
|
+
static constexpr const CharT* double_value_name = JSONCONS_CSTRING_CONSTANT(CharT, "double_value");
|
|
62
|
+
|
|
63
|
+
switch (tag)
|
|
64
|
+
{
|
|
65
|
+
case staj2_event_type::begin_array:
|
|
66
|
+
{
|
|
67
|
+
os << begin_array_name;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case staj2_event_type::end_array:
|
|
71
|
+
{
|
|
72
|
+
os << end_array_name;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case staj2_event_type::begin_object:
|
|
76
|
+
{
|
|
77
|
+
os << begin_object_name;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
case staj2_event_type::end_object:
|
|
81
|
+
{
|
|
82
|
+
os << end_object_name;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
case staj2_event_type::string_value:
|
|
86
|
+
{
|
|
87
|
+
os << string_value_name;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case staj2_event_type::byte_string_value:
|
|
91
|
+
{
|
|
92
|
+
os << byte_string_value_name;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case staj2_event_type::null_value:
|
|
96
|
+
{
|
|
97
|
+
os << null_value_name;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
case staj2_event_type::bool_value:
|
|
101
|
+
{
|
|
102
|
+
os << bool_value_name;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case staj2_event_type::int64_value:
|
|
106
|
+
{
|
|
107
|
+
os << int64_value_name;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
case staj2_event_type::uint64_value:
|
|
111
|
+
{
|
|
112
|
+
os << uint64_value_name;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
case staj2_event_type::half_value:
|
|
116
|
+
{
|
|
117
|
+
os << half_value_name;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
case staj2_event_type::double_value:
|
|
121
|
+
{
|
|
122
|
+
os << double_value_name;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return os;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
template<class CharT>
|
|
130
|
+
class basic_staj2_event
|
|
131
|
+
{
|
|
132
|
+
staj2_event_type event_type_;
|
|
133
|
+
semantic_tag tag_;
|
|
134
|
+
uint64_t ext_tag_;
|
|
135
|
+
union
|
|
136
|
+
{
|
|
137
|
+
bool bool_value_;
|
|
138
|
+
int64_t int64_value_;
|
|
139
|
+
uint64_t uint64_value_;
|
|
140
|
+
uint16_t half_value_;
|
|
141
|
+
double double_value_;
|
|
142
|
+
const CharT* string_data_;
|
|
143
|
+
const uint8_t* byte_string_data_;
|
|
144
|
+
} value_;
|
|
145
|
+
std::size_t length_;
|
|
146
|
+
public:
|
|
147
|
+
using string_view_type = jsoncons::basic_string_view<CharT>;
|
|
148
|
+
|
|
149
|
+
basic_staj2_event(staj2_event_type event_type, semantic_tag tag = semantic_tag::none)
|
|
150
|
+
: event_type_(event_type), tag_(tag), ext_tag_(0), value_(), length_(0)
|
|
151
|
+
{
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
basic_staj2_event(staj2_event_type event_type, std::size_t length, semantic_tag tag = semantic_tag::none)
|
|
155
|
+
: event_type_(event_type), tag_(tag), ext_tag_(0), value_(), length_(length)
|
|
156
|
+
{
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
basic_staj2_event(null_type, semantic_tag tag)
|
|
160
|
+
: event_type_(staj2_event_type::null_value), tag_(tag), ext_tag_(0), value_(), length_(0)
|
|
161
|
+
{
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
basic_staj2_event(bool value, semantic_tag tag)
|
|
165
|
+
: event_type_(staj2_event_type::bool_value), tag_(tag), ext_tag_(0), length_(0)
|
|
166
|
+
{
|
|
167
|
+
value_.bool_value_ = value;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
basic_staj2_event(int64_t value, semantic_tag tag)
|
|
171
|
+
: event_type_(staj2_event_type::int64_value), tag_(tag), ext_tag_(0), length_(0)
|
|
172
|
+
{
|
|
173
|
+
value_.int64_value_ = value;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
basic_staj2_event(uint64_t value, semantic_tag tag)
|
|
177
|
+
: event_type_(staj2_event_type::uint64_value), tag_(tag), ext_tag_(0), length_(0)
|
|
178
|
+
{
|
|
179
|
+
value_.uint64_value_ = value;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
basic_staj2_event(half_arg_t, uint16_t value, semantic_tag tag)
|
|
183
|
+
: event_type_(staj2_event_type::half_value), tag_(tag), ext_tag_(0), length_(0)
|
|
184
|
+
{
|
|
185
|
+
value_.half_value_ = value;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
basic_staj2_event(double value, semantic_tag tag)
|
|
189
|
+
: event_type_(staj2_event_type::double_value), tag_(tag), ext_tag_(0), length_(0)
|
|
190
|
+
{
|
|
191
|
+
value_.double_value_ = value;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
basic_staj2_event(const string_view_type& s,
|
|
195
|
+
staj2_event_type event_type,
|
|
196
|
+
semantic_tag tag = semantic_tag::none)
|
|
197
|
+
: event_type_(event_type), tag_(tag), ext_tag_(0), length_(s.length())
|
|
198
|
+
{
|
|
199
|
+
value_.string_data_ = s.data();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
basic_staj2_event(const byte_string_view& s,
|
|
203
|
+
staj2_event_type event_type,
|
|
204
|
+
semantic_tag tag = semantic_tag::none)
|
|
205
|
+
: event_type_(event_type), tag_(tag), ext_tag_(0), length_(s.size())
|
|
206
|
+
{
|
|
207
|
+
value_.byte_string_data_ = s.data();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
basic_staj2_event(const byte_string_view& s,
|
|
211
|
+
staj2_event_type event_type,
|
|
212
|
+
uint64_t ext_tag)
|
|
213
|
+
: event_type_(event_type), tag_(semantic_tag::ext), ext_tag_(ext_tag), length_(s.size())
|
|
214
|
+
{
|
|
215
|
+
value_.byte_string_data_ = s.data();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
std::size_t size() const
|
|
219
|
+
{
|
|
220
|
+
return length_;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
template <class T>
|
|
224
|
+
T get() const
|
|
225
|
+
{
|
|
226
|
+
std::error_code ec;
|
|
227
|
+
T val = get<T>(ec);
|
|
228
|
+
if (ec)
|
|
229
|
+
{
|
|
230
|
+
JSONCONS_THROW(ser_error(ec));
|
|
231
|
+
}
|
|
232
|
+
return val;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
template<class T, class CharT_ = CharT>
|
|
236
|
+
typename std::enable_if<traits_extension::is_string<T>::value && std::is_same<typename T::value_type, CharT_>::value, T>::type
|
|
237
|
+
get(std::error_code& ec) const
|
|
238
|
+
{
|
|
239
|
+
switch (event_type_)
|
|
240
|
+
{
|
|
241
|
+
case staj2_event_type::string_value:
|
|
242
|
+
{
|
|
243
|
+
value_converter<jsoncons::basic_string_view<CharT>,T> converter;
|
|
244
|
+
return converter.convert(jsoncons::basic_string_view<CharT>(value_.string_data_, length_), tag(), ec);
|
|
245
|
+
}
|
|
246
|
+
case staj2_event_type::byte_string_value:
|
|
247
|
+
{
|
|
248
|
+
value_converter<byte_string_view,T> converter;
|
|
249
|
+
return converter.convert(byte_string_view(value_.byte_string_data_,length_),tag(),ec);
|
|
250
|
+
}
|
|
251
|
+
case staj2_event_type::uint64_value:
|
|
252
|
+
{
|
|
253
|
+
value_converter<uint64_t,T> converter;
|
|
254
|
+
return converter.convert(value_.uint64_value_, tag(), ec);
|
|
255
|
+
}
|
|
256
|
+
case staj2_event_type::int64_value:
|
|
257
|
+
{
|
|
258
|
+
value_converter<int64_t,T> converter;
|
|
259
|
+
return converter.convert(value_.int64_value_, tag(), ec);
|
|
260
|
+
}
|
|
261
|
+
case staj2_event_type::half_value:
|
|
262
|
+
{
|
|
263
|
+
value_converter<half_arg_t,T> converter;
|
|
264
|
+
return converter.convert(value_.half_value_, tag(), ec);
|
|
265
|
+
}
|
|
266
|
+
case staj2_event_type::double_value:
|
|
267
|
+
{
|
|
268
|
+
value_converter<double,T> converter;
|
|
269
|
+
return converter.convert(value_.double_value_, tag(), ec);
|
|
270
|
+
}
|
|
271
|
+
case staj2_event_type::bool_value:
|
|
272
|
+
{
|
|
273
|
+
value_converter<bool,T> converter;
|
|
274
|
+
return converter.convert(value_.bool_value_,tag(),ec);
|
|
275
|
+
}
|
|
276
|
+
case staj2_event_type::null_value:
|
|
277
|
+
{
|
|
278
|
+
value_converter<null_type,T> converter;
|
|
279
|
+
return converter.convert(tag(),ec);
|
|
280
|
+
}
|
|
281
|
+
default:
|
|
282
|
+
{
|
|
283
|
+
ec = conv_errc::not_string;
|
|
284
|
+
return T{};
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
template<class T, class CharT_ = CharT>
|
|
290
|
+
typename std::enable_if<traits_extension::is_string_view<T>::value && std::is_same<typename T::value_type, CharT_>::value, T>::type
|
|
291
|
+
get(std::error_code& ec) const
|
|
292
|
+
{
|
|
293
|
+
T s;
|
|
294
|
+
switch (event_type_)
|
|
295
|
+
{
|
|
296
|
+
case staj2_event_type::string_value:
|
|
297
|
+
s = T(value_.string_data_, length_);
|
|
298
|
+
break;
|
|
299
|
+
default:
|
|
300
|
+
ec = conv_errc::not_string_view;
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
return s;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
template<class T>
|
|
307
|
+
typename std::enable_if<std::is_same<T, byte_string_view>::value, T>::type
|
|
308
|
+
get(std::error_code& ec) const
|
|
309
|
+
{
|
|
310
|
+
T s;
|
|
311
|
+
switch (event_type_)
|
|
312
|
+
{
|
|
313
|
+
case staj2_event_type::byte_string_value:
|
|
314
|
+
s = T(value_.byte_string_data_, length_);
|
|
315
|
+
break;
|
|
316
|
+
default:
|
|
317
|
+
ec = conv_errc::not_byte_string_view;
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
return s;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
template<class T>
|
|
324
|
+
typename std::enable_if<traits_extension::is_list_like<T>::value &&
|
|
325
|
+
std::is_same<typename T::value_type,uint8_t>::value,T>::type
|
|
326
|
+
get(std::error_code& ec) const
|
|
327
|
+
{
|
|
328
|
+
switch (event_type_)
|
|
329
|
+
{
|
|
330
|
+
case staj2_event_type::byte_string_value:
|
|
331
|
+
{
|
|
332
|
+
value_converter<byte_string_view,T> converter;
|
|
333
|
+
return converter.convert(byte_string_view(value_.byte_string_data_, length_), tag(), ec);
|
|
334
|
+
}
|
|
335
|
+
case staj2_event_type::string_value:
|
|
336
|
+
{
|
|
337
|
+
value_converter<basic_string_view<CharT>,T> converter;
|
|
338
|
+
return converter.convert(jsoncons::basic_string_view<CharT>(value_.string_data_, length_), tag(), ec);
|
|
339
|
+
}
|
|
340
|
+
default:
|
|
341
|
+
ec = conv_errc::not_byte_string;
|
|
342
|
+
return T{};
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
template <class IntegerType>
|
|
347
|
+
typename std::enable_if<traits_extension::is_integer<IntegerType>::value, IntegerType>::type
|
|
348
|
+
get(std::error_code& ec) const
|
|
349
|
+
{
|
|
350
|
+
switch (event_type_)
|
|
351
|
+
{
|
|
352
|
+
case staj2_event_type::string_value:
|
|
353
|
+
{
|
|
354
|
+
IntegerType val;
|
|
355
|
+
auto result = jsoncons::detail::to_integer(value_.string_data_, length_, val);
|
|
356
|
+
if (!result)
|
|
357
|
+
{
|
|
358
|
+
ec = conv_errc::not_integer;
|
|
359
|
+
return IntegerType();
|
|
360
|
+
}
|
|
361
|
+
return val;
|
|
362
|
+
}
|
|
363
|
+
case staj2_event_type::half_value:
|
|
364
|
+
return static_cast<IntegerType>(value_.half_value_);
|
|
365
|
+
case staj2_event_type::double_value:
|
|
366
|
+
return static_cast<IntegerType>(value_.double_value_);
|
|
367
|
+
case staj2_event_type::int64_value:
|
|
368
|
+
return static_cast<IntegerType>(value_.int64_value_);
|
|
369
|
+
case staj2_event_type::uint64_value:
|
|
370
|
+
return static_cast<IntegerType>(value_.uint64_value_);
|
|
371
|
+
case staj2_event_type::bool_value:
|
|
372
|
+
return static_cast<IntegerType>(value_.bool_value_ ? 1 : 0);
|
|
373
|
+
default:
|
|
374
|
+
ec = conv_errc::not_integer;
|
|
375
|
+
return IntegerType();
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
template<class T>
|
|
380
|
+
typename std::enable_if<std::is_floating_point<T>::value, T>::type
|
|
381
|
+
get(std::error_code& ec) const
|
|
382
|
+
{
|
|
383
|
+
return static_cast<T>(as_double(ec));
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
template<class T>
|
|
387
|
+
typename std::enable_if<traits_extension::is_bool<T>::value, T>::type
|
|
388
|
+
get(std::error_code& ec) const
|
|
389
|
+
{
|
|
390
|
+
return as_bool(ec);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
staj2_event_type event_type() const noexcept { return event_type_; }
|
|
394
|
+
|
|
395
|
+
semantic_tag tag() const noexcept { return tag_; }
|
|
396
|
+
|
|
397
|
+
uint64_t ext_tag() const noexcept { return ext_tag_; }
|
|
398
|
+
|
|
399
|
+
private:
|
|
400
|
+
|
|
401
|
+
double as_double(std::error_code& ec) const
|
|
402
|
+
{
|
|
403
|
+
switch (event_type_)
|
|
404
|
+
{
|
|
405
|
+
case staj2_event_type::string_value:
|
|
406
|
+
{
|
|
407
|
+
jsoncons::detail::chars_to f;
|
|
408
|
+
return f(value_.string_data_, length_);
|
|
409
|
+
}
|
|
410
|
+
case staj2_event_type::double_value:
|
|
411
|
+
return value_.double_value_;
|
|
412
|
+
case staj2_event_type::int64_value:
|
|
413
|
+
return static_cast<double>(value_.int64_value_);
|
|
414
|
+
case staj2_event_type::uint64_value:
|
|
415
|
+
return static_cast<double>(value_.uint64_value_);
|
|
416
|
+
case staj2_event_type::half_value:
|
|
417
|
+
{
|
|
418
|
+
double x = binary::decode_half(value_.half_value_);
|
|
419
|
+
return static_cast<double>(x);
|
|
420
|
+
}
|
|
421
|
+
default:
|
|
422
|
+
ec = conv_errc::not_double;
|
|
423
|
+
return double();
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
bool as_bool(std::error_code& ec) const
|
|
428
|
+
{
|
|
429
|
+
switch (event_type_)
|
|
430
|
+
{
|
|
431
|
+
case staj2_event_type::bool_value:
|
|
432
|
+
return value_.bool_value_;
|
|
433
|
+
case staj2_event_type::double_value:
|
|
434
|
+
return value_.double_value_ != 0.0;
|
|
435
|
+
case staj2_event_type::int64_value:
|
|
436
|
+
return value_.int64_value_ != 0;
|
|
437
|
+
case staj2_event_type::uint64_value:
|
|
438
|
+
return value_.uint64_value_ != 0;
|
|
439
|
+
default:
|
|
440
|
+
ec = conv_errc::not_bool;
|
|
441
|
+
return bool();
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
public:
|
|
445
|
+
friend bool send_value_event(const basic_staj2_event<CharT>& ev,
|
|
446
|
+
basic_json_visitor2<CharT>& visitor,
|
|
447
|
+
const ser_context& context,
|
|
448
|
+
std::error_code& ec)
|
|
449
|
+
{
|
|
450
|
+
switch (ev.event_type())
|
|
451
|
+
{
|
|
452
|
+
case staj2_event_type::begin_array:
|
|
453
|
+
return visitor.begin_array(ev.tag(), context);
|
|
454
|
+
case staj2_event_type::end_array:
|
|
455
|
+
return visitor.end_array(context);
|
|
456
|
+
case staj2_event_type::begin_object:
|
|
457
|
+
return visitor.begin_object(ev.tag(), context, ec);
|
|
458
|
+
case staj2_event_type::end_object:
|
|
459
|
+
return visitor.end_object(context, ec);
|
|
460
|
+
case staj2_event_type::string_value:
|
|
461
|
+
return visitor.string_value(string_view_type(ev.value_.string_data_,ev.length_), ev.tag(), context);
|
|
462
|
+
case staj2_event_type::byte_string_value:
|
|
463
|
+
return visitor.byte_string_value(byte_string_view(ev.value_.byte_string_data_,ev.length_), ev.tag(), context);
|
|
464
|
+
case staj2_event_type::null_value:
|
|
465
|
+
return visitor.null_value(ev.tag(), context);
|
|
466
|
+
case staj2_event_type::bool_value:
|
|
467
|
+
return visitor.bool_value(ev.value_.bool_value_, ev.tag(), context);
|
|
468
|
+
case staj2_event_type::int64_value:
|
|
469
|
+
return visitor.int64_value(ev.value_.int64_value_, ev.tag(), context);
|
|
470
|
+
case staj2_event_type::uint64_value:
|
|
471
|
+
return visitor.uint64_value(ev.value_.uint64_value_, ev.tag(), context);
|
|
472
|
+
case staj2_event_type::half_value:
|
|
473
|
+
return visitor.half_value(ev.value_.half_value_, ev.tag(), context);
|
|
474
|
+
case staj2_event_type::double_value:
|
|
475
|
+
return visitor.double_value(ev.value_.double_value_, ev.tag(), context);
|
|
476
|
+
default:
|
|
477
|
+
return false;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
// basic_staj2_visitor
|
|
483
|
+
|
|
484
|
+
enum class staj2_cursor_state
|
|
485
|
+
{
|
|
486
|
+
typed_array = 1,
|
|
487
|
+
multi_dim,
|
|
488
|
+
shape
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
template <class CharT>
|
|
492
|
+
class basic_staj2_visitor : public basic_json_visitor2<CharT>
|
|
493
|
+
{
|
|
494
|
+
using super_type = basic_json_visitor2<CharT>;
|
|
495
|
+
public:
|
|
496
|
+
using char_type = CharT;
|
|
497
|
+
using typename super_type::string_view_type;
|
|
498
|
+
private:
|
|
499
|
+
std::function<bool(const basic_staj2_event<CharT>&, const ser_context&)> pred_;
|
|
500
|
+
basic_staj2_event<CharT> event_;
|
|
501
|
+
|
|
502
|
+
staj2_cursor_state state_;
|
|
503
|
+
typed_array_view data_;
|
|
504
|
+
jsoncons::span<const size_t> shape_;
|
|
505
|
+
std::size_t index_;
|
|
506
|
+
public:
|
|
507
|
+
basic_staj2_visitor()
|
|
508
|
+
: pred_(accept), event_(staj2_event_type::null_value),
|
|
509
|
+
state_(), data_(), shape_(), index_(0)
|
|
510
|
+
{
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
basic_staj2_visitor(std::function<bool(const basic_staj2_event<CharT>&, const ser_context&)> pred)
|
|
514
|
+
: pred_(pred), event_(staj2_event_type::null_value),
|
|
515
|
+
state_(), data_(), shape_(), index_(0)
|
|
516
|
+
{
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
void reset()
|
|
520
|
+
{
|
|
521
|
+
event_ = staj2_event_type::null_value;
|
|
522
|
+
state_ = {};
|
|
523
|
+
data_ = {};
|
|
524
|
+
shape_ = {};
|
|
525
|
+
index_ = 0;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
const basic_staj2_event<CharT>& event() const
|
|
529
|
+
{
|
|
530
|
+
return event_;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
bool in_available() const
|
|
534
|
+
{
|
|
535
|
+
return state_ != staj2_cursor_state();
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
void send_available(std::error_code& ec)
|
|
539
|
+
{
|
|
540
|
+
switch (state_)
|
|
541
|
+
{
|
|
542
|
+
case staj2_cursor_state::typed_array:
|
|
543
|
+
advance_typed_array(ec);
|
|
544
|
+
break;
|
|
545
|
+
case staj2_cursor_state::multi_dim:
|
|
546
|
+
case staj2_cursor_state::shape:
|
|
547
|
+
advance_multi_dim(ec);
|
|
548
|
+
break;
|
|
549
|
+
default:
|
|
550
|
+
break;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
bool is_typed_array() const
|
|
555
|
+
{
|
|
556
|
+
return data_.type() != typed_array_type();
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
staj2_cursor_state state() const
|
|
560
|
+
{
|
|
561
|
+
return state_;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
void advance_typed_array(std::error_code& ec)
|
|
565
|
+
{
|
|
566
|
+
if (is_typed_array())
|
|
567
|
+
{
|
|
568
|
+
if (index_ < data_.size())
|
|
569
|
+
{
|
|
570
|
+
switch (data_.type())
|
|
571
|
+
{
|
|
572
|
+
case typed_array_type::uint8_value:
|
|
573
|
+
{
|
|
574
|
+
this->uint64_value(data_.data(uint8_array_arg)[index_], semantic_tag::none, ser_context(), ec);
|
|
575
|
+
break;
|
|
576
|
+
}
|
|
577
|
+
case typed_array_type::uint16_value:
|
|
578
|
+
{
|
|
579
|
+
this->uint64_value(data_.data(uint16_array_arg)[index_], semantic_tag::none, ser_context(), ec);
|
|
580
|
+
break;
|
|
581
|
+
}
|
|
582
|
+
case typed_array_type::uint32_value:
|
|
583
|
+
{
|
|
584
|
+
this->uint64_value(data_.data(uint32_array_arg)[index_], semantic_tag::none, ser_context(), ec);
|
|
585
|
+
break;
|
|
586
|
+
}
|
|
587
|
+
case typed_array_type::uint64_value:
|
|
588
|
+
{
|
|
589
|
+
this->uint64_value(data_.data(uint64_array_arg)[index_], semantic_tag::none, ser_context(), ec);
|
|
590
|
+
break;
|
|
591
|
+
}
|
|
592
|
+
case typed_array_type::int8_value:
|
|
593
|
+
{
|
|
594
|
+
this->int64_value(data_.data(int8_array_arg)[index_], semantic_tag::none, ser_context(), ec);
|
|
595
|
+
break;
|
|
596
|
+
}
|
|
597
|
+
case typed_array_type::int16_value:
|
|
598
|
+
{
|
|
599
|
+
this->int64_value(data_.data(int16_array_arg)[index_], semantic_tag::none, ser_context(), ec);
|
|
600
|
+
break;
|
|
601
|
+
}
|
|
602
|
+
case typed_array_type::int32_value:
|
|
603
|
+
{
|
|
604
|
+
this->int64_value(data_.data(int32_array_arg)[index_], semantic_tag::none, ser_context(), ec);
|
|
605
|
+
break;
|
|
606
|
+
}
|
|
607
|
+
case typed_array_type::int64_value:
|
|
608
|
+
{
|
|
609
|
+
this->int64_value(data_.data(int64_array_arg)[index_], semantic_tag::none, ser_context(), ec);
|
|
610
|
+
break;
|
|
611
|
+
}
|
|
612
|
+
case typed_array_type::half_value:
|
|
613
|
+
{
|
|
614
|
+
this->half_value(data_.data(half_array_arg)[index_], semantic_tag::none, ser_context(), ec);
|
|
615
|
+
break;
|
|
616
|
+
}
|
|
617
|
+
case typed_array_type::float_value:
|
|
618
|
+
{
|
|
619
|
+
this->double_value(data_.data(float_array_arg)[index_], semantic_tag::none, ser_context(), ec);
|
|
620
|
+
break;
|
|
621
|
+
}
|
|
622
|
+
case typed_array_type::double_value:
|
|
623
|
+
{
|
|
624
|
+
this->double_value(data_.data(double_array_arg)[index_], semantic_tag::none, ser_context(), ec);
|
|
625
|
+
break;
|
|
626
|
+
}
|
|
627
|
+
default:
|
|
628
|
+
break;
|
|
629
|
+
}
|
|
630
|
+
++index_;
|
|
631
|
+
}
|
|
632
|
+
else
|
|
633
|
+
{
|
|
634
|
+
this->end_array();
|
|
635
|
+
state_ = staj2_cursor_state();
|
|
636
|
+
data_ = typed_array_view();
|
|
637
|
+
index_ = 0;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
void advance_multi_dim(std::error_code& ec)
|
|
643
|
+
{
|
|
644
|
+
if (shape_.size() != 0)
|
|
645
|
+
{
|
|
646
|
+
if (state_ == staj2_cursor_state::multi_dim)
|
|
647
|
+
{
|
|
648
|
+
this->begin_array(shape_.size(), semantic_tag::none, ser_context(), ec);
|
|
649
|
+
state_ = staj2_cursor_state::shape;
|
|
650
|
+
}
|
|
651
|
+
else if (index_ < shape_.size())
|
|
652
|
+
{
|
|
653
|
+
this->uint64_value(shape_[index_], semantic_tag::none, ser_context(), ec);
|
|
654
|
+
++index_;
|
|
655
|
+
}
|
|
656
|
+
else
|
|
657
|
+
{
|
|
658
|
+
state_ = staj2_cursor_state();
|
|
659
|
+
this->end_array(ser_context(), ec);
|
|
660
|
+
shape_ = jsoncons::span<const size_t>();
|
|
661
|
+
index_ = 0;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
bool dump(basic_json_visitor2<CharT>& visitor, const ser_context& context, std::error_code& ec)
|
|
667
|
+
{
|
|
668
|
+
bool more = true;
|
|
669
|
+
if (is_typed_array())
|
|
670
|
+
{
|
|
671
|
+
if (index_ != 0)
|
|
672
|
+
{
|
|
673
|
+
more = send_value_event(event(), visitor, context, ec);
|
|
674
|
+
while (more && is_typed_array())
|
|
675
|
+
{
|
|
676
|
+
if (index_ < data_.size())
|
|
677
|
+
{
|
|
678
|
+
switch (data_.type())
|
|
679
|
+
{
|
|
680
|
+
case typed_array_type::uint8_value:
|
|
681
|
+
{
|
|
682
|
+
more = visitor.uint64_value(data_.data(uint8_array_arg)[index_]);
|
|
683
|
+
break;
|
|
684
|
+
}
|
|
685
|
+
case typed_array_type::uint16_value:
|
|
686
|
+
{
|
|
687
|
+
more = visitor.uint64_value(data_.data(uint16_array_arg)[index_]);
|
|
688
|
+
break;
|
|
689
|
+
}
|
|
690
|
+
case typed_array_type::uint32_value:
|
|
691
|
+
{
|
|
692
|
+
more = visitor.uint64_value(data_.data(uint32_array_arg)[index_]);
|
|
693
|
+
break;
|
|
694
|
+
}
|
|
695
|
+
case typed_array_type::uint64_value:
|
|
696
|
+
{
|
|
697
|
+
more = visitor.uint64_value(data_.data(uint64_array_arg)[index_]);
|
|
698
|
+
break;
|
|
699
|
+
}
|
|
700
|
+
case typed_array_type::int8_value:
|
|
701
|
+
{
|
|
702
|
+
more = visitor.int64_value(data_.data(int8_array_arg)[index_]);
|
|
703
|
+
break;
|
|
704
|
+
}
|
|
705
|
+
case typed_array_type::int16_value:
|
|
706
|
+
{
|
|
707
|
+
more = visitor.int64_value(data_.data(int16_array_arg)[index_]);
|
|
708
|
+
break;
|
|
709
|
+
}
|
|
710
|
+
case typed_array_type::int32_value:
|
|
711
|
+
{
|
|
712
|
+
more = visitor.int64_value(data_.data(int32_array_arg)[index_]);
|
|
713
|
+
break;
|
|
714
|
+
}
|
|
715
|
+
case typed_array_type::int64_value:
|
|
716
|
+
{
|
|
717
|
+
more = visitor.int64_value(data_.data(int64_array_arg)[index_]);
|
|
718
|
+
break;
|
|
719
|
+
}
|
|
720
|
+
case typed_array_type::float_value:
|
|
721
|
+
{
|
|
722
|
+
more = visitor.double_value(data_.data(float_array_arg)[index_]);
|
|
723
|
+
break;
|
|
724
|
+
}
|
|
725
|
+
case typed_array_type::double_value:
|
|
726
|
+
{
|
|
727
|
+
more = visitor.double_value(data_.data(double_array_arg)[index_]);
|
|
728
|
+
break;
|
|
729
|
+
}
|
|
730
|
+
default:
|
|
731
|
+
break;
|
|
732
|
+
}
|
|
733
|
+
++index_;
|
|
734
|
+
}
|
|
735
|
+
else
|
|
736
|
+
{
|
|
737
|
+
more = visitor.end_array();
|
|
738
|
+
state_ = staj2_cursor_state();
|
|
739
|
+
data_ = typed_array_view();
|
|
740
|
+
index_ = 0;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
else
|
|
745
|
+
{
|
|
746
|
+
switch (data_.type())
|
|
747
|
+
{
|
|
748
|
+
case typed_array_type::uint8_value:
|
|
749
|
+
{
|
|
750
|
+
more = visitor.typed_array(data_.data(uint8_array_arg));
|
|
751
|
+
break;
|
|
752
|
+
}
|
|
753
|
+
case typed_array_type::uint16_value:
|
|
754
|
+
{
|
|
755
|
+
more = visitor.typed_array(data_.data(uint16_array_arg));
|
|
756
|
+
break;
|
|
757
|
+
}
|
|
758
|
+
case typed_array_type::uint32_value:
|
|
759
|
+
{
|
|
760
|
+
more = visitor.typed_array(data_.data(uint32_array_arg));
|
|
761
|
+
break;
|
|
762
|
+
}
|
|
763
|
+
case typed_array_type::uint64_value:
|
|
764
|
+
{
|
|
765
|
+
more = visitor.typed_array(data_.data(uint64_array_arg));
|
|
766
|
+
break;
|
|
767
|
+
}
|
|
768
|
+
case typed_array_type::int8_value:
|
|
769
|
+
{
|
|
770
|
+
more = visitor.typed_array(data_.data(int8_array_arg));
|
|
771
|
+
break;
|
|
772
|
+
}
|
|
773
|
+
case typed_array_type::int16_value:
|
|
774
|
+
{
|
|
775
|
+
more = visitor.typed_array(data_.data(int16_array_arg));
|
|
776
|
+
break;
|
|
777
|
+
}
|
|
778
|
+
case typed_array_type::int32_value:
|
|
779
|
+
{
|
|
780
|
+
more = visitor.typed_array(data_.data(int32_array_arg));
|
|
781
|
+
break;
|
|
782
|
+
}
|
|
783
|
+
case typed_array_type::int64_value:
|
|
784
|
+
{
|
|
785
|
+
more = visitor.typed_array(data_.data(int64_array_arg));
|
|
786
|
+
break;
|
|
787
|
+
}
|
|
788
|
+
case typed_array_type::float_value:
|
|
789
|
+
{
|
|
790
|
+
more = visitor.typed_array(data_.data(float_array_arg));
|
|
791
|
+
break;
|
|
792
|
+
}
|
|
793
|
+
case typed_array_type::double_value:
|
|
794
|
+
{
|
|
795
|
+
more = visitor.typed_array(data_.data(double_array_arg));
|
|
796
|
+
break;
|
|
797
|
+
}
|
|
798
|
+
default:
|
|
799
|
+
break;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
state_ = staj2_cursor_state();
|
|
803
|
+
data_ = typed_array_view();
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
else
|
|
807
|
+
{
|
|
808
|
+
more = send_value_event(event(), visitor, context, ec);
|
|
809
|
+
}
|
|
810
|
+
return more;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
private:
|
|
814
|
+
static constexpr bool accept(const basic_staj2_event<CharT>&, const ser_context&)
|
|
815
|
+
{
|
|
816
|
+
return true;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
bool visit_begin_object(semantic_tag tag, const ser_context& context, std::error_code&) override
|
|
820
|
+
{
|
|
821
|
+
event_ = basic_staj2_event<CharT>(staj2_event_type::begin_object, tag);
|
|
822
|
+
return !pred_(event_, context);
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
bool visit_begin_object(std::size_t length, semantic_tag tag, const ser_context& context, std::error_code&) override
|
|
826
|
+
{
|
|
827
|
+
event_ = basic_staj2_event<CharT>(staj2_event_type::begin_object, length, tag);
|
|
828
|
+
return !pred_(event_, context);
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
bool visit_end_object(const ser_context& context, std::error_code&) override
|
|
832
|
+
{
|
|
833
|
+
event_ = basic_staj2_event<CharT>(staj2_event_type::end_object);
|
|
834
|
+
return !pred_(event_, context);
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
bool visit_begin_array(semantic_tag tag, const ser_context& context, std::error_code&) override
|
|
838
|
+
{
|
|
839
|
+
event_ = basic_staj2_event<CharT>(staj2_event_type::begin_array, tag);
|
|
840
|
+
return !pred_(event_, context);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
bool visit_begin_array(std::size_t length, semantic_tag tag, const ser_context& context, std::error_code&) override
|
|
844
|
+
{
|
|
845
|
+
event_ = basic_staj2_event<CharT>(staj2_event_type::begin_array, length, tag);
|
|
846
|
+
return !pred_(event_, context);
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
bool visit_end_array(const ser_context& context, std::error_code&) override
|
|
850
|
+
{
|
|
851
|
+
event_ = basic_staj2_event<CharT>(staj2_event_type::end_array);
|
|
852
|
+
return !pred_(event_, context);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
bool visit_null(semantic_tag tag, const ser_context& context, std::error_code&) override
|
|
856
|
+
{
|
|
857
|
+
event_ = basic_staj2_event<CharT>(staj2_event_type::null_value, tag);
|
|
858
|
+
return !pred_(event_, context);
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
bool visit_bool(bool value, semantic_tag tag, const ser_context& context, std::error_code&) override
|
|
862
|
+
{
|
|
863
|
+
event_ = basic_staj2_event<CharT>(value, tag);
|
|
864
|
+
return !pred_(event_, context);
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
bool visit_string(const string_view_type& s, semantic_tag tag, const ser_context& context, std::error_code&) override
|
|
868
|
+
{
|
|
869
|
+
event_ = basic_staj2_event<CharT>(s, staj2_event_type::string_value, tag);
|
|
870
|
+
return !pred_(event_, context);
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
bool visit_byte_string(const byte_string_view& s,
|
|
874
|
+
semantic_tag tag,
|
|
875
|
+
const ser_context& context,
|
|
876
|
+
std::error_code&) override
|
|
877
|
+
{
|
|
878
|
+
event_ = basic_staj2_event<CharT>(s, staj2_event_type::byte_string_value, tag);
|
|
879
|
+
return !pred_(event_, context);
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
bool visit_byte_string(const byte_string_view& s,
|
|
883
|
+
uint64_t ext_tag,
|
|
884
|
+
const ser_context& context,
|
|
885
|
+
std::error_code&) override
|
|
886
|
+
{
|
|
887
|
+
event_ = basic_staj2_event<CharT>(s, staj2_event_type::byte_string_value, ext_tag);
|
|
888
|
+
return !pred_(event_, context);
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
bool visit_uint64(uint64_t value,
|
|
892
|
+
semantic_tag tag,
|
|
893
|
+
const ser_context& context,
|
|
894
|
+
std::error_code&) override
|
|
895
|
+
{
|
|
896
|
+
event_ = basic_staj2_event<CharT>(value, tag);
|
|
897
|
+
return !pred_(event_, context);
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
bool visit_int64(int64_t value,
|
|
901
|
+
semantic_tag tag,
|
|
902
|
+
const ser_context& context,
|
|
903
|
+
std::error_code&) override
|
|
904
|
+
{
|
|
905
|
+
event_ = basic_staj2_event<CharT>(value, tag);
|
|
906
|
+
return !pred_(event_, context);
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
bool visit_half(uint16_t value,
|
|
910
|
+
semantic_tag tag,
|
|
911
|
+
const ser_context& context,
|
|
912
|
+
std::error_code&) override
|
|
913
|
+
{
|
|
914
|
+
event_ = basic_staj2_event<CharT>(half_arg, value, tag);
|
|
915
|
+
return !pred_(event_, context);
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
bool visit_double(double value,
|
|
919
|
+
semantic_tag tag,
|
|
920
|
+
const ser_context& context,
|
|
921
|
+
std::error_code&) override
|
|
922
|
+
{
|
|
923
|
+
event_ = basic_staj2_event<CharT>(value, tag);
|
|
924
|
+
return !pred_(event_, context);
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
bool visit_typed_array(const jsoncons::span<const uint8_t>& v,
|
|
928
|
+
semantic_tag tag,
|
|
929
|
+
const ser_context& context,
|
|
930
|
+
std::error_code& ec) override
|
|
931
|
+
{
|
|
932
|
+
state_ = staj2_cursor_state::typed_array;
|
|
933
|
+
data_ = typed_array_view(v.data(), v.size());
|
|
934
|
+
index_ = 0;
|
|
935
|
+
return this->begin_array(tag, context, ec);
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
bool visit_typed_array(const jsoncons::span<const uint16_t>& data,
|
|
939
|
+
semantic_tag tag,
|
|
940
|
+
const ser_context& context,
|
|
941
|
+
std::error_code& ec) override
|
|
942
|
+
{
|
|
943
|
+
state_ = staj2_cursor_state::typed_array;
|
|
944
|
+
data_ = typed_array_view(data.data(), data.size());
|
|
945
|
+
index_ = 0;
|
|
946
|
+
return this->begin_array(tag, context, ec);
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
bool visit_typed_array(const jsoncons::span<const uint32_t>& data,
|
|
950
|
+
semantic_tag tag,
|
|
951
|
+
const ser_context& context,
|
|
952
|
+
std::error_code& ec) override
|
|
953
|
+
{
|
|
954
|
+
state_ = staj2_cursor_state::typed_array;
|
|
955
|
+
data_ = typed_array_view(data.data(), data.size());
|
|
956
|
+
index_ = 0;
|
|
957
|
+
return this->begin_array(tag, context, ec);
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
bool visit_typed_array(const jsoncons::span<const uint64_t>& data,
|
|
961
|
+
semantic_tag tag,
|
|
962
|
+
const ser_context& context,
|
|
963
|
+
std::error_code& ec) override
|
|
964
|
+
{
|
|
965
|
+
state_ = staj2_cursor_state::typed_array;
|
|
966
|
+
data_ = typed_array_view(data.data(), data.size());
|
|
967
|
+
index_ = 0;
|
|
968
|
+
return this->begin_array(tag, context, ec);
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
bool visit_typed_array(const jsoncons::span<const int8_t>& data,
|
|
972
|
+
semantic_tag tag,
|
|
973
|
+
const ser_context& context,
|
|
974
|
+
std::error_code& ec) override
|
|
975
|
+
{
|
|
976
|
+
state_ = staj2_cursor_state::typed_array;
|
|
977
|
+
data_ = typed_array_view(data.data(), data.size());
|
|
978
|
+
index_ = 0;
|
|
979
|
+
return this->begin_array(tag, context, ec);
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
bool visit_typed_array(const jsoncons::span<const int16_t>& data,
|
|
983
|
+
semantic_tag tag,
|
|
984
|
+
const ser_context& context,
|
|
985
|
+
std::error_code& ec) override
|
|
986
|
+
{
|
|
987
|
+
state_ = staj2_cursor_state::typed_array;
|
|
988
|
+
data_ = typed_array_view(data.data(), data.size());
|
|
989
|
+
index_ = 0;
|
|
990
|
+
return this->begin_array(tag, context, ec);
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
bool visit_typed_array(const jsoncons::span<const int32_t>& data,
|
|
994
|
+
semantic_tag tag,
|
|
995
|
+
const ser_context& context,
|
|
996
|
+
std::error_code& ec) override
|
|
997
|
+
{
|
|
998
|
+
state_ = staj2_cursor_state::typed_array;
|
|
999
|
+
data_ = typed_array_view(data.data(), data.size());
|
|
1000
|
+
index_ = 0;
|
|
1001
|
+
return this->begin_array(tag, context, ec);
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
bool visit_typed_array(const jsoncons::span<const int64_t>& data,
|
|
1005
|
+
semantic_tag tag,
|
|
1006
|
+
const ser_context& context,
|
|
1007
|
+
std::error_code& ec) override
|
|
1008
|
+
{
|
|
1009
|
+
state_ = staj2_cursor_state::typed_array;
|
|
1010
|
+
data_ = typed_array_view(data.data(), data.size());
|
|
1011
|
+
index_ = 0;
|
|
1012
|
+
return this->begin_array(tag, context, ec);
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
bool visit_typed_array(half_arg_t, const jsoncons::span<const uint16_t>& data,
|
|
1016
|
+
semantic_tag tag,
|
|
1017
|
+
const ser_context& context,
|
|
1018
|
+
std::error_code& ec) override
|
|
1019
|
+
{
|
|
1020
|
+
state_ = staj2_cursor_state::typed_array;
|
|
1021
|
+
data_ = typed_array_view(data.data(), data.size());
|
|
1022
|
+
index_ = 0;
|
|
1023
|
+
return this->begin_array(tag, context, ec);
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
bool visit_typed_array(const jsoncons::span<const float>& data,
|
|
1027
|
+
semantic_tag tag,
|
|
1028
|
+
const ser_context& context,
|
|
1029
|
+
std::error_code& ec) override
|
|
1030
|
+
{
|
|
1031
|
+
state_ = staj2_cursor_state::typed_array;
|
|
1032
|
+
data_ = typed_array_view(data.data(), data.size());
|
|
1033
|
+
index_ = 0;
|
|
1034
|
+
return this->begin_array(tag, context, ec);
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
bool visit_typed_array(const jsoncons::span<const double>& data,
|
|
1038
|
+
semantic_tag tag,
|
|
1039
|
+
const ser_context& context,
|
|
1040
|
+
std::error_code& ec) override
|
|
1041
|
+
{
|
|
1042
|
+
state_ = staj2_cursor_state::typed_array;
|
|
1043
|
+
data_ = typed_array_view(data.data(), data.size());
|
|
1044
|
+
index_ = 0;
|
|
1045
|
+
return this->begin_array(tag, context, ec);
|
|
1046
|
+
}
|
|
1047
|
+
/*
|
|
1048
|
+
bool visit_typed_array(const jsoncons::span<const float128_type>&,
|
|
1049
|
+
semantic_tag,
|
|
1050
|
+
const ser_context&,
|
|
1051
|
+
std::error_code&) override
|
|
1052
|
+
{
|
|
1053
|
+
return true;
|
|
1054
|
+
}
|
|
1055
|
+
*/
|
|
1056
|
+
bool visit_begin_multi_dim(const jsoncons::span<const size_t>& shape,
|
|
1057
|
+
semantic_tag tag,
|
|
1058
|
+
const ser_context& context,
|
|
1059
|
+
std::error_code& ec) override
|
|
1060
|
+
{
|
|
1061
|
+
state_ = staj2_cursor_state::multi_dim;
|
|
1062
|
+
shape_ = shape;
|
|
1063
|
+
return this->begin_array(2, tag, context, ec);
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
bool visit_end_multi_dim(const ser_context& context,
|
|
1067
|
+
std::error_code& ec) override
|
|
1068
|
+
{
|
|
1069
|
+
return this->end_array(context, ec);
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
void visit_flush() override
|
|
1073
|
+
{
|
|
1074
|
+
}
|
|
1075
|
+
};
|
|
1076
|
+
|
|
1077
|
+
// basic_staj2_cursor
|
|
1078
|
+
|
|
1079
|
+
template<class CharT>
|
|
1080
|
+
class basic_staj2_cursor
|
|
1081
|
+
{
|
|
1082
|
+
public:
|
|
1083
|
+
virtual ~basic_staj2_cursor() noexcept = default;
|
|
1084
|
+
|
|
1085
|
+
virtual void array_expected(std::error_code& ec)
|
|
1086
|
+
{
|
|
1087
|
+
if (!(current().event_type() == staj2_event_type::begin_array || current().event_type() == staj2_event_type::byte_string_value))
|
|
1088
|
+
{
|
|
1089
|
+
ec = conv_errc::not_vector;
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
virtual bool done() const = 0;
|
|
1094
|
+
|
|
1095
|
+
virtual const basic_staj2_event<CharT>& current() const = 0;
|
|
1096
|
+
|
|
1097
|
+
virtual void read_to(basic_json_visitor2<CharT>& visitor) = 0;
|
|
1098
|
+
|
|
1099
|
+
virtual void read_to(basic_json_visitor2<CharT>& visitor,
|
|
1100
|
+
std::error_code& ec) = 0;
|
|
1101
|
+
|
|
1102
|
+
virtual void next() = 0;
|
|
1103
|
+
|
|
1104
|
+
virtual void next(std::error_code& ec) = 0;
|
|
1105
|
+
|
|
1106
|
+
virtual const ser_context& context() const = 0;
|
|
1107
|
+
};
|
|
1108
|
+
|
|
1109
|
+
template<class CharT>
|
|
1110
|
+
class basic_staj2_filter_view : basic_staj2_cursor<CharT>
|
|
1111
|
+
{
|
|
1112
|
+
basic_staj2_cursor<CharT>* cursor_;
|
|
1113
|
+
std::function<bool(const basic_staj2_event<CharT>&, const ser_context&)> pred_;
|
|
1114
|
+
public:
|
|
1115
|
+
basic_staj2_filter_view(basic_staj2_cursor<CharT>& cursor,
|
|
1116
|
+
std::function<bool(const basic_staj2_event<CharT>&, const ser_context&)> pred)
|
|
1117
|
+
: cursor_(std::addressof(cursor)), pred_(pred)
|
|
1118
|
+
{
|
|
1119
|
+
while (!done() && !pred_(current(),context()))
|
|
1120
|
+
{
|
|
1121
|
+
cursor_->next();
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
bool done() const override
|
|
1126
|
+
{
|
|
1127
|
+
return cursor_->done();
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
const basic_staj2_event<CharT>& current() const override
|
|
1131
|
+
{
|
|
1132
|
+
return cursor_->current();
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
void read_to(basic_json_visitor2<CharT>& visitor) override
|
|
1136
|
+
{
|
|
1137
|
+
cursor_->read_to(visitor);
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
void read_to(basic_json_visitor2<CharT>& visitor,
|
|
1141
|
+
std::error_code& ec) override
|
|
1142
|
+
{
|
|
1143
|
+
cursor_->read_to(visitor, ec);
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
void next() override
|
|
1147
|
+
{
|
|
1148
|
+
cursor_->next();
|
|
1149
|
+
while (!done() && !pred_(current(),context()))
|
|
1150
|
+
{
|
|
1151
|
+
cursor_->next();
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
void next(std::error_code& ec) override
|
|
1156
|
+
{
|
|
1157
|
+
cursor_->next(ec);
|
|
1158
|
+
while (!done() && !pred_(current(),context()) && !ec)
|
|
1159
|
+
{
|
|
1160
|
+
cursor_->next(ec);
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
const ser_context& context() const override
|
|
1165
|
+
{
|
|
1166
|
+
return cursor_->context();
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
friend
|
|
1170
|
+
basic_staj2_filter_view<CharT> operator|(basic_staj2_filter_view& cursor,
|
|
1171
|
+
std::function<bool(const basic_staj2_event<CharT>&, const ser_context&)> pred)
|
|
1172
|
+
{
|
|
1173
|
+
return basic_staj2_filter_view<CharT>(cursor, pred);
|
|
1174
|
+
}
|
|
1175
|
+
};
|
|
1176
|
+
|
|
1177
|
+
using staj2_event = basic_staj2_event<char>;
|
|
1178
|
+
using wstaj2_event = basic_staj2_event<wchar_t>;
|
|
1179
|
+
|
|
1180
|
+
using staj2_cursor = basic_staj2_cursor<char>;
|
|
1181
|
+
using wstaj2_cursor = basic_staj2_cursor<wchar_t>;
|
|
1182
|
+
|
|
1183
|
+
using staj2_filter_view = basic_staj2_filter_view<char>;
|
|
1184
|
+
using wstaj2_filter_view = basic_staj2_filter_view<wchar_t>;
|
|
1185
|
+
|
|
1186
|
+
} // namespace jsoncons
|
|
1187
|
+
|
|
1188
|
+
#endif
|
|
1189
|
+
|