14#include <daw/daw_consteval.h>
15#include <daw/daw_likely.h>
16#include <daw/daw_sort_n.h>
17#include <daw/daw_string_view.h>
18#include <daw/daw_uint_buffer.h>
23#if defined( DAW_JSON_PARSER_DIAGNOSTICS )
30 namespace json_details {
31 template<
bool FullNameMatch,
typename CharT>
40 [[maybe_unused, nodiscard]]
inline constexpr bool missing( )
const {
41 return first ==
nullptr;
44 template<
typename ParseState>
53 template<
typename ParseState>
54 constexpr auto get_range( template_param<ParseState> )
const {
55 using range_t =
typename ParseState::without_allocator_type;
62 template<
typename CharT>
70 [[maybe_unused, nodiscard]]
inline constexpr bool missing( )
const {
71 return first ==
nullptr;
74 template<
typename ParseState>
83 template<
typename ParseState>
84 constexpr auto get_range( template_param<ParseState> )
const {
86 using range_t =
typename ParseState::without_allocator_type;
97 template<std::size_t MemberCount,
typename CharT,
98 bool DoFullNameMatch =
true>
117 static constexpr std::size_t
size( ) {
121 template<
bool expect_
long_
strings, std::
size_t start_pos>
122 DAW_ATTRIB_INLINE [[nodiscard]]
inline constexpr std::size_t
124 daw::string_view key )
const {
125 UInt32
const hash = name_hash<expect_long_strings>( key );
126#if defined( _MSC_VER ) and not defined( __clang__ )
130 for( std::size_t
n = 0;
n < MemberCount; ++
n ) {
132 for( std::size_t
n = start_pos;
n < MemberCount; ++
n ) {
136 if( DAW_UNLIKELY( key !=
names[
n].name ) ) {
148 template<
typename... MemberNames>
150 daw::UInt32
hashes[
sizeof...( MemberNames )]{
151 name_hash<false>( MemberNames::name )... };
153 daw::sort( std::data(
hashes ), daw::data_end(
hashes ) );
154 return daw::algorithm::adjacent_find( std::data(
hashes ),
156 []( UInt32 l, UInt32 r ) {
158 } ) != daw::data_end(
hashes );
160#if defined( _MSC_VER ) and not defined( __clang__ )
161#define DAW_JSON_MAKE_LOC_INFO_CONSTEVAL constexpr
163#define DAW_JSON_MAKE_LOC_INFO_CONSTEVAL DAW_CONSTEVAL
166 template<
typename ParseState,
typename... JsonMembers>
169 using CharT =
typename ParseState::CharT;
170#if defined( DAW_JSON_PARSER_DIAGNOSTICS ) or \
171 ( defined( __MSC_VER ) and not defined( __clang__ ) )
175 { daw::name_hash<false>( JsonMembers::name )... },
177 JsonMembers::name }... } };
181 ParseState::force_name_equal_check or
186 { daw::name_hash<false>( JsonMembers::name )... },
188 JsonMembers::name }... } };
192 { daw::name_hash<false>( JsonMembers::name )... }, {} };
208 bool from_start =
false, std::size_t N,
typename ParseState,
209 bool B,
typename CharT>
210 [[nodiscard]]
inline constexpr std::pair<ParseState, bool>
213 bool is_nullable, daw::string_view member_name ) {
224 bool known = not locations[pos].missing( );
225 while( locations[pos].missing( ) & (
parse_state.front( ) !=
'}' ) ) {
229 auto const name_pos =
230 locations.template find_name<ParseState::expect_long_strings>(
231 template_vals<( from_start ? 0 : pos )>, name );
236#if defined( DAW_JSON_PARSER_DIAGNOSTICS )
237 std::cerr <<
"DEBUG: Unknown member '" << name <<
'\n';
239 if( name_pos >= std::size( locations ) ) {
246 if( name_pos == pos ) {
250#if defined( DAW_JSON_PARSER_DIAGNOSTICS )
251 std::cerr <<
"DEBUG: Out of order member '"
253 <<
"' found, looking for '" << locations.
names[pos].
name
255 << std::abs(
static_cast<long long>( pos ) -
256 static_cast<long long>( name_pos ) )
257 <<
" members ahead in constructor\n";
269 if constexpr( ParseState::is_unchecked_input ) {
270 if( name_pos + 1 < std::size( locations ) ) {
280 if( locations[pos].missing( ) ) {
283 if constexpr( ParseState::has_allocator ) {
284 return std::pair<ParseState, bool>{
286 .get_range( template_arg<ParseState> )
290 return std::pair<ParseState, bool>{
291 locations[pos].get_range( template_arg<ParseState> ), known };
#define daw_json_assert_weak(Bool,...)
Definition: daw_json_assert.h:190
#define daw_json_assert(Bool,...)
Definition: daw_json_assert.h:179
#define DAW_JSON_MAKE_LOC_INFO_CONSTEVAL
Definition: daw_json_location_info.h:163
ParseState & parse_state
Definition: daw_json_parse_class.h:182
constexpr DAW_ATTRIB_FLATTEN daw::string_view parse_name(ParseState &parse_state)
Definition: daw_json_parse_name.h:128
DAW_ATTRIB_FLATINLINE DAW_JSON_MAKE_LOC_INFO_CONSTEVAL auto make_locations_info()
Definition: daw_json_location_info.h:168
constexpr ParseState skip_value(ParseState &parse_state)
Definition: daw_json_skip.h:304
DAW_CONSTEVAL bool do_hashes_collide()
Definition: daw_json_location_info.h:149
constexpr std::pair< ParseState, bool > find_class_member(ParseState &parse_state, locations_info_t< N, CharT, B > &locations, bool is_nullable, daw::string_view member_name)
Definition: daw_json_location_info.h:211
AllMembersMustExist
Definition: daw_json_location_info.h:206
Definition: daw_from_json.h:22
constexpr bool missing() const
Definition: daw_json_location_info.h:70
constexpr void set_range(ParseState const &parse_state)
Definition: daw_json_location_info.h:75
constexpr auto get_range(template_param< ParseState >) const
Definition: daw_json_location_info.h:84
Definition: daw_json_location_info.h:32
constexpr auto get_range(template_param< ParseState >) const
Definition: daw_json_location_info.h:54
constexpr void set_range(ParseState const &parse_state)
Definition: daw_json_location_info.h:45
std::size_t counter
Definition: daw_json_location_info.h:38
constexpr bool missing() const
Definition: daw_json_location_info.h:40
CharT * class_last
Definition: daw_json_location_info.h:37
CharT * first
Definition: daw_json_location_info.h:34
CharT * class_first
Definition: daw_json_location_info.h:36
daw::string_view name
Definition: daw_json_location_info.h:33
CharT * last
Definition: daw_json_location_info.h:35
Definition: daw_json_location_info.h:99
value_type names[MemberCount]
Definition: daw_json_location_info.h:105
constexpr reference operator[](std::size_t idx)
Definition: daw_json_location_info.h:112
static constexpr std::size_t size()
Definition: daw_json_location_info.h:117
static constexpr bool do_full_name_match
Definition: daw_json_location_info.h:103
value_type const & const_reference
Definition: daw_json_location_info.h:102
daw::UInt32 hashes[MemberCount]
Definition: daw_json_location_info.h:104
constexpr DAW_ATTRIB_INLINE std::size_t find_name(daw::template_vals_t< start_pos >, daw::string_view key) const
Definition: daw_json_location_info.h:123
constexpr const_reference operator[](std::size_t idx) const
Definition: daw_json_location_info.h:107
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.
Definition: version.h:16