aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::ListConstIteratorSafe< Val > Class Template Reference

Safe const iterators for Lists. More...

#include <agrum/tools/core/list.h>

+ Inheritance diagram for gum::ListConstIteratorSafe< Val >:
+ Collaboration diagram for gum::ListConstIteratorSafe< Val >:

Public Member Functions

template<typename Alloc >
INLINE ListConstIteratorSafe (const List< Val, Alloc > &theList)
 
Constructors / Destructors
 ListConstIteratorSafe () noexcept
 Default constructor. More...
 
template<typename Alloc >
 ListConstIteratorSafe (const List< Val, Alloc > &theList)
 Constructor for a begin. More...
 
 ListConstIteratorSafe (const ListConstIteratorSafe< Val > &src)
 Copy constructor. More...
 
template<typename Alloc >
 ListConstIteratorSafe (const List< Val, Alloc > &theList, Size ind_elt)
 Constructor for an iterator pointing to the ind_eltth element of a List. More...
 
 ListConstIteratorSafe (ListConstIteratorSafe< Val > &&src)
 Move constructor. More...
 
 ~ListConstIteratorSafe ()
 Class Desctructor. More...
 
Accessors / Modifiers
void clear ()
 Makes the iterator point toward nothing. More...
 
void setToEnd ()
 Positions the iterator to the end of the list. More...
 
bool isEnd () const
 Returns a bool indicating whether the iterator points to the end of the list. More...
 
Operators
ListConstIteratorSafe< Val > & operator= (const ListConstIteratorSafe< Val > &src)
 Copy operator. More...
 
ListConstIteratorSafe< Val > & operator= (ListConstIteratorSafe< Val > &&src)
 Move operator. More...
 
ListConstIteratorSafe< Val > & operator++ () noexcept
 Makes the iterator point to the next element in the List. More...
 
ListConstIteratorSafe< Val > & operator+= (difference_type i) noexcept
 Makes the iterator point to i elements further in the List. More...
 
ListConstIteratorSafe< Val > & operator-- () noexcept
 Makes the iterator point to the preceding element in the List. More...
 
ListConstIteratorSafe< Val > & operator-= (difference_type i) noexcept
 Makes the iterator point to i elements befor in the List. More...
 
ListConstIteratorSafe< Val > operator+ (difference_type i) noexcept
 Returns a new iterator pointing to i further elements in the gum::List. More...
 
ListConstIteratorSafe< Val > operator- (difference_type i) noexcept
 Returns a new iterator pointing to i preceding elements in the gum::List. More...
 
bool operator!= (const ListConstIteratorSafe< Val > &src) const
 Checks whether two iterators point toward different elements. More...
 
bool operator== (const ListConstIteratorSafe< Val > &src) const
 Checks whether two iterators point toward the same elements. More...
 
const Val & operator* () const
 Gives access to the content of the iterator. More...
 
const Val * operator-> () const
 Dereferences the value pointed to by the iterator. More...
 

Public Types

using iterator_category = std::bidirectional_iterator_tag
 Types for STL compliance. More...
 
using value_type = Val
 Types for STL compliance. More...
 
using reference = Val &
 Types for STL compliance. More...
 
using const_reference = const Val &
 Types for STL compliance. More...
 
using pointer = Val *
 Types for STL compliance. More...
 
using const_pointer = const Val *
 Types for STL compliance. More...
 
using difference_type = std::ptrdiff_t
 Types for STL compliance. More...
 

Friends

template<typename T , typename A >
class List
 class List must be a friend because it uses the getBucket method to speed up some processes. More...
 
class ListConstIterator< Val >
 class List must be a friend because it uses the getBucket method to speed up some processes. More...
 

Detailed Description

template<typename Val>
class gum::ListConstIteratorSafe< Val >

Safe const iterators for Lists.

Class ListConstIteratorSafe implements safe const iterators for List. However, developers may consider using List<x>::const_iterator_safe instead of ListConstIteratorSafe<x>.

These const iterators ensure that whenever they point to an element that is being deleted from memory, their accessing this element will never produce a segmentation fault but rather throw an exception. Similarly, incrementing or decrementing an iterator pointing to a deleted element is guaranteed to make the iterator point on the next (or preceding) element that has not been deleted.

