18#include <daw/daw_move.h>
19#include <daw/daw_uint_buffer.h>
29 namespace json_details {
30 template<
typename ParseState>
40 daw::
name_hash<ParseState::expect_long_strings>( Name ) )
43 [[nodiscard]]
constexpr bool is_match( daw::string_view Name )
const {
47 [[nodiscard]]
constexpr bool is_match( daw::string_view Name,
48 daw::UInt32 hash )
const {
62 :
name( std::data( Name ), std::size( Name ) )
71 template<
typename ParseState>
74 std::vector<json_details::basic_stateful_json_value_state<ParseState>>
84 std::size_t
const Sz = std::size( m_locs );
85 for( ; pos < Sz; ++pos ) {
92 if( m_locs.empty( ) ) {
93 return m_value.
begin( );
95 auto res = m_locs.back( ).location;
99 auto const last = m_value.
end( );
100 while(
it != last ) {
101 auto name =
it.name( );
103 auto const &new_loc = m_locs.emplace_back(
104 daw::string_view( std::data( *name ), std::size( *name ) ),
it );
105 if( new_loc.is_match( member.
name ) ) {
111 return std::size( m_locs );
119 [[nodiscard]]
constexpr std::size_t move_to( std::size_t index ) {
120 if( index < std::size( m_locs ) ) {
124 if( m_locs.empty( ) ) {
125 return m_value.
begin( );
127 auto res = m_locs.back( ).location;
131 auto last = m_value.
end( );
132 std::size_t pos = std::size( m_locs );
133 while(
it != last ) {
134 auto name =
it.name( );
137 daw::string_view( std::data( *name ), std::size( *name ) ),
it );
139 m_locs.emplace_back( daw::string_view( ),
it );
147 return std::size( m_locs );
152 : m_value( DAW_MOVE( val ) ) {
155 auto t = m_value.
type( );
159 ErrorReason::ExpectedArrayOrClassStart,
174 m_value = DAW_MOVE( val );
188 ErrorReason::UnknownMember );
189 return m_locs[pos].location->value;
200 std::size_t pos = move_to( member );
202 ErrorReason::UnknownMember );
203 return m_locs[pos].location->value;
214 at( std::string_view key ) {
215 auto const k = std::string_view( std::data( key ), std::size( key ) );
216 std::size_t pos = move_to( k );
217 if( pos < std::size( m_locs ) ) {
218 return m_locs[pos].location->value;
229 [[nodiscard]] std::size_t
size( ) {
231 switch( current_type ) {
234 return move_to( ( daw::numeric_limits<std::size_t>::max )( ) );
247 [[nodiscard]] std::size_t
index_of( std::string_view key ) {
248 auto const k = std::string_view( std::data( key ), std::size( key ) );
258 [[nodiscard]]
constexpr bool contains( std::string_view key ) {
259 auto const k = std::string_view( std::data( key ), std::size( key ) );
260 return move_to( k ) < std::size( m_locs );
269 [[nodiscard]]
constexpr bool contains( std::size_t index ) {
270 return move_to( index ) <
size( m_locs );
280 template<
typename Integer,
281 std::enable_if_t<std::is_integral<Integer>::value,
282 std::nullptr_t> =
nullptr>
283 [[nodiscard]] std::optional<std::string_view>
name_of( Integer index ) {
284 if constexpr( std::is_signed<Integer>::value ) {
288 if(
static_cast<std::size_t
>( index ) >= sz ) {
291 sz -=
static_cast<std::size_t
>( index );
292 return std::string_view( std::data( m_locs[sz].name( ) ),
293 std::size( m_locs[sz].name( ) ) );
296 std::size_t pos = move_to(
static_cast<std::size_t
>( index ) );
297 if( pos < std::size( m_locs ) ) {
298 return std::string_view( std::data( m_locs[pos].name( ) ),
299 std::size( m_locs[pos].name( ) ) );
312 template<
typename Integer,
313 std::enable_if_t<std::is_integral<Integer>::value,
314 std::nullptr_t> =
nullptr>
317 if constexpr( std::is_signed<Integer>::value ) {
322 ErrorReason::UnknownMember );
323 sz -=
static_cast<std::size_t
>( index );
324 return m_locs[sz].location->value;
327 std::size_t pos = move_to(
static_cast<std::size_t
>( index ) );
329 ErrorReason::UnknownMember );
330 return m_locs[pos].location->value;
340 template<
typename Integer,
341 std::enable_if_t<std::is_integral<Integer>::value,
342 std::nullptr_t> =
nullptr>
343 [[nodiscard]]
constexpr std::optional<basic_json_value<ParseState>>
344 at( Integer index ) {
345 if constexpr( std::is_signed<Integer>::value ) {
349 if(
static_cast<std::size_t
>( index ) >= sz ) {
352 sz -=
static_cast<std::size_t
>( index );
353 return m_locs[sz].location->value( );
356 std::size_t pos = move_to(
static_cast<std::size_t
>( index ) );
357 if( pos < std::size( m_locs ) ) {
358 return m_locs[pos].location->value( );
Definition: daw_json_value.h:320
constexpr ParseState get_raw_state() const
Definition: daw_json_value.h:369
JsonBaseParseTypes type() const
Definition: daw_json_value.h:399
constexpr iterator begin() const
Definition: daw_json_value.h:378
constexpr iterator end() const
Definition: daw_json_value.h:390
Definition: daw_json_value_state.h:72
std::optional< std::string_view > name_of(Integer index)
Definition: daw_json_value_state.h:283
constexpr basic_stateful_json_value()
Definition: daw_json_value_state.h:163
constexpr bool contains(std::string_view key)
Definition: daw_json_value_state.h:258
std::size_t size()
Definition: daw_json_value_state.h:229
constexpr basic_json_value< ParseState > operator[](json_member_name member)
Definition: daw_json_value_state.h:199
constexpr void reset(basic_json_value< ParseState > val)
Definition: daw_json_value_state.h:173
constexpr basic_stateful_json_value(basic_json_value< ParseState > val)
Definition: daw_json_value_state.h:151
constexpr basic_stateful_json_value(std::string_view json_data)
Definition: daw_json_value_state.h:166
constexpr basic_json_value< ParseState > at(std::string_view key)
Definition: daw_json_value_state.h:214
constexpr std::optional< basic_json_value< ParseState > > at(Integer index)
Definition: daw_json_value_state.h:344
constexpr basic_json_value< ParseState > operator[](Integer index)
Definition: daw_json_value_state.h:316
constexpr basic_json_value< ParseState > operator[](std::string_view key)
Definition: daw_json_value_state.h:185
constexpr bool contains(std::size_t index)
Definition: daw_json_value_state.h:269
constexpr basic_json_value< ParseState > get_json_value() const
Definition: daw_json_value_state.h:367
std::size_t index_of(std::string_view key)
Definition: daw_json_value_state.h:247
#define daw_json_assert_weak(Bool,...)
Definition: daw_json_assert.h:190
Iterator & it
Definition: daw_json_traits.h:251
JsonBaseParseTypes
The fundamental JSON types.
Definition: daw_json_enums.h:53
Definition: daw_from_json.h:22
Definition: daw_from_json.h:22
constexpr DAW_ATTRIB_INLINE auto name_hash(StringView key) -> std::enable_if_t< daw::traits::is_string_view_like_v< StringView >, UInt32 >
Definition: daw_murmur3.h:72
Definition: daw_json_value.h:106
Definition: daw_json_value_state.h:31
constexpr basic_stateful_json_value_state(daw::string_view Name, basic_json_value_iterator< ParseState > val)
Definition: daw_json_value_state.h:36
basic_json_value_iterator< ParseState > location
Definition: daw_json_value_state.h:34
constexpr bool is_match(daw::string_view Name) const
Definition: daw_json_value_state.h:43
daw::string_view name
Definition: daw_json_value_state.h:32
daw::UInt32 hash_value
Definition: daw_json_value_state.h:33
constexpr bool is_match(daw::string_view Name, daw::UInt32 hash) const
Definition: daw_json_value_state.h:47
Definition: daw_json_value_state.h:57
daw::string_view name
Definition: daw_json_value_state.h:58
daw::UInt32 hash_value
Definition: daw_json_value_state.h:59
constexpr json_member_name(std::string_view Name)
Definition: daw_json_value_state.h:61
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.
Definition: version.h:16