AFF --- A container for numbers (array) by Friederich and Forbriger.
series.h
Go to the documentation of this file.
1 
81 // include guard
82 #ifndef AFF_SERIES_H_VERSION
83 
84 #define AFF_SERIES_H_VERSION \
85  "AFF_SERIES_H V1.12"
86 
87 #include <aff/lib/sharedheap.h>
88 #include <aff/lib/linearshape.h>
89 #include <aff/lib/seriesstepper.h>
90 #include <aff/lib/error.h>
91 #include <aff/lib/deepcopy.h>
92 
93 namespace aff {
94 
104  template<class T>
105  class ConstSeries:
106  private aff::LinearShape
107  {
108  public:
125  typedef T Tvalue;
127  typedef T* Tpointer;
129  typedef T& Treference;
131  typedef const T Tconst_value;
133  typedef const T* Tconst_pointer;
135  typedef const T& Tconst_reference;
141  typedef Tcontainer Tcoc;
143 
144  /*-----------------------------------------------------------------*/
145 
161  ConstSeries() { }
167  { check_consistency(); }
170  Tshape(0,representation.size()-1,0),
173 
174  /*-----------------------------------------------------------------*/
175 
177  const T& operator()(const Tsubscript& i) const
178  { return(Mrepresentation[this->Tshape::offset(i)]); }
179 
188  const T* pointer() const
189  { return &this->operator()(this->first()); }
190 
191  /*-----------------------------------------------------------------*/
192 
196  const Tsubscript& f() const
198  { return(this->first()); }
200  const Tsubscript& l() const
201  { return(this->last()); }
203 
205 
206  using Tshape::first;
208  using Tshape::last;
209  using Tshape::size;
210  using Tshape::setfirstindex;
211  using Tshape::setlastindex;
212  using Tshape::setindexrange;
213  using Tshape::shift;
215 
234  Tcontainer copyout() const;
235 
238  { return (Mrepresentation); }
239 
241  const Tshape& shape() const
242  { return(*this); }
243 
244  protected:
246  using Tshape::offset;
247 
248  private:
250  void check_consistency() const;
251 
254 
255  }; // class ConstSeries<T>
256 
257  /*======================================================================*/
258 
265  template<class T>
266  class Series: public ConstSeries<T> {
267  public:
272  typedef Series<T> Tcontainer;
281  typedef Tbase Tcoc;
285  typedef T Tvalue;
287  typedef T* Tpointer;
289  typedef T& Treference;
291  typedef const T Tconst_value;
293  typedef const T* Tconst_pointer;
295  typedef const T& Tconst_reference;
297 
298  /*-----------------------------------------------------------------*/
299 
311  Series() { }
314  Series(const Tsize& size)
315  {
316  Tshape newshape(0, size-1, 0);
318  Tbase::operator=(Tbase(newshape, Mrepresentation));
319  }
322  {
323  Tshape newshape(first, last, 0);
325  Tbase::operator=(Tbase(newshape, Mrepresentation));
326  }
329  {
330  Tshape newshape(shape.first(), shape.last(), 0);
331  Mrepresentation=Trepresentation(newshape.memory_size());
332  this->Tbase::operator=(Tbase(newshape, Mrepresentation));
333  }
338  { }
341  const Tsubscript& shift=0)
342  {
343  Tshape newshape(shift, shift+representation.size()-1, 0);
345  Tbase::operator=(Tbase(newshape, Mrepresentation));
346  }
348 
349  /*-----------------------------------------------------------------*/
350 
352 
353  using Tbase::operator();
355  using Tbase::shape;
357 
359  T& operator()(const Tsubscript& i) const
360  { return(Mrepresentation[this->Tbase::offset(i)]); }
361 
370  T* pointer() const
371  { return &this->operator()(this->first()); }
372 
374  Tcontainer& operator=(const T& value);
375 
377  template<class C>
378  Tcontainer& copyin(const C& a)
379  {
380  aff::deepcopy(a, *this);
381  return(*this);
382  }
383 
385  Tcontainer copyout() const;
386 
389  { return (Mrepresentation); }
390 
391  private:
394 
395  }; // class series
396 
397  /*======================================================================*/
398  // definition part
399 
401  template<class T>
403  {
404  AFF_assert((this->Tshape::offset(this->first())>=0),
405  "ERROR (ConstSeries): invalid shape");
406  AFF_assert((this->Tshape::offset(this->last())<
407  Tsubscript(Mrepresentation.size())),
408  "ERROR (ConstSeries): shape and representation are inconsistent");
409  }
410 
411  /*----------------------------------------------------------------------*/
412 
414  template<class T>
416  {
417  for (Tsubscript i=this->first(); i<=this->last(); i++)
418  { Mrepresentation[this->Tbase::offset(i)]=value; }
419  return(*this);
420  }
421 
422  /*----------------------------------------------------------------------*/
423 
425  template<class T>
427  {
428  Tcontainer copy(this->first(),this->last());
429  copy.copyin(*this);
430  return(copy);
431  }
432 
433  /*----------------------------------------------------------------------*/
434 
436  template<class T>
438  {
439  // must use a writeable container as intermediate object
440  Series<T> copy(this->first(),this->last());
441  copy.copyin(*this);
442  return(copy);
443  }
444 }
445 
446 #endif // AFF_SERIES_H_VERSION (includeguard)
447 
448 /* ----- END OF series.h ----- */
Series< T > Tcontainer
Type of this array.
Definition: series.h:273
const T * Tconst_pointer
Type of pointer to element.
Definition: series.h:133
Root namespace of library.
Definition: array.h:148
Tsize memory_size() const
return size of addressed memory
Definition: linearshape.h:116
T * Tpointer
Type of pointer to element.
Definition: series.h:127
void deepcopy(const S &source, T &target)
deep copy
Definition: deepcopy.h:65
const Tshape & shape() const
provide access to const shape
Definition: series.h:241
T Tvalue
Element type.
Definition: series.h:285
T & Treference
Type of reference to element.
Definition: series.h:289
const T * Tconst_pointer
Type of pointer to const element.
Definition: series.h:293
ConstSeries< T > Tcontainer
Type of this array.
Definition: series.h:137
void check_consistency() const
check consistency between shape and representation
Definition: series.h:402
const Tsubscript & l() const
(short for) last valid index
Definition: series.h:200
aff::LinearShape Tshape
Type of shape.
Definition: series.h:279
const Trepresentation & representation() const
offer conversion only to constant version of representation
Definition: series.h:237
Tcontainer & copyin(const C &a)
copy in is allowed here
Definition: series.h:378
const T Tconst_value
Element const type.
Definition: series.h:291
void setlastindex(const Tsubscript &last)
set last index to last
Definition: linearshape.h:152
A template class to share heap memory for different array projections.
Definition: sharedheap.h:252
Series()
construct from nothing (empty)
Definition: series.h:312
Shape for Series class (prototypes)
T * Tpointer
Type of pointer to element.
Definition: series.h:287
exceptions and error handling macros (prototypes)
aff::SharedHeap< T > Trepresentation
Type of representation.
Definition: series.h:283
const T & Tconst_reference
Type of reference to const element.
Definition: series.h:295
T & operator()(const Tsubscript &i) const
Data modification access.
Definition: series.h:359
void setfirstindex(const Tsubscript &first)
set first index to first
Definition: linearshape.h:145
aff::LinearShape Tshape
Type of shape.
Definition: series.h:121
#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
T & Treference
Type of reference to element.
Definition: series.h:129
const Trepresentation & representation() const
expose representation
Definition: series.h:388
Tbase Tcoc
short for Tcontainer_of_const
Definition: series.h:281
base class
Definition: series.h:105
ConstSeries(const Tshape &shape, const Trepresentation &representation)
construct from shape and representation
Definition: series.h:164
void shift(const Tsubscript &i)
shift effective index range by i
Definition: linearshape.h:159
Trepresentation Mrepresentation
my memory representation
Definition: series.h:253
T Tvalue
Element type.
Definition: series.h:125
const Tsubscript & first() const
return first legal index
Definition: linearshape.h:105
const T * pointer() const
Definition: series.h:188
Tcontainer copyout() const
create an identical copy (deep copy) of this array
Definition: series.h:437
ConstSeries< T > Tbase
base is container of const (see specialization below)
Definition: series.h:275
const T & operator()(const Tsubscript &i) const
Data read access.
Definition: series.h:177
shared heap representation (prototypes)
aff::ConstSharedHeap< T > Trepresentation
Type of representation.
Definition: series.h:119
Tsubscript offset(const Tsubscript &i) const
return offset in representation for indes i
Definition: linearshape.h:109
a stepper class for aff::Series (prototypes)
external deep copy function (prototypes)
This is the base class for const elements.
Definition: sharedheap.h:139
Shape for class aff::Series.
Definition: linearshape.h:78
Series(const Tsize &size)
construct for a given size
Definition: series.h:314
Series(const Tsubscript &first, const Tsubscript &last)
construct from index range limits
Definition: series.h:321
A stepper for aff::Series.
Definition: seriesstepper.h:63
Tcontainer copyout() const
create a (deep) copy of this
Definition: series.h:426
const T & Tconst_reference
Type of reference to element.
Definition: series.h:135
Trepresentation Mrepresentation
my (mutable) memory representation
Definition: series.h:393
Tcontainer & operator=(const T &value)
set whole series to value
Definition: series.h:415
ConstSeries()
construct from nothing (empty)
Definition: series.h:162
Tshape::Tstepper Tstepper
Type of stepper.
Definition: series.h:123
void setindexrange(const Tsubscript &first, const Tsubscript last)
set index range [ first , last ]
Definition: linearshape.h:136
Series(const Tshape &shape, const Trepresentation &representation)
construct from shape and representation
Definition: series.h:335
T * pointer() const
Definition: series.h:370
const T Tconst_value
Element type.
Definition: series.h:131
A base class for time series and spectra.
Definition: series.h:266
ptrdiff_t Tsubscript
Type to hold an array&#39;s subscript value.
Definition: types.h:53
const Tsize & size() const
access to base class function
Definition: sharedheap.h:179
Series(const Trepresentation &representation, const Tsubscript &shift=0)
construct from representation
Definition: series.h:340
const Tsubscript & f() const
(short for) first valid index
Definition: series.h:197
Tbase Tcontainer_of_const
Type of the array of const values.
Definition: series.h:277
Series(const Tshape &shape)
construct from shape
Definition: series.h:328
Tcontainer Tcoc
short for Tcontainer_of_const
Definition: series.h:141
ConstSeries(const Trepresentation &representation)
construct from representation
Definition: series.h:169
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
Tcontainer Tcontainer_of_const
Type of the array of const values.
Definition: series.h:139