mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
feb1e7feb6
* work on the ondemand iterators * guarding two SIMDJSON_ASSUME * simplify following @jkeiser's comment * adding safety rails to the iterators * silencing a warning. * updating the amalgamation files
85 lines
3.2 KiB
C++
85 lines
3.2 KiB
C++
#ifndef SIMDJSON_GENERIC_ONDEMAND_OBJECT_ITERATOR_H
|
|
|
|
#ifndef SIMDJSON_CONDITIONAL_INCLUDE
|
|
#define SIMDJSON_GENERIC_ONDEMAND_OBJECT_ITERATOR_H
|
|
#include "simdjson/generic/ondemand/base.h"
|
|
#include "simdjson/generic/implementation_simdjson_result_base.h"
|
|
#include "simdjson/generic/ondemand/value_iterator.h"
|
|
#endif // SIMDJSON_CONDITIONAL_INCLUDE
|
|
|
|
namespace simdjson {
|
|
namespace SIMDJSON_IMPLEMENTATION {
|
|
namespace ondemand {
|
|
|
|
class object_iterator {
|
|
public:
|
|
/**
|
|
* Create a new invalid object_iterator.
|
|
*
|
|
* Exists so you can declare a variable and later assign to it before use.
|
|
*/
|
|
simdjson_inline object_iterator() noexcept = default;
|
|
|
|
//
|
|
// Iterator interface
|
|
//
|
|
|
|
// Reads key and value, yielding them to the user.
|
|
// MUST ONLY BE CALLED ONCE PER ITERATION.
|
|
simdjson_inline simdjson_result<field> operator*() noexcept;
|
|
// Assumes it's being compared with the end. true if depth < iter->depth.
|
|
simdjson_inline bool operator==(const object_iterator &) const noexcept;
|
|
// Assumes it's being compared with the end. true if depth >= iter->depth.
|
|
simdjson_inline bool operator!=(const object_iterator &) const noexcept;
|
|
// Checks for ']' and ','
|
|
// YOU MUST NOT CALL THIS IF operator* YIELDED AN ERROR.
|
|
// YOU MUST NOT CALL THIS WITHOUT A CORRESPONDING operator* CALL.
|
|
simdjson_inline object_iterator &operator++() noexcept;
|
|
|
|
private:
|
|
#if SIMDJSON_DEVELOPMENT_CHECKS
|
|
bool has_been_referenced{false};
|
|
#endif
|
|
/**
|
|
* The underlying JSON iterator.
|
|
*
|
|
* PERF NOTE: expected to be elided in favor of the parent document: this is set when the object
|
|
* is first used, and never changes afterwards.
|
|
*/
|
|
value_iterator iter{};
|
|
|
|
simdjson_inline object_iterator(const value_iterator &iter) noexcept;
|
|
friend struct simdjson_result<object_iterator>;
|
|
friend class object;
|
|
};
|
|
|
|
} // namespace ondemand
|
|
} // namespace SIMDJSON_IMPLEMENTATION
|
|
} // namespace simdjson
|
|
|
|
namespace simdjson {
|
|
|
|
template<>
|
|
struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object_iterator> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::object_iterator> {
|
|
public:
|
|
simdjson_inline simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::object_iterator &&value) noexcept; ///< @private
|
|
simdjson_inline simdjson_result(error_code error) noexcept; ///< @private
|
|
simdjson_inline simdjson_result() noexcept = default;
|
|
|
|
//
|
|
// Iterator interface
|
|
//
|
|
|
|
// Reads key and value, yielding them to the user.
|
|
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::field> operator*() noexcept; // MUST ONLY BE CALLED ONCE PER ITERATION.
|
|
// Assumes it's being compared with the end. true if depth < iter->depth.
|
|
simdjson_inline bool operator==(const simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object_iterator> &) const noexcept;
|
|
// Assumes it's being compared with the end. true if depth >= iter->depth.
|
|
simdjson_inline bool operator!=(const simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object_iterator> &) const noexcept;
|
|
// Checks for ']' and ','
|
|
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object_iterator> &operator++() noexcept;
|
|
};
|
|
|
|
} // namespace simdjson
|
|
|
|
#endif // SIMDJSON_GENERIC_ONDEMAND_OBJECT_ITERATOR_H
|