42 const char*
what() const noexcept
override
52 exception(
int id_, const
char* what_arg) :
id(id_), m(what_arg) {}
54 static std::string
name(
const std::string& ename,
int id_)
56 return concat(
"[json.exception.", ename,
'.', std::to_string(id_),
"] ");
64 template<
typename BasicJsonType>
65 static std::string
diagnostics(
const BasicJsonType* leaf_element)
68 std::vector<std::string> tokens;
69 for (
const auto* current = leaf_element; current !=
nullptr && current->m_parent !=
nullptr; current = current->m_parent)
71 switch (current->m_parent->type())
75 for (std::size_t i = 0; i < current->m_parent->m_data.m_value.array->size(); ++i)
77 if (¤t->m_parent->m_data.m_value.array->operator[](i) == current)
79 tokens.emplace_back(std::to_string(i));
88 for (
const auto& element : *current->m_parent->m_data.m_value.object)
90 if (&element.second == current)
92 tokens.emplace_back(element.first.c_str());
117 auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
118 [](
const std::string & a,
const std::string & b)
120 return concat(a,
'/', detail::escape(b));
122 return concat(
'(', str,
") ");
124 static_cast<void>(leaf_element);
131 std::runtime_error m;
148 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
156 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
160 (byte_ != 0 ? (
concat(
" at byte ", std::to_string(byte_))) :
""),
162 return {id_, byte_, w.c_str()};
177 parse_error(
int id_, std::size_t byte_,
const char* what_arg)
180 static std::string position_string(
const position_t& pos)
192 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
196 return {id_, w.c_str()};
210 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
214 return {id_, w.c_str()};
227 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
231 return {id_, w.c_str()};
244 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
248 return {id_, w.c_str()};
#define WPI_JSON_NAMESPACE_END
Definition abi_macros.h:59
#define WPI_JSON_NAMESPACE_BEGIN
Definition abi_macros.h:53
general exception of the basic_json class
Definition exceptions.h:39
const int id
the id of the exception
Definition exceptions.h:48
static std::string diagnostics(std::nullptr_t)
Definition exceptions.h:59
static std::string name(const std::string &ename, int id_)
Definition exceptions.h:54
const char * what() const noexcept override
returns the explanatory string
Definition exceptions.h:42
static std::string diagnostics(const BasicJsonType *leaf_element)
Definition exceptions.h:65
exception indicating errors with iterators
Definition exceptions.h:190
static invalid_iterator create(int id_, const std::string &what_arg, BasicJsonContext context)
Definition exceptions.h:193
exception indicating other library errors
Definition exceptions.h:242
static other_error create(int id_, const std::string &what_arg, BasicJsonContext context)
Definition exceptions.h:245
exception indicating access out of the defined range
Definition exceptions.h:225
static out_of_range create(int id_, const std::string &what_arg, BasicJsonContext context)
Definition exceptions.h:228
exception indicating a parse error
Definition exceptions.h:137
static parse_error create(int id_, const position_t &pos, const std::string &what_arg, BasicJsonContext context)
create a parse error exception
Definition exceptions.h:149
static parse_error create(int id_, std::size_t byte_, const std::string &what_arg, BasicJsonContext context)
Definition exceptions.h:157
const std::size_t byte
byte index of the parse error
Definition exceptions.h:174
exception indicating executing a member function with a wrong type
Definition exceptions.h:208
static type_error create(int id_, const std::string &what_arg, BasicJsonContext context)
Definition exceptions.h:211
#define JSON_HEDLEY_NON_NULL(...)
Definition hedley.h:1288
detail namespace with internal helper functions
Definition input_adapters.h:32
OutStringType concat(Args &&... args)
Definition string_concat.h:137
@ number_integer
number value (signed integer)
@ discarded
discarded by the parser callback function
@ binary
binary array (ordered collection of bytes)
@ object
object (unordered set of name/value pairs)
@ number_float
number value (floating-point)
@ number_unsigned
number value (unsigned integer)
@ array
array (ordered collection of values)
struct to capture the start position of the current token
Definition position_t.h:21
std::size_t chars_read_current_line
the number of characters read in the current line
Definition position_t.h:25
std::size_t lines_read
the number of lines read
Definition position_t.h:27
std::size_t chars_read_total
the total number of characters read
Definition position_t.h:23