The OpenD Programming Language

IntervalRange

A range over an Interval.

IntervalRange is only ever constructed by Interval. However, when it is constructed, it is given a function, func, which is used to generate the time points which are iterated over. func takes a time point and returns a time point of the same type. For instance, to iterate over all of the days in the interval Interval!Date, pass a function to Interval's fwdRange where that function took a std.datetime.date.Date and returned a std.datetime.date.Date which was one day later. That function would then be used by IntervalRange's popFront to iterate over the std.datetime.date.Dates in the interval.

If dir == Direction.fwd, then a range iterates forward in time, whereas if dir == Direction.bwd, then it iterates backwards in time. So, if dir == Direction.fwd then front == interval.begin, whereas if dir == Direction.bwd then front == interval.end. func must generate a time point going in the proper direction of iteration, or a std.datetime.date.DateTimeException will be thrown. So, to iterate forward in time, the time point that func generates must be later in time than the one passed to it. If it's either identical or earlier in time, then a std.datetime.date.DateTimeException will be thrown. To iterate backwards, then the generated time point must be before the time point which was passed in.

If the generated time point is ever passed the edge of the range in the proper direction, then the edge of that range will be used instead. So, if iterating forward, and the generated time point is past the interval's end, then front becomes end. If iterating backwards, and the generated time point is before begin, then front becomes begin. In either case, the range would then be empty.

Also note that while normally the begin of an interval is included in it and its end is excluded from it, if dir == Direction.bwd, then begin is treated as excluded and end is treated as included. This allows for the same behavior in both directions. This works because none of Interval's functions which care about whether begin or end is included or excluded are ever called by IntervalRange. interval returns a normal interval, regardless of whether dir == Direction.fwd or if dir == Direction.bwd, so any Interval functions which are called on it which care about whether begin or end are included or excluded will treat begin as included and end as excluded.

Members

Functions

func
TP delegate(scope const TP) func()

The function used to generate the next time point in the range.

opAssign
IntervalRange opAssign(IntervalRange rhs)
popFront
void popFront()

Pops front from the range, using func to generate the next time point in the range. If the generated time point is beyond the edge of the range, then front is set to that edge, and the range is then empty. So, if iterating forwards, and the generated time point is greater than the interval's end, then front is set to end. If iterating backwards, and the generated time point is less than the interval's begin, then front is set to begin.

Properties

direction
Direction direction [@property getter]

The Direction that this range iterates in.

empty
bool empty [@property getter]

Whether this IntervalRange is empty.

front
TP front [@property getter]

The first time point in the range.

interval
Interval!TP interval [@property getter]

The interval that this IntervalRange currently covers.

save
IntervalRange save [@property getter]

Returns a copy of this.

Meta