last update 20 Sep 2009 |
#include <cvrGenericVector.h>
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 |
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.
typedef const T* cvr::genericVector< T >::const_pointer |
Const pointer to value_type.
typedef const T& cvr::genericVector< T >::const_reference |
Const reference to value_type.
typedef cvr::constReferenceException cvr::genericVector< T >::constReferenceException |
Exception thrown when a constant reference is violated.
typedef T* cvr::genericVector< T >::pointer |
Pointer to value_type.
typedef T& cvr::genericVector< T >::reference |
Reference to value_type.
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.
typedef T cvr::genericVector< T >::value_type |
Type of the genericVector elements.
cvr::genericVector< T >::genericVector | ( | ) | [package] |
Default constructor creates an empty genericVector.
cvr::genericVector< T >::genericVector | ( | const size_type | theSize | ) | [explicit, package] |
Create a genericVector of the given size but do not initialize its elements.
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.theSize | number of elements of the genericVector. |
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.
theSize | number of elements of the genericVector. | |
iniValue | all elements will be initialized with this value. |
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.
theSize | number of elements of the genericVector. | |
data | a pointer to the data that will be copied. |
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!.
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. |
cvr::genericVector< T >::genericVector | ( | const genericVector< T > & | other | ) | [package] |
Create this genericVector as a copy of another genericVector.
other | the genericVector to be copied. |
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.
other | the genericVector to be copied. | |
from | starting point included | |
to | end point included. |
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.
other | the genericVector to be copied. | |
idx | indices of the elements to be copied |
cvr::genericVector< T >::genericVector | ( | const std::vector< T > & | other | ) | [package] |
Create this genericVector as a copy of another std::genericVector.
other | the genericVector to be copied. |
virtual cvr::genericVector< T >::~genericVector | ( | ) | [package, virtual] |
Destructor.
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).
newSize | new vector size. All current data will be discarded. |
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!
a | the first genericVector | |
b | the second genericVector | |
function | a pointer to a two parameters C-function |
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);
a | the first genericVector | |
b | the second genericVector | |
function | a pointer to a two parameters C-function |
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!
other | the second genericVector to be considered (the first genericVector will be this object!) | |
function | a pointer to a two parameters C-function |
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!
other | the second genericVector to be considered (the first genericVector will be this object!) | |
function | a pointer to a two parameters C-function |
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.
other | the genericVector with the source data | |
function | a pointer to a C-function |
genericVector<T>& cvr::genericVector< T >::apply | ( | T(*)(const T &) | function | ) | [package] |
Applies a C-function to each element of the genericVector.
function | a pointer to a C-function |
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.
other | the source genericVector | |
function | a pointer to a C-function |
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);
function | a pointer to a C-function |
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).
const_reference cvr::genericVector< T >::at | ( | const size_type | x | ) | const [inline, package] |
Access element x of the genericVector in a read-only modus.
x | index of the genericVector element to be accessed. It should be between firstIndex() and lastIndex() |
reference cvr::genericVector< T >::at | ( | const size_type | x | ) | [inline, package] |
Access element x of the genericVector.
x | index of the genericVector element to be accessed. It should be between firstIndex() and lastIndex() |
Referenced by cvr::histogramEqualization::getEqualized().
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().
theSize | number of elements of the genericVector | |
data | a pointer to the memory block to be used |
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!!
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. }
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()
genericVector<T>& cvr::genericVector< T >::castFrom | ( | const std::vector< U > & | other | ) | [inline, package] |
Cast from a std::genericVector of the same type.
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.
other | The genericVector to be copied. | |
from | starting point included | |
to | end point included |
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.
other | The genericVector to be copied. | |
from | starting point included | |
to | end point included. |
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.
other | The genericVector to be copied. |
genericVector<T>& cvr::genericVector< T >::castFrom | ( | const genericVector< U > & | other | ) | [inline, package] |
Copy the other genericVector by casting each of its elements.
other | The genericVector to be copied. |
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!!
void cvr::genericVector< T >::clear | ( | ) | [package] |
Removes all elements from the genericVector (Set dimensions to 0).
virtual genericVector<T>* cvr::genericVector< T >::clone | ( | ) | const [package, virtual] |
Create a clone of this genericVector.
Implements cvr::container.
Reimplemented in cvr::vector< T >, cvr::vector< double >, cvr::vector< value_type >, cvr::vector< float >, cvr::vector< int >, cvr::vector< integer >, cvr::vector< ubyte >, cvr::vector< frgbPixel >, and cvr::vector< rgbaPixel >.
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.
other | the genericVector to be copied. | |
idx | indices of the elements to be copied |
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).
other | the genericVector to be copied. | |
from | starting point included | |
to | end point included. |
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.
other | the source genericVector to be copied. |
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.
receiver | the genericVector which will receive the memory block. All data of that genericVector will be first deleted! |
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.
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.
bool cvr::genericVector< T >::empty | ( | ) | const [inline, package] |
Returns true if the genericVector is empty.
iterator cvr::genericVector< T >::end | ( | ) | [inline, package] |
Returns last index as an iterator.
For an example see begin()
const_iterator cvr::genericVector< T >::end | ( | ) | const [inline, package] |
Returns last index as a const_iterator.
For an example see begin()
bool cvr::genericVector< T >::equals | ( | const genericVector< T > & | other | ) | const [package] |
Compare this genericVector with other.
other | the other genericVector to be compared with |
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.
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. |
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.
data | the data to by copied into this genericVector | |
from | first element index | |
to | last element index |
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]
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.
iniValue | the elements will be initialized with this value. | |
from | first element index | |
to | last element index |
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]
size_type cvr::genericVector< T >::firstIndex | ( | ) | const [inline, package] |
Returns last index (in a genericVector this is always size()-1).
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.
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; }
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.
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.
size_type cvr::genericVector< T >::lastIndex | ( | ) | const [inline, package] |
Returns last index (in a genericVector this is always size()-1).
virtual const std::string& cvr::genericVector< T >::name | ( | ) | const [package, virtual] |
Returns the name of this type.
Implements cvr::ioObject.
Reimplemented in cvr::vector< T >, cvr::vector< double >, cvr::vector< value_type >, cvr::vector< float >, cvr::vector< int >, cvr::vector< integer >, cvr::vector< ubyte >, cvr::vector< frgbPixel >, and cvr::vector< rgbaPixel >.
virtual genericVector<T>* cvr::genericVector< T >::newInstance | ( | ) | const [package, virtual] |
Create a clone of this genericVector.
Implements cvr::container.
Reimplemented in cvr::vector< T >, cvr::vector< double >, cvr::vector< value_type >, cvr::vector< float >, cvr::vector< int >, cvr::vector< integer >, cvr::vector< ubyte >, cvr::vector< frgbPixel >, and cvr::vector< rgbaPixel >.
bool cvr::genericVector< T >::operator!= | ( | const genericVector< T > & | other | ) | const [inline, package] |
Compare this genericVector with other.
other | the other genericVector to be compared with. |
genericVector<T>& cvr::genericVector< T >::operator= | ( | const genericVector< T > & | other | ) | [package] |
Assigment operator (alias for copy(other)).
other | the genericVector to be copied |
bool cvr::genericVector< T >::operator== | ( | const genericVector< T > & | other | ) | const [inline, package] |
Compare this genericVector with other.
other | the other genericVector to be compared with |
const_reference cvr::genericVector< T >::operator[] | ( | const size_type | x | ) | const [inline, package] |
Constant access operator (alias for at(const size_type x) const).
reference cvr::genericVector< T >::operator[] | ( | const size_type | x | ) | [inline, package] |
Access operator (alias for at(const size_type x)).
bool cvr::genericVector< T >::ownsData | ( | ) | const [inline, package] |
Check whether this object owns the data.
virtual bool cvr::genericVector< T >::read | ( | ioHandler & | handler, | |
const bool | complete = true | |||
) | [package, virtual] |
void cvr::genericVector< T >::releaseMem | ( | pointer & | block | ) | const [protected] |
Release the block pointed, but leave this vector alone.
void cvr::genericVector< T >::releaseMem | ( | ) | [protected] |
Release all reserved memory.
Clean all memory and leave the vector in a clean, empty state.
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.
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.
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);
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.
newSize | the new size of the genericVector | |
iniValue | the initialization value. | |
resizeType | specifies what should happen with the data of the resized vector. |
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!
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.
size_type cvr::genericVector< T >::size | ( | ) | const [inline, package] |
Returns the number of elements of the genericVector.
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.
other | the genericVector with which the data will be exchanged. |
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!.
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() |
virtual bool cvr::genericVector< T >::write | ( | ioHandler & | handler, | |
const bool | complete = true | |||
) | const [package, virtual] |
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()).
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()).
true cvr::genericVector< T >::const_iterator [package] |
Exception thrown when a constant reference is violated.
Reimplemented in cvr::vector< T >, cvr::vector< double >, cvr::vector< value_type >, cvr::vector< float >, cvr::vector< int >, cvr::vector< integer >, cvr::vector< ubyte >, cvr::vector< frgbPixel >, and cvr::vector< rgbaPixel >.
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())
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.
false cvr::genericVector< T >::iterator [package] |
Exception thrown when a constant reference is violated.
Reimplemented in cvr::vector< T >, cvr::vector< double >, cvr::vector< value_type >, cvr::vector< float >, cvr::vector< int >, cvr::vector< integer >, cvr::vector< ubyte >, cvr::vector< frgbPixel >, and cvr::vector< rgbaPixel >.
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())
pointer cvr::genericVector< T >::theElements_ [protected] |
Pointer to the first element of the genericVector.
size_type cvr::genericVector< T >::vectorSize_ [protected] |
Dimension of the genericVector.