11#include "../daw_json_exception.h"
14#include <daw/daw_assume.h>
15#include <daw/daw_attributes.h>
16#include <daw/daw_check_exceptions.h>
17#include <daw/daw_likely.h>
18#include <daw/daw_string_view.h>
29#ifdef DAW_USE_EXCEPTIONS
37 template<
bool ShouldThrow = use_daw_json_exceptions_v>
38 [[maybe_unused, noreturn]] DAW_ATTRIB_NOINLINE
void
40#ifdef DAW_USE_EXCEPTIONS
41 if constexpr( ShouldThrow ) {
42 throw json_exception( reason );
48#ifdef DAW_USE_EXCEPTIONS
53 template<
bool ShouldThrow = use_daw_json_exceptions_v,
typename ParseState>
54 [[maybe_unused, noreturn]] DAW_ATTRIB_NOINLINE
static void
56#ifdef DAW_USE_EXCEPTIONS
57 if constexpr( ShouldThrow ) {
58 if( location.first ) {
59 throw json_exception( reason, location.first );
61 if( location.class_first ) {
62 throw json_exception( reason, location.class_first );
64 throw json_exception( reason );
71#ifdef DAW_USE_EXCEPTIONS
76 template<
bool ShouldThrow = use_daw_json_exceptions_v>
77 [[maybe_unused, noreturn]] DAW_ATTRIB_NOINLINE
static void
79#ifdef DAW_USE_EXCEPTIONS
80 if constexpr( ShouldThrow ) {
81 throw json_exception( reason );
87#ifdef DAW_USE_EXCEPTIONS
92 template<
bool ShouldThrow = use_daw_json_exceptions_v>
93 [[maybe_unused, noreturn]] DAW_ATTRIB_NOINLINE
static void
95#ifdef DAW_USE_EXCEPTIONS
96 if constexpr( ShouldThrow ) {
97 throw json_exception( reason );
103#ifdef DAW_USE_EXCEPTIONS
108 template<
bool ShouldThrow = use_daw_json_exceptions_v,
typename ParseState>
109 [[maybe_unused, noreturn]] DAW_ATTRIB_NOINLINE
static void
111 ParseState
const &location ) {
112#ifdef DAW_USE_EXCEPTIONS
113 if constexpr( ShouldThrow ) {
114 using namespace std::string_literals;
115 if( location.class_first and location.first ) {
116 static constexpr std::size_t max_len = 150;
117 std::size_t
const len = [&]( ) -> std::size_t {
118 if( location.first ==
nullptr or location.class_first ==
nullptr ) {
119 if( location.class_first ==
nullptr or
120 location.class_last ==
nullptr ) {
124 static_cast<std::size_t
>(
125 std::distance( location.class_first, location.class_last ) ),
128 return ( std::min )(
static_cast<std::size_t
>( std::distance(
129 location.class_first, location.first + 1 ) ),
132 throw json_exception( reason,
133 std::string_view( location.class_first, len ) );
135 throw json_exception( reason );
143#ifdef DAW_USE_EXCEPTIONS
148 template<
bool ShouldThrow = use_daw_json_exceptions_v,
typename ParseState>
149 [[maybe_unused, noreturn]] DAW_ATTRIB_NOINLINE
static void
151 ParseState
const &location ) {
152#ifdef DAW_USE_EXCEPTIONS
153 if constexpr( ShouldThrow ) {
154 using namespace std::string_literals;
155 if( location.first ) {
156 throw json_exception( reason, location.first );
158 if( location.class_first ) {
159 throw json_exception( reason, location.class_first );
161 throw json_exception( reason );
168#ifdef DAW_USE_EXCEPTIONS
179#define daw_json_assert( Bool, ... ) \
181 if( DAW_UNLIKELY( not( Bool ) ) ) { \
182 daw_json_error( __VA_ARGS__ ); \
190#define daw_json_assert_weak( Bool, ... ) \
192 if constexpr( not ParseState::is_unchecked_input ) { \
193 if( DAW_UNLIKELY( not( Bool ) ) ) { \
194 daw_json_error( __VA_ARGS__ ); \
constexpr bool use_daw_json_exceptions_v
Definition: daw_json_assert.h:32
DAW_ATTRIB_NOINLINE void daw_json_error(ErrorReason reason)
Definition: daw_json_assert.h:39
Definition: daw_from_json.h:22
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.
Definition: version.h:16