Flow123d  release_3.0.0-869-g0e4dab6
Public Types | Public Member Functions | Private Attributes | Friends | List of all members
flow::VectorId< T > Class Template Reference

Small extension of Vector<T> container with support to Id numbers. More...

#include <output_msh.hh>

Collaboration diagram for flow::VectorId< T >:
Collaboration graph
[legend]

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 FullIteratorId< T > FullIter
 Type of FullIterator that should be used to iterate through this container. More...
 

Public Member Functions

 VectorId (unsigned int size=0)
 Construct with reserve the space. Includes default constructor. More...
 
FullIter add_item (int id)
 
unsigned int index (const T *pointer) const
 
FullIter begin ()
 
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...
 
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...
 
const Iter operator() (unsigned int idx) const
 Gets iterator of the element specified by index. More...
 
FullIter full_iter (Iter it)
 
FullIter find_id (const int id)
 
const T * find_id (const int id) const
 
int get_id (const T *it) const
 
int get_id (int idx) const
 
void reserve (unsigned int size)
 Reallocates the container space. More...
 
virtual ~VectorId ()
 Since storage is direct member it is deallocated by its own destructor. More...
 

Private Attributes

std::vector< T > storage
 Underlying vector container. More...
 
std::vector< int > id_storage
 Space to save id numbers. More...
 
std::map< int, unsigned int > id_map
 Maps id numbers to indexes into storage vector. More...
 

Friends

class FullIterator< VectorId< T > >
 
class FullIteratorId< T >
 

Detailed Description

template<class T>
class flow::VectorId< T >

Small extension of Vector<T> container with support to Id numbers.

Small extension of the class FullIterator<Cont>. Provides id() method to get id number of the iterator. In contrast to FullIterator<> this is templated only by the element type of the container which is always VectorId<T>.

This stores Id numbers of added elements and can latter access elements by id. An Id can be any integer number that only has to be unique for every element in the container. In particular Id numbers are need not to be continuous neither keep the ordering of the elements. Main application is to keep Id numbers from input, which are only necessary to amke correct references during input and possibly to generate consistent output. Id numbers are useless for calculations.

Developer Note:

I have tried to make one common base class VectorBase which should have storage member and implements basic operations with it. But I can not make it to return FullIterator which has to be initialized with reference to the container so not VectorBase but some of its descendants. Only way seems to construct FullIterator by any pointer which could be type cast to the type of the container which is template parameter of FullIter. But such constructor should be used only by VectorXXX classes, but we can not make VectorBase<T, It> friend for any T and any It. However all this seems to be too complicated and ugly so I and up with lot of repetitive code in implementation of VectorXXX classes.

Definition at line 24 of file output_msh.hh.

Member Typedef Documentation

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

Definition at line 347 of file sys_vector.hh.

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

We have to export template type for FullIteraror.

Definition at line 341 of file sys_vector.hh.

template<class T>
typedef FullIteratorId< T > flow::VectorId< T >::FullIter

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

Definition at line 349 of file sys_vector.hh.

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

Default iterator for this class.

Definition at line 343 of file sys_vector.hh.

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

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

Definition at line 346 of file sys_vector.hh.

Constructor & Destructor Documentation

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

Construct with reserve the space. Includes default constructor.

Definition at line 352 of file sys_vector.hh.

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

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

Definition at line 477 of file sys_vector.hh.

Member Function Documentation

template<class T>
FullIter flow::VectorId< T >::add_item ( int  id)
inline

Adds a new element into the container. Return iterator to it to set vales of the new element. This way we need not copy a new element. You are forced to set the id when adding a new element.

Definition at line 359 of file sys_vector.hh.

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

Returns FullFullIterer of the first element. Do not try to set these as const methods. Such has to produce const iterators which requires const anlaogy of FullIter - really ugly

Definition at line 383 of file sys_vector.hh.

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

Returns FullFullIterer of the fictions past the end element.

Definition at line 387 of file sys_vector.hh.

template<class T>
FullIter flow::VectorId< T >::find_id ( const int  id)
inline

Returns FullIter of the element with given id. This is implemented by std::map which use balanced trees and ensure access in O(nlog n) time.

Definition at line 434 of file sys_vector.hh.

template<class T>
const T* flow::VectorId< T >::find_id ( const int  id) const
inline

Returns FullIter of the element with given id. This is implemented by std::map which use balanced trees and ensure access in O(nlog n) time.

Definition at line 446 of file sys_vector.hh.

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

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

Definition at line 428 of file sys_vector.hh.

template<class T>
int flow::VectorId< T >::get_id ( const T *  it) const
inline

Returns Id of the element given by pointer i.e. Iter. FullIter i.e. FullIteratorId<T> provides its own method for the same.

Definition at line 458 of file sys_vector.hh.

template<class T>
int flow::VectorId< T >::get_id ( int  idx) const
inline

Definition at line 463 of file sys_vector.hh.

template<class T>
unsigned int flow::VectorId< T >::index ( const T *  pointer) const
inline

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

Definition at line 373 of file sys_vector.hh.

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

Gets iterator of the element specified by index.

Definition at line 411 of file sys_vector.hh.

template<class T>
const Iter flow::VectorId< T >::operator() ( unsigned int  idx) const
inline

Gets iterator of the element specified by index.

Definition at line 418 of file sys_vector.hh.

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

Gets reference to the element specified by index.

Definition at line 395 of file sys_vector.hh.

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

Gets reference to the element specified by index.

Definition at line 403 of file sys_vector.hh.

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

Reallocates the container space.

Definition at line 469 of file sys_vector.hh.

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

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

Definition at line 391 of file sys_vector.hh.

Friends And Related Function Documentation

template<class T>
friend class FullIterator< VectorId< T > >
friend

Definition at line 487 of file sys_vector.hh.

template<class T>
friend class FullIteratorId< T >
friend

Definition at line 488 of file sys_vector.hh.

Member Data Documentation

template<class T>
std::map<int, unsigned int> flow::VectorId< T >::id_map
private

Maps id numbers to indexes into storage vector.

Definition at line 485 of file sys_vector.hh.

template<class T>
std::vector<int> flow::VectorId< T >::id_storage
private

Space to save id numbers.

Definition at line 484 of file sys_vector.hh.

template<class T>
std::vector<T> flow::VectorId< T >::storage
private

Underlying vector container.

Definition at line 482 of file sys_vector.hh.


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