All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
nlohmann::detail::json_sax_dom_parser< BasicJsonType > Class Template Reference

SAX implementation to create a JSON value from SAX events. More...

#include <json.hpp>

Public Types

using number_integer_t = typename BasicJsonType::number_integer_t
 
using number_unsigned_t = typename BasicJsonType::number_unsigned_t
 
using number_float_t = typename BasicJsonType::number_float_t
 
using string_t = typename BasicJsonType::string_t
 

Public Member Functions

 json_sax_dom_parser (BasicJsonType &r, const bool allow_exceptions_=true)
 
 json_sax_dom_parser (const json_sax_dom_parser &)=delete
 
 json_sax_dom_parser (json_sax_dom_parser &&)=default
 
json_sax_dom_parseroperator= (const json_sax_dom_parser &)=delete
 
json_sax_dom_parseroperator= (json_sax_dom_parser &&)=default
 
 ~json_sax_dom_parser ()=default
 
bool null ()
 
bool boolean (bool val)
 
bool number_integer (number_integer_t val)
 
bool number_unsigned (number_unsigned_t val)
 
bool number_float (number_float_t val, const string_t &)
 
bool string (string_t &val)
 
bool start_object (std::size_t len)
 
bool key (string_t &val)
 
bool end_object ()
 
bool start_array (std::size_t len)
 
bool end_array ()
 
bool parse_error (std::size_t, const std::string &, const detail::exception &ex)
 
constexpr bool is_errored () const
 

Private Member Functions

template<typename Value >
JSON_HEDLEY_RETURNS_NON_NULL
BasicJsonType * 
handle_value (Value &&v)
 

Private Attributes

BasicJsonType & root
 the parsed JSON value More...
 
std::vector< BasicJsonType * > ref_stack {}
 stack to model hierarchy of values More...
 
BasicJsonType * object_element = nullptr
 helper to hold the reference for the next object element More...
 
bool errored = false
 whether a syntax error occurred More...
 
const bool allow_exceptions = true
 whether to throw exceptions in case of errors More...
 

Detailed Description

template<typename BasicJsonType>
class nlohmann::detail::json_sax_dom_parser< BasicJsonType >

SAX implementation to create a JSON value from SAX events.

This class implements the json_sax interface and processes the SAX events to create a JSON value which makes it basically a DOM parser. The structure or hierarchy of the JSON value is managed by the stack ref_stack which contains a pointer to the respective array or object for each recursion depth.

After successful parsing, the value that is passed by reference to the constructor contains the parsed value.

Template Parameters
BasicJsonTypethe JSON type

Definition at line 4454 of file json.hpp.

Member Typedef Documentation

template<typename BasicJsonType>
using nlohmann::detail::json_sax_dom_parser< BasicJsonType >::number_float_t = typename BasicJsonType::number_float_t

Definition at line 4459 of file json.hpp.

template<typename BasicJsonType>
using nlohmann::detail::json_sax_dom_parser< BasicJsonType >::number_integer_t = typename BasicJsonType::number_integer_t

Definition at line 4457 of file json.hpp.

template<typename BasicJsonType>
using nlohmann::detail::json_sax_dom_parser< BasicJsonType >::number_unsigned_t = typename BasicJsonType::number_unsigned_t

Definition at line 4458 of file json.hpp.

template<typename BasicJsonType>
using nlohmann::detail::json_sax_dom_parser< BasicJsonType >::string_t = typename BasicJsonType::string_t

Definition at line 4460 of file json.hpp.

Constructor & Destructor Documentation

template<typename BasicJsonType>
nlohmann::detail::json_sax_dom_parser< BasicJsonType >::json_sax_dom_parser ( BasicJsonType &  r,
const bool  allow_exceptions_ = true 
)
inlineexplicit
Parameters
[in,out]rreference to a JSON value that is manipulated while parsing
[in]allow_exceptions_whether parse errors yield exceptions

Definition at line 4467 of file json.hpp.

4468  : root(r), allow_exceptions(allow_exceptions_)
4469  {}
BasicJsonType & root
the parsed JSON value
Definition: json.hpp:4624
esac echo uname r
const bool allow_exceptions
whether to throw exceptions in case of errors
Definition: json.hpp:4632
template<typename BasicJsonType>
nlohmann::detail::json_sax_dom_parser< BasicJsonType >::json_sax_dom_parser ( const json_sax_dom_parser< BasicJsonType > &  )
delete
template<typename BasicJsonType>
nlohmann::detail::json_sax_dom_parser< BasicJsonType >::json_sax_dom_parser ( json_sax_dom_parser< BasicJsonType > &&  )
default
template<typename BasicJsonType>
nlohmann::detail::json_sax_dom_parser< BasicJsonType >::~json_sax_dom_parser ( )
default

