CVR-Lib last update 20 Sep 2009

cvr::genericVector< T > Class Template Reference
[Aggregate Data Types]

Vector container class. More...

#include <cvrGenericVector.h>

Inheritance diagram for cvr::genericVector< T >:

Inheritance graph
[legend]
Collaboration diagram for cvr::genericVector< T >:

Collaboration graph
[legend]

List of all members.

Protected Member Functions

Memory allocation and deallocation
Restrict all memory allocation and deallocation to these functions.

void reserveMem (const size_type size)
pointer reserveNewMem (const size_type size) const
void releaseMem ()
void releaseMem (pointer &block) const

Protected Attributes

size_type vectorSize_
size_type idxLastElement_
pointer theElements_
bool ownData_
eConstantReference constReference_

Package Functions

 genericVector ()
 genericVector (const size_type theSize)
 genericVector (const size_type theSize, const_reference iniValue)
 genericVector (const size_type theSize, const value_type data[])
 genericVector (const size_type theSize, value_type data[], const eConstantReference constRef)
 genericVector (const genericVector< T > &other)
 genericVector (const genericVector< T > &other, const size_type from, const size_type to=MaxIndex)
 genericVector (const genericVector< T > &other, const genericVector< size_type > &idx)
 genericVector (const std::vector< T > &other)
virtual ~genericVector ()
bool ownsData () const
void restoreOwnership ()
void useExternData (const size_type theSize, pointer data, const eConstantReference constRef=VariableReference)
void attach (const size_type theSize, pointer data)
void detach (genericVector< T > &receiver)
void swap (genericVector< T > &other)
size_type size () const
const_iterator begin () const
iterator begin ()
size_type firstIndex () const
size_type lastIndex () const
const_iterator end () const
iterator end ()
iterator inverseBegin ()
const_iterator inverseBegin () const
iterator inverseEnd ()
const_iterator inverseEnd () const
void resize (const size_type newSize, const_reference iniValue, const eResizeType resizeType=CopyAndInit)
void resize (const size_type newSize)
void allocate (const size_type newSize)
void assign (const size_type newSize, const_reference initValue)
void clear ()
bool empty () const
void fill (const_reference iniValue, const size_type from=0, const size_type to=MaxIndex)
void fill (const value_type data[], const size_type from=0, const size_type to=MaxIndex)
void fill (const genericVector< T > &vct, const size_type from=0, const size_type to=MaxIndex, const size_type startAt=0)
reference at (const size_type x)
const_reference at (const size_type x) const
reference operator[] (const size_type x)
const_reference operator[] (const size_type x) const
reference elem (const size_type n)
const_reference elem (const size_type n) const
genericVector< T > & copy (const genericVector< T > &other)
genericVector< T > & copy (const genericVector< T > &other, const size_type from, const size_type to=MaxIndex)
genericVector< T > & copy (const genericVector< T > &other, const genericVector< size_type > &idx)
genericVector< T > & operator= (const genericVector< T > &other)
virtual const std::string & name () const
virtual genericVector< T > * clone () const
virtual genericVector< T > * newInstance () const
bool equals (const genericVector< T > &other) const
bool operator== (const genericVector< T > &other) const
bool operator!= (const genericVector< T > &other) const
template<typename U >
genericVector< T > & castFrom (const genericVector< U > &other)
genericVector< T > & castFrom (const genericVector< T > &other)
template<typename U >
genericVector< T > & castFrom (const genericVector< U > &other, const size_type from, const size_type to=MaxIndex)
genericVector< T > & castFrom (const genericVector< T > &other, const size_type from, const size_type to=MaxIndex)
template<typename U >
genericVector< T > & castFrom (const std::vector< U > &other)
Apply Methods
genericVector< T > & apply (T(*function)(T))
genericVector< T > & apply (const genericVector< T > &other, T(*function)(T))
genericVector< T > & apply (T(*function)(const T &))
genericVector< T > & apply (const genericVector< T > &other, T(*function)(const T &))
genericVector< T > & apply (const genericVector< T > &other, T(*function)(const T &, const T &))
genericVector< T > & apply (const genericVector< T > &other, T(*function)(T, T))
genericVector< T > & apply (const genericVector< T > &a, const genericVector< T > &b, T(*function)(const T &, const T &))
genericVector< T > & apply (const genericVector< T > &a, const genericVector< T > &b, T(*function)(T, T))
Input and Output
virtual bool write (ioHandler &handler, const bool complete=true) const
virtual bool read (ioHandler &handler, const bool complete=true)

