fixArray< type, maxElements > Class Template Reference

template for an array with well defined number of elements More...

#include <fixArray.h>

List of all members.

Public Member Functions

 fixArray ()
 default constructor
virtual ~fixArray ()
 virtual destructor
unsigned int size ()
 returns the max. number of elements in this array
unsigned int count ()
 returns the number of used elements in this array
type & getAt (const unsigned int index, BM_STATUS *elementStatus=(BM_STATUS *) 0)
 returns the reference to the member at index (0-based)
int setAt (const unsigned int index, const type &elem, BM_STATUS elementStatus=0)
 copies the content of elem into the element in the array at index (0-based)
type & operator[] (const unsigned int index)
 returns the reference of the element at index (0-based)
int find (type &elem, BM_STATUS *elementStatus=(BM_STATUS *) 0)
 looks for a same element in the array
bool isEmpty (unsigned int *index=(unsigned int *) 0)
 checks if the array is empty (all status == undef)
type & first (unsigned int &iterateIndex, BM_STATUS *elementStatus=(BM_STATUS *) 0)
 returns the element at index 0
type & next (unsigned int &iterateIndex, BM_STATUS *elementStatus=(BM_STATUS *) 0)
 returns the next element of iterateIndex (roll over index 0)
type & prev (unsigned int &iterateIndex, BM_STATUS *elementStatus=(BM_STATUS *) 0)
 returns the previous element of iterateIndex (roll over index 0)
type & last (unsigned int &iterateIndex, BM_STATUS *elementStatus=(BM_STATUS *) 0)
 returns the last element (at index maxElements-1)
int isSubset (const fixArray &superSet)
 returns 0 if all elements of this array are in the array superSet
int isEqual (const fixArray &set)
 returns 0 if all elements of this array are in the array superSet and visa verse
int assignSortAscendant ()
 sorts this array in ascendant order. The result is this array.
fixArrayassignOverlap (const fixArray &set2)
 makes all elements in this array undef which are not in set2
int overlap (fixArray &result, const fixArray &set2) const
 returns in result all elements which are in both arrays.
int assignConcatenate (const fixArray &set2)
 returns in this array all elements of both arrays (concatenate).
int concatenate (fixArray &result, const fixArray &set2) const
 returns in result all elements of both arrays (concatenate).
int notInSet (fixArray &result, const fixArray &set2) const
 returns in result all elements of this array which are not in set2.

Public Attributes

type errElement
 an error element of same data type
type element [maxElements]
 the elements
BM_STATUS bms [maxElements]
 basic math status of each element

Detailed Description

template<class type, unsigned int maxElements>
class fixArray< type, maxElements >

template for an array with well defined number of elements

acces to the members of the array are safe. If the index into the array is out of bounds you receive an error element. All well known functionalities on arrays are implemented e.g. operator [](), find(), setAt(), getAt(), isEmpty(), ...

Parameters:
type data type of an element. This can be a simple data type like int or double but also typedefs and classes are allowed.
maxElements max. number of elements in the array
Usage:
    fixArray<double, 3> xyz; //same as double xyz[3];
    fixArray<fpv, 3> fpv_xyz; //same as fpv fpv_xyz[3];

Constructor & Destructor Documentation

template<class type, unsigned int maxElements>
fixArray< type, maxElements >::fixArray (  )  [inline]

default constructor

creates an array of maxElements of data type.
If you create this class on the stack, the elements are also on the stack.
If you create this class on the heap, the elements are also on the heap.

type
data type of an element. This can be a simple data type like int or double but also typedefs and classes are allowed.
maxElements
max. number of elements in the array
Usage:
    fixArray<double, 3> xyz; //same as double xyz[3];
    fixArray<fpv, 3> fpv_xyz; //same as fpv fpv_xyz[3];
template<class type, unsigned int maxElements>
virtual fixArray< type, maxElements >::~fixArray (  )  [inline, virtual]

virtual destructor

The elements will be destroyed.


Member Function Documentation

template<class type, unsigned int maxElements>
int fixArray< type, maxElements >::assignConcatenate ( const fixArray< type, maxElements > &  set2  )  [inline]

returns in this array all elements of both arrays (concatenate).

all elements from set2 will be appended. Elements which are undef will be ignored.

Parameters:
set2 [in] the elements to be appended into this array
Returns:
the number of elements appended
-1 = this array has not enough space
0 = ok, but set2 array is empty
template<class type, unsigned int maxElements>
fixArray& fixArray< type, maxElements >::assignOverlap ( const fixArray< type, maxElements > &  set2  )  [inline]

