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_callback_parser< BasicJsonType > Class Template Reference

#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
 
using parser_callback_t = typename BasicJsonType::parser_callback_t
 
using parse_event_t = typename BasicJsonType::parse_event_t
 

Public Member Functions

 json_sax_dom_callback_parser (BasicJsonType &r, const parser_callback_t cb, const bool allow_exceptions_=true)
 
 json_sax_dom_callback_parser (const json_sax_dom_callback_parser &)=delete
 
 json_sax_dom_callback_parser (json_sax_dom_callback_parser &&)=default
 
json_sax_dom_callback_parseroperator= (const json_sax_dom_callback_parser &)=delete
 
json_sax_dom_callback_parseroperator= (json_sax_dom_callback_parser &&)=default
 
 ~json_sax_dom_callback_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 >
std::pair< bool, BasicJsonType * > handle_value (Value &&v, const bool skip_callback=false)
 

Private Attributes

BasicJsonType & root
 the parsed JSON value More...
 
std::vector< BasicJsonType * > ref_stack {}
 stack to model hierarchy of values More...
 
std::vector< bool > keep_stack {}
 stack to manage which values to keep More...
 
std::vector< bool > key_keep_stack {}
 stack to manage which object keys to keep 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 parser_callback_t callback = nullptr
 callback function More...
 
const bool allow_exceptions = true
 whether to throw exceptions in case of errors More...
 
BasicJsonType discarded = BasicJsonType::value_t::discarded
 a discarded value for the callback More...
 

Detailed Description

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

Definition at line 4636 of file json.hpp.

Member Typedef Documentation

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

Definition at line 4641 of file json.hpp.

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

Definition at line 4639 of file json.hpp.

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

Definition at line 4640 of file json.hpp.

template<typename BasicJsonType>
using nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::parse_event_t = typename BasicJsonType::parse_event_t

Definition at line 4644 of file json.hpp.

template<typename BasicJsonType>
using nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::parser_callback_t = typename BasicJsonType::parser_callback_t

Definition at line 4643 of file json.hpp.

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

Definition at line 4642 of file json.hpp.

Constructor & Destructor Documentation

template<typename BasicJsonType>
nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::json_sax_dom_callback_parser ( BasicJsonType &  r,
const parser_callback_t  cb,
const bool  allow_exceptions_ = true 
)
inline

Definition at line 4646 of file json.hpp.

4649  : root(r), callback(cb), allow_exceptions(allow_exceptions_)
4650  {
4651  keep_stack.push_back(true);
4652  }
const parser_callback_t callback
callback function
Definition: json.hpp:4932
const bool allow_exceptions
whether to throw exceptions in case of errors
Definition: json.hpp:4934
std::vector< bool > keep_stack
stack to manage which values to keep
Definition: json.hpp:4924
BasicJsonType & root
the parsed JSON value
Definition: json.hpp:4920
esac echo uname r
template<typename BasicJsonType>
nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::json_sax_dom_callback_parser ( const json_sax_dom_callback_parser< BasicJsonType > &  )
delete
template<typename BasicJsonType>
nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::json_sax_dom_callback_parser ( json_sax_dom_callback_parser< BasicJsonType > &&  )
default
template<typename BasicJsonType>
nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::~json_sax_dom_callback_parser ( )
default

Member Function Documentation

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

Definition at line 4667 of file json.hpp.

4668  {
4669  handle_value(val);
4670  return true;
4671  }
std::pair< bool, BasicJsonType * > handle_value(Value &&v, const bool skip_callback=false)
Definition: json.hpp:4856
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::end_array ( )
inline

Definition at line 4778 of file json.hpp.