Internal types and classes

typedef
cvr::constReferenceException 
constReferenceException
typedef T value_type
typedef int size_type
typedef T * pointer
typedef const T * const_pointer
typedef T & reference
typedef const T & const_reference
 __pad0__:debugIterator<genericVector<T>
false iterator
 __pad1__:debugIterator<genericVector<T>
true const_iterator


Detailed Description

template<typename T>
class cvr::genericVector< T >

Vector container class.

The cvr::genericVector class allows the representation of n-dimensional vectors. The elements of the vector will be indexed between 0 an n-1.

Note that this class is NOT intended to be a substitute for std::vector. If you need a vector of elements which use some sort of dynamic memory allocation then you have to use the std::vector class of the Standard Template Library (STL). This means, you should not try to make a cvr::genericVector of other vectors or matrices, which administrate some memory. If you do so, the behaviour of copy or fill operations will be unpredictable.

Most of times you will want to use cvr::vector instead.

The difference between cvr::genericVector and its most used inherited class cvr::vector is the support for arithmetical operations. The generic vector is more a "pure" container than a multi-dimensional point representation. It inherits its memory management versatility to cvr::vector. Again, it is usually employed as a container of any static type, which do not do by itself any memory managment.

The genericVector class is a generic container class implemented as template, where the template type T is the type of the elements in the vector.

If you need to create a vector of floats with 256 elements, all of them initialized with a value of 4.27 just create it with

 cvr::genericVector<float> myVct(256,4.27f) // creates vector with 256
                                            // elements all initialized
                                            // with 4.27f

To access the vector elements use the access operators at() (or the overloaded operator[]()). For example:

 float accu = 0; // initialize accumulator

 for (int i = 0; i < myVct.size(); i++) {
   tmp += myVct.at(i); // access each element of the vector
 }

Here is also a difference to the STL std::vector. In the STL there is always a boundary check for at() and the boundary is never checked with operator[](). In the CVR-Lib, the debug-mode library always makes a boundary check for both at() and operator[](), and in the release-mode there is no check for any of both methods.


Member Typedef Documentation

template<typename T>
typedef const T* cvr::genericVector< T >::const_pointer

Const pointer to value_type.

template<typename T>
typedef const T& cvr::genericVector< T >::const_reference

Const reference to value_type.

Exception thrown when a constant reference is violated.

template<typename T>
typedef T* cvr::genericVector< T >::pointer

Pointer to value_type.

template<typename T>
typedef T& cvr::genericVector< T >::reference

Reference to value_type.

template<typename T>
typedef int cvr::genericVector< T >::size_type

Type used for indices and size of the vector.

Note that this type is in the CVR-Lib usually signed integer.

template<typename T>
typedef T cvr::genericVector< T >::value_type

Type of the genericVector elements.


Constructor & Destructor Documentation

template<typename T>
cvr::genericVector< T >::genericVector (  )  [package]

Default constructor creates an empty genericVector.

template<typename T>
cvr::genericVector< T >::genericVector ( const size_type  theSize  )  [explicit, package]

Create a genericVector of the given size but do not initialize its elements.

Warning:
This is an interface change with the previous library. It has been done to be consistent with the more basic features of the C++ language. If you write for example "int c;", the content of c is not defined, and in the same way, if you want a vector with initialized data, you have to specify explicitely the value with which the elements have to be initialized.
Parameters:
theSize number of elements of the genericVector.

template<typename T>
cvr::genericVector< T >::genericVector ( const size_type  theSize,
const_reference  iniValue 
) [explicit, package]

Create a genericVector of the given size and initialize it with the given value.

Parameters:
theSize number of elements of the genericVector.
iniValue all elements will be initialized with this value.

template<typename T>
cvr::genericVector< T >::genericVector ( const size_type  theSize,
const value_type  data[] 
) [package]

Create a genericVector of the given size and initialize it with the given data.

The data will be copied.

If you need to just use the memory block without copying it, then you can wether use a third parameter of eConstantReference type or later call the useExternData() method.

See also:
useExternData()
Parameters:
theSize number of elements of the genericVector.
data a pointer to the data that will be copied.

template<typename T>
cvr::genericVector< T >::genericVector ( const size_type  theSize,
value_type  data[],
const eConstantReference  constRef 
) [package]

Create a genericVector of the given size and initialize it with the given data, the same way "useExternData" does, i.e.

