LTI-Lib latest version v1.9 - last update 10 Apr 2010

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

Vector container class. More...

#include <ltiGenericVector.h>

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

List of all members.

Classes

class  const_iterator
 const iterator type (allows read-only operations). More...
class  constReferenceException
 constReferenceException class More...
class  iterator
 iterator type (allows read and write operations). More...

Public Types

typedef T value_type
typedef int size_type

Public Member Functions

 genericVector ()
 genericVector (int theSize, const T &iniValue=T())
 genericVector (int theSize, const T data[])
 genericVector (int theSize, T data[], const bool constRef)
 genericVector (const genericVector< T > &other)
 genericVector (const genericVector< T > &other, int from, int to=MaxInt32)
 genericVector (const genericVector< T > &other, const genericVector< int > &idx)
 genericVector (const std::vector< T > &other)
 genericVector (bool init, int theSize)
virtual ~genericVector ()
const char * getTypeName () const
bool ownsData () const
void restoreOwnership ()
void useExternData (int theSize, T *data, bool constRef=false)
void attach (int theSize, T *data)
void detach (genericVector< T > &receiver)
void exchange (genericVector< T > &other)
void swap (genericVector< T > &other)
const int & size () const
int firstIdx () const
const_iterator begin () const
iterator begin ()
int lastIdx () const
const_iterator end () const
iterator end ()
iterator inverseBegin ()
const_iterator inverseBegin () const
iterator inverseEnd ()
const_iterator inverseEnd () const
void resize (int newSize, const T &iniValue=T(), bool copyData=true, bool initNew=true)
void clear ()
bool empty () const
void fill (const T &iniValue, int from=0, int to=MaxInt32)
void fill (const T data[], int from=0, int to=MaxInt32)
void fill (const genericVector< T > &vct, int from=0, int to=MaxInt32, int startAt=0)
T & at (const int x)
const T & at (const int x) const
T & operator[] (const int x)
const T & operator[] (const int x) const
genericVector< T > & copy (const genericVector< T > &other)
genericVector< T > & copy (const genericVector< T > &other, int from, int to=MaxInt32)
genericVector< T > & copy (const genericVector< T > &other, const genericVector< int > &idx)
genericVector< T > & operator= (const genericVector< T > &other)
virtual mathObjectclone () const
bool equals (const genericVector< T > &other) const
bool operator== (const genericVector< T > &other) const
bool operator!= (const genericVector< T > &other) const
template<class U >
genericVector< T > & castFrom (const genericVector< U > &other)
template<class 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)

Protected Attributes

int vectorSize
int idxLastElement
T * theElements
bool ownData
bool constReference

Detailed Description

template<class T>
class lti::genericVector< T >

Vector container class.

The lti::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 subtitute for std::vector. If you need a vector of elements which use some sort of dynamic memory allocation then you should use the std::vector class of the Standard Template Library. This means, you should not try to make lti::genericVector of other vectors or matrices, which administrate some memory. If you do so, the behaviour of copy or fill operations will be unpredictable.

The difference between lti::genericVector and its most used inherited class lti::vector is the support for arithmetical operations. The generic vector is more a container than a multi-dimensional point representation. It inherits its memory managment versatility to lti::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.

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

 lti::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
 }

Member Typedef Documentation

template<class T>
typedef int lti::genericVector< T >::size_type

Return type of the size() member.

template<class T>
typedef T lti::genericVector< T >::value_type

Type of the genericVector elements.


Constructor & Destructor Documentation

template<class T>
lti::genericVector< T >::genericVector (  ) 

Default constructor creates an empty genericVector;.

template<class T>
lti::genericVector< T >::genericVector ( int  theSize,
const T &  iniValue = T() 
) [explicit]

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<class T>
lti::genericVector< T >::genericVector ( int  theSize,
const T  data[] 
)

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

The data will be copied.

See also:
useExternData()
Parameters:
theSize number of elements of the genericVector.
data a pointer to the data that will be copied.
template<class T>
lti::genericVector< T >::genericVector ( int  theSize,
data[],
const bool  constRef 
)

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

The 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 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.
template<class T>
lti::genericVector< T >::genericVector ( const genericVector< T > &  other  ) 

Create this genericVector as a copy of another genericVector.

Parameters:
other the genericVector to be copied.
template<class T>
lti::genericVector< T >::genericVector ( const genericVector< T > &  other,
int  from,
int  to = MaxInt32 
)

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<class T>
lti::genericVector< T >::genericVector ( const genericVector< T > &  other,
const genericVector< int > &  idx 
)

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<class T>
lti::genericVector< T >::genericVector ( const std::vector< T > &  other  ) 

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

Parameters:
other the genericVector to be copied.
template<class T>
lti::genericVector< T >::genericVector ( bool  init,
int  theSize 
)

If init is true this constructor is equivalent to calling genericVector(int theSize), and thus initializing all elements with T().

However, in some cases the elements need not be initialized during construction, since complex initializion is required. Especially for large genericVectors, the unnecessary constructor initialization is very time consuming.

If init is false, memory is allocated but no initialization takes place. Thus the following is equivalent:

 genericVector<int> a(false,10000);

 matrix<int> a;
 a.resize(10000,0,false,false);
Parameters:
init initialize matrix or not
theSize number of elements of the genericVector.
template<class T>
virtual lti::genericVector< T >::~genericVector (  )  [virtual]

destructor


Member Function Documentation

template<class T>
genericVector<T>& lti::genericVector< T >::apply ( const genericVector< T > &  a,
const genericVector< T > &  b,
T(*)(T, T)  function 
)

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

Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.

template<class T>
genericVector<T>& lti::genericVector< T >::apply ( const genericVector< T > &  a,
const genericVector< T > &  b,
T(*)(const T &, const T &)  function 
)

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 lti::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,lti::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

Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.

template<class T>
genericVector<T>& lti::genericVector< T >::apply ( const genericVector< T > &  other,
T(*)(T, T)  function 
)

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

Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.

template<class T>
genericVector<T>& lti::genericVector< T >::apply ( const genericVector< T > &  other,
T(*)(const T &, const T &)  function 
)

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

Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.

template<class T>
genericVector<T>& lti::genericVector< T >::apply ( const genericVector< T > &  other,
T(*)(const T &)  function 
)

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

Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.

template<class T>
genericVector<T>& lti::genericVector< T >::apply ( T(*)(const T &)  function  ) 

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

Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.

template<class T>
genericVector<T>& lti::genericVector< T >::apply ( const genericVector< T > &  other,
T(*)(T)  function 
)

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

Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.

template<class T>
genericVector<T>& lti::genericVector< T >::apply ( T(*)(T)  function  ) 

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

Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.

template<class T>
const T& lti::genericVector< T >::at ( const int  x  )  const [inline]

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 firstIdx() and lastIdx()

Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.

template<class T>
T& lti::genericVector< T >::at ( const int  x  )  [inline]
template<class T>
void lti::genericVector< T >::attach ( int  theSize,
T *  data 
)

Attach extern data to the matrix.

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 (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:

 lti::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<class T>
iterator lti::genericVector< T >::begin (  )  [inline]

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
   lti::genericVector<int> myVct(10,1);                  // a genericVector with 10 elements
   lti::genericVector<int>::iterator it=myVct.begin();   // an iterator set to the beginning of myVct
   lti::genericVector<int>::iterator eit=myVct.begin();  // an iterator set to the end of myVct

   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<class T>
const_iterator lti::genericVector< T >::begin (  )  const [inline]
template<class T>
template<class U >
genericVector<T>& lti::genericVector< T >::castFrom ( const std::vector< U > &  other  )  [inline]

cast from a std::vector of the same type

template<class T>
template<class U >
genericVector<T>& lti::genericVector< T >::castFrom ( const genericVector< U > &  other  )  [inline]

copy the other genericVector by casting each of its elements.

Parameters:
other The genericVector to be copied.

For Example:

   lti::genericVector<int> vctA(10,1);  // a genericVector of integers
   lti::genericVector<double> vctB;     // a genericVector of doubles

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

Referenced by lti::mapperFunctor< Tin, Tout >::parameters::generateFrom().

template<class T>
void lti::genericVector< T >::clear (  ) 
template<class T>
virtual mathObject* lti::genericVector< T >::clone (  )  const [virtual]
template<class T>
genericVector<T>& lti::genericVector< T >::copy ( const genericVector< T > &  other,
const genericVector< int > &  idx 
)

assignment operator.

copy of specified elements of other in 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
template<class T>
genericVector<T>& lti::genericVector< T >::copy ( const genericVector< T > &  other,
int  from,
int  to = MaxInt32 
)

assignment operator.

copy of specified interval of elements of another genericVector.

Parameters:
other the genericVector to be copied.
from starting point included
to end point included.
template<class T>
genericVector<T>& lti::genericVector< T >::copy ( const genericVector< T > &  other  ) 
template<class T>
void lti::genericVector< T >::detach ( genericVector< T > &  receiver  ) 

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!

Referenced by lti::decimation::apply().

template<class T>
bool lti::genericVector< T >::empty (  )  const

returns true if the genericVector is empty

template<class T>
iterator lti::genericVector< T >::end (  )  [inline]

returns last index as an iterator For an example see begin()

template<class T>
const_iterator lti::genericVector< T >::end (  )  const [inline]
template<class T>
bool lti::genericVector< T >::equals ( const genericVector< T > &  other  )  const

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<class T>
void lti::genericVector< T >::exchange ( genericVector< T > &  other  ) 
Deprecated:
Please use swap() instead.
template<class T>
void lti::genericVector< T >::fill ( const genericVector< T > &  vct,
int  from = 0,
int  to = MaxInt32,
int  startAt = 0 
)

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<class T>
void lti::genericVector< T >::fill ( const T  data[],
int  from = 0,
int  to = MaxInt32 
)

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};
   lti::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<class T>
void lti::genericVector< T >::fill ( const T &  iniValue,
int  from = 0,
int  to = MaxInt32 
)

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:

   lti::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]

Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.

Referenced by lti::MLP::signFunctor::deriv(), lti::MLP::linearActFunctor::deriv(), and lti::medianFilter::realMedian().

template<class T>
int lti::genericVector< T >::firstIdx (  )  const [inline]

Returns first index (normally 0).

Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.

template<class T>
const char* lti::genericVector< T >::getTypeName ( void   )  const [inline, virtual]
template<class T>
const_iterator lti::genericVector< T >::inverseBegin (  )  const [inline]

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

See inverseBegin() for more details.

template<class T>
iterator lti::genericVector< T >::inverseBegin (  )  [inline]

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 LTI-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<class T>
const_iterator lti::genericVector< T >::inverseEnd (  )  const [inline]

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

template<class T>
iterator lti::genericVector< T >::inverseEnd (  )  [inline]

This method returns 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 LTI-Lib.

template<class T>
int lti::genericVector< T >::lastIdx (  )  const [inline]

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

Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.

template<class T>
bool lti::genericVector< T >::operator!= ( const genericVector< T > &  other  )  const [inline]

compare this genericVector with other

Parameters:
other the other genericVector to be compared with
Returns:
true if both genericVectors different dimensions or elements
template<class T>
genericVector<T>& lti::genericVector< T >::operator= ( const genericVector< T > &  other  )  [inline]

assigment operator (alias for copy(other)).

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

Reimplemented from lti::ioObject.

Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.

template<class T>
bool lti::genericVector< T >::operator== ( const genericVector< T > &  other  )  const [inline]

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<class T>
const T& lti::genericVector< T >::operator[] ( const int  x  )  const [inline]

const access operator (alias for at(const int x) const).

Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.

template<class T>
T& lti::genericVector< T >::operator[] ( const int  x  )  [inline]

access operator (alias for at(const int x)).

Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.

template<class T>
bool lti::genericVector< T >::ownsData (  )  const [inline]

Check whether this object owns the data.

returns false if this genericVector contains a reference to extern data.

template<class T>
virtual bool lti::genericVector< T >::read ( ioHandler handler,
const bool  complete = true 
) [virtual]
template<class T>
void lti::genericVector< T >::resize ( int  newSize,
const T &  iniValue = T(),
bool  copyData = true,
bool  initNew = true 
)

change dimension of the genericVector.

Parameters:
newSize the new size of the genericVector
iniValue the initialization value.
copyData if this parameter is true, the old data of the genericVector will be copied. If it is false, the old data will be lost.
initNew if this parameter is true, then all new elements (if they exist) will be initialized with iniValue. if initNew is false, then the new elements are left uninitialized.

For example:

   lti::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,false,false); // now the genericVector has 20
                                   // elements but their values
                                   // are unknown.
   myVct.resize(5,1,false,true); // the genericVector has now 5
                                 // elements initialized with 1

   // note that the last line could also be written:

   myVct.resize(5,1,false);      // the genericVector has now 5
                                 // elements initialized with 1

If the new size is not equal to the old size, the genericVector always owns the data afterwards (i.e. new memory is allocated) even if it didn't own the data before. Otherwise the ownership remains unchanged. You can use restoreOwnership() if you just want to own the data.

Referenced by lti::MLP::sigmoidFunctor::apply(), lti::MLP::signFunctor::apply(), lti::decimation::apply(), lti::genericVector< point >::castFrom(), and lti::mapperFunctor< Tin, Tout >::parameters::generateFrom().

template<class T>
void lti::genericVector< T >::restoreOwnership (  ) 

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

You can also be sure, that the new memory block will be connected (see also getMode() ). If this genericVector already owns its data nothing happens.

template<class T>
const int& lti::genericVector< T >::size (  )  const [inline]
template<class T>
void lti::genericVector< T >::swap ( genericVector< T > &  other  ) 

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<class T>
void lti::genericVector< T >::useExternData ( int  theSize,
T *  data,
bool  constRef = false 
)

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
 }

 lti::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<class T>
virtual bool lti::genericVector< T >::write ( ioHandler handler,
const bool  complete = true 
) const [virtual]

Member Data Documentation

template<class T>
bool lti::genericVector< T >::constReference [protected]

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

Important for the matrix class!! (see useExternData())

template<class T>
int lti::genericVector< T >::idxLastElement [protected]

index of the last element of the genericVector (always vectorSize-1)

template<class T>
bool lti::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<class T>
T* lti::genericVector< T >::theElements [protected]

pointer to the first element of the genericVector.

Referenced by lti::array< int >::at(), and lti::array< int >::castFrom().

template<class T>
int lti::genericVector< T >::vectorSize [protected]

dimension of the genericVector.


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

Generated on Sat Apr 10 15:28:23 2010 for LTI-Lib by Doxygen 1.6.1