Usage example:
// create a list of strings
List<string> list;
list.pushBack ("toto"); list.pushBack ("titi");
// parse all the elements of a list
for ( List<string>::const_iterator_safe iter = list.cbeginSafe ();
iter != list.cendSafe (); ++iter )
cerr << *iter << endl;
for ( List<string>::const_iterator_safe iter = list.cbeginSafe ();
iter != list.cendSafe (); iter += 2 ) // step = 2
cerr << *iter << endl;
for ( List<string>::const_iterator_safe iter = list.cbeginSafe ();
iter != list.cendSafe (); iter = iter + 2 ) // step = 2
cerr << *iter << endl;
for ( List<string>::const_iterator_safe iter = list.crbeginSafe ();
iter != list.crendSafe (); --iter )
cerr << *iter << endl;
// use member size() of the strings
for ( List<string>::const_iterator_safe iter = list.cbeginSafe ();
iter != list.cendSafe (); ++iter )
cerr << iter->size() << endl;
Template Parameters
ValThe gum::List values type.

Definition at line 2018 of file list.h.

Member Typedef Documentation

◆ const_pointer

template<typename Val >
using gum::ListConstIteratorSafe< Val >::const_pointer = const Val*

Types for STL compliance.

Definition at line 2027 of file list.h.

◆ const_reference

template<typename Val >
using gum::ListConstIteratorSafe< Val >::const_reference = const Val&

Types for STL compliance.

Definition at line 2025 of file list.h.

◆ difference_type

template<typename Val >
using gum::ListConstIteratorSafe< Val >::difference_type = std::ptrdiff_t

Types for STL compliance.

Definition at line 2028 of file list.h.

◆ iterator_category

template<typename Val >
using gum::ListConstIteratorSafe< Val >::iterator_category = std::bidirectional_iterator_tag

Types for STL compliance.

Definition at line 2022 of file list.h.

◆ pointer

template<typename Val >
using gum::ListConstIteratorSafe< Val >::pointer = Val*

Types for STL compliance.

Definition at line 2026 of file list.h.

◆ reference

template<typename Val >
using gum::ListConstIteratorSafe< Val >::reference = Val&

Types for STL compliance.

Definition at line 2024 of file list.h.

◆ value_type

template<typename Val >
using gum::ListConstIteratorSafe< Val >::value_type = Val

Types for STL compliance.

Definition at line 2023 of file list.h.

Constructor & Destructor Documentation

◆ ListConstIteratorSafe() [1/6]

template<typename Val >
INLINE gum::ListConstIteratorSafe< Val >::ListConstIteratorSafe ( )
noexcept

Default constructor.

Returns an iterator pointing toward nothing.

Definition at line 472 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

472  {
473  // for debugging purposes
474  GUM_CONSTRUCTOR(ListConstIteratorSafe);
475  }
ListConstIteratorSafe() noexcept
Default constructor.
Definition: list_tpl.h:472
+ Here is the call graph for this function:

◆ ListConstIteratorSafe() [2/6]

template<typename Val >
template<typename Alloc >
gum::ListConstIteratorSafe< Val >::ListConstIteratorSafe ( const List< Val, Alloc > &  theList)

Constructor for a begin.

Template Parameters
AllocThe gum::List allocator.

◆ ListConstIteratorSafe() [3/6]

template<typename Val >
INLINE gum::ListConstIteratorSafe< Val >::ListConstIteratorSafe ( const ListConstIteratorSafe< Val > &  src)

Copy constructor.

Parameters
srcThe gum::ListConstIteratorSafe to copy.

Definition at line 493 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

493  :
494  _list_{src._list_},
495  _bucket_{src._bucket_}, _next_current_bucket_{src._next_current_bucket_},
496  _prev_current_bucket_{src._prev_current_bucket_}, _null_pointing_{src._null_pointing_} {
497  // for debugging purposes
498  GUM_CONS_CPY(ListConstIteratorSafe);
499 
500  // add the iterator to the list of safe iterators
501  if (_list_ != nullptr) _list_->_safe_iterators_.push_back(this);
502  }
ListConstIteratorSafe() noexcept
Default constructor.
Definition: list_tpl.h:472
std::vector< const_iterator_safe *> _safe_iterators_
The list of "safe" iterators attached to the list.
Definition: list.h:1306
const List< Val, std::allocator< Val > > * _list_
The list the iterator is pointing to.
Definition: list.h:2240
ListBucket< Val > * _prev_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a –...
Definition: list.h:2251
ListBucket< Val > * _next_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a ++...
Definition: list.h:2247
bool _null_pointing_
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2254
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2243
+ Here is the call graph for this function:

◆ ListConstIteratorSafe() [4/6]

template<typename Val >
template<typename Alloc >
gum::ListConstIteratorSafe< Val >::ListConstIteratorSafe ( const List< Val, Alloc > &  theList,
Size  ind_elt 
)

