/* -*- mode: c++; indent-tabs-mode: nil -*- */
/** @file QC_AbstractIterator.qpp AbstractIterator class (interface) definition */
/*
  Qore Programming Language

  Copyright (C) 2003 - 2023 Qore Technologies, s.r.o.

  Permission is hereby granted, free of charge, to any person obtaining a
  copy of this software and associated documentation files (the "Software"),
  to deal in the Software without restriction, including without limitation
  the rights to use, copy, modify, merge, publish, distribute, sublicense,
  and/or sell copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  DEALINGS IN THE SOFTWARE.

  Note that the Qore library is released under a choice of three open-source
  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
  information.
*/

#include <qore/Qore.h>

//! This class defines an abstract interface for iterators
/** Classes inheriting this class can be used to iterate abstract or complex objects with @ref while (using AbstractIterator::next()) or directly in the following language constructs:
    - @ref map
    - @ref foldr and @ref foldl
    - @ref select
    - @ref foreach
 */
qclass AbstractIterator [arg=AbstractIterator* i; ns=Qore];

//! Moves the current position to the next element; returns @ref False if there are no more elements
/** This method will return @ref True again after it returns @ref False once if the object being iterated is not empty, otherwise it will always return @ref False.
    The iterator object should not be used after this method returns @ref False

    @return @ref False if there are no more elements (in which case the iterator object is invalid and should not be used); @ref True if successful (meaning that the iterator object is valid)

    @par Example:
    @code{.py}
while (i.next()) {
    printf(" + %y\n", i.getValue());
}
    @endcode
 */
abstract bool AbstractIterator::next();

//! returns the current value
/** @return the current value

    @par Example:
    @code{.py}
while (i.next()) {
    printf("+ %y\n", i.getValue());
}
    @endcode

    @throw INVALID-ITERATOR the iterator is not pointing at a valid element

    @see AbstractIterator::valid()
 */
abstract auto AbstractIterator::getValue();

//! returns @ref True "True" if the iterator is currently pointing at a valid element, @ref False "False" if not
/** @return @ref True "True" if the iterator is currently pointing at a valid element, @ref False "False" if not

    @par Example:
    @code{.py}
if (i.valid())
    printf("current value: %y\n", i.getValue());
    @endcode
 */
abstract bool AbstractIterator::valid();
