27 #ifndef SCHNEK_RANGE_HPP_ 28 #define SCHNEK_RANGE_HPP_ 31 #include "boost/concept/assert.hpp" 32 #include "boost/concept_check.hpp" 41 template<
size_t>
class CheckingPolicy = ArrayNoArgCheck
53 Range(
const Range &domain): lo(domain.lo), hi(domain.hi) {}
56 template<
template<
size_t>
class ArrayCheckingPolicy>
61 template<
template<
size_t>
class ArrayCheckingPolicy>
74 SCHNEK_INLINE
const LimitType &
getLo()
const {
return lo; }
76 SCHNEK_INLINE
const LimitType &
getHi()
const {
return hi; }
79 SCHNEK_INLINE LimitType &
getLo() {
return lo;}
81 SCHNEK_INLINE LimitType &
getHi() {
return hi;}
84 SCHNEK_INLINE T &
getLo(
size_t i) {
return lo[i]; }
86 SCHNEK_INLINE T &
getHi(
size_t i) {
return hi[i]; }
89 SCHNEK_INLINE
const T
getLo(
size_t i)
const {
return lo[i]; }
91 SCHNEK_INLINE
const T
getHi(
size_t i)
const {
return hi[i]; }
96 for (
int i=0; i<rank; ++i)
97 if ((p[i]<lo[i]) || (p[i]>hi[i]))
return false;
102 template<
int destLength>
108 Range<T,rank-1,CheckingPolicy> projectDim(
int dim)
const 110 return Range<T,rank-1,CheckingPolicy>(lo.projectDim(dim), hi.projectDim(dim));
113 void grow(
const T &s)
115 for (
int i=0; i<rank; ++i)
122 void grow(
const T &d0,
const T &d1)
124 BOOST_STATIC_ASSERT(2==rank);
131 void grow(
const T &d0,
const T &d1,
const T &d2)
133 BOOST_STATIC_ASSERT(3==rank);
142 void grow(
const T &d0,
const T &d1,
const T &d2,
const T &d3)
144 BOOST_STATIC_ASSERT(4==rank);
155 void grow(
const T &d0,
const T &d1,
const T &d2,
const T &d3,
const T &d4)
157 BOOST_STATIC_ASSERT(5==rank);
170 void grow(
const T &d0,
const T &d1,
const T &d2,
const T &d3,
const T &d4,
173 BOOST_STATIC_ASSERT(6==rank);
188 void grow(
const T &d0,
const T &d1,
const T &d2,
const T &d3,
const T &d4,
189 const T &d5,
const T &d6)
191 BOOST_STATIC_ASSERT(7==rank);
208 void grow(
const T &d0,
const T &d1,
const T &d2,
const T &d3,
const T &d4,
209 const T &d5,
const T &d6,
const T &d7)
211 BOOST_STATIC_ASSERT(8==rank);
230 void grow(
const T &d0,
const T &d1,
const T &d2,
const T &d3,
const T &d4,
231 const T &d5,
const T &d6,
const T &d7,
const T &d8)
233 BOOST_STATIC_ASSERT(9==rank);
254 void grow(
const T &d0,
const T &d1,
const T &d2,
const T &d3,
const T &d4,
255 const T &d5,
const T &d6,
const T &d7,
const T &d8,
const T &d9)
257 BOOST_STATIC_ASSERT(10==rank);
285 class iterator :
public std::iterator<std::forward_iterator_tag, LimitType> {
287 BOOST_CONCEPT_ASSERT((boost::Integer<T>));
297 iterator(
const Range &domain_,
const LimitType &pos_,
bool atEnd_=
false)
298 : pos(pos_), domain(domain_), atEnd(atEnd_) {}
309 if (++pos[d] > domain.
getHi()[d])
311 pos[d] = domain.
getLo()[d];
338 return (atEnd==it.atEnd) && (pos==it.pos);
348 const LimitType&
getPos() {
return pos; }
353 return iterator(*
this, this->
getLo());
358 return iterator(*
this, this->
getLo(),
true);
SCHNEK_INLINE T & getLo(size_t i)
Return the i-th coordinate of the rectangle minimum.
Definition: range.hpp:84
const iterator operator++(int)
Postfix increment. Increments the iterator by one position.
Definition: range.hpp:329
SCHNEK_INLINE const LimitType & getLo() const
Return rectangle minimum.
Definition: range.hpp:74
bool operator==(const iterator &it)
Equality test.
Definition: range.hpp:336
SCHNEK_INLINE LimitType & getHi()
Return rectangle maximum.
Definition: range.hpp:81
iterator(const iterator &it)
Copy constructor.
Definition: range.hpp:320
Forward iterator over the rectangular domain.
Definition: range.hpp:285
SCHNEK_INLINE const T getLo(size_t i) const
Return the i-th coordinate of the rectangle minimum.
Definition: range.hpp:89
iterator & operator++()
Prefix increment. Increments the iterator by one position.
Definition: range.hpp:323
SCHNEK_INLINE LimitType & getLo()
Return rectangle minimum.
Definition: range.hpp:79
const LimitType & getPos()
Returns the current iterator position.
Definition: range.hpp:348
bool inside(const LimitType &p)
Returns true if the argument lies within the range.
Definition: range.hpp:94
Range(const Array< T, rank, ArrayCheckingPolicy > &lo_, const Array< T, rank, ArrayCheckingPolicy > &hi_)
Construct with rectangle minimum and maximum.
Definition: range.hpp:57
Range()
Default constructor.
Definition: range.hpp:52
iterator end()
Creates an iterator pointing to a position after the end of the rectangle.
Definition: range.hpp:357
const LimitType & operator*()
Returns the current iterator position.
Definition: range.hpp:345
Range< T, destLength, CheckingPolicy > project() const
projects the Array onto an Array of shorter length
Definition: range.hpp:103
Range & operator=(const Range &domain)
Assignment operator.
Definition: range.hpp:66
bool operator!=(const iterator &it)
Equality test.
Definition: range.hpp:342
iterator begin()
Creates an iterator pointing to the beginning of the rectangle.
Definition: range.hpp:352
SCHNEK_INLINE T & getHi(size_t i)
Return the i-th coordinate of the rectangle maximum.
Definition: range.hpp:86
SCHNEK_INLINE const T getHi(size_t i) const
Return the i-th coordinate of the rectangle maximum.
Definition: range.hpp:91
SCHNEK_INLINE const LimitType & getHi() const
Return rectangle maximum.
Definition: range.hpp:76
Range(const Range< T, rank, ArrayCheckingPolicy > &domain)
Copy constructor.
Definition: range.hpp:62