Flow123d  release_3.0.0-1106-ga3b2e4c
Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
flow::Vector< T > Class Template Reference

Envelop over std::vector, use enhanced iterators. More...

#include <sys_vector.hh>

Public Types

typedef T ElementType
 We have to export template type for FullIteraror. More...
 
typedef T * Iter
 Default iterator for this class. More...
 
typedef std::vector< T >::iterator iterator
 
typedef std::vector< T >::const_iterator const_iterator
 
typedef FullIterator< Vector< T > > FullIter
 Type of FullIterator that should be used to iterate through this container. More...
 

Public Member Functions

 Vector (unsigned int size=0)
 Construct with reserve the space. Includes default constructor. More...
 
FullIter add_item ()
 
unsigned int index (Iter pointer) const
 
FullIter begin ()
 Returns FullFullIterer of the first element. More...
 
FullIter end ()
 Returns FullFullIterer of the fictions past the end element. More...
 
unsigned int size () const
 Returns size of the container. This is independent of the allocated space. More...
 
void resize (const unsigned int size)
 Returns size of the container. This is independent of the allocated space. More...
 
T & operator[] (unsigned int idx)
 Gets reference to the element specified by index. More...
 
const T & operator[] (unsigned int idx) const
 Gets reference to the element specified by index. More...
 
FullIter operator() (unsigned int idx)
 Gets iterator of the element specified by index. More...
 
void reserve (unsigned int size)
 Reallocates the container space. More...
 
FullIter full_iter (Iter it)
 
virtual ~Vector ()
 Since storage is direct member it is deallocated by its own destructor. More...
 

Protected Attributes

std::vector< T > storage
 Underlying vector container. More...
 

Friends

class FullIterator< Vector< T > >
 

Detailed Description

template<class T>
class flow::Vector< T >

Envelop over std::vector, use enhanced iterators.

Differences compared to std::vector.

  1. Implement only subset of std::vector methods.
  2. iterator Iter - which is nothing else then T *. This we use since it can be initializeted to NULL as universal "non valid value". for iterators one has to comapre to std::vector.end(), but the container is not always at hand. This should be used in complex mesh structures to save space.
  3. iterator FullIter - this is standard iterator which contains also reference to the containre it points to. Then it has more save "non valid value" method. Can be constructer from Iter and a container. You can get the index of this iterator. This is meant to be use as local variable. Using this instead of standard iterators It provides function to get index of an iterator
  4. Provides method to get index of a pointer i.e. Iter.
  5. add_item can be used to add a new element and get reference to it so that it can be initialized Useful even for T be class since when creating a new element the default constructor is called which can not fill it with values.

Developer note:

It appears very dangerous to combine reallocating std::vectors with iterators implemented as pointers. Indeed, when vector array is reallocated old pointers become invalid. One possibility is to strictly distinguish crating of the array and later creating references into it. Another is to implement iterators by indexes which means also to use only FullIterators.

Definition at line 206 of file sys_vector.hh.

Member Typedef Documentation

template<class T >
typedef std::vector<T>::const_iterator flow::Vector< T >::const_iterator

Definition at line 216 of file sys_vector.hh.

template<class T >
typedef T flow::Vector< T >::ElementType

We have to export template type for FullIteraror.

Definition at line 210 of file sys_vector.hh.

template<class T >
typedef FullIterator<Vector<T> > flow::Vector< T >::FullIter

Type of FullIterator that should be used to iterate through this container.

Definition at line 218 of file sys_vector.hh.

template<class T >
typedef T* flow::Vector< T >::Iter

Default iterator for this class.

Definition at line 212 of file sys_vector.hh.

template<class T >
typedef std::vector<T>::iterator flow::Vector< T >::iterator

For compatibility with std::algorithms we provide also standard iterators. Theoretically it should work also with Iter. Test that if you need it.

Definition at line 215 of file sys_vector.hh.

Constructor & Destructor Documentation

template<class T >
flow::Vector< T >::Vector ( unsigned int  size = 0)
inline

Construct with reserve the space. Includes default constructor.

Definition at line 222 of file sys_vector.hh.

template<class T >
virtual flow::Vector< T >::~Vector ( )
inlinevirtual

Since storage is direct member it is deallocated by its own destructor.

Definition at line 300 of file sys_vector.hh.

Member Function Documentation

template<class T >
FullIter flow::Vector< T >::add_item ( )
inline

Add a new element into the container. Return iterator to it. Provides a way to add new element to the container and get an iterator to set its values. This way we need not copy a new element.

Definition at line 230 of file sys_vector.hh.

template<class T >
FullIter flow::Vector< T >::begin ( )
inline

Returns FullFullIterer of the first element.

Definition at line 247 of file sys_vector.hh.

template<class T >
FullIter flow::Vector< T >::end ( )
inline

Returns FullFullIterer of the fictions past the end element.

Definition at line 251 of file sys_vector.hh.

template<class T >
FullIter flow::Vector< T >::full_iter ( Iter  it)
inline

Alternative way to make FullIterer form Iter. This way you need not write the full FullIter type to call the constructor. Then the result can be assigned to suitable local FullIter variable.

Definition at line 296 of file sys_vector.hh.

template<class T >
unsigned int flow::Vector< T >::index ( Iter  pointer) const
inline

For given pointer returns the index of the element in the Vector. The first element has zero index.

Definition at line 239 of file sys_vector.hh.

template<class T >
FullIter flow::Vector< T >::operator() ( unsigned int  idx)
inline

Gets iterator of the element specified by index.

Definition at line 279 of file sys_vector.hh.

template<class T >
T& flow::Vector< T >::operator[] ( unsigned int  idx)
inline

Gets reference to the element specified by index.

Definition at line 264 of file sys_vector.hh.

template<class T >
const T& flow::Vector< T >::operator[] ( unsigned int  idx) const
inline

Gets reference to the element specified by index.

Definition at line 271 of file sys_vector.hh.

template<class T >
void flow::Vector< T >::reserve ( unsigned int  size)
inline

Reallocates the container space.

Definition at line 287 of file sys_vector.hh.

template<class T >
void flow::Vector< T >::resize ( const unsigned int  size)
inline

Returns size of the container. This is independent of the allocated space.

Definition at line 259 of file sys_vector.hh.

template<class T >
unsigned int flow::Vector< T >::size ( ) const
inline

Returns size of the container. This is independent of the allocated space.

Definition at line 255 of file sys_vector.hh.

Friends And Related Function Documentation

template<class T >
friend class FullIterator< Vector< T > >
friend

Definition at line 306 of file sys_vector.hh.

Member Data Documentation

template<class T >
std::vector<T> flow::Vector< T >::storage
protected

Underlying vector container.

Definition at line 304 of file sys_vector.hh.


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