latest version v1.9 - last update 10 Apr 2010 |
sequence container class. More...
#include <ltiSequence.h>
Public Types | |
typedef std::vector< T >::iterator | iterator |
typedef std::vector< T > ::const_iterator | const_iterator |
Public Member Functions | |
sequence () | |
sequence (const int &theSize) | |
sequence (const sequence< T > &other) | |
virtual | ~sequence () |
const char * | getTypeName () const |
virtual int | size () const |
virtual int | firstIdx () const |
virtual const_iterator | begin () const |
virtual iterator | begin () |
virtual int | lastIdx () const |
virtual const_iterator | end () const |
virtual iterator | end () |
virtual void | append (const T &theElement=T()) |
virtual void | resize (const int &newSize, const T &iniValue=T(), const bool ©Data=true, const bool &initNew=true) |
virtual void | fill (const T &iniValue, const int &from=0, const int &to=MaxInt32) |
virtual void | fill (const sequence< T > &vct, const int &from=0, const int &to=MaxInt32, const int &startAt=0) |
virtual T & | at (const int &x) |
virtual const T & | at (const int &x) const |
virtual T & | operator[] (const int &x) |
virtual const T & | operator[] (const int &x) const |
virtual sequence< T > & | copy (const sequence< T > &other) |
virtual object * | clone () const |
virtual bool | equals (const sequence< T > &other) const |
virtual bool | operator== (const sequence< T > &other) const |
virtual sequence< T > & | operator= (const sequence< T > &other) |
virtual sequence< T > & | concatenate (const sequence< T > &other) |
virtual bool | write (ioHandler &handler, const bool complete=true) const |
virtual bool | read (ioHandler &handler, const bool complete=true) |
Protected Attributes | |
std::vector< T > | theSequence |
sequence container class.
The ltisequence class allows the representation of sequences of other lti objects. It can be used as a sort of vector of other objects.
The elements of the sequence will be indexed between 0 an n-1.
An example of a sequence of lti::vectors:
// creates a sequence of 256 vectors lti::sequence< lti::vector<float> > mySeq(256)
To access the vector elements use the access operators at() (or the overloaded operator[]()). For example:
for (int i = 0; i < mySeq.size(); i++) { // each element of the sequence is a vector filled with i/2 mySeq.at(i).resize(10,float(i)/2.0f); }
The sequence has following methods:
typedef std::vector<T>::const_iterator lti::sequence< 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 lti::sequence::begin() for an example.
typedef std::vector<T>::iterator lti::sequence< 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 lti::sequence::begin() for an example
lti::sequence< T >::sequence | ( | ) |
default constructor creates an empty sequence;
lti::sequence< T >::sequence | ( | const int & | theSize | ) |
lti::sequence< T >::sequence | ( | const sequence< T > & | other | ) |
virtual lti::sequence< T >::~sequence | ( | ) | [virtual] |
destructor
virtual void lti::sequence< T >::append | ( | const T & | theElement = T() |
) | [virtual] |
virtual const T& lti::sequence< T >::at | ( | const int & | x | ) | const [virtual] |
access element x of the sequence in a read-only modus
x | index of the sequence element to be accessed. It should be between firstIdx() and lastIdx() |
virtual T& lti::sequence< T >::at | ( | const int & | x | ) | [virtual] |
access element x of the sequence
x | index of the sequence element to be accessed. It should be between firstIdx() and lastIdx() |
virtual iterator lti::sequence< T >::begin | ( | ) | [virtual] |
returns an iterator pointing to the first element of the sequence The use of the interators is similar to the iterators of the Standard Template Library (STL).
If you need to iterate on all elements of the sequence, you can use following code:
int accu = 1; lti::sequence<vector<int> > mySeq(10); // a sequence with 10 elements lti::sequence<vector<int> >::iterator it; // an iterator for (it=mySeq.begin();it!=mySeq.end();it++) { vector<int>& tmp = *it; // tmp is a reference to the vector // pointed by the iterator. accu++; tmp.resize(accu,accu); // resize and initialize the vector }
virtual const_iterator lti::sequence< T >::begin | ( | ) | const [virtual] |
virtual object* lti::sequence< T >::clone | ( | ) | const [virtual] |
virtual sequence<T>& lti::sequence< T >::concatenate | ( | const sequence< T > & | other | ) | [virtual] |
virtual sequence<T>& lti::sequence< T >::copy | ( | const sequence< T > & | other | ) | [virtual] |
assigment operator.
copy the contents of other
in this object.
other | the source sequence to be copied. |
Reimplemented from lti::ioObject.
Referenced by lti::sequence< sequence< dvector > >::operator=().
virtual iterator lti::sequence< T >::end | ( | ) | [virtual] |
returns last index as an iterator For an example see begin()
virtual const_iterator lti::sequence< T >::end | ( | ) | const [virtual] |
returns last index as a const iterator.
For an example see begin()
virtual bool lti::sequence< T >::equals | ( | const sequence< T > & | other | ) | const [virtual] |
virtual void lti::sequence< T >::fill | ( | const sequence< T > & | vct, | |
const int & | from = 0 , |
|||
const int & | to = MaxInt32 , |
|||
const int & | startAt = 0 | |||
) | [virtual] |
fills the sequence elements from from
to to
with the elements of vct
starting at startAt
.
vct | sequence with the elements to be copied | |
from | first element index of the actual sequence | |
to | last element index of the actual sequence | |
startAt | start index of the source sequence 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]
virtual void lti::sequence< T >::fill | ( | const T & | iniValue, | |
const int & | from = 0 , |
|||
const int & | to = MaxInt32 | |||
) | [virtual] |
fills the sequence elements with iniValue
between from
and to
.
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::sequence<double> myVct(10,0); // sequence with 10 elements // with 0 myVct.fill(9,1,3); // myVct=[0,9,9,9,0,0,0,0,0,0]
virtual int lti::sequence< T >::firstIdx | ( | ) | const [virtual] |
returns first index (normally 0)
const char* lti::sequence< T >::getTypeName | ( | void | ) | const [inline, virtual] |
returns the name of this class: "sequence"
Reimplemented from lti::ioObject.
virtual int lti::sequence< T >::lastIdx | ( | ) | const [virtual] |
virtual sequence<T>& lti::sequence< T >::operator= | ( | const sequence< T > & | other | ) | [inline, virtual] |
assigment operator (alias for copy(other)).
other | the sequence to be copied |
Reimplemented from lti::ioObject.
virtual bool lti::sequence< T >::operator== | ( | const sequence< T > & | other | ) | const [virtual] |
virtual const T& lti::sequence< T >::operator[] | ( | const int & | x | ) | const [virtual] |
const access operator (alias for at(const int& x) const).
virtual T& lti::sequence< T >::operator[] | ( | const int & | x | ) | [virtual] |
access operator (alias for at(const int& x)).
virtual bool lti::sequence< T >::read | ( | ioHandler & | handler, | |
const bool | complete = true | |||
) | [virtual] |
read the sequence from the given ioHandler
Reimplemented from lti::ioObject.
Referenced by lti::read().
virtual void lti::sequence< T >::resize | ( | const int & | newSize, | |
const T & | iniValue = T() , |
|||
const bool & | copyData = true , |
|||
const bool & | initNew = true | |||
) | [virtual] |
change dimension of the sequence.
newSize | the new size of the sequence | |
iniValue | the initialization value. | |
copyData | if this parameter is true, the old data of the sequence 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::sequence<int> myVct; // creates empty sequence myVct.resize(5,0); // sequence with 5 elements initialized // with 0 myVct.resize(10,2); // sequence has now 10 elements: the // first five are still 0 and the // rest have a 2 myVct.resize(20,3,false,false); // now the sequence has 20 // elements but their values // are unknown. myVct.resize(5,1,false,true); // the sequence has now 5 // elements initialized with 1 // note that the last line could also be written: myVct.resize(5,1,false); // the sequence has now 5 // elements initialized with 1
If the resize is possible (see useExternData()), this object will always owns the data!
virtual int lti::sequence< T >::size | ( | ) | const [virtual] |
returns the number of elements of the sequence
virtual bool lti::sequence< T >::write | ( | ioHandler & | handler, | |
const bool | complete = true | |||
) | const [virtual] |
write the sequence in the given ioHandler
Reimplemented from lti::ioObject.
Referenced by lti::write().
std::vector<T> lti::sequence< T >::theSequence [protected] |
this sequence class is implemented with a std::vector instance