| [658] | 1 | #ifndef BZ_DOMAIN_H
 | 
|---|
 | 2 | #define BZ_DOMAIN_H
 | 
|---|
 | 3 | 
 | 
|---|
 | 4 | #ifndef BZ_TINYVEC_H
 | 
|---|
 | 5 |  #include <blitz/tinyvec.h>
 | 
|---|
 | 6 | #endif
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | #ifndef BZ_RANGE_H
 | 
|---|
 | 9 |  #include <blitz/range.h>
 | 
|---|
 | 10 | #endif
 | 
|---|
 | 11 | 
 | 
|---|
 | 12 | /*
 | 
|---|
 | 13 |  * Portions of this class were inspired by the "RectDomain" class
 | 
|---|
 | 14 |  * provided by the Titanium language (UC Berkeley).
 | 
|---|
 | 15 |  */
 | 
|---|
 | 16 | 
 | 
|---|
 | 17 | BZ_NAMESPACE(blitz)
 | 
|---|
 | 18 | 
 | 
|---|
 | 19 | template<int N_rank>
 | 
|---|
 | 20 | class RectDomain {
 | 
|---|
 | 21 | 
 | 
|---|
 | 22 | public:
 | 
|---|
 | 23 |     RectDomain(const TinyVector<int,N_rank>& lbound,
 | 
|---|
 | 24 |         const TinyVector<int,N_rank>& ubound)
 | 
|---|
 | 25 |       : lbound_(lbound), ubound_(ubound)
 | 
|---|
 | 26 |     { }
 | 
|---|
 | 27 | 
 | 
|---|
 | 28 |     // NEEDS_WORK: better constructors
 | 
|---|
 | 29 |     // RectDomain(Range, Range, ...)
 | 
|---|
 | 30 |     // RectDomain with any combination of Range and int
 | 
|---|
 | 31 | 
 | 
|---|
 | 32 |     const TinyVector<int,N_rank>& lbound() const
 | 
|---|
 | 33 |     { return lbound_; }
 | 
|---|
 | 34 | 
 | 
|---|
 | 35 |     int lbound(int i) const
 | 
|---|
 | 36 |     { return lbound_(i); }
 | 
|---|
 | 37 | 
 | 
|---|
 | 38 |     const TinyVector<int,N_rank>& ubound() const
 | 
|---|
 | 39 |     { return ubound_; }
 | 
|---|
 | 40 | 
 | 
|---|
 | 41 |     int ubound(int i) const
 | 
|---|
 | 42 |     { return ubound_(i); }
 | 
|---|
 | 43 | 
 | 
|---|
 | 44 |     Range operator[](int rank) const
 | 
|---|
 | 45 |     { return Range(lbound_(rank), ubound_(rank)); }
 | 
|---|
 | 46 | 
 | 
|---|
 | 47 |     void shrink(int amount)
 | 
|---|
 | 48 |     {
 | 
|---|
 | 49 |         lbound_ += amount;
 | 
|---|
 | 50 |         ubound_ -= amount;
 | 
|---|
 | 51 |     }
 | 
|---|
 | 52 | 
 | 
|---|
 | 53 |     void shrink(int dim, int amount)
 | 
|---|
 | 54 |     {
 | 
|---|
 | 55 |         lbound_(dim) += amount;
 | 
|---|
 | 56 |         ubound_(dim) -= amount;
 | 
|---|
 | 57 |     }
 | 
|---|
 | 58 | 
 | 
|---|
 | 59 |     void expand(int amount)
 | 
|---|
 | 60 |     {
 | 
|---|
 | 61 |         lbound_ -= amount;
 | 
|---|
 | 62 |         ubound_ += amount;
 | 
|---|
 | 63 |     }
 | 
|---|
 | 64 | 
 | 
|---|
 | 65 |     void expand(int dim, int amount)
 | 
|---|
 | 66 |     {
 | 
|---|
 | 67 |         lbound_(dim) -= amount;
 | 
|---|
 | 68 |         ubound_(dim) += amount;
 | 
|---|
 | 69 |     }
 | 
|---|
 | 70 | 
 | 
|---|
 | 71 | private:
 | 
|---|
 | 72 |     TinyVector<int,N_rank> lbound_, ubound_;
 | 
|---|
 | 73 | };
 | 
|---|
 | 74 | 
 | 
|---|
 | 75 | template<int N_rank>
 | 
|---|
 | 76 | inline RectDomain<N_rank> strip(const TinyVector<int,N_rank>& startPosition,
 | 
|---|
 | 77 |     int stripDimension, int ubound)
 | 
|---|
 | 78 | {
 | 
|---|
 | 79 |     BZPRECONDITION((stripDimension >= 0) && (stripDimension < N_rank));
 | 
|---|
 | 80 |     BZPRECONDITION(ubound >= startPosition(stripDimension));
 | 
|---|
 | 81 | 
 | 
|---|
 | 82 |     TinyVector<int,N_rank> endPosition = startPosition;
 | 
|---|
 | 83 |     endPosition(stripDimension) = ubound;
 | 
|---|
 | 84 |     return RectDomain<N_rank>(startPosition, endPosition);
 | 
|---|
 | 85 | }
 | 
|---|
 | 86 | 
 | 
|---|
 | 87 | BZ_NAMESPACE_END
 | 
|---|
 | 88 | 
 | 
|---|
 | 89 | #endif // BZ_DOMAIN_H
 | 
|---|