AFF --- A container for numbers (array) by Friederich and Forbriger.
shaper.h
Go to the documentation of this file.
1 
50 // include guard
51 #ifndef AFF_SHAPER_H_VERSION
52 
53 #define AFF_SHAPER_H_VERSION \
54  "AFF_SHAPER_H V1.6"
55 
56 #include<aff/lib/strided.h>
57 #include<aff/lib/error.h>
58 
59 namespace aff {
60 
66 class Shaper
67 {
68  public:
70  typedef Strided Tshape;
72  Shaper(const Tsubscript& last):
73  Mfirst(1), Mlast(1), Mmaxlast(1), Mdim(1)
74  {
75  AFF_assert((last>=1), "ERROR (shaper): invalid limit");
76  Mfirst[0]=1;
77  Mlast[0]=last;
78  Mmaxlast[0]=last;
79  }
81  Shaper(const Tsubscript& first, const Tsubscript& last):
82  Mfirst(1), Mlast(1), Mmaxlast(1), Mdim(1)
83  {
84  AFF_assert((last>=first), "ERROR (shaper): invalid index range");
85  Mfirst[0]=first;
86  Mlast[0]=last;
87  Mmaxlast[0]=last;
88  }
90  Shaper(const Tsubscript& first, const Tsubscript& last,
91  const Tsubscript& maxlast):
92  Mfirst(1), Mlast(1), Mmaxlast(1), Mdim(1)
93  {
94  AFF_assert((last>=first), "ERROR (shaper): invalid index range");
95  AFF_assert((maxlast>=last), "ERROR (shaper): invalid alloc size");
96  Mfirst[0]=first;
97  Mlast[0]=last;
98  Mmaxlast[0]=maxlast;
99  }
102  {
103  AFF_assert((last>=1), "ERROR (shaper): invalid limit");
104  check_dim();
105  Mfirst[Mdim]=1;
106  Mlast[Mdim]=last;
107  Mmaxlast[Mdim]=last;
108  Mdim++;
109  return(*this);
110  }
112  Shaper& operator() (const Tsubscript& first, const Tsubscript& last)
113  {
114  AFF_assert((last>=first), "ERROR (shaper): invalid index range");
115  check_dim();
116  Mfirst[Mdim]=first;
117  Mlast[Mdim]=last;
118  Mmaxlast[Mdim]=last;
119  Mdim++;
120  return(*this);
121  }
123  Shaper& operator() (const Tsubscript& first, const Tsubscript& last,
124  const Tsubscript& maxlast)
125  {
126  AFF_assert((last>=first), "ERROR (shaper): invalid index range");
127  AFF_assert((maxlast>=last), "ERROR (shaper): invalid alloc size");
128  check_dim();
129  Mfirst[Mdim]=first;
130  Mlast[Mdim]=last;
131  Mmaxlast[Mdim]=maxlast;
132  Mdim++;
133  return(*this);
134  }
136  operator Tshape () const
137  {
138  Tshape shape(Mfirst, Mmaxlast);
139  shape.shrink(Mlast);
140  return(shape);
141  }
142  private:
144  void check_dim() const
145  {
147  "ERROR (Shaper): you use too many dimensions!");
148  }
153 }; // Shaper
154 
155 } // namespace aff
156 
157 #endif // AFF_SHAPER_H_VERSION (includeguard)
158 
159 /* ----- END OF shaper.h ----- */
Shaper(const Tsubscript &last)
First dimension is defined by constructor.
Definition: shaper.h:72
void check_dim() const
check dimensions
Definition: shaper.h:144
Root namespace of library.
Definition: array.h:148
Shape for a rectangular array layout.
Definition: strided.h:117
Shaper & operator()(const Tsubscript &last)
Other dimensions are defined by bracket operator.
Definition: shaper.h:101
Tdim Mdim
next dimension to set
Definition: shaper.h:152
Strided Tshape
Type of Shape class.
Definition: shaper.h:70
exceptions and error handling macros (prototypes)
Tshape::TIndexVec Mfirst
limits
Definition: shaper.h:150
static const Tdim Mmax_dimen
instantiate static member (otherwise the linker won&#39;t find it)
Definition: strided.h:123
#define AFF_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:162
shape of s strided array (prototypes)
Shaper(const Tsubscript &first, const Tsubscript &last, const Tsubscript &maxlast)
First dimension is defined by constructor.
Definition: shaper.h:90
Tshape::TIndexVec Mmaxlast
Definition: shaper.h:150
Shaper(const Tsubscript &first, const Tsubscript &last)
First dimension is defined by constructor.
Definition: shaper.h:81
unsigned short int Tdim
Type to hold an array dimensionality.
Definition: types.h:49
ptrdiff_t Tsubscript
Type to hold an array&#39;s subscript value.
Definition: types.h:53
Shaper class for Fortran layout.
Definition: shaper.h:66
Tshape::TIndexVec Mlast
Definition: shaper.h:150
Strided & shrink(const TIndexVec &last)
subarray
Definition: strided.cc:151