1 #ifndef RANGE_ITERATOR_H_ 2 #define RANGE_ITERATOR_H_ 3 4 #include <vector> 5 6 #include <sarray/Range.h> 7 8 namespace jags { 9 10 /** 11 * @short Mutable index that traverses a Range 12 * 13 * A RangeIterator is a numeric vector that traverses a given 14 * Range in row- or column-major order. 15 * 16 * @see Range 17 */ 18 class RangeIterator : public std::vector<int> { 19 std::vector<std::vector<int> > _scope; 20 std::vector<unsigned int> _dim; 21 std::vector<unsigned int> _index; 22 unsigned int _atend; 23 //Forbid assignment 24 RangeIterator &operator=(std::vector<int> const &); 25 public: 26 /** 27 * Constructor. The initial value of a RangeIterator is the 28 * beginning of the range. 29 * 30 * It is not possible to construct a RangeIterator if any of 31 * the dimensions of the Range are zero because there can be 32 * no index value corresponding to a zero dimension. In this 33 * case a logic_error is thrown. 34 * 35 * @param range. Range to traverse 36 */ 37 RangeIterator(Range const &range); 38 /** 39 * Goes to the next index in column-major order, (i.e. moving 40 * the left hand index fastest). If the RangeIterator reaches 41 * the end of the Range, then a call to nextLeft will move it 42 * to the beginning again. 43 * 44 * @return reference to self after incrementation 45 * @see nextRight 46 */ 47 RangeIterator &nextLeft(); 48 /** 49 * Goes to the next index in row-major order (i.e. moving the 50 * right hand index fastest) but otherwise behaves like 51 * nextLeft. 52 * 53 * @return reference to self after incrementation 54 * @see nextLeft 55 */ 56 RangeIterator &nextRight(); 57 /** 58 * Returns a numeric counter of the number of times the 59 * RangeIterator has gone past the end of the Range (and 60 * returned to the beginning) in a call to nexLeft or 61 * nextRight. The initial value is zero. 62 */ 63 unsigned int atEnd() const; 64 }; 65 66 } /* namespace jags */ 67 68 #endif /* RANGE_ITERATOR_H_ */ 69 70