32 #ifndef _QORE_RANGEITERATOR_H
34 #define _QORE_RANGEITERATOR_H
59 m_increasing(start < stop),
61 val((!v.isNothing() && step >= 0) ? v.refSelf() :
QoreValue()) {
63 xsink->
raiseException(
"RANGEITERATOR-ERROR",
"Value of the 'step' argument has to be greater than 0 " \
64 "(value passed: " QLLD
")", step);
76 DLLLOCAL RangeIterator(
const RangeIterator& old)
77 : m_start(old.m_start), m_stop(old.m_stop), m_step(old.m_step),
78 m_position(old.m_position), m_increasing(old.m_increasing),
79 m_valid(old.m_valid), val(old.val.refSelf()) {
82 DLLLOCAL
virtual ~RangeIterator() {
90 DLLLOCAL
bool next() {
92 m_valid = m_increasing ? (calculateCurrent() < m_stop) : (calculateCurrent() > m_stop);
98 DLLLOCAL
bool valid()
const {
104 xsink->
raiseException(
"INVALID-ITERATOR",
"the %s is not pointing at a valid element; make sure " \
105 "%s::next() returns True before calling this method", getName(), getName());
109 int64 rv = calculateCurrent();
113 DLLLOCAL
void reset() {
118 DLLLOCAL
virtual const char* getName()
const {
return "RangeIterator"; }
120 DLLLOCAL
virtual const QoreTypeInfo* getElementType()
const {
121 return val.isNothing() ? bigIntTypeInfo : val.
getTypeInfo();
125 DLLLOCAL
int64 calculateCurrent() {
127 return m_start + (m_position * m_step);
129 return m_start - (m_position * m_step);
#define PO_BROKEN_RANGE
allow for old pre-Qore 0.9.5 "range()" and "xrange()" behavior where the upper limit was included in ...
Definition: Restrictions.h:99
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
DLLEXPORT AbstractQoreNode * raiseException(const char *err, const char *fmt,...)
appends a Qore-language exception to the list
defines a Qore-language class
Definition: QoreClass.h:249
abstract base class for iterator private data
Definition: QoreIteratorBase.h:68
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:275
DLLEXPORT void discard(ExceptionSink *xsink)
dereferences any contained AbstractQoreNode pointer and sets to 0; does not modify other values
DLLEXPORT const QoreTypeInfo * getTypeInfo() const
returns the type of the value
DLLEXPORT bool hasNode() const
returns true if the object contains a non-null AbstractQoreNode pointer (ie type == QV_Node && v....
DLLEXPORT QoreValue refSelf() const
references the contained value if type == QV_Node, returns itself