\hypertarget{class_qore_1_1_range_iterator}{}\section{Qore\+:\+:Range\+Iterator Class Reference}
\label{class_qore_1_1_range_iterator}\index{Qore\+::\+Range\+Iterator@{Qore\+::\+Range\+Iterator}}


This class defines a range-\/like iterator to be used to iterate numerical sequences.  




Inheritance diagram for Qore\+:\+:Range\+Iterator\+:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=193pt]{class_qore_1_1_range_iterator__inherit__graph}
\end{center}
\end{figure}
\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\mbox{\hyperlink{class_qore_1_1_range_iterator_ae1659e4a23b185f2cf371b015d806088}{constructor}} (\mbox{\hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int}} start, \mbox{\hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int}} stop, \mbox{\hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int}} step=1, auto val)
\begin{DoxyCompactList}\small\item\em creates the numerical sequence iterator with the initial arguments \end{DoxyCompactList}\item 
\mbox{\hyperlink{class_qore_1_1_range_iterator_acdcab14b075fb022dfd4a221c3ddf1ab}{constructor}} (\mbox{\hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int}} stop)
\begin{DoxyCompactList}\small\item\em creates the numerical sequence iterator with the initial arguments \end{DoxyCompactList}\item 
\mbox{\hyperlink{class_qore_1_1_range_iterator_a20eb3d239c57b2f40ef5c9e7bd7334f1}{copy}} ()
\begin{DoxyCompactList}\small\item\em Creates a copy of the \mbox{\hyperlink{class_qore_1_1_range_iterator}{Range\+Iterator}} object, iterating the same object as the original and in the same position. \end{DoxyCompactList}\item 
auto \mbox{\hyperlink{class_qore_1_1_range_iterator_a96d2eb508ede8cc4a26141ccf94acecc}{get\+Value}} ()
\begin{DoxyCompactList}\small\item\em returns the current value or throws an {\ttfamily I\+N\+V\+A\+L\+I\+D-\/\+I\+T\+E\+R\+A\+T\+OR} exception if the iterator is invalid \end{DoxyCompactList}\item 
bool \mbox{\hyperlink{class_qore_1_1_range_iterator_ab2c4071b0c75ac9f721880e483e3e81a}{next}} ()
\begin{DoxyCompactList}\small\item\em This method returns \mbox{\hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True}} while there are more numbers to iterate and \mbox{\hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False}} when the range has been completely iterated. \end{DoxyCompactList}\item 
\mbox{\hyperlink{class_qore_1_1_range_iterator_aa29d1b2be6d564c030c79ca73645da6f}{reset}} ()
\begin{DoxyCompactList}\small\item\em Reset the iterator instance to its initial state (start, stop, and step). \end{DoxyCompactList}\item 
bool \mbox{\hyperlink{class_qore_1_1_range_iterator_ad235b23928683ba0929d97f6d6401bb9}{valid}} ()
\begin{DoxyCompactList}\small\item\em returns \mbox{\hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True}} if the iterator is currently pointing at a valid element, \mbox{\hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False}} if not \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
This class defines a range-\/like iterator to be used to iterate numerical sequences. 

The main purpose is to provide resource friendly iterator to generate numerical rows (sequences) with ascending and descending ordering.

The \mbox{\hyperlink{class_qore_1_1_range_iterator}{Range\+Iterator}} class provides an iterator for loop statements with functionality similar to \mbox{\hyperlink{group__list__functions_gabf1a283eed97fa22a32be14b30add9e6}{range()}}. Unlike \mbox{\hyperlink{group__list__functions_gabf1a283eed97fa22a32be14b30add9e6}{range()}}, \mbox{\hyperlink{class_qore_1_1_range_iterator}{Range\+Iterator}} objects do not generate real \mbox{\hyperlink{container_data_types_list}{lists}} but calculate iteration values on demand.

This results in memory-\/friendly handling for large numerical sequences compared to generating a list in memory and iterating that list (as with \mbox{\hyperlink{group__list__functions_gabf1a283eed97fa22a32be14b30add9e6}{Qore\+::range()}}).

\begin{DoxyParagraph}{Example\+: Range\+Iterator basic usage}

\begin{DoxyCode}
RangeIterator r(0, 2);
foreach int i \textcolor{keywordflow}{in} (r)
    \mbox{\hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}}(\textcolor{stringliteral}{"i=%d\(\backslash\)n"}, i);
\textcolor{comment}{# i=0}
\textcolor{comment}{# i=1}
\textcolor{comment}{# i=2}
\end{DoxyCode}

\end{DoxyParagraph}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{group__list__functions_gabf1a283eed97fa22a32be14b30add9e6}{range()}} 

\mbox{\hyperlink{group__range__functions_gad5b4d3ad3f6c36d2e714bc6ed757a507}{xrange()}}
\end{DoxySeeAlso}
\begin{DoxySince}{Since}
Qore 0.\+8.\+6 
\end{DoxySince}


\subsection{Member Function Documentation}
\mbox{\Hypertarget{class_qore_1_1_range_iterator_ae1659e4a23b185f2cf371b015d806088}\label{class_qore_1_1_range_iterator_ae1659e4a23b185f2cf371b015d806088}} 
\index{Qore\+::\+Range\+Iterator@{Qore\+::\+Range\+Iterator}!constructor@{constructor}}
\index{constructor@{constructor}!Qore\+::\+Range\+Iterator@{Qore\+::\+Range\+Iterator}}
\subsubsection{\texorpdfstring{constructor()}{constructor()}\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily Qore\+::\+Range\+Iterator\+::constructor (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int}}}]{start,  }\item[{\mbox{\hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int}}}]{stop,  }\item[{\mbox{\hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int}}}]{step = {\ttfamily 1},  }\item[{auto}]{val }\end{DoxyParamCaption})}



creates the numerical sequence iterator with the initial arguments 


\begin{DoxyParams}{Parameters}
{\em start} & an initial value \\
\hline
{\em stop} & a final value \\
\hline
{\em step} & is the interval. Default = 1 \\
\hline
{\em val} & an optional value to be returned instead of the default integer value\\
\hline
\end{DoxyParams}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
RangeIterator i(5, 10, 2);
\end{DoxyCode}

\end{DoxyParagraph}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{group__range__functions_gad5b4d3ad3f6c36d2e714bc6ed757a507}{xrange()}}
\end{DoxySeeAlso}
\begin{DoxySince}{Since}
Qore 0.\+8.\+11.\+1 this method takes the optional {\itshape val} argument 
\end{DoxySince}
\mbox{\Hypertarget{class_qore_1_1_range_iterator_acdcab14b075fb022dfd4a221c3ddf1ab}\label{class_qore_1_1_range_iterator_acdcab14b075fb022dfd4a221c3ddf1ab}} 
\index{Qore\+::\+Range\+Iterator@{Qore\+::\+Range\+Iterator}!constructor@{constructor}}
\index{constructor@{constructor}!Qore\+::\+Range\+Iterator@{Qore\+::\+Range\+Iterator}}
\subsubsection{\texorpdfstring{constructor()}{constructor()}\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily Qore\+::\+Range\+Iterator\+::constructor (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int}}}]{stop }\end{DoxyParamCaption})}



creates the numerical sequence iterator with the initial arguments 


\begin{DoxyParams}{Parameters}
{\em stop} & a final value\\
\hline
\end{DoxyParams}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
RangeIterator i(5);
\end{DoxyCode}

\end{DoxyParagraph}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{group__range__functions_gad5b4d3ad3f6c36d2e714bc6ed757a507}{xrange()}}
\end{DoxySeeAlso}
\begin{DoxySince}{Since}
Qore 0.\+8.\+11.\+1 
\end{DoxySince}
\mbox{\Hypertarget{class_qore_1_1_range_iterator_a20eb3d239c57b2f40ef5c9e7bd7334f1}\label{class_qore_1_1_range_iterator_a20eb3d239c57b2f40ef5c9e7bd7334f1}} 
\index{Qore\+::\+Range\+Iterator@{Qore\+::\+Range\+Iterator}!copy@{copy}}
\index{copy@{copy}!Qore\+::\+Range\+Iterator@{Qore\+::\+Range\+Iterator}}
\subsubsection{\texorpdfstring{copy()}{copy()}}
{\footnotesize\ttfamily Qore\+::\+Range\+Iterator\+::copy (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Creates a copy of the \mbox{\hyperlink{class_qore_1_1_range_iterator}{Range\+Iterator}} object, iterating the same object as the original and in the same position. 

\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
RangeIterator ni = i.copy();
\end{DoxyCode}
 
\end{DoxyParagraph}
\mbox{\Hypertarget{class_qore_1_1_range_iterator_a96d2eb508ede8cc4a26141ccf94acecc}\label{class_qore_1_1_range_iterator_a96d2eb508ede8cc4a26141ccf94acecc}} 
\index{Qore\+::\+Range\+Iterator@{Qore\+::\+Range\+Iterator}!get\+Value@{get\+Value}}
\index{get\+Value@{get\+Value}!Qore\+::\+Range\+Iterator@{Qore\+::\+Range\+Iterator}}
\subsubsection{\texorpdfstring{get\+Value()}{getValue()}}
{\footnotesize\ttfamily auto Qore\+::\+Range\+Iterator\+::get\+Value (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [virtual]}}



returns the current value or throws an {\ttfamily I\+N\+V\+A\+L\+I\+D-\/\+I\+T\+E\+R\+A\+T\+OR} exception if the iterator is invalid 

\begin{DoxyReturn}{Returns}
the current value or throws an {\ttfamily I\+N\+V\+A\+L\+I\+D-\/\+I\+T\+E\+R\+A\+T\+OR} exception if the iterator is invalid
\end{DoxyReturn}
\begin{DoxyParagraph}{Code Flags\+:}
\mbox{\hyperlink{code_flags_RET_VALUE_ONLY}{R\+E\+T\+\_\+\+V\+A\+L\+U\+E\+\_\+\+O\+N\+LY}}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
\textcolor{keywordflow}{while} (i.next()) \{
    \mbox{\hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}}(\textcolor{stringliteral}{"+ %y\(\backslash\)n"}, i.getValue());
\}
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em I\+N\+V\+A\+L\+I\+D-\/\+I\+T\+E\+R\+A\+T\+OR} & the iterator is not pointing at a valid element \\
\hline
{\em I\+T\+E\+R\+A\+T\+O\+R-\/\+T\+H\+R\+E\+A\+D-\/\+E\+R\+R\+OR} & this exception is thrown if this method is called from any thread other than the thread that created the object\\
\hline
\end{DoxyExceptions}
\begin{DoxyNote}{Note}
if a value was passed to the constructor, then that value is returned instead of the current range index 
\end{DoxyNote}


Implements \mbox{\hyperlink{class_qore_1_1_abstract_iterator_a1f7b94aa7237f59c4f959f4d33333d9a}{Qore\+::\+Abstract\+Iterator}}.

\mbox{\Hypertarget{class_qore_1_1_range_iterator_ab2c4071b0c75ac9f721880e483e3e81a}\label{class_qore_1_1_range_iterator_ab2c4071b0c75ac9f721880e483e3e81a}} 
\index{Qore\+::\+Range\+Iterator@{Qore\+::\+Range\+Iterator}!next@{next}}
\index{next@{next}!Qore\+::\+Range\+Iterator@{Qore\+::\+Range\+Iterator}}
\subsubsection{\texorpdfstring{next()}{next()}}
{\footnotesize\ttfamily bool Qore\+::\+Range\+Iterator\+::next (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [virtual]}}



This method returns \mbox{\hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True}} while there are more numbers to iterate and \mbox{\hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False}} when the range has been completely iterated. 

The iterator object should not be used after this method returns \mbox{\hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False}}.

\begin{DoxyReturn}{Returns}
\mbox{\hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True}} and \mbox{\hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False}} alternately unless it has no value iterate.
\end{DoxyReturn}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
\textcolor{keywordflow}{while} (i.next()) \{
    \mbox{\hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}}(\textcolor{stringliteral}{"value: %y\(\backslash\)n"}, i.getValue());
