AFF --- A container for numbers (array) by Friederich and Forbriger.
linearshape.h
Go to the documentation of this file.
1 
44 // include guard
45 #ifndef AFF_LINEARSHAPE_H_VERSION
46 
47 #define AFF_LINEARSHAPE_H_VERSION \
48  "AFF_LINEARSHAPE_H V1.4"
49 
50 namespace aff {
51 
52  namespace util {
54  class SeriesStepper;
55  } // namespace util
56 
78  class LinearShape
79  {
80  public:
89  static const Tdim Mmax_dimen=1;
94  LinearShape(): Mfirst(0), Mlast(0), Mbase(0) { }
97  const Tsubscript& last,
98  const Tsubscript& firstinrepr):
99  Mfirst(first), Mlast(last), Mbase(first-firstinrepr)
100  {
101  AFF_assert((this->size()>=0),
102  "ERROR (LinearShape): inconsistent constructor arguments");
103  }
105  const Tsubscript& first() const { return(Mfirst); }
107  const Tsubscript& last() const { return(Mlast); }
109  Tsubscript offset(const Tsubscript& i) const { return(i-Mbase); }
111  const Tsize& base() const { return(Mbase); }
113  Tsize size() const
114  { return(static_cast<Tsize>(Mlast-Mfirst+1)); }
116  Tsize memory_size() const { return(this->size()); }
119  LinearShape& shrink(const Tdim& i,
120  const Tsubscript& first, const Tsubscript& last)
121  {
122  AFF_assert((i==0),"ERROR (LinearShape::shrink): illegal dimension!");
123  this->setindexrange(first, last);
124  return(*this);
125  }
128  LinearShape& shrink(const Tdim& i,
129  const Tsubscript& last)
130  {
131  AFF_assert((i==0),"ERROR (LinearShape::shrink): illegal dimension!");
132  this->setlastindex(last);
133  return(*this);
134  }
137  const Tsubscript last)
138  {
139  AFF_assert((last>=first),
140  "ERROR (LinearShape::setindexrange): inconsistent arguments");
143  }
146  {
147  AFF_assert(((first>=Mfirst)&&(first<=Mlast)),
148  "ERROR (LinearShape::setfirstindex): index value out of range");
149  Mfirst=first;
150  }
153  {
154  AFF_assert(((last>=Mfirst)&&(last<=Mlast)),
155  "ERROR (LinearShape::setlastindex): index value out of range");
156  Mlast=last;
157  }
159  void shift(const Tsubscript& i)
160  {
161  Mfirst+=i;
162  Mlast+=i;
163  Mbase+=i;
164  }
165  private:
169  }; // LinearShape
170 
171 }
172 
173 #endif // AFF_LINEARSHAPE_H_VERSION (includeguard)
174 
175 /* ----- END OF linearshape.h ----- */
aff::util::SeriesStepper Tstepper
stepper class for LinearShape (useid through Series by Iterator e.g.)
Definition: linearshape.h:92
Root namespace of library.
Definition: array.h:148
Tsize memory_size() const
return size of addressed memory
Definition: linearshape.h:116
LinearShape(const Tsubscript &first, const Tsubscript &last, const Tsubscript &firstinrepr)
constructor to use for full definition
Definition: linearshape.h:96
void setlastindex(const Tsubscript &last)
set last index to last
Definition: linearshape.h:152
void setfirstindex(const Tsubscript &first)
set first index to first
Definition: linearshape.h:145
#define AFF_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:162
Tsize size() const
by size we mean the size defined by the shape
Definition: linearshape.h:113
void shift(const Tsubscript &i)
shift effective index range by i
Definition: linearshape.h:159
const Tsubscript & first() const
return first legal index
Definition: linearshape.h:105
static const Tdim Mmax_dimen
the linear shape is used to address one-dimensional arrays
Definition: linearshape.h:90
Tsubscript offset(const Tsubscript &i) const
return offset in representation for indes i
Definition: linearshape.h:109
LinearShape()
default constructor defines range of size 1
Definition: linearshape.h:94
Shape for class aff::Series.
Definition: linearshape.h:78
LinearShape & shrink(const Tdim &i, const Tsubscript &first, const Tsubscript &last)
set index range [ first , last ] for dimension i (used by aff::util::Subarray)
Definition: linearshape.h:119
A stepper for aff::Series.
Definition: seriesstepper.h:63
void setindexrange(const Tsubscript &first, const Tsubscript last)
set index range [ first , last ]
Definition: linearshape.h:136
LinearShape & shrink(const Tdim &i, const Tsubscript &last)
set last index of dimension i to last (used by aff::util::Subarray)
Definition: linearshape.h:128
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
Tsize Mbase
base for access to representation
Definition: linearshape.h:168
Tsubscript Mlast
last valid index
Definition: linearshape.h:167
const Tsize & base() const
return base for access to representation
Definition: linearshape.h:111
Tsubscript Mfirst
first valid index
Definition: linearshape.h:166
const Tsubscript & last() const
return last legal index
Definition: linearshape.h:107
size_t Tsize
Type to hold the size of an array dimension.
Definition: types.h:51