| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #pragma once
- #include <iterator>
- #include <jvalidate/detail/deref_proxy.h>
- namespace jvalidate::adapter::detail {
- /**
- * @brief An iterator for binding JSON values of type Array - which are
- * congruent to a vector<JSON>.
- *
- * @tparam It The underlying iterator type being operated on
- * @tparam Adapter The owning adapter type, must fulfill the following
- * contracts:
- * - is constructible from the value_type of It
- * Additionally, Adapter is expected to conform to the jvalidate::Adapter
- * concept.
- */
- template <typename It, typename Adapter> class JsonArrayIterator : public It {
- public:
- using value_type = Adapter;
- using reference = Adapter;
- using pointer = ::jvalidate::detail::DerefProxy<reference>;
- using difference_type = std::ptrdiff_t;
- using iterator_category = std::forward_iterator_tag;
- JsonArrayIterator() = default; // Sentinel for handling null objects
- JsonArrayIterator(It it) : It(it) {}
- reference operator*() const { return Adapter(It::operator*()); }
- pointer operator->() const { return {operator*()}; }
- JsonArrayIterator operator++(int) {
- auto tmp = *this;
- ++*this;
- return tmp;
- }
- JsonArrayIterator & operator++() {
- It::operator++();
- return *this;
- }
- };
- }
|