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

lti::sequence< T > Class Template Reference

sequence container class. More...

#include <ltiSequence.h>

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

List of all members.

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 &copyData=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 objectclone () 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

Detailed Description

template<class T>
class lti::sequence< T >

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:


Member Typedef Documentation

template<class T>
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.

template<class T>
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


Constructor & Destructor Documentation

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

default constructor creates an empty sequence;

template<class T>
lti::sequence< T >::sequence ( const int &  theSize  ) 

create a sequence of the given size.

The member will not be initialized

Parameters:
theSize number of elements of the sequence
template<class T>
lti::sequence< T >::sequence ( const sequence< T > &  other  ) 

create this sequence as a copy of another sequence

Parameters:
other the sequence to be copied.
template<class T>
virtual lti::sequence< T >::~sequence (  )  [virtual]

destructor


Member Function Documentation

template<class T>
virtual void lti::sequence< T >::append ( const T &  theElement = T()  )  [virtual]

append element to sequence.

Parameters:
theElement will be appended to the end of the sequence.

Automatically resizes the vector. To remove Elements from end of sequence use resize()

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

access element x of the sequence in a read-only modus

Parameters:
x index of the sequence element to be accessed. It should be between firstIdx() and lastIdx()
template<class T>
virtual T& lti::sequence< T >::at ( const int &  x  )  [virtual]

access element x of the sequence

Parameters:
x index of the sequence element to be accessed. It should be between firstIdx() and lastIdx()
template<class T>
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
 }
template<class T>
virtual const_iterator lti::sequence< T >::begin (  )  const [virtual]

returns first element as a const_iterator.

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

template<class T>
virtual object* lti::sequence< T >::clone (  )  const [virtual]

create a clone of this sequence

Returns:
a pointer to a copy of this sequence
template<class T>
virtual sequence<T>& lti::sequence< T >::concatenate ( const sequence< T > &  other  )  [virtual]

concatenate another sequence to this one the elements of the other sequence will be concatenated

Parameters:
other the sequence to be concatenated at the end of this one
Returns:
a reference to this sequence
template<class T>
virtual sequence<T>& lti::sequence< T >::copy ( const sequence< T > &  other  )  [virtual]

assigment operator.

copy the contents of other in this object.

Parameters:
other the source sequence to be copied.

Reimplemented from lti::ioObject.

Referenced by lti::sequence< sequence< dvector > >::operator=().

template<class T>
virtual iterator lti::sequence< T >::end (  )  [virtual]

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

template<class T>
virtual const_iterator lti::sequence< T >::end (  )  const [virtual]

returns last index as a const iterator.

For an example see begin()

template<class T>
virtual bool lti::sequence< T >::equals ( const sequence< T > &  other  )  const [virtual]

compare this sequence with other

Parameters:
other the other sequence to be compared with
Returns:
true if both sequences have the same elements and same size
template<class T>
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.

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

template<class T>
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.

Parameters:
iniValue the elements will be initialized with this value.
from first element index
to last element index

If from or to are out of bounds, they will be (internaly) adjusted to to correct value.

Example:

   lti::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]
template<class T>
virtual int lti::sequence< T >::firstIdx (  )  const [virtual]

returns first index (normally 0)

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

returns the name of this class: "sequence"

Reimplemented from lti::ioObject.

template<class T>
virtual int lti::sequence< T >::lastIdx (  )  const [virtual]

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

template<class T>
virtual sequence<T>& lti::sequence< T >::operator= ( const sequence< T > &  other  )  [inline, virtual]

assigment operator (alias for copy(other)).

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

Reimplemented from lti::ioObject.

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

compare this sequence with other

Parameters:
other the other sequence to be compared with
Returns:
true if both sequences have the same elements and same size
template<class T>
virtual const T& lti::sequence< T >::operator[] ( const int &  x  )  const [virtual]

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

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

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

template<class T>
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().

template<class T>
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.

Parameters:
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!

template<class T>
virtual int lti::sequence< T >::size (  )  const [virtual]

returns the number of elements of the sequence

template<class T>
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().


Member Data Documentation

template<class T>
std::vector<T> lti::sequence< T >::theSequence [protected]

this sequence class is implemented with a std::vector instance


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

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