makes all elements in this array undef which are not in set2

Elements which are undef will be ignored. This function uses find() to compare this elements with set2.elements

Parameters:
set2 [in] the elements to be compared with this->elements
Returns:
this array, the elements which are in both arrays
template<class type, unsigned int maxElements>
int fixArray< type, maxElements >::assignSortAscendant (  )  [inline]

sorts this array in ascendant order. The result is this array.

Elements which are undef will be sorted to the end of the array. This function uses Compare() to sort the elements

Returns:
-1 = this array has no elements (maxElements = 0)
0 = ok
template<class type, unsigned int maxElements>
int fixArray< type, maxElements >::concatenate ( fixArray< type, maxElements > &  result,
const fixArray< type, maxElements > &  set2 
) const [inline]

returns in result all elements of both arrays (concatenate).

First all elements from this array will be copied. Then all elements from set2 will be copied into result. Elements which are undef will be ignored.

Parameters:
result [out] the result of this method
set2 [in] the elements to be added
Returns:
the number of elements copied into result
-1 = the result array has not enough space
0 = ok, but this array and set2 array are both empty
template<class type, unsigned int maxElements>
unsigned int fixArray< type, maxElements >::count (  )  [inline]

returns the number of used elements in this array

use size() to retrieve the total number of elements in this array

Returns:
the number of elements whose status bit undef is not set.
Attention: the elements with undef==0 and undef==1 can be in unsorted order!
template<class type, unsigned int maxElements>
int fixArray< type, maxElements >::find ( type &  elem,
BM_STATUS elementStatus = (BM_STATUS*)0 
) [inline]

looks for a same element in the array

and returns the zero based index into the array if an equal element is found

Parameters:
elem the element to be searched for
elementStatus [out,opt] (can be null) A pointer to receive also basic math status informations of the found element.
Returns:
the zero based index of the found element.
-1 if no element matched
template<class type, unsigned int maxElements>
type& fixArray< type, maxElements >::first ( unsigned int &  iterateIndex,
BM_STATUS elementStatus = (BM_STATUS*)0 
) [inline]

returns the element at index 0

Parameters:
iterateIndex [out] the index of the returned element (here 0). This index can be used for next() and prev()
elementStatus [out,opt] (can be null) A pointer to receive also basic math status informations of the returned element.
Returns:
the element at index 0
template<class type, unsigned int maxElements>
type& fixArray< type, maxElements >::getAt ( const unsigned int  index,
BM_STATUS elementStatus = (BM_STATUS*)0 
) [inline]

returns the reference to the member at index (0-based)

if index is out of bound (index >= maxElements) the reference to errElement will be returned.

Parameters:
index the zero based index into this array to the element to be received
elementStatus [out,opt] A pointer to receive basic math status informations (can be null).
elementStatus remains unchanged if there is no error in this operation.
elementStatus acts accumulative.
Returns:
the reference to the element at index
template<class type, unsigned int maxElements>
bool fixArray< type, maxElements >::isEmpty ( unsigned int *  index = (unsigned int*)0  )  [inline]

checks if the array is empty (all status == undef)

and returns true if all array elements are undef

Parameters:
index [out,opt] pointer to receive the index of the first defined element.
Returns:
true if all elements in the array are undefined
false if at least one element is defined
template<class type, unsigned int maxElements>
int fixArray< type, maxElements >::isEqual ( const fixArray< type, maxElements > &  set  )  [inline]

returns 0 if all elements of this array are in the array superSet and visa verse

Parameters:
set [in] the array in which this array searches for all its elements and the elements of set will be searched in this array.
Returns:
0: if all elements are found in set and all elements of set are found in this array.
> 0: index+1 of the element in this array which is not found in set
< 0: index-1 of the element in set which is not found in this array
INT_MAX: error in this array ( maxElements == 0 )
-INT_MAX: error in set array ( maxElements == 0 )
Hint:
  • undef-elements are ignored.
  • the order of the elements is ignored.
template<class type, unsigned int maxElements>
int fixArray< type, maxElements >::isSubset ( const fixArray< type, maxElements > &  superSet  )  [inline]

returns 0 if all elements of this array are in the array superSet

the order of the elements is ignored.

Parameters:
superSet [in] the array in which this array searches for all its elements
Returns:
0 if all elements are found in superSet. Undef-elements are ignored.
>0 = index+1 of the first element not found in superSet
INT_MAX if this array has no members ( maxElements == 0 )
Hint:
if this array has only undef-elements (count() == 0), 0 is returned.
template<class type, unsigned int maxElements>
type& fixArray< type, maxElements >::last ( unsigned int &  iterateIndex,
BM_STATUS elementStatus = (BM_STATUS*)0 
) [inline]

