18 #include <daw/daw_attributes.h>
19 #include <daw/daw_move.h>
23 namespace json_details {
24 template<
typename ParseState,
bool>
25 struct json_parse_kv_array_iterator_base {
26 using iterator_category = std::input_iterator_tag;
27 using difference_type = std::ptrdiff_t;
28 static constexpr
bool has_counter =
false;
29 ParseState *parse_state =
nullptr;
32 template<
typename ParseState>
33 struct json_parse_kv_array_iterator_base<ParseState, true> {
34 #if defined( DAW_JSON_HAS_CPP23_RANGE_CTOR )
35 using iterator_category = std::input_iterator_tag;
38 using iterator_category = std::random_access_iterator_tag;
40 using difference_type = std::ptrdiff_t;
41 static constexpr
bool has_counter =
true;
42 ParseState *parse_state =
nullptr;
43 difference_type counter = 0;
45 explicit json_parse_kv_array_iterator_base( ) =
default;
49 json_parse_kv_array_iterator_base( ParseState *pd ) noexcept
51 , counter(
static_cast<difference_type
>( pd->counter ) ) {}
53 constexpr difference_type
54 operator-( json_parse_kv_array_iterator_base
const &rhs )
const {
62 template<
typename JsonMember,
typename ParseState,
bool KnownBounds>
63 struct json_parse_kv_array_iterator final
64 : json_parse_kv_array_iterator_base<
65 ParseState, can_be_random_iterator_v<KnownBounds>> {
67 using base = json_parse_kv_array_iterator_base<
68 ParseState, can_be_random_iterator_v<KnownBounds>>;
69 using iterator_category =
typename base::iterator_category;
70 using json_key_t =
typename JsonMember::json_key_t;
71 using json_element_t =
typename JsonMember::json_value_t;
72 using value_type = std::pair<json_result_t<json_key_t>
const,
73 json_result_t<json_element_t>>;
74 using reference = value_type;
75 using pointer = arrow_proxy<value_type>;
76 using parse_state_t = ParseState;
77 using difference_type =
typename base::difference_type;
79 using json_class_type =
typename JsonMember::json_class_t;
80 explicit json_parse_kv_array_iterator( ) =
default;
82 explicit constexpr json_parse_kv_array_iterator( parse_state_t &r )
84 if( DAW_UNLIKELY( base::parse_state->front( ) ==
']' ) ) {
85 if constexpr( not KnownBounds ) {
87 base::parse_state->remove_prefix( );
88 base::parse_state->trim_left_checked( );
91 base::parse_state =
nullptr;
95 static constexpr value_type
96 get_pair( json_result_t<json_class_type> &&v ) {
97 return value_type( std::get<0>( std::move( v.members ) ),
98 std::get<1>( std::move( v.members ) ) );
101 DAW_ATTRIB_NOINLINE value_type operator*( )
const {
106 DAW_ATTRIB_INLINE constexpr value_type operator*( ) {
108 base::parse_state and base::parse_state->has_more( ),
109 ErrorReason::UnexpectedEndOfData, *base::parse_state );
112 parse_value<json_class_type, false, JsonParseTypes::Class>(
113 *base::parse_state ) );
116 DAW_ATTRIB_INLINE constexpr json_parse_kv_array_iterator &
119 ErrorReason::UnexpectedEndOfData );
120 base::parse_state->trim_left( );
123 base::parse_state->has_more( ) and
124 base::parse_state->is_at_next_array_element( ),
125 ErrorReason::UnexpectedEndOfData, *base::parse_state );
127 base::parse_state->move_next_member_or_end( );
129 ErrorReason::UnexpectedEndOfData );
130 if( DAW_UNLIKELY( base::parse_state->front( ) ==
']' ) ) {
131 #if not defined( NDEBUG )
132 if constexpr( base::has_counter ) {
134 ErrorReason::UnexpectedEndOfData );
137 if constexpr( not KnownBounds ) {
139 base::parse_state->remove_prefix( );
140 base::parse_state->trim_left_checked( );
143 base::parse_state =
nullptr;
145 #if not defined( NDEBUG )
146 if constexpr( base::has_counter ) {
148 ErrorReason::UnexpectedEndOfData );
155 DAW_ATTRIB_INLINE constexpr
void operator++(
int ) {
159 friend constexpr
bool
160 operator==( json_parse_kv_array_iterator
const &lhs,
161 json_parse_kv_array_iterator
const &rhs ) {
162 return lhs.parse_state == rhs.parse_state;
165 friend constexpr
bool
166 operator!=( json_parse_kv_array_iterator
const &lhs,
167 json_parse_kv_array_iterator
const &rhs ) {
168 return not( lhs == rhs );
#define daw_json_assert_weak(Bool,...)
Assert that Bool is true when in Checked Input mode If false pass rest of args to daw_json_error.
DAW_ATTRIB_NOINLINE void daw_json_error(ErrorReason reason)
Customization point traits.
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.