Relacs Numerics Library  0.9.8
Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
CyclicArray< T > Class Template Reference

#include <cyclicarray.h>

Inheritance diagram for CyclicArray< T >:
Inheritance graph
[legend]

Public Types

typedef T value_type
 
typedef T * pointer
 
typedef T & reference
 
typedef const T & const_reference
 
typedef int size_type
 

Public Member Functions

 CyclicArray (void)
 
 CyclicArray (int n)
 
 CyclicArray (CyclicArray< T > *ca)
 
 CyclicArray (const CyclicArray< T > &ca)
 
virtual ~CyclicArray (void)
 
const CyclicArray< T > & operator= (const CyclicArray< T > &a)
 
const CyclicArray< T > & assign (const CyclicArray< T > &a)
 
const CyclicArray< T > & assign (const CyclicArray< T > *a)
 
int size (void) const
 
virtual int accessibleSize (void) const
 
virtual int minIndex (void) const
 
bool empty (void) const
 
virtual void resize (int n, const T &val=0)
 
virtual void clear (void)
 
int capacity (void) const
 
virtual void reserve (int n)
 
void update (const CyclicArray< T > *a)
 
const T & operator[] (int i) const
 
T & operator[] (int i)
 
const T & at (int i) const
 
T & at (int i)
 
const T & front (void) const
 
T & front (void)
 
const T & back (void) const
 
T & back (void)
 
void push (const T &val)
 
pop (void)
 
int maxPush (void) const
 
T * pushBuffer (void)
 
void push (int n)
 
virtual int readSize (void) const
 
int readIndex (void) const
 
read (void)
 
min (int from, int upto) const
 
max (int from, int upto) const
 
void minMax (T &min, T &max, int from, int upto) const
 
minAbs (int from, int upto) const
 
maxAbs (int from, int upto) const
 
numerical_traits< T >::mean_type mean (int from, int upto) const
 
numerical_traits< T >
::variance_type 
variance (int from, int upto) const
 
numerical_traits< T >
::variance_type 
stdev (int from, int upto) const
 
numerical_traits< T >
::variance_type 
rms (int from, int upto) const
 
template<typename S >
void hist (SampleData< S > &h, int from, int upto) const
 
template<typename S >
void hist (SampleData< S > &h) const
 
const T * readBuffer (int index, int &maxn) const
 
int saveBinary (ostream &os, int index) const
 
int loadBinary (istream &is, int index)
 

Protected Attributes

bool Own
 
T * Buffer
 
int NBuffer
 
int RCycles
 
int R
 
int LCycles
 
int L
 
Val
 
Dummy
 

Friends

template<typename TT >
ostream & operator<< (ostream &str, const CyclicArray< TT > &ca)
 

Detailed Description

template<typename T = double>
class relacs::CyclicArray< T >

A template defining an one-dimensional cyclic array of data.

Author
Jan Benda

This class is very similar to the vector class from the standard template library, in that it is a random access container of objects of type T. The size() of CyclicArray, however, can exceed its capacity(). Data elements below size()-capacity() are therefore not accessible.

Member Typedef Documentation

typedef T value_type

The type of object, T, stored in the arry.

typedef T* pointer

Pointer to the type of object, T, stored in the array.

typedef T& reference

Reference to the type of object, T, stored in the array.

typedef const T& const_reference

Const reference to the type of object, T, stored in the array.

typedef int size_type

The type used for sizes and indices.

Constructor & Destructor Documentation

CyclicArray ( void  )

Creates an empty CyclicArray.

CyclicArray ( int  n)

Creates an empty array with capacity n data elements.

References CyclicArray< T >::Buffer, CyclicArray< T >::NBuffer, and CyclicArray< T >::Own.

CyclicArray ( CyclicArray< T > *  ca)

Creates an CyclicArray with the same size and content as ca that shares the buffer with the one of ca.

CyclicArray ( const CyclicArray< T > &  ca)

Copy constructor. Creates an CyclicArray with the same size and content as ca.

References CyclicArray< T >::Buffer, CyclicArray< T >::capacity(), CyclicArray< T >::NBuffer, and CyclicArray< T >::Own.

~CyclicArray ( void  )
virtual

The destructor.

Member Function Documentation

const CyclicArray< T > & operator= ( const CyclicArray< T > &  a)

Assigns a to *this by copying the content.