returns the last element (at index maxElements-1)

Parameters:
iterateIndex [out] the index of the returned element (here maxElements-1). This index can be used for next() and prev()
elementStatus [out,opt] (can be null) A pointer to receive also basic math status informations of the returned element.
Returns:
the element at index maxElements-1
template<class type, unsigned int maxElements>
type& fixArray< type, maxElements >::next ( unsigned int &  iterateIndex,
BM_STATUS elementStatus = (BM_STATUS*)0 
) [inline]

returns the next element of iterateIndex (roll over index 0)

for roll over see parameter iterateIndex

Parameters:
iterateIndex [in,out] [in] zero based index of the last received element (can be >= maxElements)
[out] the index of the returned element.
This index can be used for next() and prev()
Hint: if iterateIndex will be maxElements we rolled over the bounds of the array. In this case element[0] was returned (maxElements % maxElements = 0).
elementStatus [out,opt] (can be null) A pointer to receive also basic math status informations of the returned element.
Returns:
the element followed by iterateIndex [in].
Hint: next can roll over the bounds of the array. See parameter iterateIndex for details.
template<class type, unsigned int maxElements>
int fixArray< type, maxElements >::notInSet ( fixArray< type, maxElements > &  result,
const fixArray< type, maxElements > &  set2 
) const [inline]

returns in result all elements of this array which are not in set2.

Elements which are undef will be ignored.

Parameters:
result [out] the result of this method
set2 [in] the elements excluded from result
Returns:
the number of elements copied into result
-1 = the result array has not enough space
0 = ok, but this array is empty
template<class type, unsigned int maxElements>
type& fixArray< type, maxElements >::operator[] ( const unsigned int  index  )  [inline]

returns the reference of the element at index (0-based)

if index is out of bound (index >= maxElements) the reference to errElement will be returned.

Parameters:
index the zero based index into this array to the element to be received
Returns:
the reference to the element at index
template<class type, unsigned int maxElements>
int fixArray< type, maxElements >::overlap ( fixArray< type, maxElements > &  result,
const fixArray< type, maxElements > &  set2 
) const [inline]

returns in result all elements which are in both arrays.

Elements which are undef will be ignored. This function uses find() to compare this elements with set2.elements

Parameters:
result [out] the result of this method
set2 [in] the elements to be compared with this->elements
Returns:
the number of elements which are in both arrays
-1 = the result array has not enough space
0 = ok, but no elements are equal
template<class type, unsigned int maxElements>
type& fixArray< type, maxElements >::prev ( unsigned int &  iterateIndex,
BM_STATUS elementStatus = (BM_STATUS*)0 
) [inline]

returns the previous element of iterateIndex (roll over index 0)

for roll over see parameter iterateIndex

Parameters:
iterateIndex [in,out] [in] zero based index of the last received element (can be >= maxElements)
[out] the index of the returned element.
This index can be used for next() and prev().
Hint: iterateIndex will be 2*maxElements -1 if we rolled over bounds. In this case element[maxElements-1] was returned.
elementStatus [out,opt] (can be null) A pointer to receive also basic math status informations of the returned element.
Returns:
the element in front of iterateIndex [in].
Hint: prev can roll over the bounds of the array. See parameter iterateIndex for details.
template<class type, unsigned int maxElements>
int fixArray< type, maxElements >::setAt ( const unsigned int  index,
const type &  elem,
BM_STATUS  elementStatus = 0 
) [inline]

copies the content of elem into the element in the array at index (0-based)

if index is out of bound (index >= maxElements) -1 will be returned and nothing is copied

Parameters:
index the zero based index into this array to the element to be set
elem reference to the element which content will be copied into the element in the array at index
elementStatus [in,opt] basic math status informations to be set for this element.
Returns:
0 = ok
-1 = error (index out of bounds)
template<class type, unsigned int maxElements>
unsigned int fixArray< type, maxElements >::size (  )  [inline]

returns the max. number of elements in this array

use count() to retrieve the number of used elements in this array


Member Data Documentation

template<class type, unsigned int maxElements>
type fixArray< type, maxElements >::errElement

an error element of same data type

the reference to this error element will be returned if the index of a member function exceeded (index >= maxElements)


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Defines
Generated on Mon Nov 22 06:27:34 2010 by  doxygen 1.6.3