AFF --- A container for numbers (array) by Friederich and Forbriger.
converters.h
Go to the documentation of this file.
1 
36 // include guard
37 #ifndef AFF_CONVERTERS_H_VERSION
38 
39 #define AFF_CONVERTERS_H_VERSION \
40  "AFF_CONVERTERS_H V1.0 "
41 
42 #include<aff/array.h>
43 #include<aff/series.h>
44 #include<aff/lib/error.h>
45 
46 namespace aff {
47 
52  template<class T>
54  {
55  typedef aff::Series<T> Tseries;
56  typedef aff::Array<T> Tarray;
57  typename Tarray::Tshape shape(array.shape());
59  "ERROR: array is not suitable to be converted to series");
60  typename Tseries::Trepresentation representation=array.representation();
61  typename Tseries::Tshape seriesshape(shape.first(0),
62  shape.last(0),
63  shape.first_offset());
64  Tseries retval(seriesshape, representation);
65  return retval;
66  } // aff::Series<T> series_from_array(const aff::Array<T>& array)
67 
68  /*----------------------------------------------------------------------*/
69 
74  template<class T>
76  {
77  typedef aff::ConstSeries<T> Tseries;
78  typedef aff::ConstArray<T> Tarray;
79  typename Tarray::Tshape shape(array.shape());
81  "ERROR: array is not suitable to be converted to series");
82  typename Tseries::Trepresentation representation=array.representation();
83  typename Tseries::Tshape seriesshape(shape.first(0),
84  shape.last(0),
85  shape.first_offset());
86  Tseries retval(seriesshape, representation);
87  return retval;
88  } // aff::ConstSeries<T> series_from_array(const aff::ConstArray<T>& array)
89 
90  /*----------------------------------------------------------------------*/
91 
98  template<class T>
100  {
101  AFF_abort("not yet implemented");
102  } // aff::Series<T> series_from_array(const aff::Array<T>& array)
103 
104  /*----------------------------------------------------------------------*/
105 
112  template<class T>
114  {
115  AFF_abort("not yet implemented");
116  } // aff::Series<T> series_from_array(const aff::Array<T>& array)
117 
118  /*----------------------------------------------------------------------*/
119 
128  template<class T>
130  const unsigned int size)
131  {
132  typedef aff::Series<T> Tseries;
133  typename Tseries::Tshape shape(0, size-1, 0);
134  typename Tseries::Trepresentation representation(pointer, size);
135  Tseries retval(shape, representation);
136  return(retval);
137  } // aff::Series<T> series_from_raw_memory
138 
139  /*----------------------------------------------------------------------*/
140 
145  template<class T>
146  class CSeries {
147  public:
158  typedef aff::Series<T> Tseries;
163  typedef typename Tseries::Tshape Tshape;
165  typedef typename Tseries::Tvalue Tvalue;
167  typedef typename Tseries::Tpointer Tpointer;
169  typedef typename Tseries::Treference Treference;
179 
180  /*-----------------------------------------------------------------*/
181 
188  CSeries(const Tseries& series)
190  : Mrepresentation(series.representation())
191  {
192  Tshape shape=series.shape();
193  Moffset=shape.offset(shape.first());
194  Msize=shape.size();
195  }
197 
198  /*------------------------------------------------------------------*/
199 
203  const Tsize& size() const
205  { return (Msize); }
207 
208  /*-----------------------------------------------------------------*/
209 
214  Tpointer pointer() const
216  { return(&Mrepresentation[Moffset]); }
226  template<class TT>
227  TT* castedpointer() const
228  { return(SizeCheckedCast<Tvalue,TT>::cast(this->pointer())); }
230 
231  private:
233  Trepresentation Mrepresentation;
238  }; // class CSeries
239 
240 } // namespace aff
241 
242 #endif // AFF_CONVERTERS_H_VERSION (includeguard)
243 
244 /* ----- END OF converters.h ----- */
Root namespace of library.
Definition: array.h:148
utility for compile-time checked cast
Definition: checkedcast.h:84
Tseries::Tconst_value Tconst_value
const element type
Definition: converters.h:171
Tseries::Tconst_reference Tconst_reference
Type of reference to const element.
Definition: converters.h:175
Tseries::Treference Treference
Type of reference to element.
Definition: converters.h:169
const Trepresentation & representation() const
return full access representation
Definition: array.h:494
const Trepresentation & representation() const
provide restricted access representation
Definition: array.h:324
TT * castedpointer() const
return type-casted pointer to first element in Fortran layout
Definition: converters.h:227
T Tvalue
Element type.
Definition: series.h:285
Tseries::Tshape Tshape
Type of shape.
Definition: converters.h:163
T & Treference
Type of reference to element.
Definition: series.h:289
bool is_dense_1D_array(const aff::Strided &shape)
check whether array shape describes a 1D array with dense layout in the memory.
Definition: strided.cc:302
const T * Tconst_pointer
Type of pointer to const element.
Definition: series.h:293
Tseries::Tconst_pointer Tconst_pointer
Type of pointer to const element.
Definition: converters.h:173
access Series contents through raw memory
Definition: converters.h:146
CSeries(const Tseries &series)
construct from shape and representation
Definition: converters.h:189
const T Tconst_value
Element const type.
Definition: series.h:291
aff::Tsize Moffset
offset of memory location of first element
Definition: converters.h:237
A template class to share heap memory for different array projections.
Definition: sharedheap.h:252
const Tsize & size() const
size of dimension
Definition: converters.h:204
aff::Series< T > series_from_raw_memory(T *pointer, const unsigned int size)
create a series class from raw memory.
Definition: converters.h:129
T * Tpointer
Type of pointer to element.
Definition: series.h:287
full template array class headers (prototypes)
exceptions and error handling macros (prototypes)
linear series class (prototypes)
const T & Tconst_reference
Type of reference to const element.
Definition: series.h:295
const Tshape & shape() const
provide access to const shape
Definition: series.h:241
Tseries::Trepresentation Trepresentation
Type of representation.
Definition: converters.h:161
#define AFF_abort(M)
Abort and give a message.
Definition: error.h:170
aff::Series< T > Tseries
Type of array to be interfaced.
Definition: converters.h:159
#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
base class
Definition: series.h:105
const Tsubscript & first() const
return first legal index
Definition: linearshape.h:105
const Tshape & shape() const
provide access to const shape
Definition: array.h:318
Tsubscript offset(const Tsubscript &i) const
return offset in representation for indes i
Definition: linearshape.h:109
Shape for class aff::Series.
Definition: linearshape.h:78
aff::Series< T > series_from_array(const aff::Array< T > &array)
create a series container from an array container.
Definition: converters.h:53
Tseries::Tvalue Tvalue
Element type.
Definition: converters.h:165
Full multi-dimensional array functionality.This is the full array class template. It adds no addition...
Definition: array.h:151
aff::Tsize Msize
sizes of series
Definition: converters.h:235
aff::Array< T > array_from_series(const aff::Series< T > &array)
create an array container from a series container.
Definition: converters.h:99
Tseries::Tpointer Tpointer
Type of pointer to element.
Definition: converters.h:167
A base class for time series and spectra.
Definition: series.h:266
Trepresentation Mrepresentation
representation member
Definition: converters.h:233
const Tshape & shape() const
provide access to const shape
Definition: array.h:318
Array base classThis is a multidimensional (array) container that uses a strided memory layout (Fortr...
Definition: array.h:172
Tpointer pointer() const
return pointer to first element in Fortran layout
Definition: converters.h:215
CSeries< T > Tcontainer
Type of this array.
Definition: converters.h:177
size_t Tsize
Type to hold the size of an array dimension.
Definition: types.h:51