Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
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)
 
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 >
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 4260 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 4265 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 4263 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 4264 of file json.hpp.

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

Definition at line 4266 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 4273 of file json.hpp.

4274  : root(r), allow_exceptions(allow_exceptions_)
4275  {}
BasicJsonType & root
the parsed JSON value
Definition: json.hpp:4423
const bool allow_exceptions
whether to throw exceptions in case of errors
Definition: json.hpp:4431

Member Function Documentation

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

Definition at line 4283 of file json.hpp.

4284  {
4285  handle_value(val);
4286  return true;
4287  }
BasicJsonType * handle_value(Value &&v)
Definition: json.hpp:4399
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::end_array ( )
inline

Definition at line 4352 of file json.hpp.

4353  {
4354  ref_stack.pop_back();
4355  return true;
4356  }
std::vector< BasicJsonType * > ref_stack
stack to model hierarchy of values
Definition: json.hpp:4425
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::end_object ( )
inline

Definition at line 4333 of file json.hpp.

4334  {
4335  ref_stack.pop_back();
4336  return true;
4337  }
std::vector< BasicJsonType * > ref_stack
stack to model hierarchy of values
Definition: json.hpp:4425
template<typename BasicJsonType>
template<typename Value >
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 4399 of file json.hpp.

References run_pk_param_space::root.

4400  {
4401  if (ref_stack.empty())
4402  {
4403  root = BasicJsonType(std::forward<Value>(v));
4404  return &root;
4405  }
4406 
4407  assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
4408 
4409  if (ref_stack.back()->is_array())
4410  {
4411  ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v));
4412  return &(ref_stack.back()->m_value.array->back());
4413  }
4414  else
4415  {
4416  assert(object_element);
4417  *object_element = BasicJsonType(std::forward<Value>(v));
4418  return object_element;
4419  }
4420  }
std::vector< BasicJsonType * > ref_stack
stack to model hierarchy of values
Definition: json.hpp:4425
BasicJsonType & root
the parsed JSON value
Definition: json.hpp:4423
BasicJsonType * object_element
helper to hold the reference for the next object element
Definition: json.hpp:4427
template<typename BasicJsonType>
constexpr bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::is_errored ( ) const
inline

Definition at line 4386 of file json.hpp.

Referenced by nlohmann::detail::parser< BasicJsonType >::parse().

4387  {
4388  return errored;
4389  }
bool errored
whether a syntax error occurred
Definition: json.hpp:4429
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::key ( string_t val)
inline

Definition at line 4326 of file json.hpp.

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

Definition at line 4277 of file json.hpp.

4278  {
4279  handle_value(nullptr);
4280  return true;
4281  }
BasicJsonType * handle_value(Value &&v)
Definition: json.hpp:4399
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::number_float ( number_float_t  val,
const string_t  
)
inline

Definition at line 4301 of file json.hpp.

4302  {
4303  handle_value(val);
4304  return true;
4305  }
BasicJsonType * handle_value(Value &&v)
Definition: json.hpp:4399
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::number_integer ( number_integer_t  val)
inline

Definition at line 4289 of file json.hpp.

4290  {
4291  handle_value(val);
4292  return true;
4293  }
BasicJsonType * handle_value(Value &&v)
Definition: json.hpp:4399
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::number_unsigned ( number_unsigned_t  val)
inline

Definition at line 4295 of file json.hpp.

4296  {
4297  handle_value(val);
4298  return true;
4299  }
BasicJsonType * handle_value(Value &&v)
Definition: json.hpp:4399
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 4358 of file json.hpp.

References nlohmann::detail::exception::id, and JSON_THROW.

Referenced by nlohmann::detail::parser< BasicJsonType >::parse().

4360  {
4361  errored = true;
4362  if (allow_exceptions)
4363  {
4364  // determine the proper exception type from the id
4365  switch ((ex.id / 100) % 100)
4366  {
4367  case 1:
4368  JSON_THROW(*reinterpret_cast<const detail::parse_error*>(&ex));
4369  case 4:
4370  JSON_THROW(*reinterpret_cast<const detail::out_of_range*>(&ex));
4371  // LCOV_EXCL_START
4372  case 2:
4373  JSON_THROW(*reinterpret_cast<const detail::invalid_iterator*>(&ex));
4374  case 3:
4375  JSON_THROW(*reinterpret_cast<const detail::type_error*>(&ex));
4376  case 5:
4377  JSON_THROW(*reinterpret_cast<const detail::other_error*>(&ex));
4378  default:
4379  assert(false);
4380  // LCOV_EXCL_STOP
4381  }
4382  }
4383  return false;
4384  }
#define JSON_THROW(exception)
Definition: json.hpp:162
bool errored
whether a syntax error occurred
Definition: json.hpp:4429
const bool allow_exceptions
whether to throw exceptions in case of errors
Definition: json.hpp:4431
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::start_array ( std::size_t  len)
inline

Definition at line 4339 of file json.hpp.

References nlohmann::detail::out_of_range::create(), JSON_THROW, and JSON_UNLIKELY.

4340  {
4341  ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
4342 
4343  if (JSON_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
4344  {
4346  "excessive array size: " + std::to_string(len)));
4347  }
4348 
4349  return true;
4350  }
std::vector< BasicJsonType * > ref_stack
stack to model hierarchy of values
Definition: json.hpp:4425
#define JSON_UNLIKELY(x)
Definition: json.hpp:194
#define JSON_THROW(exception)
Definition: json.hpp:162
BasicJsonType * handle_value(Value &&v)
Definition: json.hpp:4399
static out_of_range create(int id_, const std::string &what_arg)
Definition: json.hpp:1070
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::start_object ( std::size_t  len)
inline

Definition at line 4313 of file json.hpp.

References nlohmann::detail::out_of_range::create(), JSON_THROW, and JSON_UNLIKELY.

4314  {
4315  ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
4316 
4317  if (JSON_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
4318  {
4320  "excessive object size: " + std::to_string(len)));
4321  }
4322 
4323  return true;
4324  }
std::vector< BasicJsonType * > ref_stack
stack to model hierarchy of values
Definition: json.hpp:4425
#define JSON_UNLIKELY(x)
Definition: json.hpp:194
#define JSON_THROW(exception)
Definition: json.hpp:162
BasicJsonType * handle_value(Value &&v)
Definition: json.hpp:4399
static out_of_range create(int id_, const std::string &what_arg)
Definition: json.hpp:1070
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_parser< BasicJsonType >::string ( string_t val)
inline

Definition at line 4307 of file json.hpp.

4308  {
4309  handle_value(val);
4310  return true;
4311  }
BasicJsonType * handle_value(Value &&v)
Definition: json.hpp:4399

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 4431 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 4429 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 4427 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 4425 of file json.hpp.

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

the parsed JSON value

Definition at line 4423 of file json.hpp.


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