tThe data will not be copied!.

See also:
useExternData()
Parameters:
theSize number of elements of the genericVector.
data a pointer to the data that will be used.
constRef if this parameter is ConstantReference it will not be possible to change the pointer to the external memory block nor to resize the genericVector. Despite this, the value of each element can be changed by the access operators.

template<typename T>
cvr::genericVector< T >::genericVector ( const genericVector< T > &  other  )  [package]

Create this genericVector as a copy of another genericVector.

Parameters:
other the genericVector to be copied.

template<typename T>
cvr::genericVector< T >::genericVector ( const genericVector< T > &  other,
const size_type  from,
const size_type  to = MaxIndex 
) [package]

Create this genericVector as a copy of specified interval of elements of another genericVector.

Indices below zero are set to zero, indices greater than the size of the genericVector to the size-1.

Parameters:
other the genericVector to be copied.
from starting point included
to end point included.

template<typename T>
cvr::genericVector< T >::genericVector ( const genericVector< T > &  other,
const genericVector< size_type > &  idx 
) [package]

Create this genericVector as a copy of specified elements of another genericVector.

idx can contain the same index more than once.

Parameters:
other the genericVector to be copied.
idx indices of the elements to be copied

template<typename T>
cvr::genericVector< T >::genericVector ( const std::vector< T > &  other  )  [package]

Create this genericVector as a copy of another std::genericVector.

Parameters:
other the genericVector to be copied.

template<typename T>
virtual cvr::genericVector< T >::~genericVector (  )  [package, virtual]

Destructor.


Member Function Documentation

template<typename T>
void cvr::genericVector< T >::allocate ( const size_type  newSize  )  [inline, package]

Change the vector to contain exactltly the given number of elements.

In opposition to resize, allocate() does not copy the previous data but only modifies the size of the vector, discarding all contained data and leaving the new data uninitialized.

This is in principle an alias to resize(newSize,T(),AllocateOnly).

Parameters:
newSize new vector size. All current data will be discarded.
See also:
eResizeType,

resize(const size_type,const_reference,const eResizeType)

resize(const size_type),allocate(), assign()

template<typename T>
genericVector<T>& cvr::genericVector< T >::apply ( const genericVector< T > &  a,
const genericVector< T > &  b,
T(*)(T, T)  function 
) [package]

A two-parameter C-function receives the i-th elements of the given genericVectors and leaves the result here.

Note that both genericVectors MUST have the same size! If both genericVectors have different size, the function will throw an assertion without changing anything!

Parameters:
a the first genericVector
b the second genericVector
function a pointer to a two parameters C-function
Returns:
a reference to the actual genericVector

template<typename T>
genericVector<T>& cvr::genericVector< T >::apply ( const genericVector< T > &  a,
const genericVector< T > &  b,
T(*)(const T &, const T &)  function 
) [package]

A two-parameter C-function receives the i-th elements of the given genericVectors and leaves the result here.

Note that both genericVectors MUST have the same size! If both genericVectors have different size, the function will throw an assertion without changing anything!

The following example uses cvr::min as function. The genericVectors a and b contain the values [1,2,3,4] and [4,3,2,1], respectively. After applying the function, genericVector c contains the values [1,2,2,1].

 igenericVector a,b,c;
 int i=0;
 for (i=0; i<4; ++i) {
   a.at(i)=i+1;
   b.at(i)=4-i;
 }
 c.apply(a,b,cvr::min);

Parameters:
a the first genericVector
b the second genericVector
function a pointer to a two parameters C-function
Returns:
A reference to the actual genericVector

template<typename T>
genericVector<T>& cvr::genericVector< T >::apply ( const genericVector< T > &  other,
T(*)(T, T)  function 
) [package]

A two-parameter C-function receives the i-th elements of this and the given genericVector and the result will be left in this genericVector.

Note that both genericVectors MUST have the same size! If both genericVectors have different size, the function will throw an assertion without changing anything!

Parameters:
other the second genericVector to be considered (the first genericVector will be this object!)
function a pointer to a two parameters C-function
Returns:
A reference to the actual genericVector.

template<typename T>
genericVector<T>& cvr::genericVector< T >::apply ( const genericVector< T > &  other,
T(*)(const T &, const T &)  function 
) [package]

A two-parameter C-function receives the i-th elements of this and the given genericVector and the result will be left in this genericVector.

Note that both genericVectors MUST have the same size! If both genericVectors have different size, the function will throw an assertion without changing anything!

