AFF --- A container for numbers (array) by Friederich and Forbriger.
Carray.h
Go to the documentation of this file.
1 
36 // include guard
37 #ifndef AFF_CARRAY_H_VERSION
38 
39 #define AFF_CARRAY_H_VERSION \
40  "AFF_CARRAY_H V1.0 "
41 
42 #include<aff/array.h>
43 #include<aff/lib/checkedcast.h>
44 
45 namespace aff {
46 
92  template<class T>
94  {
95  public:
106  typedef ConstArray<T> Tarray;
111  typedef typename Tarray::Tshape Tshape;
113  typedef typename Tshape::TSizeVec TSizeVec;
115  typedef typename Tarray::Tvalue Tvalue;
117  typedef typename Tarray::Tpointer Tpointer;
119  typedef typename Tarray::Treference Treference;
131  typedef Tcontainer Tcoc;
133 
134  /*-----------------------------------------------------------------*/
135 
142  ConstCArray(const Tarray& array)
144  : Mrepresentation(array.representation())
145  {
146  Tshape shape=array.shape();
147  // index range is zero based
148  shape.setfirst(typename Tshape::TIndexVec(0));
149  // offset to first element in represented memory
150  Moffset=shape.first_offset();
151  // strides
152  Mstride=shape.stride();
153  // sizes
154  Msize=shape.last();
155  for (unsigned i=0; i<Msize.size(); ++i)
156  {
157  ++Msize[i];
158  }
159  }
161 
162  /*------------------------------------------------------------------*/
163 
167  const Tsize& size(const Tsubscript& i) const
169  { return (Msize[i]); }
171  const Tsize& stride(const Tsubscript& i) const
172  { return Mstride[i]; }
174  const TSizeVec& size() const
175  { return (Msize); }
177  const TSizeVec& stride() const
178  { return Mstride; }
180 
181  /*-----------------------------------------------------------------*/
182 
187  Tconst_pointer pointer() const
189  { return(&Mrepresentation[this->offset()]); }
199  template<class TT>
200  TT* castedpointer() const
201  { return(SizeCheckedCast<Tconst_value,TT>::cast(this->pointer())); }
203 
204  protected:
206  const typename TSizeVec::Tvalue& offset() const { return Moffset; }
207 
208  private:
217 
218  }; // class ConstCArray
219 
220  /*======================================================================*/
221 
228  template<class T>
229  class CArray:
230  public ConstCArray<T>
231  {
232  public:
243  typedef aff::Array<T> Tarray;
250  typedef typename Tarray::Tshape Tshape;
252  typedef typename Tshape::TSizeVec TSizeVec;
254  typedef typename Tarray::Tvalue Tvalue;
256  typedef typename Tarray::Tpointer Tpointer;
258  typedef typename Tarray::Treference Treference;
270  typedef Tcontainer Tcoc;
272 
273  /*-----------------------------------------------------------------*/
274 
281  CArray(const Tarray& array)
283  : Tbase(array), Mrepresentation(array.representation())
284  { }
286 
287  /*-----------------------------------------------------------------*/
288 
293  Tpointer pointer() const
295  { return(&Mrepresentation[this->offset()]); }
305  template<class TT>
306  TT* castedpointer() const
307  { return(SizeCheckedCast<Tvalue,TT>::cast(this->pointer())); }
309 
310  private:
312  Trepresentation Mrepresentation;
313 
314  }; // class CArray
315 
316 } // namespace aff
317 
318 #endif // AFF_CARRAY_H_VERSION (includeguard)
319 
320 /* ----- END OF Carray.h ----- */
aff::Array< T > Tarray
Type of array to be interfaced.
Definition: Carray.h:244
Root namespace of library.
Definition: array.h:148
utility for compile-time checked cast
Definition: checkedcast.h:84
Shape for a rectangular array layout.
Definition: strided.h:117
ConstCArray(const Tarray &array)
construct from shape and representation
Definition: Carray.h:143
Interface class to raw memory (C style array)
Definition: Carray.h:229
T & Treference
Type of reference to element.
Definition: array.h:205
Tarray::Treference Treference
Type of reference to element.
Definition: Carray.h:119
CArray< T > Tcontainer
Type of this array.
Definition: Carray.h:266
Tarray::Tconst_value Tconst_value
const element type
Definition: Carray.h:121
const Tsize & stride(const Tsubscript &i) const
stride of dimension
Definition: Carray.h:171
Trepresentation Mrepresentation
my (mutable) data representation
Definition: Carray.h:312
TT * castedpointer() const
return type-casted pointer to first element in Fortran layout
Definition: Carray.h:200
const T & Tconst_reference
Type of reference to const element.
Definition: array.h:211
Tarray::Trepresentation Trepresentation
Type of representation.
Definition: Carray.h:109
ConstArray< T > Tarray
Type of array to be interfaced.
Definition: Carray.h:107
const TSizeVec::Tvalue & offset() const
pass offset to derived class
Definition: Carray.h:206
Strided & setfirst(const Tdim &i, const Tsubscript &index)
setfirst
Definition: strided.cc:279
Tarray::Tconst_pointer Tconst_pointer
Type of pointer to const element.
Definition: Carray.h:123
size checked pointer cast (prototypes)
Tshape::TSizeVec TSizeVec
we use this for one of the access operators
Definition: Carray.h:252
Tcontainer Tcoc
Short for Tcontainer_of_const.
Definition: Carray.h:131
ConstCArray< T > Tcontainer
Type of this array.
Definition: Carray.h:127
const TSizeVec & size() const
size of dimensions
Definition: Carray.h:174
Tarray::Tvalue Tvalue
Element type.
Definition: Carray.h:115
const Tsize & stride(const Tsubscript &i) const
stride of dimension
Definition: strided.h:203
full template array class headers (prototypes)
Tarray::Tconst_reference Tconst_reference
Type of reference to const element.
Definition: Carray.h:264
Tarray::Tvalue Tvalue
Element type.
Definition: Carray.h:254
T * Tpointer
Type of pointer to element.
Definition: array.h:203
T Tvalue
Element type.
Definition: array.h:201
Tconst_pointer pointer() const
return pointer to first element in Fortran layout
Definition: Carray.h:188
Tpointer pointer() const
return pointer to first element in Fortran layout
Definition: Carray.h:294
Tbase Tcontainer_of_const
Type of the array of const values.
Definition: Carray.h:268
Tshape::TSizeVec TSizeVec
we use this for one of the access operators
Definition: Carray.h:113
Tsize size() const
size of array
Definition: simplearray.h:164
const T Tconst_value
const element type
Definition: array.h:207
Tarray::Tconst_value Tconst_value
const element type
Definition: Carray.h:260
Tarray::Tpointer Tpointer
Type of pointer to element.
Definition: Carray.h:117
const Tshape & shape() const
provide access to const shape
Definition: array.h:318
Tcontainer Tcoc
Short for Tcontainer_of_const.
Definition: Carray.h:270
This is the base class for const elements.
Definition: sharedheap.h:139
Trepresentation Mrepresentation
representation member
Definition: Carray.h:210
Interface class to raw memory (C style array)
Definition: Carray.h:93
const T * Tconst_pointer
Type of pointer to const element.
Definition: array.h:209
CArray(const Tarray &array)
construct from shape and representation
Definition: Carray.h:282
Full multi-dimensional array functionality.This is the full array class template. It adds no addition...
Definition: array.h:151
Tarray::Tpointer Tpointer
Type of pointer to element.
Definition: Carray.h:256
TSizeVec::Tvalue Moffset
offset to first index
Definition: Carray.h:216
Tcontainer Tcontainer_of_const
Type of the array of const values.
Definition: Carray.h:129
Tarray::Treference Treference
Type of reference to element.
Definition: Carray.h:258
Tarray::Tconst_reference Tconst_reference
Type of reference to const element.
Definition: Carray.h:125
TSizeVec Msize
sizes of dimensions
Definition: Carray.h:212
Tsubscript first_offset() const
first mapped position
Definition: strided.h:188
const TSizeVec & stride() const
strides of dimensions
Definition: Carray.h:177
ptrdiff_t Tsubscript
Type to hold an array&#39;s subscript value.
Definition: types.h:53
Tarray::Tconst_pointer Tconst_pointer
Type of pointer to const element.
Definition: Carray.h:262
Tarray::Tshape Tshape
Type of shape.
Definition: Carray.h:111
Tarray::Tshape Tshape
Type of shape.
Definition: Carray.h:250
TSizeVec Mstride
strides of dimensions
Definition: Carray.h:214
Array base classThis is a multidimensional (array) container that uses a strided memory layout (Fortr...
Definition: array.h:172
TT * castedpointer() const
return type-casted pointer to first element in Fortran layout
Definition: Carray.h:306
const Tsubscript & last(const Tsubscript &i) const
last index of dimension
Definition: strided.h:197
aff::ConstCArray< T > Tbase
Base class.
Definition: Carray.h:246
Tarray::Trepresentation Trepresentation
Type of representation.
Definition: Carray.h:248
size_t Tsize
Type to hold the size of an array dimension.
Definition: types.h:51