Flow123d
release_3.0.0-973-g92f55e826
|
Go to the documentation of this file.
21 #ifndef SYS_VECTOR_HH_
22 #define SYS_VECTOR_HH_
54 iter(cont_par.storage.end()) {}
66 if (
it == NULL)
iter = cont_par.storage.end();
67 else iter = cont_par.storage.begin() +
cont.index(
it);
72 {
return this->
iter != this->
cont.storage.end(); }
79 {
if (this->
iter != this->
cont.storage.end())
return this->
iter -
cont.storage.begin();
97 inline operator typename Cont::Iter ()
const
98 {
return &(*(this->
iter)); }
102 {
return *(this->
iter); }
106 {
return &(*(this->
iter)); }
109 { this->
iter+=shift;
return (*
this); }
112 { this->
iter-=shift;
return (*
this); }
125 ++(this->
iter);
return *
this;
134 OLD_ASSERT(
iter !=
cont.storage.begin(),
"Can not advance iterator to previous of begin().\n");
135 this->
iter--;
return *
this;
146 typename Cont :: iterator
iter;
170 {
return this->
cont.id_storage[ this->
index() ]; }
242 "Wrong pointer %d to obtain its index (%d, %d).\n",pointer, &(
storage.front()), &(
storage.back()));
243 return ( pointer - &(
storage.front()) );
255 inline unsigned int size()
const
266 OLD_ASSERT( idx < this->
size(),
"Index %d outside of Vector of size %d\n",idx, this->
size());
273 OLD_ASSERT( idx < this->
size(),
"Index %d outside of Vector of size %d\n",idx, this->
size());
281 OLD_ASSERT( idx < this->
size(),
"Index %d outside of Vector of size %d\n",idx, this->
size());
289 OLD_ASSERT(
size >= this->
size(),
"Vector can not be reallocated into space %d smaller then its size %d\n",size,this->
size());
361 OLD_ASSERT(
id_map.find(
id) ==
id_map.end(),
"Can not add item with id number %d since it already exists.",
id);
366 return FullIter( *
this, this->
storage.begin() + this->storage.size() - 1 );
373 inline unsigned int index(
const T * pointer)
const
376 "Wrong pointer %p to obtain its index (%p, %p).\n",pointer, &(
storage.front()), &(
storage.back()));
377 return ( pointer - &(
storage.front()) );
391 inline unsigned int size()
const
397 OLD_ASSERT( idx < this->
size(),
"Index %d outside of Vector of size %d\n",idx, this->
size());
405 OLD_ASSERT( idx < this->
size(),
"Index %d outside of Vector of size %d\n",idx, this->
size());
413 OLD_ASSERT( idx < this->
size(),
"Index %d outside of Vector of size %d\n",idx, this->
size());
420 OLD_ASSERT( idx < this->
size(),
"Index %d outside of Vector of size %d\n",idx, this->
size());
437 if ( iter ==
id_map.end() ) {
449 if ( iter ==
id_map.end() ) {
450 return &(*(this->
storage.end()));
452 return &(*(this->
storage.begin() + iter->second));
471 OLD_ASSERT(
size >= this->
size(),
"Vector can not be reallocated into space %d smaller then its size %d\n",size,this->
size());
void reserve(unsigned int size)
Reallocates the container space.
virtual ~VectorId()
Since storage is direct member it is deallocated by its own destructor.
FullIteratorId< T > FullIter
Type of FullIterator that should be used to iterate through this container.
FullIteratorId(const VectorId< T > &cont, typename std::vector< T >::iterator it)
Constructor. Just call base class.
Vector(unsigned int size=0)
Construct with reserve the space. Includes default constructor.
unsigned int size() const
Returns size of the container. This is independent of the allocated space.
unsigned int index(const T *pointer) const
T & operator[](unsigned int idx)
Gets reference to the element specified by index.
FullIterator & operator-=(const int shift)
int id()
Returns id of the iterator. See VectorId documentation.
Cont::ElementType & operator*() const
General iterator template. Provides iterator over objects in some container.
std::vector< T > storage
Underlying vector container.
T * Iter
Default iterator for this class.
FullIter operator()(unsigned int idx)
Gets iterator of the element specified by index.
FullIter end()
Returns FullFullIterer of the fictions past the end element.
virtual ~Vector()
Since storage is direct member it is deallocated by its own destructor.
FullIterator(Cont &cont_par)
Constructor to make uninitialized FullIterator for a container.
Envelop over std::vector, use enhanced iterators.
Cont & container()
Get reference to the container of the FullIterator.
std::vector< T >::const_iterator const_iterator
std::vector< T > storage
Underlying vector container.
FullIterator(Cont &cont_par, const typename Cont::Iter it)
Constructor to make FullIterator from container and Iter i.e. T*.
int get_id(int idx) const
void reserve(unsigned int size)
Reallocates the container space.
FullIter full_iter(Iter it)
FullIter begin()
Returns FullFullIterer of the first element.
const Iter operator()(unsigned int idx) const
Gets iterator of the element specified by index.
VectorId(unsigned int size=0)
Construct with reserve the space. Includes default constructor.
std::vector< int > id_storage
Space to save id numbers.
T & operator[](unsigned int idx)
Gets reference to the element specified by index.
const T & operator[](unsigned int idx) const
Gets reference to the element specified by index.
T ElementType
We have to export template type for FullIteraror.
int get_id(const T *it) const
FullIteratorId(VectorId< T > &cont, const typename VectorId< T >::Iter it)
Constructor. Just call base class.
std::vector< T >::iterator iterator
Iterator that keeps also reference to its container. Safer and provides indexes.
FullIter end()
Returns FullFullIterer of the fictions past the end element.
FullIter add_item(int id)
bool is_valid()
Check validity of FullIterator.
FullIterator< Vector< T > > FullIter
Type of FullIterator that should be used to iterate through this container.
FullIterator(const Cont &cont_par, const typename Cont::iterator it)
Cont::ElementType * operator->() const
-> dereference operator
FullIter full_iter(Iter it)
FullIterator & operator+=(const int shift)
unsigned int index(Iter pointer) const
std::vector< T >::iterator iterator
std::vector< T >::const_iterator const_iterator
FullIterator & operator--()
Prefix. Advance to previous operator.
Global macros to enhance readability and debugging, general constants.
const T & operator[](unsigned int idx) const
Gets reference to the element specified by index.
FullIterator & operator++()
Prefix. Advance operator.
Small extension of Vector<T> container with support to Id numbers.
std::map< int, unsigned int > id_map
Maps id numbers to indexes into storage vector.
const T * find_id(const int id) const
FullIter operator()(unsigned int idx)
Gets iterator of the element specified by index.
const Cont & cont
We have here reference to the container of the iterator. So, an instance of this class can not change...
unsigned int size() const
Returns size of the container. This is independent of the allocated space.
bool operator!=(const FullIterator &it) const
void resize(const unsigned int size)
Returns size of the container. This is independent of the allocated space.
FullIteratorId(VectorId< T > &cont)
Constructor. Just call base class.
bool operator==(const FullIterator &it) const
Comparison of two FullIterator.
T ElementType
We have to export template type for FullIteraror.
FullIterator & operator=(const FullIterator &orig)
Assign operator. In debugging version check that containers of both FullIterator match.
T * Iter
Default iterator for this class.
FullIter find_id(const int id)