Member Function Documentation

template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::boolean ( bool  val)
inline

Definition at line 4484 of file json.hpp.

4485  {
4486  handle_value(val);
4487  return true;
4488  }
JSON_HEDLEY_RETURNS_NON_NULL BasicJsonType * handle_value(Value &&v)
Definition: json.hpp:4601
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::end_array ( )
inline

Definition at line 4553 of file json.hpp.

4554  {
4555  ref_stack.pop_back();
4556  return true;
4557  }
std::vector< BasicJsonType * > ref_stack
stack to model hierarchy of values
Definition: json.hpp:4626
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::end_object ( )
inline

Definition at line 4534 of file json.hpp.

4535  {
4536  ref_stack.pop_back();
4537  return true;
4538  }
std::vector< BasicJsonType * > ref_stack
stack to model hierarchy of values
Definition: json.hpp:4626
template<typename BasicJsonType>
template<typename Value >
JSON_HEDLEY_RETURNS_NON_NULL BasicJsonType* nlohmann::detail::json_sax_dom_parser< BasicJsonType >::handle_value ( Value &&  v)
inlineprivate
Invariant
If the ref stack is empty, then the passed value will be the new root.
If the ref stack contains a value, then it is an array or an object to which we can add elements

Definition at line 4601 of file json.hpp.

4602  {
4603  if (ref_stack.empty())
4604  {
4605  root = BasicJsonType(std::forward<Value>(v));
4606  return &root;
4607  }
4608 
4609  assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
4610 
4611  if (ref_stack.back()->is_array())
4612  {
4613  ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v));
4614  return &(ref_stack.back()->m_value.array->back());
4615  }
4616 
4617  assert(ref_stack.back()->is_object());
4618  assert(object_element);
4619  *object_element = BasicJsonType(std::forward<Value>(v));
4620  return object_element;
4621  }
std::vector< BasicJsonType * > ref_stack
stack to model hierarchy of values
Definition: json.hpp:4626
BasicJsonType & root
the parsed JSON value
Definition: json.hpp:4624
BasicJsonType * object_element
helper to hold the reference for the next object element
Definition: json.hpp:4628
template<typename BasicJsonType>
constexpr bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::is_errored ( ) const
inline

Definition at line 4587 of file json.hpp.

4588  {
4589  return errored;
4590  }
bool errored
whether a syntax error occurred
Definition: json.hpp:4630
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::key ( string_t val)
inline

Definition at line 4527 of file json.hpp.

4528  {
4529  // add null at given key and store the reference for later
4530  object_element = &(ref_stack.back()->m_value.object->operator[](val));
4531  return true;
4532  }
std::vector< BasicJsonType * > ref_stack
stack to model hierarchy of values
Definition: json.hpp:4626
BasicJsonType * object_element
helper to hold the reference for the next object element
Definition: json.hpp:4628
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::null ( )
inline

Definition at line 4478 of file json.hpp.

4479  {
4480  handle_value(nullptr);
4481  return true;
4482  }
JSON_HEDLEY_RETURNS_NON_NULL BasicJsonType * handle_value(Value &&v)
Definition: json.hpp:4601
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::number_float ( number_float_t  val,
const string_t  
)
inline

Definition at line 4502 of file json.hpp.

4503  {
4504  handle_value(val);
4505  return true;
4506  }
JSON_HEDLEY_RETURNS_NON_NULL BasicJsonType * handle_value(Value &&v)
Definition: json.hpp:4601
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::number_integer ( number_integer_t  val)
inline

Definition at line 4490 of file json.hpp.

4491  {
4492  handle_value(val);
4493  return true;
4494  }
JSON_HEDLEY_RETURNS_NON_NULL BasicJsonType * handle_value(Value &&v)
Definition: json.hpp:4601
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::number_unsigned ( number_unsigned_t  val)
inline

Definition at line 4496 of file json.hpp.

4497  {
4498  handle_value(val);
4499  return true;
4500  }
JSON_HEDLEY_RETURNS_NON_NULL BasicJsonType * handle_value(Value &&v)
Definition: json.hpp:4601
template<typename BasicJsonType>
json_sax_dom_parser& nlohmann::detail::json_sax_dom_parser< BasicJsonType >::operator= ( const json_sax_dom_parser< BasicJsonType > &  )
delete
template<typename BasicJsonType>
json_sax_dom_parser& nlohmann::detail::json_sax_dom_parser< BasicJsonType >::operator= ( json_sax_dom_parser< BasicJsonType > &&  )
default
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::parse_error ( std::size_t  ,
const std::string ,
const detail::exception ex 
)
inline

