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


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




{\ttfamily \#include $<$QC\+\_\+\+Range\+Iterator.\+dox.\+h$>$}



Inheritance diagram for Qore\+::Range\+Iterator\+:
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=202pt]{class_qore_1_1_range_iterator__inherit__graph}
\end{center}
\end{figure}
\doxysubsection*{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 INVALID-\/\+ITERATOR} 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{basic_data_types_True}{True}} while there are more numbers to iterate and \mbox{\hyperlink{basic_data_types_False}{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{basic_data_types_True}{True}} if the iterator is currently pointing at a valid element, \mbox{\hyperlink{basic_data_types_False}{False}} if not \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{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_ga0bf214ec2c777032a6078bd979637e69}{range()}}. Unlike \mbox{\hyperlink{group__list__functions_ga0bf214ec2c777032a6078bd979637e69}{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_ga0bf214ec2c777032a6078bd979637e69}{Qore\+::range()}}).

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

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

\end{DoxyCode}

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

\mbox{\hyperlink{group__range__functions_gad5b4d3ad3f6c36d2e714bc6ed757a507}{xrange()}}
\end{DoxySeeAlso}
\begin{DoxySince}{Since}

\begin{DoxyItemize}
\item Qore 0.\+8.\+6
\item Qore 0.\+9.\+5 does not include the upper limit in the range unless \mbox{\hyperlink{parse_directives_broken-range}{\%broken-\/range}} is set 
\end{DoxyItemize}
\end{DoxySince}


\doxysubsection{Member Function Documentation}
\mbox{\Hypertarget{class_qore_1_1_range_iterator_ae1659e4a23b185f2cf371b015d806088}\label{class_qore_1_1_range_iterator_ae1659e4a23b185f2cf371b015d806088}} 
\index{Qore::RangeIterator@{Qore::RangeIterator}!constructor@{constructor}}
\index{constructor@{constructor}!Qore::RangeIterator@{Qore::RangeIterator}}
\doxysubsubsection{\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}{0}
\DoxyCodeLine{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::RangeIterator@{Qore::RangeIterator}!constructor@{constructor}}
\index{constructor@{constructor}!Qore::RangeIterator@{Qore::RangeIterator}}
\doxysubsubsection{\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}{0}
\DoxyCodeLine{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::RangeIterator@{Qore::RangeIterator}!copy@{copy}}
\index{copy@{copy}!Qore::RangeIterator@{Qore::RangeIterator}}
\doxysubsubsection{\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}{0}
\DoxyCodeLine{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::RangeIterator@{Qore::RangeIterator}!getValue@{getValue}}
\index{getValue@{getValue}!Qore::RangeIterator@{Qore::RangeIterator}}
\doxysubsubsection{\texorpdfstring{getValue()}{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 INVALID-\/\+ITERATOR} exception if the iterator is invalid 

\begin{DoxyReturn}{Returns}
the current value or throws an {\ttfamily INVALID-\/\+ITERATOR} exception if the iterator is invalid
\end{DoxyReturn}
\begin{DoxyParagraph}{Code Flags\+:}
\mbox{\hyperlink{code_flags_RET_VALUE_ONLY}{RET\+\_\+\+VALUE\+\_\+\+ONLY}}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example\+:}

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

\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em INVALID-\/\+ITERATOR} & the iterator is not pointing at a valid element \\
\hline
{\em ITERATOR-\/\+THREAD-\/\+ERROR} & 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_aa01374b285003faa21b045082063ac12}{Qore\+::\+Abstract\+Iterator}}.

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



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

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

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

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

\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em ITERATOR-\/\+THREAD-\/\+ERROR} & 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::RangeIterator@{Qore::RangeIterator}!reset@{reset}}
\index{reset@{reset}!Qore::RangeIterator@{Qore::RangeIterator}}
\doxysubsubsection{\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}{0}
\DoxyCodeLine{\textcolor{comment}{\# raw RangeIterator object usage}}
\DoxyCodeLine{RangeIterator r(0, 2);}
\DoxyCodeLine{foreach int i \textcolor{keywordflow}{in} (r) \{}
\DoxyCodeLine{    printf(\textcolor{stringliteral}{"{}i=\%d\(\backslash\)n"{}}, i);}
\DoxyCodeLine{    \textcolor{keywordflow}{if} (i == 1)}
\DoxyCodeLine{        \textcolor{keywordflow}{break};}
\DoxyCodeLine{\}}
\DoxyCodeLine{\textcolor{comment}{\# i=0}}
\DoxyCodeLine{\textcolor{comment}{\# i=1}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{comment}{\# show the reset feature; start iterating all over again}}
\DoxyCodeLine{r.reset();}
\DoxyCodeLine{foreach int i \textcolor{keywordflow}{in} (r)}
\DoxyCodeLine{    printf(\textcolor{stringliteral}{"{}reused i=\%d\(\backslash\)n"{}}, i);}
\DoxyCodeLine{\textcolor{comment}{\# reused i=0}}
\DoxyCodeLine{\textcolor{comment}{\# reused i=1}}
\DoxyCodeLine{\textcolor{comment}{\# reused i=2}}

\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em ITERATOR-\/\+THREAD-\/\+ERROR} & 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::RangeIterator@{Qore::RangeIterator}!valid@{valid}}
\index{valid@{valid}!Qore::RangeIterator@{Qore::RangeIterator}}
\doxysubsubsection{\texorpdfstring{valid()}{valid()}}
{\footnotesize\ttfamily bool Qore\+::\+Range\+Iterator\+::valid (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [virtual]}}



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

\begin{DoxyReturn}{Returns}
\mbox{\hyperlink{basic_data_types_True}{True}} if the iterator is currently pointing at a valid element, \mbox{\hyperlink{basic_data_types_False}{False}} if not
\end{DoxyReturn}
\begin{DoxyParagraph}{Code Flags\+:}
\mbox{\hyperlink{code_flags_CONSTANT}{CONSTANT}}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keywordflow}{if} (i.valid())}
\DoxyCodeLine{    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}}.