4779  {
4780  bool keep = true;
4781 
4782  if (ref_stack.back())
4783  {
4784  keep = callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());
4785  if (not keep)
4786  {
4787  // discard array
4788  *ref_stack.back() = discarded;
4789  }
4790  }
4791 
4792  assert(not ref_stack.empty());
4793  assert(not keep_stack.empty());
4794  ref_stack.pop_back();
4795  keep_stack.pop_back();
4796 
4797  // remove discarded value
4798  if (not keep and not ref_stack.empty() and ref_stack.back()->is_array())
4799  {
4800  ref_stack.back()->m_value.array->pop_back();
4801  }
4802 
4803  return true;
4804  }
const parser_callback_t callback
callback function
Definition: json.hpp:4932
BasicJsonType discarded
a discarded value for the callback
Definition: json.hpp:4936
std::vector< BasicJsonType * > ref_stack
stack to model hierarchy of values
Definition: json.hpp:4922
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
std::vector< bool > keep_stack
stack to manage which values to keep
Definition: json.hpp:4924
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::end_object ( )
inline

Definition at line 4732 of file json.hpp.

4733  {
4734  if (ref_stack.back() and not callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
4735  {
4736  // discard object
4737  *ref_stack.back() = discarded;
4738  }
4739 
4740  assert(not ref_stack.empty());
4741  assert(not keep_stack.empty());
4742  ref_stack.pop_back();
4743  keep_stack.pop_back();
4744 
4745  if (not ref_stack.empty() and ref_stack.back() and ref_stack.back()->is_object())
4746  {
4747  // remove discarded value
4748  for (auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
4749  {
4750  if (it->is_discarded())
4751  {
4752  ref_stack.back()->erase(it);
4753  break;
4754  }
4755  }
4756  }
4757 
4758  return true;
4759  }
const parser_callback_t callback
callback function
Definition: json.hpp:4932
BasicJsonType discarded
a discarded value for the callback
Definition: json.hpp:4936
std::vector< BasicJsonType * > ref_stack
stack to model hierarchy of values
Definition: json.hpp:4922
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
std::vector< bool > keep_stack
stack to manage which values to keep
Definition: json.hpp:4924
template<typename BasicJsonType>
template<typename Value >
std::pair<bool, BasicJsonType*> nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::handle_value ( Value &&  v,
const bool  skip_callback = false 
)
inlineprivate
Parameters
[in]vvalue to add to the JSON value we build during parsing
[in]skip_callbackwhether we should skip calling the callback function; this is required after start_array() and start_object() SAX events, because otherwise we would call the callback function with an empty array or object, respectively.
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
Returns
pair of boolean (whether value should be kept) and pointer (to the passed value in the ref_stack hierarchy; nullptr if not kept)

Definition at line 4856 of file json.hpp.

4857  {
4858  assert(not keep_stack.empty());
4859 
4860  // do not handle this value if we know it would be added to a discarded
4861  // container
4862  if (not keep_stack.back())
4863  {
4864  return {false, nullptr};
4865  }
4866 
4867  // create value
4868  auto value = BasicJsonType(std::forward<Value>(v));
4869 
4870  // check callback
4871  const bool keep = skip_callback or callback(static_cast<int>(ref_stack.size()), parse_event_t::value, value);
4872 
4873  // do not handle this value if we just learnt it shall be discarded
4874  if (not keep)
4875  {
4876  return {false, nullptr};
4877  }
4878 
4879  if (ref_stack.empty())
4880  {
4881  root = std::move(value);
4882  return {true, &root};
4883  }
4884 
4885  // skip this value if we already decided to skip the parent
4886  // (https://github.com/nlohmann/json/issues/971#issuecomment-413678360)
4887  if (not ref_stack.back())
4888  {
4889  return {false, nullptr};
4890  }
4891 
4892  // we now only expect arrays and objects
4893  assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
4894 
4895  // array
4896  if (ref_stack.back()->is_array())
4897  {
4898  ref_stack.back()->m_value.array->push_back(std::move(value));
4899  return {true, &(ref_stack.back()->m_value.array->back())};
4900  }
4901 
4902  // object
4903  assert(ref_stack.back()->is_object());
4904  // check if we should store an element for the current key
4905  assert(not key_keep_stack.empty());
4906  const bool store_element = key_keep_stack.back();
4907  key_keep_stack.pop_back();
4908 
4909  if (not store_element)
4910  {
4911  return {false, nullptr};
4912  }
4913 
4914  assert(object_element);
4915  *object_element = std::move(value);
4916  return {true, object_element};
4917  }
const parser_callback_t callback
callback function
Definition: json.hpp:4932
std::vector< BasicJsonType * > ref_stack
stack to model hierarchy of values
Definition: json.hpp:4922
std::vector< bool > key_keep_stack
stack to manage which object keys to keep
Definition: json.hpp:4926
std::vector< bool > keep_stack
stack to manage which values to keep
Definition: json.hpp:4924
BasicJsonType & root
the parsed JSON value
Definition: json.hpp:4920
temporary value
BasicJsonType * object_element
helper to hold the reference for the next object element
Definition: json.hpp:4928
template<typename BasicJsonType>
constexpr bool nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::is_errored ( ) const
inline

Definition at line 4834 of file json.hpp.

4835  {
4836  return errored;
4837  }
bool errored
whether a syntax error occurred
Definition: json.hpp:4930
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::key ( string_t val)
inline

Definition at line 4715 of file json.hpp.

4716  {
4717  BasicJsonType k = BasicJsonType(val);
4718 
4719  // check callback for key
4720  const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::key, k);
4721  key_keep_stack.push_back(keep);
4722 
4723  // add discarded value at given key and store the reference for later
4724  if (keep and ref_stack.back())
4725  {
4726  object_element = &(ref_stack.back()->m_value.object->operator[](val) = discarded);
4727  }
4728 
4729  return true;
4730  }
const parser_callback_t callback
callback function
Definition: json.hpp:4932
BasicJsonType discarded
a discarded value for the callback
Definition: json.hpp:4936
std::vector< BasicJsonType * > ref_stack
stack to model hierarchy of values
Definition: json.hpp:4922
std::vector< bool > key_keep_stack
stack to manage which object keys to keep
Definition: json.hpp:4926
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
pdgs k
Definition: selectors.fcl:22
BasicJsonType * object_element
helper to hold the reference for the next object element
Definition: json.hpp:4928
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::null ( )
inline

Definition at line 4661 of file json.hpp.

4662  {
4663  handle_value(nullptr);
4664  return true;
4665  }
std::pair< bool, BasicJsonType * > handle_value(Value &&v, const bool skip_callback=false)
Definition: json.hpp:4856
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::number_float ( number_float_t  val,
const string_t  
)
inline

Definition at line 4685 of file json.hpp.

4686  {
4687  handle_value(val);
4688  return true;
4689  }
std::pair< bool, BasicJsonType * > handle_value(Value &&v, const bool skip_callback=false)
Definition: json.hpp:4856
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::number_integer ( number_integer_t  val)
inline

Definition at line 4673 of file json.hpp.

4674  {
4675  handle_value(val);
4676  return true;
4677  }
std::pair< bool, BasicJsonType * > handle_value(Value &&v, const bool skip_callback=false)
Definition: json.hpp:4856
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::number_unsigned ( number_unsigned_t  val)
inline

Definition at line 4679 of file json.hpp.

4680  {
4681  handle_value(val);
4682  return true;
4683  }
std::pair< bool, BasicJsonType * > handle_value(Value &&v, const bool skip_callback=false)
Definition: json.hpp:4856
template<typename BasicJsonType>
json_sax_dom_callback_parser& nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::operator= ( const json_sax_dom_callback_parser< BasicJsonType > &  )
delete
template<typename BasicJsonType>
json_sax_dom_callback_parser& nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::operator= ( json_sax_dom_callback_parser< BasicJsonType > &&  )
default
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::parse_error ( std::size_t  ,
const std::string ,
const detail::exception ex 
)
inline

Definition at line 4806 of file json.hpp.

4808  {
4809  errored = true;
4810  if (allow_exceptions)
4811  {
4812  // determine the proper exception type from the id
4813  switch ((ex.id / 100) % 100)
4814  {
4815  case 1:
4816  JSON_THROW(*static_cast<const detail::parse_error*>(&ex));
4817  case 4:
4818  JSON_THROW(*static_cast<const detail::out_of_range*>(&ex));
4819  // LCOV_EXCL_START
4820  case 2:
4821  JSON_THROW(*static_cast<const detail::invalid_iterator*>(&ex));
4822  case 3:
4823  JSON_THROW(*static_cast<const detail::type_error*>(&ex));
4824  case 5:
4825  JSON_THROW(*static_cast<const detail::other_error*>(&ex));
4826  default:
4827  assert(false);
4828  // LCOV_EXCL_STOP
4829  }
4830  }
4831  return false;
4832  }
const bool allow_exceptions
whether to throw exceptions in case of errors
Definition: json.hpp:4934
#define JSON_THROW(exception)
Definition: json.hpp:1754
bool errored
whether a syntax error occurred
Definition: json.hpp:4930
template<typename BasicJsonType>
bool nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::start_array ( std::size_t  len)
inline

Definition at line 4761 of file json.hpp.

4762  {
4763  const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::array_start, discarded);
4764  keep_stack.push_back(keep);
4765 
4766  auto val = handle_value(BasicJsonType::value_t::array, true);
4767  ref_stack.push_back(val.second);
4768 
4769  // check array limit
4770  if (ref_stack.back() and JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
4771  {
4772  JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len)));
4773  }
4774 
4775  return true;
4776  }
const parser_callback_t callback
callback function
Definition: json.hpp:4932
BasicJsonType discarded
a discarded value for the callback
Definition: json.hpp:4936
std::vector< BasicJsonType * > ref_stack
stack to model hierarchy of values
Definition: json.hpp:4922
#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::pair< bool, BasicJsonType * > handle_value(Value &&v, const bool skip_callback=false)
Definition: json.hpp:4856
std::string to_string(WindowPattern const &pattern)
std::vector< bool > keep_stack
stack to manage which values to keep
Definition: json.hpp:4924
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_callback_parser< BasicJsonType >::start_object ( std::size_t  len)
inline