Parameters:
other the second genericVector to be considered (the first genericVector will be this object!)
function a pointer to a two parameters C-function
Returns:
A reference to the actual genericVector.

template<typename T>
genericVector<T>& cvr::genericVector< T >::apply ( const genericVector< T > &  other,
T(*)(const T &)  function 
) [package]

Applies a C-function to each element the other genericVector and leaves the result here.

Parameters:
other the genericVector with the source data
function a pointer to a C-function
Returns:
A reference to the actual genericVector

template<typename T>
genericVector<T>& cvr::genericVector< T >::apply ( T(*)(const T &)  function  )  [package]

Applies a C-function to each element of the genericVector.

Parameters:
function a pointer to a C-function
Returns:
A reference to the actual genericVector

template<typename T>
genericVector<T>& cvr::genericVector< T >::apply ( const genericVector< T > &  other,
T(*)(T)  function 
) [package]

Applies a C-function to each element of the other genericVector and leaves the result here.

Parameters:
other the source genericVector
function a pointer to a C-function
Returns:
A reference to the actual genericVector

template<typename T>
genericVector<T>& cvr::genericVector< T >::apply ( T(*)(T)  function  )  [package]

Applies a C-function to each element of the genericVector.

In the following example, genericVector vct is initialized with 4.0. After applying sqrt(), all elements of vct are 2.0.

 genericVector<float> vct(4,4.0);
 vct.apply(sqrt);

Parameters:
function a pointer to a C-function
Returns:
A reference to the actual genericVector

template<typename T>
void cvr::genericVector< T >::assign ( const size_type  newSize,
const_reference  initValue 
) [inline, package]

Assign newSize copies of initValue to the genericVector.

Change the size and contents of this vector to be exactly newSize elements long, with all the elements initialized to the value indicated in initValue. In opposition to resize, this method does not copy the previous data but changes the size of the vector, discarding all contained data, replacing it with newSize copies of initValue.

This is in principle an alias to resize(newSize,T(),Init).

Parameters:
newSize new vector size.
initValue all elements of the vector will be initialized with this value.

template<typename T>
const_reference cvr::genericVector< T >::at ( const size_type  x  )  const [inline, package]

Access element x of the genericVector in a read-only modus.

Parameters:
x index of the genericVector element to be accessed. It should be between firstIndex() and lastIndex()

template<typename T>
reference cvr::genericVector< T >::at ( const size_type  x  )  [inline, package]

Access element x of the genericVector.

Parameters:
x index of the genericVector element to be accessed. It should be between firstIndex() and lastIndex()

Referenced by cvr::histogramEqualization::getEqualized().

template<typename T>
void cvr::genericVector< T >::attach ( const size_type  theSize,
pointer  data 
) [package]

Attach extern data to the vector.

This member allows the use of this object as an access-functor for the 'data'. An access to the element at(x) is equivalent to data[x]. If theSize is an invalid dimension, the behaviour will be unpredictible.

The memory will be administrated by this genericVector instance, and may be deleted if required (e.g. genericVector deleted or resized!). The user should not try to manipulate the memory allocation of the data after the attachment! See also useExternData().

Parameters:
theSize number of elements of the genericVector
data a pointer to the memory block to be used
Example:
 cvr::genericVector<int> myVct;
 int block1[25];
 int* block2;
 block2 = new int[25];

 myVct.useExternData(25,block1); // ok
 myVct.attach(25,block1); // wrong!!! matrix will try to manipulate
                          // stack memory: DO NOT DO THIS!!!!!
 myVct.attach(25,block2); // ok!  but do not try to delete the memory
                          //      block2!!

template<typename T>
iterator cvr::genericVector< T >::begin (  )  [inline, package]

Returns iterator pointing to the first element.

The use of the iterators is similar to the iterators of the Standard Template Library (STL). If you need to iterate on all elements of the genericVector, you can use following code:

   int tmp,accu;                        // a temporal variable
   cvr::genericVector<int> myVct(10,1); // genericVector with 10 elements
   // an iterator set to the beginning of myVct
   cvr::genericVector<int>::iterator it=myVct.begin();
   // an iterator set to the end of myVct
   cvr::genericVector<int>::iterator eit=myVct.begin();

   for (; it!=eit ; ++it) {
     tmp = *it;                // tmp has value of element pointed
                               // by the iterator.
     accu += tmp;
     (*it) = accu;             // change the value in the genericVector.
    }

Note:
It is significantly faster in debug builds to use a pre-increment with iterators (++it) than a post-increment (it++).
Please note that if you define it as a const_iterator, you can not do something like *it=accu.

template<typename T>
const_iterator cvr::genericVector< T >::begin (  )  const [inline, package]

Returns first element as a const_iterator.

Note that you can not change the values of the genericVector elements when you use a const_iterator. See also begin()

template<typename T>
template<typename U >
genericVector<T>& cvr::genericVector< T >::castFrom ( const std::vector< U > &  other  )  [inline, package]

Cast from a std::genericVector of the same type.

template<typename T>
genericVector<T>& cvr::genericVector< T >::castFrom ( const genericVector< T > &  other,
const size_type  from,
const size_type  to = MaxIndex 
) [package]

This is just an alias for copy(const genericVector<T>&, const size_type from, const size_type to) to facilitate generic programming.

Parameters:
other The genericVector to be copied.
from starting point included
to end point included

template<typename T>
template<typename U >
genericVector<T>& cvr::genericVector< T >::castFrom ( const genericVector< U > &  other,
const size_type  from,
const size_type  to = MaxIndex 
) [inline, package]

Copy a subvector of the other genericVector by casting each of its elements.

Parameters:
other The genericVector to be copied.
from starting point included
to end point included.
Returns:
A reference to the current casted subvector

template<typename T>
genericVector<T>& cvr::genericVector< T >::castFrom ( const genericVector< T > &  other  )  [package]

This is just an alias for copy(const genericVector<T>&) to facilitate generic programming.

Parameters:
other The genericVector to be copied.

template<typename T>
template<typename U >
genericVector<T>& cvr::genericVector< T >::castFrom ( const genericVector< U > &  other  )  [inline, package]

Copy the other genericVector by casting each of its elements.

Parameters:
other The genericVector to be copied.
For Example:
   cvr::genericVector<int> vctA(10,1);  // a genericVector of integers
   cvr::genericVector<double> vctB;     // a genericVector of doubles

   vctB.castFrom(vctA);          // this will copy vctA in vctB!!

template<typename T>
void cvr::genericVector< T >::clear (  )  [package]

Removes all elements from the genericVector (Set dimensions to 0).

template<typename T>
virtual genericVector<T>* cvr::genericVector< T >::clone (  )  const [package, virtual]

template<typename T>
genericVector<T>& cvr::genericVector< T >::copy ( const genericVector< T > &  other,
const genericVector< size_type > &  idx 
) [package]

Assignment operator.

Copy the specified elements of other into this object. idx can contain the same index more than once.

Parameters:
other the genericVector to be copied.
idx indices of the elements to be copied
Returns:
Reference to the current object.

template<typename T>
genericVector<T>& cvr::genericVector< T >::copy ( const genericVector< T > &  other,
const size_type  from,
const size_type  to = MaxIndex 
) [package]

Assignment operator.

Copy a specified interval of elements of another genericVector. At the end this vector will contain t-f+1 elements, where f=max(0,from) and t=min(other.lastIndex(),to).

Parameters:
other the genericVector to be copied.
from starting point included
to end point included.
Returns:
Reference to the current object.

template<typename T>
genericVector<T>& cvr::genericVector< T >::copy ( const genericVector< T > &  other  )  [package]

Assigment operator.

Copy the contents of other in this object.

If this instance has a constReference, then only the contents are copied.

Parameters:
other the source genericVector to be copied.
Returns:
Reference to the current object.

template<typename T>
void cvr::genericVector< T >::detach ( genericVector< T > &  receiver  )  [package]

Free the data of this object and hand it over to the "receiver".

The value of ownsData is also transfered to the receiver. (see Note).

This function makes a "memory block transfusion" to another genericVector. It is a very efficient way to make a copy of this genericVector, if you don't need the source data anymore!

Note: Take care that if the attach() or useExternData() methods of this genericVector have been called before detachment, the same rules for memory management apply now for the receiver.

At the end of the detachment, this genericVector will be empty.

Parameters:
receiver the genericVector which will receive the memory block. All data of that genericVector will be first deleted!

template<typename T>
const_reference cvr::genericVector< T >::elem ( const size_type  n  )  const [inline, package]

Constant access to element n of the genericVector.

(alias for at(const size_type x) const)

This member function is needed for generic programming with different container types.

template<typename T>
reference cvr::genericVector< T >::elem ( const size_type  n  )  [inline, package]

Access element n of the genericVector.

