source: Sophya/trunk/SophyaExt/Blitz/blitz/array/domain.h@ 3188

Last change on this file since 3188 was 221, checked in by ansari, 26 years ago

Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99

File size: 1.9 KB
Line 
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
17BZ_NAMESPACE(blitz)
18
19template<int N_rank>
20class RectDomain {
21
22public:
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
71private:
72 TinyVector<int,N_rank> lbound_, ubound_;
73};
74
75template<int N_rank>
76inline 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
87BZ_NAMESPACE_END
88
89#endif // BZ_DOMAIN_H
Note: See TracBrowser for help on using the repository browser.