/*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2016-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2016-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
}
}
-folly::ScopeGuardImpl<DynamicParser::ParserStack::Pop>
-DynamicParser::ParserStack::push(
+DynamicParser::ParserStack::PopGuard DynamicParser::ParserStack::push(
const folly::dynamic& k,
const folly::dynamic& v) noexcept {
// Save the previous state of the parser.
- folly::ScopeGuardImpl<DynamicParser::ParserStack::Pop> guard(
- DynamicParser::ParserStack::Pop(this)
- );
+ DynamicParser::ParserStack::PopGuard guard{this};
key_ = &k;
value_ = &v;
// We create errors_ sub-objects lazily to keep the result small.
/*
- * Copyright 2017-present Facebook, Inc.
+ * Copyright 2016-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
const folly::dynamic* value_;
ParserStack* stackPtr_;
};
+ struct PopGuard {
+ explicit PopGuard(ParserStack* sp) : pop_(in_place, sp) {}
+ ~PopGuard() {
+ pop_ && ((*pop_)(), true);
+ }
+
+ private:
+ Optional<Pop> pop_;
+ };
explicit ParserStack(const folly::dynamic* input)
: value_(input),
// Lets user code nest parser calls by recording current key+value and
// returning an RAII guard to restore the old one. `noexcept` since it
// is used unwrapped.
- folly::ScopeGuardImpl<Pop> push(
- const folly::dynamic& k, const folly::dynamic& v
- ) noexcept;
+ PopGuard push(const folly::dynamic& k, const folly::dynamic& v) noexcept;
// Throws DynamicParserLogicError if used outside of a parsing function.
inline const folly::dynamic& key() const;
/*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2016-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.