const CyclicArray< T > & assign ( const CyclicArray< T > &  a)
const CyclicArray< T > & assign ( const CyclicArray< T > *  a)
int size ( void  ) const

The size of the array, i.e. the total number of added data elements. Can be larger than capacity()!

See Also
accessibleSize(), readSize(), empty()

Referenced by CyclicArray< T >::assign().

int accessibleSize ( void  ) const
virtual

The number of data elements that are actually stored in the array and therefore are accessible. Less or equal than capacity() and size()!

See Also
minIndex(), readSize(), empty()
int minIndex ( void  ) const
virtual

The index of the first accessible data element.

See Also
accessibleSize()

Reimplemented in CyclicSampleData< T >.

Referenced by CyclicSampleData< T >::minIndex().

bool empty ( void  ) const

True if the array does not contain any data elements, i.e. size() equals zero.

See Also
size(), accessibleSize(), readSize()
void resize ( int  n,
const T &  val = 0 
)
virtual

Resize the array to n data elements such that the size() of the array equals n. Data values are preserved and new data values are initialized with val. The capacity is not changed! If, however, the capacity() of the array is zero, then memory for n data elements is allocated and initialized with val.

Reimplemented in CyclicSampleData< T >.

Referenced by CyclicSampleData< T >::resize().

void clear ( void  )
virtual

Resize the array to zero length. The capacity() remains unchanged.

int capacity ( void  ) const

The capacity of the array, i.e. the number of data elements for which memory has been allocated.

Referenced by CyclicArray< T >::assign(), and CyclicArray< T >::CyclicArray().

void reserve ( int  n)
virtual

If n is less than or equal to capacity(), this call has no effect. Otherwise, it is a request for allocation of additional memory. If the request is successful, then capacity() is greater than or equal to n and the ownership is transferred to this; otherwise, capacity() is unchanged. In either case, size() is unchanged and the content of the array is preserved.

Reimplemented in CyclicSampleData< T >.

Referenced by CyclicSampleData< T >::reserve().

void update ( const CyclicArray< T > *  a)

Copy the data indices from a to this.

References CyclicArray< T >::R, and CyclicArray< T >::RCycles.

const T & operator[] ( int  i) const
inline

Returns a const reference to the data element at index i. No range checking is performed.

References relacs::minIndex().

T & operator[] ( int  i)
inline

Returns a reference to the data element at index i. No range checking is performed.

References relacs::minIndex().

const T & at ( int  i) const

Returns a const reference to the data element at index i. If i is an invalid index a reference to a variable set to zero is returned.

References relacs::minIndex().

T & at ( int  i)

Returns a reference to the data element at index i. If i is an invalid index a reference to a variable set to zero is returned.

References relacs::minIndex().

const T & front ( void  ) const

Returns a const reference to the first data element. If the array is empty or the first element is not accesible a reference to a variable set to zero is returned.

References relacs::minIndex().

T & front ( void  )

Returns a reference to the first data element. If the array is empty or the first element is not accesible a reference to a variable set to zero is returned.

References relacs::minIndex().

const T & back ( void  ) const

Returns a const reference to the last data element. If the array is empty a reference to a variable set to zero is returned.

T & back ( void  )

Returns a reference to the last data element. If the array is empty a reference to a variable set to zero is returned.

void push ( const T &  val)
inline

Add val as a new element to the array.

T pop ( void  )
inline

Remove the last element of the array and return its value.

int maxPush ( void  ) const

Maximum number of data elements allowed to be added to the buffer at once.

See Also
pushBuffer(), push()
T * pushBuffer ( void  )

Pointer into the buffer where to add data.

See Also
maxPush(), push()
void push ( int  n)

Tell CyclicArray that n data elements have been added to pushBuffer().

See Also
maxPush()
int readSize ( void  ) const
virtual

The number of data elements available to be read from the array.

See Also
read(), readIndex(), size(), accessibleSize()
int readIndex ( void  ) const

The index of the data element to be read next from the array.

See Also
read(), readSize()
T read ( void  )
inline

Return value of the first to be read data element and increment read index.

See Also
readSize(), readIndex()
T min ( int  from,
int  upto 
) const

Return the minimum value of the array between index from inclusively and index upto exclusively.

References relacs::minIndex().

Referenced by CyclicSampleData< T >::min().