(alias for at(const size_type x))

This member function is needed for generic programming with different container types.

template<typename T>
bool cvr::genericVector< T >::empty (  )  const [inline, package]

Returns true if the genericVector is empty.

template<typename T>
iterator cvr::genericVector< T >::end (  )  [inline, package]

Returns last index as an iterator.

For an example see begin()

template<typename T>
const_iterator cvr::genericVector< T >::end (  )  const [inline, package]

Returns last index as a const_iterator.

For an example see begin()

template<typename T>
bool cvr::genericVector< T >::equals ( const genericVector< T > &  other  )  const [package]

Compare this genericVector with other.

Parameters:
other the other genericVector to be compared with
Returns:
true if both genericVectors have the same elements and same size

template<typename T>
void cvr::genericVector< T >::fill ( const genericVector< T > &  vct,
const size_type  from = 0,
const size_type  to = MaxIndex,
const size_type  startAt = 0 
) [package]

Fills the genericVector elements from from to to with the elements of vct starting at startAt.

Parameters:
vct genericVector with the elements to be copied
from first element index of the actual genericVector
to last element index of the actual genericVector
startAt start index of the source genericVector vct.
Example: if a = [0 0 0 0 0] and b = [1 2 3], after a.fill(b,3,4,1) results a = [0 0 0 2 3]

template<typename T>
void cvr::genericVector< T >::fill ( const value_type  data[],
const size_type  from = 0,
const size_type  to = MaxIndex 
) [package]

Fills the genericVector elements with data pointed by data between from and to.

Parameters:
data the data to by copied into this genericVector
from first element index
to last element index
If from or to are out of bounds, they will be (internaly) adjusted to to correct value.

Example:

   double* data = {2,4,8,16};
   cvr::genericVector<double> myVct(10,0);  // genericVector with 10
                                            // elements with 0
   myVct.fill(data,1,3);             // myVct=[0,2,4,8,0,0,0,0,0,0]

template<typename T>
void cvr::genericVector< T >::fill ( const_reference  iniValue,
const size_type  from = 0,
const size_type  to = MaxIndex 
) [package]

Fills the genericVector elements with iniValue between from and to.

Parameters:
iniValue the elements will be initialized with this value.
from first element index
to last element index
If from or to are out of bounds, they will be (internaly) adjusted to to correct value.

Example:

   cvr::genericVector<double> myVct(10,0); // genericVector with 10
                                           // elements with 0
   myVct.fill(9,1,3);                      // myVct=[0,9,9,9,0,0,0,0,0,0]

template<typename T>
size_type cvr::genericVector< T >::firstIndex (  )  const [inline, package]

Returns last index (in a genericVector this is always size()-1).

template<typename T>
const_iterator cvr::genericVector< T >::inverseBegin (  )  const [inline, package]

Return an iterator that points to the last valid element of the genericVector.

See inverseBegin() for more details.

template<typename T>
iterator cvr::genericVector< T >::inverseBegin (  )  [inline, package]

This method returns an iterator that points to the last valid element of the genericVector.

It is used for inverse order iteration through the genericVector using normal iterators (as opposed to reverse_iterators used in the STL). This has the advantage that iterators going from front to end and in the inverse direction are the same and can thus be compared, copied etc. Further the implementation of reverse_iterators is not as fast as that of iterators and thus not desired in the CVR-Lib.

 igenericVector v(false,10);
 int i,tmp;
 for (i=0; i<10; i++) {
   v.at(i)=i;
 }
 igenericVector::iterator forwardIt=v.begin();
 igenericVector::iterator backIt=v.inverseBegin();

 while (forwardIt<=backIt) {
   tmp = (*forwardIt); (*forwardIt)=(*backIt); (*backIt)=tmp;
   ++forwardIt; ++backIt;
 }

template<typename T>
const_iterator cvr::genericVector< T >::inverseEnd (  )  const [inline, package]

Return an iterator that points to the element before the first valid element of the genericVector.

template<typename T>
iterator cvr::genericVector< T >::inverseEnd (  )  [inline, package]

Return an iterator that points to the element before the first valid element of the genericVector.

It is used to mark the end for inverse order iteration through the genericVector using normal iterators (as opposed to reverse_iterators as used in the STL). This has the advantage that iterators going from front to end and in the inverse direction are the same and can thus be compared, copied etc.Further the implementation of reverse_iterators is not as fast as that of iterators and thus not desired in the CVR-Lib.