Constructor for an iterator pointing to the ind_eltth element of a List.

Parameters
theListThe list to iterate over.
ind_eltThe iterator starting position.
Exceptions
UndefinedIteratorValueRaised if the element does not exist in the list.

Definition at line 508 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

509  :
510  _list_{reinterpret_cast< const List< Val, std::allocator< Val > >* >(&theList)} {
511  // for debugging purposes
512  GUM_CONSTRUCTOR(ListConstIteratorSafe);
513 
514  // check if the index ind_elt passed as parameter is valid
515  if (ind_elt >= _list_->_nb_elements_) {
516  GUM_ERROR(UndefinedIteratorValue, "Not enough elements in the list")
517  }
518 
519  // check if it is faster to find the indexth element src the start or
520  // src the end of the list
521  if (ind_elt < (_list_->_nb_elements_ >> 1)) {
522  // find the element we shall point to src the start of the list
523  for (_bucket_ = _list_->_deb_list_; ind_elt; --ind_elt, _bucket_ = _bucket_->_next_) {}
524  } else {
525  // find the element we shall point to src the end of the list
526  for (_bucket_ = _list_->_end_list_, ind_elt = _list_->_nb_elements_ - ind_elt - 1; ind_elt;
527  --ind_elt, _bucket_ = _bucket_->_prev_) {}
528  }
529 
530  // add the iterator to the list of safe iterators
531  theList._safe_iterators_.push_back(this);
532  }
ListConstIteratorSafe() noexcept
Default constructor.
Definition: list_tpl.h:472
ListBucket< Val > * _end_list_
A pointer on the last element of the chained list.
Definition: list.h:1300
Size _nb_elements_
The number of elements in the list.
Definition: list.h:1303
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition: list.h:1297
const List< Val, std::allocator< Val > > * _list_
The list the iterator is pointing to.
Definition: list.h:2240
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2243
+ Here is the call graph for this function:

◆ ListConstIteratorSafe() [5/6]

template<typename Val >
INLINE gum::ListConstIteratorSafe< Val >::ListConstIteratorSafe ( ListConstIteratorSafe< Val > &&  src)

Move constructor.

Parameters
srcThe gum::ListConstIterator to move.

Definition at line 536 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

536  :
537  _list_{src._list_}, _bucket_{src._bucket_}, _next_current_bucket_{src._next_current_bucket_},
538  _prev_current_bucket_{src._prev_current_bucket_}, _null_pointing_{src._null_pointing_} {
539  // for debugging purposes
540  GUM_CONS_MOV(ListConstIteratorSafe);
541 
542  if (_list_ != nullptr) {
543  // substitute src by this in the list of safe iterators
544  std::vector< ListConstIteratorSafe< Val >* >& vect = _list_->_safe_iterators_;
545 
546  for (auto ptr = vect.rbegin(); ptr != vect.rend(); --ptr) {
547  if (*ptr == &src) {
548  *ptr = this;
549  break;
550  }
551  }
552 
553  src._list_ = nullptr;
554  src._bucket_ = nullptr;
555  src._null_pointing_ = false;
556  }
557  }
ListConstIteratorSafe() noexcept
Default constructor.
Definition: list_tpl.h:472
std::vector< const_iterator_safe *> _safe_iterators_
The list of "safe" iterators attached to the list.
Definition: list.h:1306
const List< Val, std::allocator< Val > > * _list_
The list the iterator is pointing to.
Definition: list.h:2240
ListBucket< Val > * _prev_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a –...
Definition: list.h:2251
ListBucket< Val > * _next_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a ++...
Definition: list.h:2247
bool _null_pointing_
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2254
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2243
+ Here is the call graph for this function:

◆ ~ListConstIteratorSafe()

template<typename Val >
INLINE gum::ListConstIteratorSafe< Val >::~ListConstIteratorSafe ( )

Class Desctructor.

Definition at line 660 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

660  {
661  // for debugging purposes
662  GUM_DESTRUCTOR(ListConstIteratorSafe);
663 
664  // remove the iterator src the table's iterator list
666  }
ListConstIteratorSafe() noexcept
Default constructor.
Definition: list_tpl.h:472
void _removeFromSafeList_() const
Remove the iterator for its list&#39; safe iterators list.
Definition: list_tpl.h:561
const List< Val, std::allocator< Val > > * _list_
The list the iterator is pointing to.
Definition: list.h:2240
+ Here is the call graph for this function:

◆ ListConstIteratorSafe() [6/6]

template<typename Val >
template<typename Alloc >
INLINE gum::ListConstIteratorSafe< Val >::ListConstIteratorSafe ( const List< Val, Alloc > &  theList)

Definition at line 480 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

480  :
481  _list_{reinterpret_cast< const List< Val, std::allocator< Val > >* >(&theList)},
482  _bucket_{theList._deb_list_} {
483  // for debugging purposes
484  GUM_CONSTRUCTOR(ListConstIteratorSafe);
485 
486  // add the iterator to the list of safe iterators
487  theList._safe_iterators_.push_back(this);
488  }
ListConstIteratorSafe() noexcept
Default constructor.
Definition: list_tpl.h:472
const List< Val, std::allocator< Val > > * _list_
The list the iterator is pointing to.
Definition: list.h:2240
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2243
+ Here is the call graph for this function:

Member Function Documentation

◆ _getBucket_()

template<typename Val >
INLINE ListBucket< Val > * gum::ListConstIteratorSafe< Val >::_getBucket_ ( ) const
privatenoexcept

Returns the bucket the iterator is pointing to.

Definition at line 670 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

670  {
671  return _bucket_;
672  }
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2243
+ Here is the call graph for this function:

◆ _opMinus_()

template<typename Val >
INLINE ListConstIteratorSafe< Val > & gum::ListConstIteratorSafe< Val >::_opMinus_ ( Size  i)
privatenoexcept

Makes the iterator point to i elements before in the List.

Definition at line 739 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

739  {
740  // check if we are pointing to something that has been deleted
741  if (_null_pointing_) {
742  _null_pointing_ = false;
743 
744  // if we are pointing to an element of the chained list that has been
745  // deleted
746  // but that has a preceding element, just point on the latter
747  if (_prev_current_bucket_ != nullptr) {
749  } else {
750  // here we were pointing on an extremity of the list (either end or
751  // rend)
752  // if next_current_bucket is not null, then we are at end and doing
753  // a -- shall now point to the beginning of the list
754  if (_next_current_bucket_ != nullptr) {
756  } else {
757  // here, we are at the rend of the chained list, hence we shall remain
758  // at rend
759  _bucket_ = nullptr;
760  return *this;
761  }
762  }
763  } else {
764  // if we are pointing to an element of the chained list, just
765  // point on the preceding bucket in this list
766  if (_bucket_ != nullptr) { _bucket_ = _bucket_->_prev_; }
767  }
768 
769  for (--i; i && (_bucket_ != nullptr); --i, _bucket_ = _bucket_->_prev_) {}
770 
771  return *this;
772  }
ListBucket< Val > * _prev_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a –...
Definition: list.h:2251
ListBucket< Val > * _next_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a ++...
Definition: list.h:2247
bool _null_pointing_
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2254
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2243
+ Here is the call graph for this function:

◆ _opPlus_()

template<typename Val >
INLINE ListConstIteratorSafe< Val > & gum::ListConstIteratorSafe< Val >::_opPlus_ ( Size  i)
privatenoexcept

Makes the iterator point to the next element in the List.

Definition at line 776 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

776  {
777  // check if we are pointing to something that has been deleted
778  if (_null_pointing_) {
779  _null_pointing_ = false;
780 
781  // if we are pointing to an element of the chained list that has been
782  // deleted
783  // but that has a next element, just point on the latter
784  if (_next_current_bucket_ != nullptr) {
786  } else {
787  // here we were pointing on an extremity of the list (either end or
788  // rend)
789  // if prev_current_bucket is not null, then we are at rend and doing
790  // a ++ shall now point to the beginning of the list
791  if (_prev_current_bucket_ != nullptr) {
793  } else {
794  // here, we are at the end of the chained list, hence we shall
795  // remain at end
796  _bucket_ = nullptr;
797  return *this;
798  }
799  }
800  } else {
801  // if we are pointing to an element of the chained list, just
802  // point on the next bucket in this list
803  if (_bucket_ != nullptr) { _bucket_ = _bucket_->_next_; }
804  }
805 
806  for (--i; i && (_bucket_ != nullptr); --i, _bucket_ = _bucket_->_next_) {}
807 
808  return *this;
809  }
ListBucket< Val > * _prev_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a –...
Definition: list.h:2251
ListBucket< Val > * _next_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a ++...
Definition: list.h:2247
bool _null_pointing_
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2254
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2243
+ Here is the call graph for this function:

◆ _removeFromSafeList_()

template<typename Val >
INLINE void gum::ListConstIteratorSafe< Val >::_removeFromSafeList_ ( ) const
private

Remove the iterator for its list' safe iterators list.

Definition at line 561 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

561  {
562  // find where the iterator is
563  std::vector< ListConstIteratorSafe< Val >* >& vect = _list_->_safe_iterators_;
564 
565  for (auto i = vect.size() - 1; i >= 0; --i) {
566  if (vect[i] == this) {
567  vect.erase(vect.begin() + i);
568  break;
569  }
570  }
571  }
std::vector< const_iterator_safe *> _safe_iterators_
The list of "safe" iterators attached to the list.
Definition: list.h:1306
const List< Val, std::allocator< Val > > * _list_
The list the iterator is pointing to.
Definition: list.h:2240
+ Here is the call graph for this function:

◆ clear()

template<typename Val >
INLINE void gum::ListConstIteratorSafe< Val >::clear ( )

Makes the iterator point toward nothing.

A method for detaching the iterator from the List it is attached to. It is mainly used by the List when the latter is deleted while the iterator is still alive. After being detached, the iterator does not point to any element, i.e., trying to access its content will raise an exception.

Definition at line 676 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

676  {
677  // remove the iterator src the list's iterator list
679 
680  // set its list as well as the element it points to to nullptr
681  _list_ = nullptr;
682  _bucket_ = nullptr;
683  _null_pointing_ = false;
684  }
void _removeFromSafeList_() const
Remove the iterator for its list&#39; safe iterators list.
Definition: list_tpl.h:561
const List< Val, std::allocator< Val > > * _list_
The list the iterator is pointing to.
Definition: list.h:2240
bool _null_pointing_
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2254
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2243
+ Here is the call graph for this function:

◆ isEnd()

template<typename Val >
INLINE bool gum::ListConstIteratorSafe< Val >::isEnd ( ) const

Returns a bool indicating whether the iterator points to the end of the list.

Returns
Returns a bool indicating whether the iterator points to the end of the list.

Definition at line 695 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

695  {
696  return _null_pointing_
697  ? (_next_current_bucket_ == nullptr) && (_prev_current_bucket_ == nullptr)
698  : (_bucket_ == nullptr);
699  }
ListBucket< Val > * _prev_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a –...
Definition: list.h:2251
ListBucket< Val > * _next_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a ++...
Definition: list.h:2247
bool _null_pointing_
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2254
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2243
+ Here is the call graph for this function:

◆ operator!=()

template<typename Val >
INLINE bool gum::ListConstIteratorSafe< Val >::operator!= ( const ListConstIteratorSafe< Val > &  src) const

Checks whether two iterators point toward different elements.

Warning
the end and rend iterators are always equal, whatever the list they belong to, i.e., list1.end() == list2.rend().
Parameters
srcThe gum::ListConstIteratorSafe to test for inequality.
Returns
Returns true if src and this are equal.

Definition at line 888 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

888  {
889  return _null_pointing_ ? (_next_current_bucket_ != src._next_current_bucket_)
890  || (_prev_current_bucket_ != src._prev_current_bucket_)
891  : (_bucket_ != src._bucket_);
892  }
ListBucket< Val > * _prev_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a –...
Definition: list.h:2251
ListBucket< Val > * _next_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a ++...
Definition: list.h:2247
bool _null_pointing_
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2254
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2243
+ Here is the call graph for this function:

◆ operator*()

template<typename Val >
INLINE const Val & gum::ListConstIteratorSafe< Val >::operator* ( ) const

Gives access to the content of the iterator.

Exceptions
UndefinedIteratorValueRaised if the iterator points to nothing.
Returns
Returns the content of the iterator.

Definition at line 915 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

915  {
916  if (_bucket_ != nullptr)
917  return _bucket_->_val_;
918  else {
919  GUM_ERROR(UndefinedIteratorValue, "Accessing a NULL object")
920  }
921  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2243
+ Here is the call graph for this function:

◆ operator+()

template<typename Val >
INLINE ListConstIteratorSafe< Val > gum::ListConstIteratorSafe< Val >::operator+ ( difference_type  i)
noexcept

Returns a new iterator pointing to i further elements in the gum::List.

Parameters
iThe number of steps to move the iterator.
Returns
Returns a new gum::ListConstIteratoSafe.

Definition at line 873 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

874  {
875  return ListConstIteratorSafe< Val >(*this) += i;
876  }
+ Here is the call graph for this function:

◆ operator++()

template<typename Val >
INLINE ListConstIteratorSafe< Val > & gum::ListConstIteratorSafe< Val >::operator++ ( )
noexcept

Makes the iterator point to the next element in the List.

for (iter = list.begin(); iter != list.end(); ++iter) { }

The above loop is guaranteed to parse the whole List as long as no element is added to or deleted from the List while being in the loop. Runs in constant time.

Returns
Returns this gum::ListConstIteratorSafe.

Definition at line 703 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

703  {
704  // check if we are pointing to something that has been deleted
705  if (_null_pointing_) {
706  _null_pointing_ = false;
707 
708  // if we are pointing to an element of the chained list that has been
709  // deleted
710  // but that has a next element, just point on the latter
711  if (_next_current_bucket_ != nullptr) {
713  return *this;
714  }
715 
716  // here we were pointing on an extremity of the list (either end or rend)
717  // if prev_current_bucket is not null, then we are at rend and doing
718  // a ++ shall now point to the beginning of the list
719  if (_prev_current_bucket_ != nullptr) {
721  return *this;
722  }
723 
724  // here, we are at the end of the chained list, hence we shall remain at
725  // end
726  _bucket_ = nullptr;
727  return *this;
728  } else {
729  // if we are pointing to an element of the chained list, just
730  // point on the next bucket in this list
731  if (_bucket_ != nullptr) { _bucket_ = _bucket_->_next_; }
732 
733  return *this;
734  }
735  }
ListBucket< Val > * _prev_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a –...
Definition: list.h:2251
ListBucket< Val > * _next_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a ++...
Definition: list.h:2247
bool _null_pointing_
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2254
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2243
+ Here is the call graph for this function:

◆ operator+=()

template<typename Val >
INLINE ListConstIteratorSafe< Val > & gum::ListConstIteratorSafe< Val >::operator+= ( difference_type  i)
noexcept

Makes the iterator point to i elements further in the List.

Parameters
iThe number of steps to move the iterator.
Returns
Returns this gum::ListConstIterator.

Definition at line 813 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

814  {
815  if (!i) return *this;
816 
817  if (i < 0)
818  return _opMinus_(-i);
819  else
820  return _opPlus_(i);
821  }
ListConstIteratorSafe< Val > & _opMinus_(Size i) noexcept
Makes the iterator point to i elements before in the List.
Definition: list_tpl.h:739
ListConstIteratorSafe< Val > & _opPlus_(Size i) noexcept
Makes the iterator point to the next element in the List.
Definition: list_tpl.h:776
+ Here is the call graph for this function:

◆ operator-()

template<typename Val >
INLINE ListConstIteratorSafe< Val > gum::ListConstIteratorSafe< Val >::operator- ( difference_type  i)
noexcept

Returns a new iterator pointing to i preceding elements in the gum::List.

Parameters
iThe number of steps to move the iterator.
Returns
Returns a new gum::ListConstIteratorSafe.

Definition at line 880 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

881  {
882  return ListConstIteratorSafe< Val >(*this) -= i;
883  }
+ Here is the call graph for this function:

◆ operator--()

template<typename Val >
INLINE ListConstIteratorSafe< Val > & gum::ListConstIteratorSafe< Val >::operator-- ( )
noexcept

Makes the iterator point to the preceding element in the List.

for (iter = list.rbegin(); iter != list.rend(); --iter) { }

The above loop is guaranteed to parse the whole List as long as no element is added to or deleted from the List while being in the loop. Runs in constant time.

Returns
Returns this gum::ListConstIteratorSafe.

Definition at line 825 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

825  {
826  // check if we are pointing to something that has been deleted
827  if (_null_pointing_) {
828  _null_pointing_ = false;
829 
830  // if we are pointing to an element of the chained list that has been
831  // deleted
832  // but that has a preceding element, just point on the latter
833  if (_prev_current_bucket_ != nullptr) {
835  return *this;
836  }
837 
838  // here we were pointing on an extremity of the list (either end or rend)
839  // if next_current_bucket is not null, then we are at end and doing
840  // a -- shall now point to the beginning of the list
841  if (_next_current_bucket_ != nullptr) {
843  return *this;
844  }
845 
846  // here, we are at the rend of the chained list, hence we shall remain
847  // at rend
848  _bucket_ = nullptr;
849  return *this;
850  } else {
851  // if we are pointing to an element of the chained list, just
852  // point on the preceding bucket in this list
853  if (_bucket_ != nullptr) { _bucket_ = _bucket_->_prev_; }
854 
855  return *this;
856  }
857  }
ListBucket< Val > * _prev_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a –...
Definition: list.h:2251
ListBucket< Val > * _next_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a ++...
Definition: list.h:2247
bool _null_pointing_
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2254
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2243
+ Here is the call graph for this function:

◆ operator-=()

template<typename Val >
INLINE ListConstIteratorSafe< Val > & gum::ListConstIteratorSafe< Val >::operator-= ( difference_type  i)
noexcept

Makes the iterator point to i elements befor in the List.

Parameters
iThe number of steps to move the iterator.
Returns
Returns this gum::ListConstIteratorSafe.

Definition at line 861 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

862  {
863  if (!i) return *this;
864 
865  if (i < 0)
866  return _opPlus_(-i);
867  else
868  return _opMinus_(i);
869  }
ListConstIteratorSafe< Val > & _opMinus_(Size i) noexcept
Makes the iterator point to i elements before in the List.
Definition: list_tpl.h:739
ListConstIteratorSafe< Val > & _opPlus_(Size i) noexcept
Makes the iterator point to the next element in the List.
Definition: list_tpl.h:776
+ Here is the call graph for this function:

◆ operator->()

template<typename Val >
INLINE const Val * gum::ListConstIteratorSafe< Val >::operator-> ( ) const

Dereferences the value pointed to by the iterator.

Exceptions
UndefinedIteratorValueRaised if the iterator points to nothing.
Returns
Returns the value pointed to by the iterator.

Definition at line 905 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

905  {
906  if (_bucket_ != nullptr)
907  return &(_bucket_->_val_);
908  else {
909  GUM_ERROR(UndefinedIteratorValue, "Accessing a NULL object")
910  }
911  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2243
+ Here is the call graph for this function:

◆ operator=() [1/2]

template<typename Val >
ListConstIteratorSafe< Val > & gum::ListConstIteratorSafe< Val >::operator= ( const ListConstIteratorSafe< Val > &  src)

Copy operator.

The current iterator now points to the same element as iterator from.

Parameters
srcThe gum::ListConstIteratorSafe to copy.
Returns
Returns this gum::ListConstIteratorSafe.

Definition at line 576 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

576  {
577  // avoid self assignment
578  if (this != &src) {
579  // for debugging purposes
580  GUM_OP_CPY(ListConstIteratorSafe);
581 
582  // check if src and this belong to the same list. If this is not
583  // the case, we shall remove this from its iterator's list and
584  // put it into src's list one.
585  if (_list_ && (src._list_ != _list_)) {
587  _list_ = nullptr;
588  }
589 
590  // if necessary, put this into the same list of safe iterators as src
591  if (src._list_ && (src._list_ != _list_)) {
592  try {
593  src._list_->_safe_iterators_.push_back(this);
594  } catch (...) {
595  _list_ = nullptr;
596  _bucket_ = nullptr;
597  _null_pointing_ = false;
598  throw;
599  }
600  }
601 
602  _list_ = src._list_;
603  _bucket_ = src._bucket_;
604  _prev_current_bucket_ = src._prev_current_bucket_;
605  _next_current_bucket_ = src._next_current_bucket_;
606  _null_pointing_ = src._null_pointing_;
607  }
608 
609  return *this;
610  }
ListConstIteratorSafe() noexcept
Default constructor.
Definition: list_tpl.h:472
void _removeFromSafeList_() const
Remove the iterator for its list&#39; safe iterators list.
Definition: list_tpl.h:561
std::vector< const_iterator_safe *> _safe_iterators_
The list of "safe" iterators attached to the list.
Definition: list.h:1306
const List< Val, std::allocator< Val > > * _list_
The list the iterator is pointing to.
Definition: list.h:2240
ListBucket< Val > * _prev_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a –...
Definition: list.h:2251
ListBucket< Val > * _next_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a ++...
Definition: list.h:2247
bool _null_pointing_
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2254
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2243
+ Here is the call graph for this function:

◆ operator=() [2/2]

template<typename Val >
ListConstIteratorSafe< Val > & gum::ListConstIteratorSafe< Val >::operator= ( ListConstIteratorSafe< Val > &&  src)

Move operator.

Parameters
srcThe gum::ListConstIteratorSafe to move.
Returns
Returns this gum::ListConstIteratorSafe.

Definition at line 615 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

615  {
616  // avoid self assignment
617  if (this != &src) {
618  // for debugging purposes
619  GUM_OP_MOV(ListConstIteratorSafe);
620 
621  // if the two iterators do not point to the same list, remove
622  // the current iterator from its safe iterators list
623  if ((_list_ != nullptr) && (src._list_ != _list_)) {
625  _list_ = nullptr;
626  }
627 
628  // now if src points to a list, put this at its location
629  if ((src._list_ != nullptr)) {
630  std::vector< ListConstIteratorSafe< Val >* >& vect = src._list_->_safe_iterators_;
631  Idx index_src = Size(vect.size()) - 1;
632 
633  for (;; --index_src) {
634  if (vect[index_src] == &src) { break; }
635  }
636 
637  if (_list_ == nullptr) {
638  vect[index_src] = this;
639  } else {
640  vect.erase(vect.begin() + index_src);
641  }
642  }
643 
644  _list_ = src._list_;
645  _bucket_ = src._bucket_;
646  _prev_current_bucket_ = src._prev_current_bucket_;
647  _next_current_bucket_ = src._next_current_bucket_;
648  _null_pointing_ = src._null_pointing_;
649 
650  src._list_ = nullptr;
651  src._bucket_ = nullptr;
652  src._null_pointing_ = false;
653  }
654 
655  return *this;
656  }
ListConstIteratorSafe() noexcept
Default constructor.
Definition: list_tpl.h:472
void _removeFromSafeList_() const
Remove the iterator for its list&#39; safe iterators list.
Definition: list_tpl.h:561
std::vector< const_iterator_safe *> _safe_iterators_
The list of "safe" iterators attached to the list.
Definition: list.h:1306
const List< Val, std::allocator< Val > > * _list_
The list the iterator is pointing to.
Definition: list.h:2240
ListBucket< Val > * _prev_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a –...
Definition: list.h:2251
ListBucket< Val > * _next_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a ++...
Definition: list.h:2247
bool _null_pointing_
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2254
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2243
+ Here is the call graph for this function:

◆ operator==()

template<typename Val >
INLINE bool gum::ListConstIteratorSafe< Val >::operator== ( const ListConstIteratorSafe< Val > &  src) const

Checks whether two iterators point toward the same elements.

Warning
the end and rend iterators are always equal, whatever the list they belong to, i.e., list1.end() == list2.rend().
Parameters
srcThe gum::ListConstIteratorSafe to test for equality.
Returns
Returns true if src and this are equal.

Definition at line 897 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

897  {
898  return _null_pointing_ ? (_next_current_bucket_ == src._next_current_bucket_)
899  && (_prev_current_bucket_ == src._prev_current_bucket_)
900  : (_bucket_ == src._bucket_);
901  }
ListBucket< Val > * _prev_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a –...
Definition: list.h:2251
ListBucket< Val > * _next_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a ++...
Definition: list.h:2247
bool _null_pointing_
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2254
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2243
+ Here is the call graph for this function:

◆ setToEnd()

template<typename Val >
INLINE void gum::ListConstIteratorSafe< Val >::setToEnd ( )

Positions the iterator to the end of the list.

Definition at line 688 of file list_tpl.h.

References gum::Set< Key, Alloc >::emplace().

688  {
689  clear();
690  }
void clear()
Makes the iterator point toward nothing.
Definition: list_tpl.h:676
+ Here is the call graph for this function:

Friends And Related Function Documentation

◆ List

template<typename Val >
template<typename T , typename A >
friend class List
friend

class List must be a friend because it uses the getBucket method to speed up some processes.

Definition at line 2235 of file list.h.

◆ ListConstIterator< Val >

template<typename Val >
friend class ListConstIterator< Val >
friend

class List must be a friend because it uses the getBucket method to speed up some processes.

Definition at line 2236 of file list.h.

Member Data Documentation

◆ _bucket_

template<typename Val >
ListBucket< Val >* gum::ListConstIteratorSafe< Val >::_bucket_ {nullptr}
private

The bucket in the chained list pointed to by the iterator.

Definition at line 2243 of file list.h.

◆ _list_

template<typename Val >
const List< Val, std::allocator< Val > >* gum::ListConstIteratorSafe< Val >::_list_ {nullptr}
private

The list the iterator is pointing to.

Definition at line 2240 of file list.h.

◆ _next_current_bucket_

template<typename Val >
ListBucket< Val >* gum::ListConstIteratorSafe< Val >::_next_current_bucket_ {nullptr}
private

The bucket we should start from when we are pointing on a deleted bucket and we decide to do a ++.

Definition at line 2247 of file list.h.

◆ _null_pointing_

template<typename Val >
bool gum::ListConstIteratorSafe< Val >::_null_pointing_ {false}
private

Indicates whether the bucket the iterator points to has been deleted.

Definition at line 2254 of file list.h.

◆ _prev_current_bucket_

template<typename Val >
ListBucket< Val >* gum::ListConstIteratorSafe< Val >::_prev_current_bucket_ {nullptr}
private

The bucket we should start from when we are pointing on a deleted bucket and we decide to do a –.

Definition at line 2251 of file list.h.


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