T max ( int  from,
int  upto 
) const

Return the maximum value of the array between index from inclusively and index upto exclusively.

References relacs::minIndex().

Referenced by CyclicSampleData< T >::max().

void minMax ( T &  min,
T &  max,
int  from,
int  upto 
) const

Return the minimum and maximum value, min and max, of the array between index from inclusively and index upto exclusively.

References relacs::min(), and relacs::minIndex().

Referenced by CyclicSampleData< T >::minMax().

T minAbs ( int  from,
int  upto 
) const

Return the minimum absolute value of the array between index from inclusively and index upto exclusively.

References relacs::minIndex().

Referenced by CyclicSampleData< T >::minAbs().

T maxAbs ( int  from,
int  upto 
) const

Return the maximum absolute value of the array between index from inclusively and index upto exclusively.

References relacs::minIndex().

Referenced by CyclicSampleData< T >::maxAbs().

numerical_traits< T >::mean_type mean ( int  from,
int  upto 
) const

Return the mean value of the array between index from inclusively and index upto exclusively.

References relacs::mean(), and relacs::minIndex().

Referenced by CyclicSampleData< T >::mean().

numerical_traits< T >::variance_type variance ( int  from,
int  upto 
) const

Return the variance of the array between index from inclusively and index upto exclusively.

References relacs::mean(), and relacs::minIndex().

Referenced by CyclicSampleData< T >::variance().

numerical_traits< T >::variance_type stdev ( int  from,
int  upto 
) const

Return the standard deviation of the array between index from inclusively and index upto exclusively.

References relacs::mean(), relacs::minIndex(), and relacs::sqrt().

Referenced by CyclicSampleData< T >::stdev().

numerical_traits< T >::variance_type rms ( int  from,
int  upto 
) const

Return the root-mean-square of the array between index from inclusively and index upto exclusively.

References relacs::minIndex(), and relacs::sqrt().

Referenced by CyclicSampleData< T >::rms().

void hist ( SampleData< S > &  h,
int  from,
int  upto 
) const

Compute histogram h of all data elements between index from inclusively and index upto exclusively.

References relacs::minIndex(), SampleData< T >::rangeFront(), SampleData< T >::size(), and SampleData< T >::stepsize().

Referenced by CyclicSampleData< T >::hist().

void hist ( SampleData< S > &  h) const

Compute histogram h of all data elements currently stored in the array.

References SampleData< T >::rangeFront(), SampleData< T >::size(), and SampleData< T >::stepsize().

const T * readBuffer ( int  index,
int &  maxn 
) const
Returns
pointer to a float array starting at data element index. In maxn the maximum number of consecutive data elements in this buffer that can be read upto size() or the end of the cicular buffer is returned.

References relacs::minIndex().

int saveBinary ( ostream &  os,
int  index 
) const

Save binary data to stream os starting at index index upto size().

Returns
the number of saved data elements.

References relacs::minIndex().

int loadBinary ( istream &  is,
int  index 
)

Load binary data from stream is from index index on.

Returns
the number of loaded data elements.

Friends And Related Function Documentation

ostream& operator<< ( ostream &  str,
const CyclicArray< TT > &  ca 
)
friend

Member Data Documentation

bool Own
protected

true in case this owns the buffer.

Referenced by CyclicArray< T >::CyclicArray().

T* Buffer
protected

The data buffer.

Referenced by CyclicArray< T >::assign(), and CyclicArray< T >::CyclicArray().

int NBuffer
protected

Number of elements the data buffer can hold.

Referenced by CyclicArray< T >::assign(), and CyclicArray< T >::CyclicArray().

int RCycles
protected

The number of cycles the writing process ("right index") filled the buffer.

Referenced by CyclicArray< T >::assign(), and CyclicArray< T >::update().

int R
protected

The index into the buffer where to append data.

Referenced by CyclicArray< T >::assign(), and CyclicArray< T >::update().

int LCycles
protected

The number of cycles the reading process ("left index") filled the buffer.

Referenced by CyclicArray< T >::assign().

int L
protected

The index into the buffer where to read data.

Referenced by CyclicArray< T >::assign().

T Val
protected

Value storage for pop().

Referenced by CyclicArray< T >::assign().

T Dummy
mutableprotected

Dummy return value for invalid elements.


The documentation for this class was generated from the following file: