CVR-Lib last update 20 Sep 2009

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

Generic Lattice 1D container. More...

#include <cvrGenericLattice1D.h>

Inheritance diagram for cvr::genericLattice1D< T >:

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

Collaboration graph
[legend]

List of all members.

Public Types

Internal types and classes
typedef
cvr::constReferenceException 
constReferenceException
typedef genericVector< T >
::value_type 
value_type
typedef genericVector< T >
::size_type 
size_type
typedef genericVector< T >::pointer pointer
typedef genericVector< T >
::const_pointer 
const_pointer
typedef genericVector< T >
::reference 
reference
typedef genericVector< T >
::const_reference 
const_reference
typedef genericVector< T >
::iterator 
iterator
typedef genericVector< T >
::const_iterator 
const_iterator

Public Member Functions

 genericLattice1D ()
 genericLattice1D (const size_type from, const size_type to)
 genericLattice1D (const iinterval &indices)
 genericLattice1D (const size_type from, const size_type to, const_reference iniValue)
 genericLattice1D (const iinterval &indices, const_reference iniValue)
 genericLattice1D (const size_type from, const size_type to, const value_type data[])
 genericLattice1D (const iinterval &indices, const value_type data[])
 genericLattice1D (const size_type from, const size_type to, value_type data[], const eConstantReference constRef)
 genericLattice1D (const iinterval &indices, value_type data[], const eConstantReference constRef)
 genericLattice1D (const genericLattice1D< T > &other)
 genericLattice1D (const genericLattice1D< T > &other, const size_type from, const size_type to=MaxIndex)
 genericLattice1D (const genericLattice1D< T > &other, const iinterval &indices)
 genericLattice1D (const std::vector< T > &other, const int firstIndex=0)
 genericLattice1D (const genericVector< T > &other, const int firstIndex=0)
virtual ~genericLattice1D ()
bool ownsData () const
void restoreOwnership ()
void useExternData (const size_type from, const size_type to, pointer data, const eConstantReference constRef=VariableReference)
void useExternData (const iinterval &indices, pointer data, const eConstantReference constRef=VariableReference)
void attach (const size_type from, const size_type to, value_type data[])
void attach (const iinterval &indices, pointer data)
void detach (genericLattice1D< T > &receiver)
void swap (genericLattice1D< 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 from, const size_type to, const_reference iniValue, const eResizeType resizeType=CopyAndInit)
void resize (const iinterval &indices, const_reference iniValue, const eResizeType resizeType=CopyAndInit)
void resize (const size_type from, const size_type to)
void resize (const iinterval &indices)
void allocate (const size_type from, const size_type to)
void allocate (const iinterval &indices)
void assign (const size_type from, const size_type to, const_reference initValue)
void assign (const iinterval &indices, const_reference initValue)
void clear ()
bool empty () const
void fill (const_reference iniValue, const size_type from=MinIndex, const size_type to=MaxIndex)
void fill (const_reference iniValue, const iinterval &indices)
void fill (const value_type data[], const size_type from=MinIndex, const size_type to=MaxIndex)
void fill (const value_type data[], const iinterval &indices)
void fill (const genericLattice1D< T > &lat, const size_type from=MinIndex, const size_type to=MaxIndex, const size_type startAt=0)
void fill (const genericLattice1D< T > &vct, const iinterval &indices, 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
genericLattice1D< T > & copy (const genericLattice1D< T > &other)
genericLattice1D< T > & copy (const genericLattice1D< T > &other, const size_type from, const size_type to=MaxIndex)
genericLattice1D< T > & copy (const genericLattice1D< T > &other, const iinterval &indices)
genericLattice1D< T > & operator= (const genericLattice1D< T > &other)
virtual const std::string & name () const
virtual genericLattice1D< T > * clone () const
virtual genericLattice1D< T > * newInstance () const
bool equals (const genericLattice1D< T > &other) const
bool operator== (const genericLattice1D< T > &other) const
bool operator!= (const genericLattice1D< T > &other) const
template<typename U >
genericLattice1D< T > & castFrom (const genericLattice1D< U > &other)
genericLattice1D< T > & castFrom (const genericLattice1D< T > &other)
template<typename U >
genericLattice1D< T > & castFrom (const genericLattice1D< U > &other, const size_type from, const size_type to=MaxIndex)
template<typename U >
genericLattice1D< T > & castFrom (const genericLattice1D< U > &other, const iinterval &indices)
genericLattice1D< T > & castFrom (const genericLattice1D< T > &other, const size_type from, const size_type to=MaxIndex)
genericLattice1D< T > & castFrom (const genericLattice1D< T > &other, const iinterval &indices)
template<typename U >
genericLattice1D< T > & castFrom (const std::vector< U > &other, const int firstIndex=0)
template<typename U >
genericLattice1D< T > & castFrom (const genericVector< U > &other, const int firstIndex=0)
const genericVector< T > & getAsVector () const
Apply Methods
genericLattice1D< T > & apply (T(*function)(T))
genericLattice1D< T > & apply (const genericLattice1D< T > &other, T(*function)(T))
genericLattice1D< T > & apply (T(*function)(const T &))
genericLattice1D< T > & apply (const genericLattice1D< T > &other, T(*function)(const T &))
genericLattice1D< T > & apply (const genericLattice1D< T > &other, T(*function)(const T &, const T &))
genericLattice1D< T > & apply (const genericLattice1D< T > &other, T(*function)(T, T))
genericLattice1D< T > & apply (const genericLattice1D< T > &a, const genericLattice1D< T > &b, T(*function)(const T &, const T &))
genericLattice1D< T > & apply (const genericLattice1D< T > &a, const genericLattice1D< 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

size_type first_
size_type last_
pointer theElements0_
genericVector< T > data_


Detailed Description

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

Generic Lattice 1D container.

This container is inspired on mathematical integer lattices, at least with respect to the indices, which are taken from $Z^n$ in the general case with $n=1$ in this particular case.

You can consider this a generalization of a cvr::genericVector, in which the index of the first element is not necessarily zero, but a negative or positive value.

The main goal of this class is to provide a fast implementation for random access containers, addressable with negative indices, like filter kernels, and since speed is the premise, it is achieved at some memory costs. This means this class has some storage overhead in order to provide some information at zero time, like size, first and last indices the begin and end iterators, etc., which is only possible by storing them directly.

This class cannot be used to contain objects which use some sort of dynamic memory allocation. This means, you should not try to make a cvr::genericLattice1D 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::lattice1D instead, since they provide some mathematical functionality.

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

The genericLattice1D class is a generic container class implemented as a template, where the template type T is the type of the elements assigned to each point in the lattice.

If you need to create a lattice of floats with 255 elements indexed from -127 to 127, all of them initialized with a value of 4.27 just create it with

 cvr::genericLattice1D<float> myLat(-127,127,4.27f);

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

 float accu = 0; // initialize accumulator

 for (int i = myLat.firstIndex(); i <= myLat.lastIndex(); i++) {
   accu += myLat.at(i); // access each element of the vector
 }

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 genericVector<T>::const_iterator cvr::genericLattice1D< T >::const_iterator

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::genericLattice1D::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 genericLattice1D 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:
genericLattice1D<T>::iterator

Reimplemented in cvr::kernel1D< T >, cvr::lattice1D< T >, cvr::lattice1D< T >, and cvr::lattice1D< int >.

template<typename T>
typedef genericVector<T>::const_pointer cvr::genericLattice1D< T >::const_pointer

Const pointer to value_type.

Reimplemented in cvr::kernel1D< T >, cvr::lattice1D< T >, cvr::lattice1D< T >, and cvr::lattice1D< int >.

template<typename T>
typedef genericVector<T>::const_reference cvr::genericLattice1D< T >::const_reference

Const reference to value_type.

Reimplemented in cvr::kernel1D< T >, cvr::lattice1D< T >, cvr::lattice1D< T >, and cvr::lattice1D< int >.

Exception thrown when a constant reference is violated.

Reimplemented in cvr::lattice1D< T >, cvr::lattice1D< T >, and cvr::lattice1D< int >.

template<typename T>
typedef genericVector<T>::iterator cvr::genericLattice1D< T >::iterator

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::genericLattice1D::begin() and cvr::genericLattice1D::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 genericLattice1D 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:
genericLattice1D<T>::const_iterator

Reimplemented in cvr::kernel1D< T >, cvr::lattice1D< T >, cvr::lattice1D< T >, and cvr::lattice1D< int >.

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

Pointer to value_type.

Reimplemented in cvr::kernel1D< T >, cvr::lattice1D< T >, cvr::lattice1D< T >, and cvr::lattice1D< int >.

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

Reference to value_type.

Reimplemented in cvr::kernel1D< T >, cvr::lattice1D< T >, cvr::lattice1D< T >, and cvr::lattice1D< int >.

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

Return type of the size() member.

Reimplemented in cvr::kernel1D< T >, cvr::lattice1D< T >, cvr::lattice1D< T >, and cvr::lattice1D< int >.

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


Constructor & Destructor Documentation

template<typename T>
cvr::genericLattice1D< T >::genericLattice1D (  ) 

Default constructor creates an empty genericLattice1D.

template<typename T>
cvr::genericLattice1D< T >::genericLattice1D ( const size_type  from,
const size_type  to 
) [explicit]

Create a genericLattice1D indexed by the given interval but do not initialize its elements.

Parameters:
from initial index.
to final index.
The size of the container will be to-from+1. The to value must be greater or equal than the from value, otherwise an empty lattice will be created.

template<typename T>
cvr::genericLattice1D< T >::genericLattice1D ( const iinterval indices  )  [explicit]

Create a genericLattice1D indexed by the given interval but do not initialize its elements.

Parameters:
indices interval of indices to be used.

template<typename T>
cvr::genericLattice1D< T >::genericLattice1D ( const size_type  from,
const size_type  to,
const_reference  iniValue 
) [explicit]

Create a genericLattice1D indexed by the given interval and initialize it with the given value.

Parameters:
from initial index value
to final index value
iniValue all elements will be initialized with this value.

template<typename T>
cvr::genericLattice1D< T >::genericLattice1D ( const iinterval indices,
const_reference  iniValue 
) [explicit]

Create a genericLattice1D indexed by the given interval and initialize it with the given value.

Parameters:
indices interval of indices to be used.
iniValue all elements will be initialized with this value.

template<typename T>
cvr::genericLattice1D< T >::genericLattice1D ( const size_type  from,
const size_type  to,
const value_type  data[] 
)

Create a genericLattice1D indexed by the given interval 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:
from initial index value
to final index value
data a pointer to the data that will be copied.

template<typename T>
cvr::genericLattice1D< T >::genericLattice1D ( const iinterval indices,
const value_type  data[] 
)

Create a genericLattice1D indexed by the given interval 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:
indices interval of indices to be used.
data a pointer to the data that will be copied.

template<typename T>
cvr::genericLattice1D< T >::genericLattice1D ( const size_type  from,
const size_type  to,
value_type  data[],
const eConstantReference  constRef 
)

Create a genericLattice1D indexed by the given interval and initialize it with the given data, the same way "useExternData" does, i.e.

the data will not be copied!.

See also:
useExternData()
Parameters:
from initial index
to final index
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 genericLattice1D. Despite this, the value of each element can be changed by the access operators.

template<typename T>
cvr::genericLattice1D< T >::genericLattice1D ( const iinterval indices,
value_type  data[],
const eConstantReference  constRef 
)

Create a genericLattice1D indexed by the given interval and initialize it with the given data, the same way "useExternData" does, i.e.

the data will not be copied!.

See also:
useExternData()
Parameters:
indices interval used for the lattice indices
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 genericLattice1D. Despite this, the value of each element can be changed by the access operators.

template<typename T>
cvr::genericLattice1D< T >::genericLattice1D ( const genericLattice1D< T > &  other  ) 

Create this genericLattice1D as a copy of another genericLattice1D.

Parameters:
other the genericLattice1D to be copied.

template<typename T>
cvr::genericLattice1D< T >::genericLattice1D ( const genericLattice1D< T > &  other,
const size_type  from,
const size_type  to = MaxIndex 
)

Create this genericLattice1D as a copy of the specified interval of elements of another genericLattice1D.

The from and to values are truncated to the interval used by the other lattice.

Parameters:
other the genericLattice1D to be copied.
from starting index of other lattice.
to end index of the other lattice.

template<typename T>
cvr::genericLattice1D< T >::genericLattice1D ( const genericLattice1D< T > &  other,
const iinterval indices 
)

Create this genericLattice1D as a copy of the specified interval of elements of another genericLattice1D.

The from and to values are truncated to the interval used by the other lattice.

Parameters:
other the genericLattice1D to be copied.
indices index interval of the elements of other to be copied.

template<typename T>
cvr::genericLattice1D< T >::genericLattice1D ( const std::vector< T > &  other,
const int  firstIndex = 0 
)

Create this genericLattice1D as a copy of another std::vector<T>.

Parameters:
other the genericLattice1D to be copied.
firstIndex index to be used for the first element of the vector.

template<typename T>
cvr::genericLattice1D< T >::genericLattice1D ( const genericVector< T > &  other,
const int  firstIndex = 0 
)

Create this genericLattice1D as a copy of another cvr::genericVector.

Parameters:
other the genericLattice1D to be copied.
firstIndex optional argument indicating which index is going to be assigned to the first vector element.

template<typename T>
virtual cvr::genericLattice1D< T >::~genericLattice1D (  )  [virtual]

Destructor.


Member Function Documentation

template<typename T>
void cvr::genericLattice1D< T >::allocate ( const iinterval indices  )  [inline]

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:
indices interval used for the indices of this lattice.
All current data will be discarded.

See also:
eResizeType,

resize(const int,const int,const_reference, const eResizeType)

resize(const int),allocate(), assign()

template<typename T>
void cvr::genericLattice1D< T >::allocate ( const size_type  from,
const size_type  to 
) [inline]

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:
from initial index
to final index
All current data will be discarded.

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

resize(const int),allocate(), assign()

template<typename T>
genericLattice1D<T>& cvr::genericLattice1D< T >::apply ( const genericLattice1D< T > &  a,
const genericLattice1D< T > &  b,
T(*)(T, T)  function 
)

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

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

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

template<typename T>
genericLattice1D<T>& cvr::genericLattice1D< T >::apply ( const genericLattice1D< T > &  a,
const genericLattice1D< T > &  b,
T(*)(const T &, const T &)  function 
)

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

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

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

 igenericLattice1D 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 genericLattice1D
b the second genericLattice1D
function a pointer to a two parameters C-function
Returns:
A reference to the actual genericLattice1D

template<typename T>
genericLattice1D<T>& cvr::genericLattice1D< T >::apply ( const genericLattice1D< T > &  other,
T(*)(T, T)  function 
)

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

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

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

template<typename T>
genericLattice1D<T>& cvr::genericLattice1D< T >::apply ( const genericLattice1D< T > &  other,
T(*)(const T &, const T &)  function 
)

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

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

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

template<typename T>
genericLattice1D<T>& cvr::genericLattice1D< T >::apply ( const genericLattice1D< T > &  other,
T(*)(const T &)  function 
)

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

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

template<typename T>
genericLattice1D<T>& cvr::genericLattice1D< T >::apply ( T(*)(const T &)  function  ) 

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

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

template<typename T>
genericLattice1D<T>& cvr::genericLattice1D< T >::apply ( const genericLattice1D< T > &  other,
T(*)(T)  function 
)

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

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

template<typename T>
genericLattice1D<T>& cvr::genericLattice1D< T >::apply ( T(*)(T)  function  ) 

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

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

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

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

template<typename T>
void cvr::genericLattice1D< T >::assign ( const iinterval indices,
const_reference  initValue 
) [inline]

Assign copies of initValue to the genericVector such that the given interval is covered.

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:
indices interval of indices to be used.
initValue all elements of the vector will be initialized with this value.

template<typename T>
void cvr::genericLattice1D< T >::assign ( const size_type  from,
const size_type  to,
const_reference  initValue 
) [inline]

Assign copies of initValue to the genericVector such that the given interval is covered.

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:
from initial index.
to final index.
initValue all elements of the vector will be initialized with this value.

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

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

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

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

Access element x of the genericLattice1D.

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

template<typename T>
void cvr::genericLattice1D< T >::attach ( const iinterval indices,
pointer  data 
) [inline]

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 genericLattice1D instance, and may be deleted if required (e.g. genericLattice1D deleted or resized!). The user should not try to manipulate the memory allocation of the data after the attachment! See also useExternData().

Parameters:
indices interval of indices for the lattice.
data a pointer to the memory block to be used
Example:
 cvr::genericLattice1D<int> myLat;
 int block1[25];
 int* block2;
 block2 = new int[25];

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

template<typename T>
void cvr::genericLattice1D< T >::attach ( const size_type  from,
const size_type  to,
value_type  data[] 
) [inline]

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 genericLattice1D instance, and may be deleted if required (e.g. genericLattice1D deleted or resized!). The user should not try to manipulate the memory allocation of the data after the attachment! See also useExternData().

Parameters:
from initial index
to final index
data a pointer to the memory block to be used
Example:
 cvr::genericLattice1D<int> myLat;
 int block1[25];
 int* block2;
 block2 = new int[25];

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

template<typename T>
iterator cvr::genericLattice1D< 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 genericLattice1D, you can use following code:

   int tmp,accu;                        // a temporal variable
   // genericLattice1D with 10 elements
   cvr::genericLattice1D<int> myLat(10,1); 
   // an iterator set to the beginning of myLat
   cvr::genericLattice1D<int>::iterator it=myLat.begin();
   // an iterator set to the end of myLat
   cvr::genericLattice1D<int>::iterator eit=myLat.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 genericLattice1D.
   }

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::genericLattice1D< T >::begin (  )  const [inline]

Returns first element as a const_iterator.

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

template<typename T>
template<typename U >
genericLattice1D<T>& cvr::genericLattice1D< T >::castFrom ( const genericVector< U > &  other,
const int  firstIndex = 0 
) [inline]

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

Parameters:
other vector to be copied
firstIndex index used for the first element of the vector.

template<typename T>
template<typename U >
genericLattice1D<T>& cvr::genericLattice1D< T >::castFrom ( const std::vector< U > &  other,
const int  firstIndex = 0 
) [inline]

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

Parameters:
other vector to be copied
firstIndex index used for the first element of the vector.

template<typename T>
genericLattice1D<T>& cvr::genericLattice1D< T >::castFrom ( const genericLattice1D< T > &  other,
const iinterval indices 
)

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

Parameters:
other The genericLattice1D to be copied.
indices interval of other to be copied in this lattice.

template<typename T>
genericLattice1D<T>& cvr::genericLattice1D< T >::castFrom ( const genericLattice1D< T > &  other,
const size_type  from,
const size_type  to = MaxIndex 
)

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

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

template<typename T>
template<typename U >
genericLattice1D<T>& cvr::genericLattice1D< T >::castFrom ( const genericLattice1D< U > &  other,
const iinterval indices 
) [inline]

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

Parameters:
other The genericLattice1D to be copied.
indices interval of indices to be copied from other.
Returns:
A reference to the current casted subvector

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

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

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

template<typename T>
genericLattice1D<T>& cvr::genericLattice1D< T >::castFrom ( const genericLattice1D< T > &  other  ) 

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

Parameters:
other The genericLattice1D to be copied.

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

Copy the other genericLattice1D by casting each of its elements.

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

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

template<typename T>
void cvr::genericLattice1D< T >::clear (  ) 

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

template<typename T>
virtual genericLattice1D<T>* cvr::genericLattice1D< T >::clone (  )  const [virtual]

Create a clone of this genericLattice1D.

Returns:
A pointer to a copy of this genericLattice1D.

Implements cvr::container.

Reimplemented in cvr::kernel1D< T >, cvr::lattice1D< T >, cvr::lattice1D< T >, and cvr::lattice1D< int >.

template<typename T>
genericLattice1D<T>& cvr::genericLattice1D< T >::copy ( const genericLattice1D< T > &  other,
const iinterval indices 
) [inline]

Assignment operator.

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

Parameters:
other the genericLattice1D to be copied.
indices interval of the other lattice to be copied into this one.
Returns:
Reference to the current object.

template<typename T>
genericLattice1D<T>& cvr::genericLattice1D< T >::copy ( const genericLattice1D< T > &  other,
const size_type  from,
const size_type  to = MaxIndex 
)

Assignment operator.

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

Parameters:
other the genericLattice1D to be copied.
from starting index
to final index.
Returns:
Reference to the current object.

template<typename T>
genericLattice1D<T>& cvr::genericLattice1D< T >::copy ( const genericLattice1D< T > &  other  ) 

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 genericLattice1D to be copied.
Returns:
Reference to the current object.

template<typename T>
void cvr::genericLattice1D< T >::detach ( genericLattice1D< 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 genericLattice1D. It is a very efficient way to make a copy of this genericLattice1D, if you don't need the source data anymore!

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

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

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

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

Constant access to element n of the genericLattice1D as a vector.

The lattice is indexed from 0 to to-from.

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

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

Access element n of the genericLattice1D as a vector.

The lattice is indexed from 0 to to-from.

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

template<typename T>
bool cvr::genericLattice1D< T >::empty (  )  const [inline]

Returns true if the genericVector is empty.

template<typename T>
iterator cvr::genericLattice1D< T >::end (  )  [inline]

Returns last index as an iterator.

For an example see begin()

template<typename T>
const_iterator cvr::genericLattice1D< T >::end (  )  const [inline]

Returns last index as a const_iterator.

For an example see begin()

template<typename T>
bool cvr::genericLattice1D< T >::equals ( const genericLattice1D< T > &  other  )  const

Compare this genericLattice1D with other.

Parameters:
other the other genericLattice1D to be compared with
Returns:
true if both genericLattice1Ds have the same elements and same definition interval

template<typename T>
void cvr::genericLattice1D< T >::fill ( const genericLattice1D< T > &  vct,
const iinterval indices,
const size_type  startAt = 0 
) [inline]

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

Parameters:
vct genericLattice1D with the elements to be copied.
indices interval of the lattice to be filled.
startAt start index of the source genericLattice1D vct.

template<typename T>
void cvr::genericLattice1D< T >::fill ( const genericLattice1D< T > &  lat,
const size_type  from = MinIndex,
const size_type  to = MaxIndex,
const size_type  startAt = 0 
) [inline]

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

Parameters:
lat genericLattice1D with the elements to be copied
from first element index of the actual genericLattice1D
to last element index of the actual genericLattice1D
startAt start index of the source genericLattice1D vct.

template<typename T>
void cvr::genericLattice1D< T >::fill ( const value_type  data[],
const iinterval indices 
) [inline]

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

Parameters:
data the data to by copied into this genericLattice1D
indices interval of the lattice to be filled in.
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::genericLattice1D<double> myLat(-5,5,0);// genericLattice1D with
                                               // 11 elements with 0
   myLat.fill(data,1,3);             // myLat=[0,0,0,0,0,0,2,4,8,0,0]

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

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

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

Example:

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

template<typename T>
void cvr::genericLattice1D< T >::fill ( const_reference  iniValue,
const iinterval indices 
) [inline]

Fills the genericLattice1D elements with iniValue between from and to.

Parameters:
iniValue the elements will be initialized with this value.
indices interval of the lattice to be filled in
If from or to are out of bounds, they will be (internaly) adjusted to correct values.

Example:

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

template<typename T>
void cvr::genericLattice1D< T >::fill ( const_reference  iniValue,
const size_type  from = MinIndex,
const size_type  to = MaxIndex 
)

Fills the genericLattice1D 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 correct values.

Example:

   cvr::genericLattice1D<double> myLat(-1,8,0); // genericLattice1D with 
                                                // 10 elements with 0
   myLat.fill(9,1,3);                      // myLat=[0,0,9,9,9,0,0,0,0,0]

template<typename T>
size_type cvr::genericLattice1D< T >::firstIndex (  )  const [inline]

Returns first index (in a genericLattice1D this is always size()-1).

template<typename T>
const genericVector<T>& cvr::genericLattice1D< T >::getAsVector (  )  const [inline]

Get a read-only reference to this container as a vector.

template<typename T>
const_iterator cvr::genericLattice1D< T >::inverseBegin (  )  const [inline]

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

See inverseBegin() for more details.

template<typename T>
iterator cvr::genericLattice1D< T >::inverseBegin (  )  [inline]

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

It is used for inverse order iteration through the genericLattice1D 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.

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

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

template<typename T>
const_iterator cvr::genericLattice1D< T >::inverseEnd (  )  const [inline]

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

template<typename T>
iterator cvr::genericLattice1D< T >::inverseEnd (  )  [inline]

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

It is used to mark the end for inverse order iteration through the genericLattice1D 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::genericLattice1D< T >::lastIndex (  )  const [inline]

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

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

Returns the name of this type.

Implements cvr::ioObject.

Reimplemented in cvr::kernel1D< T >, cvr::lattice1D< T >, cvr::lattice1D< T >, and cvr::lattice1D< int >.

template<typename T>
virtual genericLattice1D<T>* cvr::genericLattice1D< T >::newInstance (  )  const [virtual]

Create a clone of this genericLattice1D.

Returns:
a pointer to a copy of this genericLattice1D

Implements cvr::container.

Reimplemented in cvr::kernel1D< T >, cvr::lattice1D< T >, cvr::lattice1D< T >, and cvr::lattice1D< int >.

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

Compare this genericLattice1D with other.

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

template<typename T>
genericLattice1D<T>& cvr::genericLattice1D< T >::operator= ( const genericLattice1D< T > &  other  ) 

Assigment operator (alias for copy(other)).

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

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

Compare this genericLattice1D with other.

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

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

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

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

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

template<typename T>
bool cvr::genericLattice1D< T >::ownsData (  )  const [inline]

Check whether this object owns the data.

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

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

Read the object from the given ioHandler.

Reimplemented from cvr::ioObject.

Reimplemented in cvr::kernel1D< T >.

template<typename T>
void cvr::genericLattice1D< T >::resize ( const iinterval indices  )  [inline]

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

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

Parameters:
indices interval used for the lattice indices.
See also:
resize(const int,const_reference, const eResizeType),

allocate(),assign()

template<typename T>
void cvr::genericLattice1D< T >::resize ( const size_type  from,
const size_type  to 
) [inline]

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

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

Parameters:
from initial index
to final index
See also:
resize(const int,const_reference,const eResizeType)

allocate(),assign()

template<typename T>
void cvr::genericLattice1D< T >::resize ( const iinterval indices,
const_reference  iniValue,
const eResizeType  resizeType = CopyAndInit 
) [inline]

Change dimension and if desired the contents of the genericVector.

Parameters:
indices interval to be used by the lattice indices.
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 int), allocate(), assign()

template<typename T>
void cvr::genericLattice1D< T >::resize ( const size_type  from,
const size_type  to,
const_reference  iniValue,
const eResizeType  resizeType = CopyAndInit 
)

Change dimension and if desired the contents of the genericVector.

Parameters:
from initial index
to final index
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 int), allocate(), assign()

template<typename T>
void cvr::genericLattice1D< T >::restoreOwnership (  )  [inline]

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 genericLattice1D already owns its data nothing happens.

template<typename T>
size_type cvr::genericLattice1D< T >::size (  )  const [inline]

Returns the number of elements of the genericLattice1D.

template<typename T>
void cvr::genericLattice1D< T >::swap ( genericLattice1D< T > &  other  ) 

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

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

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

template<typename T>
void cvr::genericLattice1D< T >::useExternData ( const iinterval indices,
pointer  data,
const eConstantReference  constRef = VariableReference 
) [inline]

Reference to extern data.

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

Parameters:
indices interval to be used by the lattice to access the data. 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 genericLattice1D. 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::genericLattice1D<double> myLat;  // an empty genericLattice1D

 myLat.resize(-2,2,0);       // resize the genericLattice1D: now 5
                             // elements initialized with 0

 myLat.useExternData(-4,5,a,true); // use the genericLattice1D as wrapper
                             // for the memory block

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

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

 myLat.resize(0,5);          // INVALID!! this will throw an exception
                             // constReferenceException()

If the size (from-to+1) is greater than the allocated memory, the behaviour could be unpredictible.

template<typename T>
void cvr::genericLattice1D< T >::useExternData ( const size_type  from,
const size_type  to,
pointer  data,
const eConstantReference  constRef = VariableReference 
) [inline]

Reference to extern data.

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

Parameters:
from initial index
to final index
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 genericLattice1D. 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::genericLattice1D<double> myLat;  // an empty genericLattice1D

 myLat.resize(-2,2,0);       // resize the genericLattice1D: now 5
                             // elements initialized with 0

 myLat.useExternData(-4,5,a,true); // use the genericLattice1D as wrapper
                             // for the memory block

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

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

 myLat.resize(0,5);          // INVALID!! this will throw an exception
                             // constReferenceException()

If the size (from-to+1) is greater than the allocated memory, the behaviour could be unpredictible.

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

Write the object in the given ioHandler.

Reimplemented from cvr::ioObject.

Reimplemented in cvr::kernel1D< T >.


Member Data Documentation

template<typename T>
genericVector<T> cvr::genericLattice1D< T >::data_ [protected]

A generic vector is used to contain the data.

template<typename T>
size_type cvr::genericLattice1D< T >::first_ [protected]

Index of the last element of the genericLattice1D.

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

template<typename T>
size_type cvr::genericLattice1D< T >::last_ [protected]

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

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

template<typename T>
pointer cvr::genericLattice1D< T >::theElements0_ [protected]

Pointer to the element with index zero.


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

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