\}
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em I\+T\+E\+R\+A\+T\+O\+R-\/\+T\+H\+R\+E\+A\+D-\/\+E\+R\+R\+OR} & this exception is thrown if this method is called from any thread other than the thread that created the object \\
\hline
\end{DoxyExceptions}


Implements \mbox{\hyperlink{class_qore_1_1_abstract_iterator_ab10d5694cc2fcd3b6689ea7494da79de}{Qore\+::\+Abstract\+Iterator}}.

\mbox{\Hypertarget{class_qore_1_1_range_iterator_aa29d1b2be6d564c030c79ca73645da6f}\label{class_qore_1_1_range_iterator_aa29d1b2be6d564c030c79ca73645da6f}} 
\index{Qore\+::\+Range\+Iterator@{Qore\+::\+Range\+Iterator}!reset@{reset}}
\index{reset@{reset}!Qore\+::\+Range\+Iterator@{Qore\+::\+Range\+Iterator}}
\subsubsection{\texorpdfstring{reset()}{reset()}}
{\footnotesize\ttfamily Qore\+::\+Range\+Iterator\+::reset (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Reset the iterator instance to its initial state (start, stop, and step). 

Reset the iterator instance to its initial state (start, stop, and step).

\begin{DoxyParagraph}{Example}

\begin{DoxyCode}
\textcolor{comment}{# raw RangeIterator object usage}
RangeIterator r(0, 2);
foreach int i \textcolor{keywordflow}{in} (r) \{
    \mbox{\hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}}(\textcolor{stringliteral}{"i=%d\(\backslash\)n"}, i);
    \textcolor{keywordflow}{if} (i == 1)
        \textcolor{keywordflow}{break};
\}
\textcolor{comment}{# i=0}
\textcolor{comment}{# i=1}

\textcolor{comment}{# show the reset feature; start iterating all over again}
r.reset();
foreach int i \textcolor{keywordflow}{in} (r)
    \mbox{\hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}}(\textcolor{stringliteral}{"reused i=%d\(\backslash\)n"}, i);
\textcolor{comment}{# reused i=0}
\textcolor{comment}{# reused i=1}
\textcolor{comment}{# reused i=2}
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em I\+T\+E\+R\+A\+T\+O\+R-\/\+T\+H\+R\+E\+A\+D-\/\+E\+R\+R\+OR} & this exception is thrown if this method is called from any thread other than the thread that created the object \\
\hline
\end{DoxyExceptions}
\mbox{\Hypertarget{class_qore_1_1_range_iterator_ad235b23928683ba0929d97f6d6401bb9}\label{class_qore_1_1_range_iterator_ad235b23928683ba0929d97f6d6401bb9}} 
\index{Qore\+::\+Range\+Iterator@{Qore\+::\+Range\+Iterator}!valid@{valid}}
\index{valid@{valid}!Qore\+::\+Range\+Iterator@{Qore\+::\+Range\+Iterator}}
\subsubsection{\texorpdfstring{valid()}{valid()}}
{\footnotesize\ttfamily bool Qore\+::\+Range\+Iterator\+::valid (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [virtual]}}



returns \mbox{\hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True}} if the iterator is currently pointing at a valid element, \mbox{\hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False}} if not 

\begin{DoxyReturn}{Returns}
\mbox{\hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True}} if the iterator is currently pointing at a valid element, \mbox{\hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False}} if not
\end{DoxyReturn}
\begin{DoxyParagraph}{Code Flags\+:}
\mbox{\hyperlink{code_flags_CONSTANT}{C\+O\+N\+S\+T\+A\+NT}}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
\textcolor{keywordflow}{if} (i.valid())
    \mbox{\hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}}(\textcolor{stringliteral}{"current value: %y\(\backslash\)n"}, i.getValue());
\end{DoxyCode}
 
\end{DoxyParagraph}


Implements \mbox{\hyperlink{class_qore_1_1_abstract_iterator_aee1def5d872b487b8917a166d9b263e8}{Qore\+::\+Abstract\+Iterator}}.

