1 #ifndef GENESIS_UTILS_FORMATS_JSON_ITERATOR_H_
2 #define GENESIS_UTILS_FORMATS_JSON_ITERATOR_H_
102 class JsonIterator :
public std::iterator<std::random_access_iterator_tag, U>
113 std::is_same<U, JsonDocument>::value or
114 std::is_same<U, const JsonDocument>::value,
115 "JsonIterator only accepts (const) JsonDocument."
127 using pointer =
typename std::conditional<std::is_const<U>::value,
131 using reference =
typename std::conditional<std::is_const<U>::value,
157 iterator_ = begin_value;
163 iterator_ = end_value;
169 return (iterator_ == begin_value);
175 return (iterator_ == end_value);
196 difference_type iterator_ = std::numeric_limits<std::ptrdiff_t>::denorm_min();
242 assert(object_ !=
nullptr);
244 switch( object_->type_ ) {
246 iterator_.
object_iterator =
typename JsonDocument::ObjectType::iterator();
251 iterator_.
array_iterator =
typename JsonDocument::ArrayType::iterator();
266 : object_(other.object_)
267 , iterator_(other.iterator_)
274 std::is_nothrow_move_constructible<pointer>::value and
275 std::is_nothrow_move_assignable<pointer>::value and
276 std::is_nothrow_move_constructible<InternalIterator>::value and
277 std::is_nothrow_move_assignable<InternalIterator>::value
296 assert(object_ !=
nullptr);
298 switch( object_->type_ ) {
308 throw std::out_of_range(
"Cannot get value from Json Iterator.");
315 throw std::out_of_range(
"Cannot get value from Json Iterator.");
326 assert(object_ !=
nullptr);
328 switch( object_->type_ ) {
342 throw std::out_of_range(
"cannot get value");
364 assert(object_ !=
nullptr);
366 switch( object_->type_ ) {
401 assert(object_ !=
nullptr);
403 switch( object_->type_ ) {
428 if( object_ != other.object_ ) {
429 throw std::domain_error(
"Cannot compare Json Iterators of different containers.");
432 assert(object_ !=
nullptr);
434 switch( object_->type_ ) {
439 return (iterator_.
array_iterator == other.iterator_.array_iterator);
463 if( object_ != other.object_ ) {
464 throw std::domain_error(
"Cannot compare Json Iterators of different containers.");
467 assert(object_ !=
nullptr);
469 switch( object_->type_ ) {
471 throw std::domain_error(
"Cannot compare order of Json object iterators.");
474 return (iterator_.
array_iterator < other.iterator_.array_iterator);
488 return not other.operator < (*this);
515 assert(object_ !=
nullptr);
517 switch( object_->type_ ) {
519 throw std::domain_error(
"Cannot use offsets with Json object iterators.");
571 assert(object_ !=
nullptr);
573 switch( object_->type_ ) {
575 throw std::domain_error(
"Cannot use offsets with Json object iterators.");
594 assert(object_ !=
nullptr);
596 switch( object_->type_ ) {
598 throw std::domain_error(
"Cannot use operator[] for Json object iterators.");
606 throw std::out_of_range(
"Cannot get value from Json Iterator.");
614 throw std::out_of_range(
"Cannot get value from Json Iterator.");
627 typename JsonDocument::ObjectType::key_type
key()
const
629 assert(object_ !=
nullptr);
631 if( object_->is_object() ) {
635 throw std::domain_error(
"Cannot use key() for non-object Json Iterators.");
657 void set_begin() noexcept
659 assert(object_ !=
nullptr);
661 switch( object_->type_ ) {
686 void set_end() noexcept
688 assert(object_ !=
nullptr);
690 switch( object_->type_ ) {
712 InternalIterator iterator_ = InternalIterator();
719 #endif // include guard