template<typename T>
size_type cvr::genericVector< T >::lastIndex (  )  const [inline, package]

Returns last index (in a genericVector this is always size()-1).

template<typename T>
virtual const std::string& cvr::genericVector< T >::name (  )  const [package, virtual]

template<typename T>
virtual genericVector<T>* cvr::genericVector< T >::newInstance (  )  const [package, virtual]

template<typename T>
bool cvr::genericVector< T >::operator!= ( const genericVector< T > &  other  )  const [inline, package]

Compare this genericVector with other.

Parameters:
other the other genericVector to be compared with.
Returns:
true if both genericVectors different dimensions or elements

template<typename T>
genericVector<T>& cvr::genericVector< T >::operator= ( const genericVector< T > &  other  )  [package]

Assigment operator (alias for copy(other)).

Parameters:
other the genericVector to be copied
Returns:
a reference to the actual genericVector

template<typename T>
bool cvr::genericVector< T >::operator== ( const genericVector< T > &  other  )  const [inline, package]

Compare this genericVector with other.

Parameters:
other the other genericVector to be compared with
Returns:
true if both genericVectors have the same elements and same size

template<typename T>
const_reference cvr::genericVector< T >::operator[] ( const size_type  x  )  const [inline, package]

Constant access operator (alias for at(const size_type x) const).

template<typename T>
reference cvr::genericVector< T >::operator[] ( const size_type  x  )  [inline, package]

Access operator (alias for at(const size_type x)).

template<typename T>
bool cvr::genericVector< T >::ownsData (  )  const [inline, package]

Check whether this object owns the data.

Returns:
false if this genericVector contains a reference to extern data.

template<typename T>
virtual bool cvr::genericVector< T >::read ( ioHandler handler,
const bool  complete = true 
) [package, virtual]

Read the object from the given ioHandler.

Reimplemented from cvr::ioObject.

template<typename T>
void cvr::genericVector< T >::releaseMem ( pointer block  )  const [protected]

Release the block pointed, but leave this vector alone.

template<typename T>
void cvr::genericVector< T >::releaseMem (  )  [protected]

Release all reserved memory.

Clean all memory and leave the vector in a clean, empty state.

template<typename T>
void cvr::genericVector< T >::reserveMem ( const size_type  size  )  [protected]

Reserve a memory block of the given size, and ensure ownership and release previous memory.

template<typename T>
pointer cvr::genericVector< T >::reserveNewMem ( const size_type  size  )  const [protected]

Reserve a memory block of the given size, but leave this vector untouched, since some other checks have to be done first.

template<typename T>
void cvr::genericVector< T >::resize ( const size_type  newSize  )  [inline, package]

Resize the vector keeping all the old elements, but without initializing the new ones.

This is an alias for resize(newSize,T(),Copy);

See also:
resize(const int,const_reference,const eResizeType), allocate(), assign()

template<typename T>
void cvr::genericVector< T >::resize ( const size_type  newSize,
const_reference  iniValue,
const eResizeType  resizeType = CopyAndInit 
) [package]

Change dimension and if desired the contents of the genericVector.

Parameters:
newSize the new size of the genericVector
iniValue the initialization value.
resizeType specifies what should happen with the data of the resized vector.
For example:
   cvr::genericVector<int> myVct;  // creates empty genericVector
   myVct.resize(5,0);       // genericVector with 5 elements initialized
                            // with 0
   myVct.resize(10,2);      // genericVector has now 10 elements: the
                            // first five are still 0 and the
                            // rest have a 2
   myVct.resize(20,3,cvr::AllocateOnly); // now the genericVector has 20
                                         // elements but their values
                                         // are unknown.
   myVct.resize(5,1,cvr::Init); // the genericVector has now 5
                                // elements initialized with 1

If the resize is possible (see useExternData()), after the resize, this object will always own the data!

See also:
eResizeType, resize(const size_type), allocate(), assign()

template<typename T>
void cvr::genericVector< T >::restoreOwnership (  )  [package]

Restore ownership.

If this object does not own its data, this member will create a new memory buffer with the same data and will make this vector its owner.

If this genericVector already owns its data nothing happens.

template<typename T>
size_type cvr::genericVector< T >::size (  )  const [inline, package]

Returns the number of elements of the genericVector.

template<typename T>
void cvr::genericVector< T >::swap ( genericVector< T > &  other  )  [package]

Exchange (in a fast way) the data between this and the other genericVector.

Similar to detach(), this method will exchange the complete memory blocks, avoiding an element-wise copy.

Parameters:
other the genericVector with which the data will be exchanged.

template<typename T>
void cvr::genericVector< T >::useExternData ( const size_type  theSize,
pointer  data,
const eConstantReference  constRef = VariableReference 
) [package]

Reference to extern data.

This member allows the use of this object as an wrapper-object to access some memory block as a genericVector. The user must take care for memory allocation and deallocation of the block. This object will never delete the external data!.

Parameters:
theSize number of elements in the external block. Note that this is NOT the number of bytes of the external block.
data pointer to the external memory block.
constRef if this parameter is true, it will not be possible to change the pointer to the external memory block nor to resize the genericVector. Despite this, the value of each element can be changed by the access operators. For Example:
 int i;
 double tmp;
 double a[10];               // memory block!

 for (i=0;i<10;i++) {
   a[i]=2*i;                 // initialize the memory block
 }

 cvr::genericVector<double> myVct;  // an empty genericVector

 myVct.resize(5,0);          // resize the genericVector: now 5 elements
                             // initialized with 0

 myVct.useExternData(10,a,true);   // use the genericVector as wrapper
                                   // for the memory block

 tmp = myVct.at(5);                // tmp is now 10

 myVct.at(9) = 3;                  // the last element of myVct
                                   // has now the value 3

 myVct.resize(5);            // INVALID!! this will throw an exception
                             // constReferenceException()
If theSize is greater than the allocated memory, the behaviour could be unpredictible.

template<typename T>
virtual bool cvr::genericVector< T >::write ( ioHandler handler,
const bool  complete = true 
) const [package, virtual]

Write the object in the given ioHandler.

Reimplemented from cvr::ioObject.


Member Data Documentation

template<typename T>
cvr::genericVector< T >::__pad0__ [package]

iterator type (allows read and write operations).

The use of the iterator classes is similar to the iterators of the STL (Standard Template Library). See cvr::genericVector::begin() and cvr::genericVector::inverseBegin() for examples.

For the debugging version of the iterators, boundary check will be done! This explains the low speed of the iterators of the debug version. In the release version, no boundary check will be done, and the iterators are sometimes a factor 10 faster than the debug iterators.

The use of the access operator at() is faster than the iterators in the debug version only. If you need to iterate on a genericVector use iterators instead (in the release version iterators are approximately a factor 3 faster than at()).

Warning:
Try to use the prefix incremental operator (i.e. ++it) instead of the postfix operator (i.e. it++) to allow efficient code also in debug-modus!
See also:
genericVector::const_iterator

template<typename T>
cvr::genericVector< T >::__pad1__ [package]

const_iterator type (allows read-only operations).

The use of the iterator classes is similar to the iterators of the STL (Standard Template Library). See cvr::genericVector::begin() for an example.

For the debugging version of the iterators, boundary check will be done! This explains the low speed of the iterators of the debug version. In the release version, no boundary check will be done, and the iterators are sometimes a factor 10 faster than the debug iterators.

The use of the access operator at() is faster than the iterators in the debug version only. If you need to iterate on a genericVector use iterators instead (in the release version iterators are approximately a factor 3 faster than at()).

Warning:
Try to use the prefix incremental operator (i.e. ++it) instead of the postfix operator (i.e. it++) to allow efficient code also in debug-modus!
See also:
genericVector<T>::iterator

template<typename T>
true cvr::genericVector< T >::const_iterator [package]

template<typename T>
eConstantReference cvr::genericVector< T >::constReference_ [protected]

If constReference=true, is not possible to resize or change the reference of this genericVector.

Very important for an efficient matrix class!! (see useExternData())

template<typename T>
size_type cvr::genericVector< T >::idxLastElement_ [protected]

Index of the last element of the genericVector (always vectorSize-1).

We sacrifice this sizeof(int) to improve speed in many operations that require this last index.

template<typename T>
false cvr::genericVector< T >::iterator [package]

template<typename T>
bool cvr::genericVector< T >::ownData_ [protected]

Reference to extern data.

If this value ist false, then the data pointed by theElements will never be deleted in this object! (see useExternData())

template<typename T>
pointer cvr::genericVector< T >::theElements_ [protected]

Pointer to the first element of the genericVector.

template<typename T>
size_type cvr::genericVector< T >::vectorSize_ [protected]

Dimension of the genericVector.


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

Generated on Sun Sep 20 22:09:08 2009 for CVR-Lib by Doxygen 1.5.8