proxygen
folly::DynamicParser::ParserStack Struct Reference

Classes

struct  Pop
 
struct  PopGuard
 

Public Member Functions

 ParserStack (const folly::dynamic *input)
 
 ParserStack (const ParserStack &)=delete
 
ParserStackoperator= (const ParserStack &)=delete
 
 ParserStack (ParserStack &&)=delete
 
ParserStackoperator= (ParserStack &&)=delete
 
PopGuard push (const folly::dynamic &k, const folly::dynamic &v) noexcept
 
const folly::dynamickey () const
 
const folly::dynamicvalue () const
 
folly::dynamicerrors (bool allow_non_string_keys) noexcept
 
folly::dynamic releaseErrors ()
 
void throwErrors ()
 

Private Member Functions

folly::dynamic releaseErrorsImpl ()
 

Private Attributes

const folly::dynamickey_ {nullptr}
 
const folly::dynamicvalue_
 
folly::dynamic errors_
 
std::vector< const folly::dynamic * > unmaterializedSubErrorKeys_
 
std::vector< folly::dynamic * > subErrors_
 

Friends

struct Pop
 

Detailed Description

Definition at line 329 of file DynamicParser.h.

Constructor & Destructor Documentation

folly::DynamicParser::ParserStack::ParserStack ( const folly::dynamic input)
inlineexplicit

Definition at line 349 of file DynamicParser.h.

References k, folly::pushmi::__adl::noexcept(), and folly::value().

350  : value_(input),
352  subErrors_({&errors_}) {}
static ObjectMaker object()
Definition: dynamic-inl.h:240
const folly::dynamic * value_
std::vector< folly::dynamic * > subErrors_
folly::DynamicParser::ParserStack::ParserStack ( const ParserStack )
delete
folly::DynamicParser::ParserStack::ParserStack ( ParserStack &&  )
delete

Member Function Documentation

folly::dynamic & folly::DynamicParser::ParserStack::errors ( bool  allow_non_string_keys)
noexcept

Definition at line 144 of file DynamicParser.cpp.

References folly::dynamic::object().

Referenced by folly::DynamicParser::reportError().

145  {
146  // Materialize the lazy "key + parent's type" error objects we'll need.
147  CHECK(!subErrors_.empty()) << "Internal bug: out of suberrors";
148  for (const auto& suberror_key : unmaterializedSubErrorKeys_) {
149  auto& nested = (*subErrors_.back())["nested"];
150  if (nested.isNull()) {
151  nested = folly::dynamic::object();
152  }
153  // Find, or insert a dummy entry for the current key
154  auto& my_errors =
155  insertAtKey(&nested, allow_non_string_keys, *suberror_key);
156  if (my_errors.isNull()) {
157  my_errors = folly::dynamic::object();
158  }
159  subErrors_.emplace_back(&my_errors);
160  }
161  unmaterializedSubErrorKeys_.clear();
162  return *subErrors_.back();
163 }
static ObjectMaker object()
Definition: dynamic-inl.h:240
std::vector< folly::dynamic * > subErrors_
std::vector< const folly::dynamic * > unmaterializedSubErrorKeys_
const folly::dynamic & folly::DynamicParser::ParserStack::key ( ) const
inline

Definition at line 315 of file DynamicParser-inl.h.

315  {
316  if (!key_) {
317  throw DynamicParserLogicError("Only call key() inside parsing callbacks.");
318  }
319  return *key_;
320 }
const folly::dynamic * key_
ParserStack& folly::DynamicParser::ParserStack::operator= ( const ParserStack )
delete
ParserStack& folly::DynamicParser::ParserStack::operator= ( ParserStack &&  )
delete
DynamicParser::ParserStack::PopGuard folly::DynamicParser::ParserStack::push ( const folly::dynamic k,
const folly::dynamic v 
)
noexcept

Definition at line 130 of file DynamicParser.cpp.

References folly::gen::guard(), k, and v.

132  {
133  // Save the previous state of the parser.
134  DynamicParser::ParserStack::PopGuard guard{this};
135  key_ = &k;
136  value_ = &v;
137  // We create errors_ sub-objects lazily to keep the result small.
138  unmaterializedSubErrorKeys_.emplace_back(key_);
139  return guard;
140 }
const folly::dynamic * key_
auto v
const folly::dynamic * value_
GuardImpl guard(ErrorHandler &&handler)
Definition: Base.h:840
std::vector< const folly::dynamic * > unmaterializedSubErrorKeys_
KeyT k
folly::dynamic folly::DynamicParser::ParserStack::releaseErrors ( )

Definition at line 165 of file DynamicParser.cpp.

165  {
166  if (key_ || unmaterializedSubErrorKeys_.size() != 0 ||
167  subErrors_.size() != 1) {
168  throw DynamicParserLogicError(
169  "Do not releaseErrors() while parsing: ",
170  key_ != nullptr,
171  " / ",
173  " / ",
174  subErrors_.size());
175  }
176  return releaseErrorsImpl();
177 }
const folly::dynamic * key_
std::vector< folly::dynamic * > subErrors_
std::vector< const folly::dynamic * > unmaterializedSubErrorKeys_
folly::dynamic folly::DynamicParser::ParserStack::releaseErrorsImpl ( )
private

Definition at line 183 of file DynamicParser.cpp.

References folly::gen::move.

183  {
184  if (errors_.isNull()) {
185  throw DynamicParserLogicError("Do not releaseErrors() twice");
186  }
187  auto errors = std::move(errors_);
188  errors_ = nullptr; // Prevent a second release.
189  value_ = nullptr; // Break attempts to parse again.
190  return errors;
191 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const folly::dynamic * value_
bool isNull() const
Definition: dynamic-inl.h:507
folly::dynamic & errors(bool allow_non_string_keys) noexcept
void folly::DynamicParser::ParserStack::throwErrors ( )

Definition at line 179 of file DynamicParser.cpp.

Referenced by folly::DynamicParser::reportError().

179  {
180  throw DynamicParserParseError(releaseErrorsImpl());
181 }
const folly::dynamic & folly::DynamicParser::ParserStack::value ( ) const
inline

Definition at line 322 of file DynamicParser-inl.h.

322  {
323  if (!value_) {
324  throw DynamicParserLogicError(
325  "Parsing nullptr, or parsing after releaseErrors()");
326  }
327  return *value_;
328 }
const folly::dynamic * value_

Friends And Related Function Documentation

friend struct Pop
friend

Definition at line 380 of file DynamicParser.h.

Member Data Documentation

folly::dynamic folly::DynamicParser::ParserStack::errors_
private

Definition at line 398 of file DynamicParser.h.

const folly::dynamic* folly::DynamicParser::ParserStack::key_ {nullptr}
private

Definition at line 385 of file DynamicParser.h.

std::vector<folly::dynamic*> folly::DynamicParser::ParserStack::subErrors_
private

Definition at line 403 of file DynamicParser.h.

std::vector<const folly::dynamic*> folly::DynamicParser::ParserStack::unmaterializedSubErrorKeys_
private

Definition at line 401 of file DynamicParser.h.

const folly::dynamic* folly::DynamicParser::ParserStack::value_
private

Definition at line 387 of file DynamicParser.h.


The documentation for this struct was generated from the following files: