31 #ifndef SYS_VECTOR_HH_
32 #define SYS_VECTOR_HH_
64 iter(cont_par.storage.end()) {}
68 FullIterator(
const Cont &cont_par,
const typename Cont::iterator it)
76 if (it == NULL)
iter = cont_par.storage.end();
77 else iter = cont_par.storage.begin() +
cont.index(it);
82 {
return this->
iter != this->
cont.storage.end(); }
89 {
if (this->
iter != this->
cont.storage.end())
return this->
iter -
cont.storage.begin();
101 ASSERT( (&(this->
cont) == &(orig.
cont)),
"Can not change container of FulIter.\n");
107 inline operator typename Cont::Iter ()
const
108 {
return &(*(this->
iter)); }
112 {
return *(this->
iter); }
116 {
return &(*(this->
iter)); }
119 { this->
iter+=shift;
return (*
this); }
122 { this->
iter-=shift;
return (*
this); }
134 ASSERT(
iter !=
cont.storage.end(),
"Can not advance iterator at the end.\n");
135 ++(this->
iter);
return *
this;
144 ASSERT(
iter !=
cont.storage.begin(),
"Can not advance iterator to previous of begin().\n");
145 this->
iter--;
return *
this;
156 typename Cont :: iterator
iter;
180 {
return this->
cont.id_storage[ this->
index() ]; }
252 "Wrong pointer %d to obtain its index (%d, %d).\n",pointer, &(
storage.front()), &(
storage.back()));
253 return ( pointer - &(
storage.front()) );
265 inline unsigned int size()
const
276 ASSERT( idx < this->
size(),
"Index %d outside of Vector of size %d\n",idx, this->
size());
283 ASSERT( idx < this->
size(),
"Index %d outside of Vector of size %d\n",idx, this->
size());
291 ASSERT( idx < this->
size(),
"Index %d outside of Vector of size %d\n",idx, this->
size());
299 ASSERT( size >= this->
size(),
"Vector can not be reallocated into space %d smaller then its size %d\n",size,this->
size());
371 ASSERT(
id_map.find(
id) ==
id_map.end(),
"Can not add item with id number %d since it already exists.", id);
383 inline unsigned int index(
const T * pointer)
const
386 "Wrong pointer %p to obtain its index (%p, %p).\n",pointer, &(
storage.front()), &(
storage.back()));
387 return ( pointer - &(
storage.front()) );
401 inline unsigned int size()
const
407 ASSERT( idx < this->
size(),
"Index %d outside of Vector of size %d\n",idx, this->
size());
415 ASSERT( idx < this->
size(),
"Index %d outside of Vector of size %d\n",idx, this->
size());
423 ASSERT( idx < this->
size(),
"Index %d outside of Vector of size %d\n",idx, this->
size());
430 ASSERT( idx < this->
size(),
"Index %d outside of Vector of size %d\n",idx, this->
size());
447 if ( iter ==
id_map.end() ) {
459 if ( iter ==
id_map.end() ) {
460 return &(*(this->
storage.end()));
462 return &(*(this->
storage.begin() + iter->second));
481 ASSERT( size >= this->
size(),
"Vector can not be reallocated into space %d smaller then its size %d\n",size,this->
size());
FullIter begin()
Returns FullFullIterer of the first element.
VectorId(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.
std::vector< T >::const_iterator const_iterator
T ElementType
We have to export template type for FullIteraror.
FullIter operator()(unsigned int idx)
Gets iterator of the element specified by index.
const T * find_id(const int id) const
std::vector< T > storage
Underlying vector container.
int get_id(const T *it) const
Envelop over std::vector, use enhanced iterators.
int get_id(int idx) const
FullIterator & operator+=(const int shift)
bool operator!=(const FullIterator &it) const
Small extension of Vector<T> container with support to Id numbers.
T ElementType
We have to export template type for FullIteraror.
void resize(const unsigned int size)
Returns size of the container. This is independent of the allocated space.
FullIter end()
Returns FullFullIterer of the fictions past the end element.
unsigned int index(Iter pointer) const
Cont & container()
Get reference to the container of the FullIterator.
const Cont & cont
We have here reference to the container of the iterator. So, an instance of this class can not change...
void reserve(unsigned int size)
Reallocates the container space.
FullIter add_item(int id)
std::vector< T >::const_iterator const_iterator
FullIter find_id(const int id)
FullIterator & operator++()
Prefix. Advance operator.
virtual ~VectorId()
Since storage is direct member it is deallocated by its own destructor.
FullIteratorId(const VectorId< T > &cont, typename std::vector< T >::iterator it)
Constructor. Just call base class.
FullIter full_iter(Iter it)
int id()
Returns id of the iterator. See VectorId documentation.
T & operator[](unsigned int idx)
Gets reference to the element specified by index.
unsigned int size() const
Returns size of the container. This is independent of the allocated space.
T * Iter
Default iterator for this class.
void reserve(unsigned int size)
Reallocates the container space.
FullIteratorId(VectorId< T > &cont)
Constructor. Just call base class.
Global macros to enhance readability and debugging, general constants.
FullIteratorId< T > FullIter
Type of FullIterator that should be used to iterate through this container.
std::map< int, unsigned int > id_map
Maps id numbers to indexes into storage vector.
Iterator that keeps also reference to its container. Safer and provides indexes.
std::vector< T >::iterator iterator
bool is_valid()
Check validity of FullIterator.
FullIter operator()(unsigned int idx)
Gets iterator of the element specified by index.
Vector(unsigned int size=0)
Construct with reserve the space. Includes default constructor.
unsigned int index(const T *pointer) const
Cont::ElementType & operator*() const
bool operator==(const FullIterator &it) const
Comparison of two FullIterator.
std::vector< T > storage
Underlying vector container.
FullIterator< Vector< T > > FullIter
Type of FullIterator that should be used to iterate through this container.
FullIterator & operator--()
Prefix. Advance to previous operator.
FullIterator(const Cont &cont_par, const typename Cont::iterator it)
std::vector< int > id_storage
Space to save id numbers.
FullIterator(Cont &cont_par, const typename Cont::Iter it)
Constructor to make FullIterator from container and Iter i.e. T*.
FullIterator & operator=(const FullIterator &orig)
Assign operator. In debugging version check that containers of both FullIterator match.
T & operator[](unsigned int idx)
Gets reference to the element specified by index.
FullIter full_iter(Iter it)
FullIterator(Cont &cont_par)
Constructor to make uninitialized FullIterator for a container.
const Iter operator()(unsigned int idx) const
Gets iterator of the element specified by index.
const T & operator[](unsigned int idx) const
Gets reference to the element specified by index.
T * Iter
Default iterator for this class.
Cont::ElementType * operator->() const
-> dereference operator
FullIteratorId(VectorId< T > &cont, const typename VectorId< T >::Iter it)
Constructor. Just call base class.
virtual ~Vector()
Since storage is direct member it is deallocated by its own destructor.
FullIterator & operator-=(const int shift)
FullIter end()
Returns FullFullIterer of the fictions past the end element.
std::vector< T >::iterator iterator
const T & operator[](unsigned int idx) const
Gets reference to the element specified by index.