Definition at line 4697 of file json.hpp.

4698  {
4699  // check callback for object start
4700  const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::object_start, discarded);
4701  keep_stack.push_back(keep);
4702 
4703  auto val = handle_value(BasicJsonType::value_t::object, true);
4704  ref_stack.push_back(val.second);
4705 
4706  // check object limit
4707  if (ref_stack.back() and JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
4708  {
4709  JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len)));
4710  }
4711 
4712  return true;
4713  }
const parser_callback_t callback
callback function
Definition: json.hpp:4932
BasicJsonType discarded
a discarded value for the callback
Definition: json.hpp:4936
std::vector< BasicJsonType * > ref_stack
stack to model hierarchy of values
Definition: json.hpp:4922
#define JSON_THROW(exception)
Definition: json.hpp:1754
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
std::pair< bool, BasicJsonType * > handle_value(Value &&v, const bool skip_callback=false)
Definition: json.hpp:4856
std::string to_string(WindowPattern const &pattern)
std::vector< bool > keep_stack
stack to manage which values to keep
Definition: json.hpp:4924
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_callback_parser< BasicJsonType >::string ( string_t val)
inline

Definition at line 4691 of file json.hpp.

4692  {
4693  handle_value(val);
4694  return true;
4695  }
std::pair< bool, BasicJsonType * > handle_value(Value &&v, const bool skip_callback=false)
Definition: json.hpp:4856

Member Data Documentation

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

whether to throw exceptions in case of errors

Definition at line 4934 of file json.hpp.

template<typename BasicJsonType>
const parser_callback_t nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::callback = nullptr
private

callback function

Definition at line 4932 of file json.hpp.

template<typename BasicJsonType>
BasicJsonType nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::discarded = BasicJsonType::value_t::discarded
private

a discarded value for the callback

Definition at line 4936 of file json.hpp.

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

whether a syntax error occurred

Definition at line 4930 of file json.hpp.

template<typename BasicJsonType>
std::vector<bool> nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::keep_stack {}
private

stack to manage which values to keep

Definition at line 4924 of file json.hpp.

template<typename BasicJsonType>
std::vector<bool> nlohmann::detail::json_sax_dom_callback_parser< BasicJsonType >::key_keep_stack {}
private

stack to manage which object keys to keep

Definition at line 4926 of file json.hpp.

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

helper to hold the reference for the next object element

Definition at line 4928 of file json.hpp.

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

stack to model hierarchy of values

Definition at line 4922 of file json.hpp.

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

the parsed JSON value

Definition at line 4920 of file json.hpp.


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