Skip to content

Commit 6722940

Browse files
committed
staj_events
1 parent ac9555f commit 6722940

28 files changed

Lines changed: 1069 additions & 1034 deletions

CHANGELOG.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ master (1.7.0 preview)
1414

1515
- Enhancements:
1616

17-
- Git Issue #692: Redefined enum `staj_event_type` as a [BitMask Type](https://en.cppreference.com/w/cpp/named_req/BitmaskType.html).
18-
This allows us to write e.g.
17+
- Git Issue #692: Redefined `staj_event_type` as an alias to `staj_events`, which meets the requirements
18+
of a [BitMask Type](https://en.cppreference.com/w/cpp/named_req/BitmaskType.html), and means that the
19+
bitwise operators operator&, operator|, operator^, operator~, operator&=, operator|=, and operator^=
20+
are defined for this type. This allows us to write e.g.
1921
```cpp
20-
constexpr auto mask = staj_event_type::begin_array | staj_event_type::begin_object;
21-
if ((event_type & mask) != staj_event_type{}) {/*...*/}
22+
constexpr auto mask = staj_events::begin_array | staj_events::begin_object;
23+
if ((event_type & mask) != staj_events{}) {/*...*/}
2224
```
2325

2426
- The `basic_json_pointer` operator `/` now accepts a `basic_string_view` as a right-hand argument,

doc/ref/corelib/staj_event_type.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ enum class staj_event_type
1010
null_value,
1111
bool_value,
1212
int64_value,
13-
uint64_value,
13+
uint64_value, (until 1.7.0)
1414
half_value,
1515
double_value,
1616
begin_array,
@@ -19,18 +19,13 @@ enum class staj_event_type
1919
end_object,
2020
key
2121
};
22+
23+
using staj_event_type = staj_events; (since 1.7.0)
2224
```
2325
Indicates the type of a staj event.
2426

25-
Since 1.7.0, `staj_event_type` is defined as a
26-
[BitMaskType](https://en.cppreference.com/w/cpp/named_req/BitmaskType.html). This
27-
allows us to write e.g.
28-
29-
```cpp
30-
constexpr auto mask = staj_event_type::begin_array | staj_event_type::begin_object;
31-
if ((event_type & mask) != staj_event_type{})
32-
{
33-
/*...*/
34-
}
35-
```
27+
Since 1.7.0, `staj_event_type` is aliased to [staj_events](staj_events.md),
28+
which meets the requirements of a [BitMaskType](https://en.cppreference.com/w/cpp/named_req/BitmaskType.html),
29+
and means that the bitwise operators operator&, operator|, operator^, operator~, operator&=, operator|=, and operator^=
30+
are defined for this type.
3631

doc/ref/corelib/staj_events.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
### jsoncons::staj_events
2+
3+
```cpp
4+
#include <jsoncons/staj_event.hpp>
5+
6+
enum class staj_events
7+
{
8+
string_value,
9+
byte_string_value,
10+
null_value,
11+
bool_value,
12+
int64_value,
13+
uint64_value, (since 1.7.0)
14+
half_value,
15+
double_value,
16+
begin_array,
17+
end_array,
18+
begin_object,
19+
end_object,
20+
key
21+
};
22+
```
23+
Represents a classification of streaming events for JSON-like formats.
24+
25+
`staj_events` satisfies the requirements of a
26+
[BitMaskType](https://en.cppreference.com/w/cpp/named_req/BitmaskType.html). This
27+
allows us to write e.g.
28+
29+
```cpp
30+
constexpr auto mask = staj_events::begin_array | staj_events::begin_object;
31+
if ((event_type & mask) != staj_events{})
32+
{
33+
/*...*/
34+
}
35+
```
36+

include/jsoncons/json_cursor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ class basic_json_cursor : public basic_staj_cursor<CharT>, private virtual ser_c
367367
read_next(visitor, ec);
368368
parser_.cursor_mode(true);
369369
parser_.mark_level(0);
370-
if (current().event_type() == staj_event_type::begin_object)
370+
if (current().event_type() == staj_events::begin_object)
371371
{
372372
cursor_visitor_.end_object(*this);
373373
}

include/jsoncons/reflect/decode_traits.hpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ struct decode_traits<std::pair<T1, T2>>
174174
{
175175
return result_type(jsoncons::unexpect, ec, cursor.line(), cursor.column());
176176
}
177-
if (cursor.current().event_type() != staj_event_type::begin_array)
177+
if (cursor.current().event_type() != staj_events::begin_array)
178178
{
179179
return result_type(jsoncons::unexpect, conv_errc::not_pair, cursor.line(), cursor.column());
180180
}
@@ -205,7 +205,7 @@ struct decode_traits<std::pair<T1, T2>>
205205
return result_type(jsoncons::unexpect, ec, cursor.line(), cursor.column());
206206
}
207207

208-
if (cursor.current().event_type() != staj_event_type::end_array)
208+
if (cursor.current().event_type() != staj_events::end_array)
209209
{
210210
return result_type(jsoncons::unexpect, conv_errc::not_pair, cursor.line(), cursor.column());
211211
}
@@ -237,13 +237,13 @@ struct decode_traits<T,
237237
{
238238
return result_type(jsoncons::unexpect, ec, cursor.line(), cursor.column());
239239
}
240-
if (cursor.current().event_type() != staj_event_type::begin_array)
240+
if (cursor.current().event_type() != staj_events::begin_array)
241241
{
242242
return result_type(jsoncons::unexpect, conv_errc::not_vector, cursor.line(), cursor.column());
243243
}
244244
cursor.next(ec);
245245
if (JSONCONS_UNLIKELY(ec)) { return result_type(jsoncons::unexpect, ec, cursor.line(), cursor.column()); }
246-
while (cursor.current().event_type() != staj_event_type::end_array && !ec)
246+
while (cursor.current().event_type() != staj_events::end_array && !ec)
247247
{
248248
auto r = decode_traits<element_type>::try_decode(aset, cursor);
249249
if (!r)
@@ -283,7 +283,7 @@ struct decode_traits<T,
283283
}
284284
switch (cursor.current().event_type())
285285
{
286-
case staj_event_type::byte_string_value:
286+
case staj_events::byte_string_value:
287287
{
288288
auto bytes = cursor.current().template get<byte_string_view>(ec);
289289
if (!ec)
@@ -305,15 +305,15 @@ struct decode_traits<T,
305305
return result_type(jsoncons::unexpect, ec, cursor.line(), cursor.column());
306306
}
307307
}
308-
case staj_event_type::begin_array:
308+
case staj_events::begin_array:
309309
{
310310
T v = jsoncons::make_obj_using_allocator<T>(aset.get_allocator());
311311
if (cursor.current().size() > 0)
312312
{
313313
reserve_storage(typename std::integral_constant<bool, ext_traits::has_reserve<T>::value>::type(), v, cursor.current().size());
314314
}
315315
cursor.next(ec);
316-
while (cursor.current().event_type() != staj_event_type::end_array && !ec)
316+
while (cursor.current().event_type() != staj_events::end_array && !ec)
317317
{
318318
auto r = decode_traits<element_type>::try_decode(aset, cursor);
319319
if (!r)
@@ -373,15 +373,15 @@ struct decode_traits<T,
373373
}
374374
switch (cursor.current().event_type())
375375
{
376-
case staj_event_type::begin_array:
376+
case staj_events::begin_array:
377377
{
378378
T v = jsoncons::make_obj_using_allocator<T>(aset.get_allocator());
379379
if (cursor.current().size() > 0)
380380
{
381381
reserve_storage(typename std::integral_constant<bool, ext_traits::has_reserve<T>::value>::type(), v, cursor.current().size());
382382
}
383383
cursor.next(ec);
384-
while (cursor.current().event_type() != staj_event_type::end_array && !ec)
384+
while (cursor.current().event_type() != staj_events::end_array && !ec)
385385
{
386386
auto r = decode_traits<element_type>::try_decode(aset, cursor);
387387
if (!r)
@@ -439,7 +439,7 @@ struct decode_traits<T,
439439
{
440440
return result_type(jsoncons::unexpect, ec, cursor.line(), cursor.column());
441441
}
442-
if (cursor.current().event_type() != staj_event_type::begin_array)
442+
if (cursor.current().event_type() != staj_events::begin_array)
443443
{
444444
return result_type(jsoncons::unexpect, conv_errc::not_vector, cursor.line(), cursor.column());
445445
}
@@ -448,7 +448,7 @@ struct decode_traits<T,
448448
reserve_storage(typename std::integral_constant<bool, ext_traits::has_reserve<T>::value>::type(), v, cursor.current().size());
449449
}
450450
cursor.next(ec);
451-
while (cursor.current().event_type() != staj_event_type::end_array && !ec)
451+
while (cursor.current().event_type() != staj_events::end_array && !ec)
452452
{
453453
auto r = decode_traits<element_type>::try_decode(aset, cursor);
454454
if (!r)
@@ -499,7 +499,7 @@ struct decode_traits<T,
499499
}
500500

501501
T v = jsoncons::make_obj_using_allocator<T>(aset.get_allocator());
502-
if (cursor.current().event_type() != staj_event_type::begin_array)
502+
if (cursor.current().event_type() != staj_events::begin_array)
503503
{
504504
return result_type(jsoncons::unexpect, conv_errc::not_vector, cursor.line(), cursor.column());
505505
}
@@ -508,7 +508,7 @@ struct decode_traits<T,
508508
reserve_storage(typename std::integral_constant<bool, ext_traits::has_reserve<T>::value>::type(), v, cursor.current().size());
509509
}
510510
cursor.next(ec);
511-
while (cursor.current().event_type() != staj_event_type::end_array && !ec)
511+
while (cursor.current().event_type() != staj_events::end_array && !ec)
512512
{
513513
auto r = decode_traits<element_type>::try_decode(aset, cursor);
514514
if (!r)
@@ -553,12 +553,12 @@ struct decode_traits<std::array<T,N>>
553553
{
554554
return result_type(jsoncons::unexpect, ec, cursor.line(), cursor.column());
555555
}
556-
if (cursor.current().event_type() != staj_event_type::begin_array)
556+
if (cursor.current().event_type() != staj_events::begin_array)
557557
{
558558
return result_type{jsoncons::unexpect, conv_errc::not_vector, cursor.line(), cursor.column()};
559559
}
560560
cursor.next(ec);
561-
for (std::size_t i = 0; i < N && cursor.current().event_type() != staj_event_type::end_array && !ec; ++i)
561+
for (std::size_t i = 0; i < N && cursor.current().event_type() != staj_events::end_array && !ec; ++i)
562562
{
563563
auto r = decode_traits<element_type>::try_decode(aset, cursor);
564564
if (!r)
@@ -596,7 +596,7 @@ struct decode_traits<T,
596596
std::error_code ec;
597597

598598
auto val = jsoncons::make_obj_using_allocator<T>(aset.get_allocator());
599-
if (cursor.current().event_type() != staj_event_type::begin_object)
599+
if (cursor.current().event_type() != staj_events::begin_object)
600600
{
601601
return result_type{jsoncons::unexpect, conv_errc::not_map, cursor.line(), cursor.column()};
602602
}
@@ -606,9 +606,9 @@ struct decode_traits<T,
606606
}
607607
cursor.next(ec);
608608

609-
while (cursor.current().event_type() != staj_event_type::end_object && !ec)
609+
while (cursor.current().event_type() != staj_events::end_object && !ec)
610610
{
611-
if (cursor.current().event_type() != staj_event_type::key)
611+
if (cursor.current().event_type() != staj_events::key)
612612
{
613613
return result_type{jsoncons::unexpect, json_errc::expected_key, cursor.line(), cursor.column()};
614614
}
@@ -669,7 +669,7 @@ struct decode_traits<T,
669669
std::error_code ec;
670670

671671
T val;
672-
if (cursor.current().event_type() != staj_event_type::begin_object)
672+
if (cursor.current().event_type() != staj_events::begin_object)
673673
{
674674
return result_type{jsoncons::unexpect, conv_errc::not_map, cursor.line(), cursor.column()};
675675
}
@@ -679,9 +679,9 @@ struct decode_traits<T,
679679
}
680680
cursor.next(ec);
681681

682-
while (cursor.current().event_type() != staj_event_type::end_object && !ec)
682+
while (cursor.current().event_type() != staj_events::end_object && !ec)
683683
{
684-
if (cursor.current().event_type() != staj_event_type::key)
684+
if (cursor.current().event_type() != staj_events::key)
685685
{
686686
return result_type{jsoncons::unexpect, json_errc::expected_key, cursor.line(), cursor.column()};
687687
}

0 commit comments

Comments
 (0)