Flow123d
release_3.0.0-1165-gffc6a5f
|
Small extension of Vector<T> container with support to Id numbers. More...
#include <output_msh.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 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 > |
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.
typedef std::vector<T>::const_iterator flow::VectorId< T >::const_iterator |
Definition at line 347 of file sys_vector.hh.
typedef T flow::VectorId< T >::ElementType |
We have to export template type for FullIteraror.
Definition at line 341 of file sys_vector.hh.
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.
typedef T* flow::VectorId< T >::Iter |
Default iterator for this class.
Definition at line 343 of file sys_vector.hh.
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.
|
inline |
Construct with reserve the space. Includes default constructor.
Definition at line 352 of file sys_vector.hh.
|
inlinevirtual |
Since storage is direct member it is deallocated by its own destructor.
Definition at line 477 of file sys_vector.hh.
|
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.
|
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.
|
inline |
Returns FullFullIterer of the fictions past the end element.
Definition at line 387 of file sys_vector.hh.
|
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.
|
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.
|
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.
|
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.
|
inline |
Definition at line 463 of file sys_vector.hh.
|
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.
|
inline |
Gets iterator of the element specified by index.
Definition at line 411 of file sys_vector.hh.
|
inline |
Gets iterator of the element specified by index.
Definition at line 418 of file sys_vector.hh.
|
inline |
Gets reference to the element specified by index.
Definition at line 395 of file sys_vector.hh.
|
inline |
Gets reference to the element specified by index.
Definition at line 403 of file sys_vector.hh.
|
inline |
Reallocates the container space.
Definition at line 469 of file sys_vector.hh.
|
inline |
Returns size of the container. This is independent of the allocated space.
Definition at line 391 of file sys_vector.hh.
|
friend |
Definition at line 487 of file sys_vector.hh.
|
friend |
Definition at line 488 of file sys_vector.hh.
|
private |
Maps id numbers to indexes into storage vector.
Definition at line 485 of file sys_vector.hh.
|
private |
Space to save id numbers.
Definition at line 484 of file sys_vector.hh.
|
private |
Underlying vector container.
Definition at line 482 of file sys_vector.hh.