Definition at line 4559 of file json.hpp.

4561  {
4562  errored = true;
4563  if (allow_exceptions)
4564  {
4565  // determine the proper exception type from the id
4566  switch ((ex.id / 100) % 100)
4567  {
4568  case 1:
4569  JSON_THROW(*static_cast<const detail::parse_error*>(&ex));
4570  case 4:
4571  JSON_THROW(*static_cast<const detail::out_of_range*>(&ex));
4572  // LCOV_EXCL_START
4573  case 2:
4574  JSON_THROW(*static_cast<const detail::invalid_iterator*>(&ex));
4575  case 3:
4576  JSON_THROW(*static_cast<const detail::type_error*>(&ex));
4577  case 5:
4578  JSON_THROW(*static_cast<const detail::other_error*>(&ex));
4579  default:
4580  assert(false);
4581  // LCOV_EXCL_STOP
4582  }
4583  }
4584  return false;
4585  }
#define JSON_THROW(exception)
Definition: json.hpp:1754
bool errored
whether a syntax error occurred
Definition: json.hpp:4630
const bool allow_exceptions
whether to throw exceptions in case of errors
Definition: json.hpp:4632
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::start_array ( std::size_t  len)
inline

Definition at line 4540 of file json.hpp.

4541  {
4543 
4544  if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
4545  {
4547  "excessive array size: " + std::to_string(len)));
4548  }
4549 
4550  return true;
4551  }
std::vector< BasicJsonType * > ref_stack
stack to model hierarchy of values
Definition: json.hpp:4626
JSON_HEDLEY_RETURNS_NON_NULL BasicJsonType * handle_value(Value &&v)
Definition: json.hpp:4601
#define JSON_THROW(exception)
Definition: json.hpp:1754
then echo ***************************************echo array
Definition: find_fhicl.sh:28
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
std::string to_string(WindowPattern const &pattern)
static out_of_range create(int id_, const std::string &what_arg)
Definition: json.hpp:2125
#define JSON_HEDLEY_UNLIKELY(expr)
Definition: json.hpp:1124
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::start_object ( std::size_t  len)
inline

Definition at line 4514 of file json.hpp.

4515  {
4516  ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
4517 
4518  if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
4519  {
4521  "excessive object size: " + std::to_string(len)));
4522  }
4523 
4524  return true;
4525  }
std::vector< BasicJsonType * > ref_stack
stack to model hierarchy of values
Definition: json.hpp:4626
JSON_HEDLEY_RETURNS_NON_NULL BasicJsonType * handle_value(Value &&v)
Definition: json.hpp:4601
#define JSON_THROW(exception)
Definition: json.hpp:1754
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
std::string to_string(WindowPattern const &pattern)
static out_of_range create(int id_, const std::string &what_arg)
Definition: json.hpp:2125
#define JSON_HEDLEY_UNLIKELY(expr)
Definition: json.hpp:1124
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::string ( string_t val)
inline

Definition at line 4508 of file json.hpp.

4509  {
4510  handle_value(val);
4511  return true;
4512  }
JSON_HEDLEY_RETURNS_NON_NULL BasicJsonType * handle_value(Value &&v)
Definition: json.hpp:4601

Member Data Documentation

template<typename BasicJsonType>
const bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::allow_exceptions = true
private

whether to throw exceptions in case of errors

Definition at line 4632 of file json.hpp.

template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::errored = false
private

whether a syntax error occurred

Definition at line 4630 of file json.hpp.

template<typename BasicJsonType>
BasicJsonType* nlohmann::detail::json_sax_dom_parser< BasicJsonType >::object_element = nullptr
private

helper to hold the reference for the next object element

Definition at line 4628 of file json.hpp.

template<typename BasicJsonType>
std::vector<BasicJsonType*> nlohmann::detail::json_sax_dom_parser< BasicJsonType >::ref_stack {}
private

stack to model hierarchy of values

Definition at line 4626 of file json.hpp.

template<typename BasicJsonType>
BasicJsonType& nlohmann::detail::json_sax_dom_parser< BasicJsonType >::root
private

the parsed JSON value

Definition at line 4624 of file json.hpp.


The documentation for this class was generated from the following file: