aGrUM  0.16.0
gum::ListConstIteratorSafe< Val > Class Template Reference

Safe const iterators for Lists. More...

#include <agrum/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 2030 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 2039 of file list.h.

◆ const_reference

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

Types for STL compliance.

Definition at line 2037 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 2040 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 2034 of file list.h.

◆ pointer

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

Types for STL compliance.

Definition at line 2038 of file list.h.

◆ reference

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

Types for STL compliance.

Definition at line 2036 of file list.h.

◆ value_type

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

Types for STL compliance.

Definition at line 2035 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 492 of file list_tpl.h.

492  {
493  // for debugging purposes
494  GUM_CONSTRUCTOR(ListConstIteratorSafe);
495  }
ListConstIteratorSafe() noexcept
Default constructor.
Definition: list_tpl.h:492

◆ 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 514 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::__bucket, gum::ListConstIteratorSafe< Val >::__list, gum::ListConstIteratorSafe< Val >::__next_current_bucket, gum::ListConstIteratorSafe< Val >::__null_pointing, gum::ListConstIteratorSafe< Val >::__prev_current_bucket, and gum::List< Val, Alloc >::__safe_iterators.

515  :
516  __list{src.__list},
517  __bucket{src.__bucket}, __next_current_bucket{src.__next_current_bucket},
518  __prev_current_bucket{src.__prev_current_bucket}, __null_pointing{
519  src.__null_pointing} {
520  // for debugging purposes
521  GUM_CONS_CPY(ListConstIteratorSafe);
522 
523  // add the iterator to the list of safe iterators
524  if (__list != nullptr) __list->__safe_iterators.push_back(this);
525  }
ListConstIteratorSafe() noexcept
Default constructor.
Definition: list_tpl.h:492
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:2260
bool __null_pointing
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2267
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2256
std::vector< const_iterator_safe *> __safe_iterators
The list of "safe" iterators attached to the list.
Definition: list.h:1311
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:2264
const List< Val, std::allocator< Val > > * __list
The list the iterator is pointing to.
Definition: list.h:2253

◆ 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 531 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::__bucket, gum::List< Val, Alloc >::__deb_list, gum::List< Val, Alloc >::__end_list, gum::ListConstIteratorSafe< Val >::__list, gum::List< Val, Alloc >::__nb_elements, and GUM_ERROR.

532  :
533  __list{
534  reinterpret_cast< const List< Val, std::allocator< Val > >* >(&theList)} {
535  // for debugging purposes
536  GUM_CONSTRUCTOR(ListConstIteratorSafe);
537 
538  // check if the index ind_elt passed as parameter is valid
539  if (ind_elt >= __list->__nb_elements) {
540  GUM_ERROR(UndefinedIteratorValue, "Not enough elements in the list");
541  }
542 
543  // check if it is faster to find the indexth element src the start or
544  // src the end of the list
545  if (ind_elt < (__list->__nb_elements >> 1)) {
546  // find the element we shall point to src the start of the list
547  for (__bucket = __list->__deb_list; ind_elt;
548  --ind_elt, __bucket = __bucket->__next) {}
549  } else {
550  // find the element we shall point to src the end of the list
551  for (__bucket = __list->__end_list,
552  ind_elt = __list->__nb_elements - ind_elt - 1;
553  ind_elt;
554  --ind_elt, __bucket = __bucket->__prev) {}
555  }
556 
557  // add the iterator to the list of safe iterators
558  theList.__safe_iterators.push_back(this);
559  }
ListConstIteratorSafe() noexcept
Default constructor.
Definition: list_tpl.h:492
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2256
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
ListBucket< Val > * __deb_list
A pointer on the first element of the chained list.
Definition: list.h:1302
const List< Val, std::allocator< Val > > * __list
The list the iterator is pointing to.
Definition: list.h:2253
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
ListBucket< Val > * __end_list
A pointer on the last element of the chained list.
Definition: list.h:1305

◆ 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 563 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::__bucket, gum::ListConstIteratorSafe< Val >::__list, gum::ListConstIteratorSafe< Val >::__next_current_bucket, gum::ListConstIteratorSafe< Val >::__null_pointing, gum::ListConstIteratorSafe< Val >::__prev_current_bucket, and gum::List< Val, Alloc >::__safe_iterators.

564  :
565  __list{src.__list},
566  __bucket{src.__bucket}, __next_current_bucket{src.__next_current_bucket},
567  __prev_current_bucket{src.__prev_current_bucket}, __null_pointing{
568  src.__null_pointing} {
569  // for debugging purposes
570  GUM_CONS_MOV(ListConstIteratorSafe);
571 
572  if (__list != nullptr) {
573  // substitute src by this in the list of safe iterators
574  std::vector< ListConstIteratorSafe< Val >* >& vect =
576 
577  for (auto ptr = vect.rbegin(); ptr != vect.rend(); --ptr) {
578  if (*ptr == &src) {
579  *ptr = this;
580  break;
581  }
582  }
583 
584  src.__list = nullptr;
585  src.__bucket = nullptr;
586  src.__null_pointing = false;
587  }
588  }
ListConstIteratorSafe() noexcept
Default constructor.
Definition: list_tpl.h:492
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:2260
bool __null_pointing
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2267
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2256
std::vector< const_iterator_safe *> __safe_iterators
The list of "safe" iterators attached to the list.
Definition: list.h:1311
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:2264
const List< Val, std::allocator< Val > > * __list
The list the iterator is pointing to.
Definition: list.h:2253

◆ ~ListConstIteratorSafe()

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

Class Desctructor.

Definition at line 692 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::__list, and gum::ListConstIteratorSafe< Val >::__removeFromSafeList().

692  {
693  // for debugging purposes
694  GUM_DESTRUCTOR(ListConstIteratorSafe);
695 
696  // remove the iterator src the table's iterator list
698  }
ListConstIteratorSafe() noexcept
Default constructor.
Definition: list_tpl.h:492
void __removeFromSafeList() const
Remove the iterator for its list&#39; safe iterators list.
Definition: list_tpl.h:592
const List< Val, std::allocator< Val > > * __list
The list the iterator is pointing to.
Definition: list.h:2253
+ 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 500 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::__bucket.

501  :
502  __list{
503  reinterpret_cast< const List< Val, std::allocator< Val > >* >(&theList)},
504  __bucket{theList.__deb_list} {
505  // for debugging purposes
506  GUM_CONSTRUCTOR(ListConstIteratorSafe);
507 
508  // add the iterator to the list of safe iterators
509  theList.__safe_iterators.push_back(this);
510  }
ListConstIteratorSafe() noexcept
Default constructor.
Definition: list_tpl.h:492
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2256
const List< Val, std::allocator< Val > > * __list
The list the iterator is pointing to.
Definition: list.h:2253

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 702 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::__bucket.

Referenced by gum::List< const gum::Potential< GUM_SCALAR > * >::__insert(), and gum::List< const gum::Potential< GUM_SCALAR > * >::erase().

703  {
704  return __bucket;
705  }
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2256
+ Here is the caller 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 774 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::__bucket, gum::ListConstIteratorSafe< Val >::__next_current_bucket, gum::ListConstIteratorSafe< Val >::__null_pointing, and gum::ListConstIteratorSafe< Val >::__prev_current_bucket.

Referenced by gum::ListConstIteratorSafe< Val >::operator+=(), and gum::ListConstIteratorSafe< Val >::operator-=().

774  {
775  // check if we are pointing to something that has been deleted
776  if (__null_pointing) {
777  __null_pointing = false;
778 
779  // if we are pointing to an element of the chained list that has been
780  // deleted
781  // but that has a preceding element, just point on the latter
782  if (__prev_current_bucket != nullptr) {
784  } else {
785  // here we were pointing on an extremity of the list (either end or
786  // rend)
787  // if next_current_bucket is not null, then we are at end and doing
788  // a -- shall now point to the beginning of the list
789  if (__next_current_bucket != nullptr) {
791  } else {
792  // here, we are at the rend of the chained list, hence we shall remain
793  // at rend
794  __bucket = nullptr;
795  return *this;
796  }
797  }
798  } else {
799  // if we are pointing to an element of the chained list, just
800  // point on the preceding bucket in this list
801  if (__bucket != nullptr) { __bucket = __bucket->__prev; }
802  }
803 
804  for (--i; i && (__bucket != nullptr); --i, __bucket = __bucket->__prev) {}
805 
806  return *this;
807  }
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:2260
bool __null_pointing
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2267
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2256
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:2264
+ Here is the caller 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 812 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::__bucket, gum::ListConstIteratorSafe< Val >::__next_current_bucket, gum::ListConstIteratorSafe< Val >::__null_pointing, and gum::ListConstIteratorSafe< Val >::__prev_current_bucket.

Referenced by gum::ListConstIteratorSafe< Val >::operator+=(), and gum::ListConstIteratorSafe< Val >::operator-=().

812  {
813  // check if we are pointing to something that has been deleted
814  if (__null_pointing) {
815  __null_pointing = false;
816 
817  // if we are pointing to an element of the chained list that has been
818  // deleted
819  // but that has a next element, just point on the latter
820  if (__next_current_bucket != nullptr) {
822  } else {
823  // here we were pointing on an extremity of the list (either end or
824  // rend)
825  // if prev_current_bucket is not null, then we are at rend and doing
826  // a ++ shall now point to the beginning of the list
827  if (__prev_current_bucket != nullptr) {
829  } else {
830  // here, we are at the end of the chained list, hence we shall
831  // remain at end
832  __bucket = nullptr;
833  return *this;
834  }
835  }
836  } else {
837  // if we are pointing to an element of the chained list, just
838  // point on the next bucket in this list
839  if (__bucket != nullptr) { __bucket = __bucket->__next; }
840  }
841 
842  for (--i; i && (__bucket != nullptr); --i, __bucket = __bucket->__next) {}
843 
844  return *this;
845  }
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:2260
bool __null_pointing
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2267
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2256
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:2264
+ Here is the caller 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 592 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::__list, gum::List< Val, Alloc >::__safe_iterators, and gum::ListConstIteratorSafe< Val >::operator=().

Referenced by gum::ListConstIteratorSafe< Val >::clear(), gum::ListConstIteratorSafe< Val >::operator=(), and gum::ListConstIteratorSafe< Val >::~ListConstIteratorSafe().

592  {
593  // find where the iterator is
594  std::vector< ListConstIteratorSafe< Val >* >& vect = __list->__safe_iterators;
595 
596  for (auto i = vect.size() - 1; i >= 0; --i) {
597  if (vect[i] == this) {
598  vect.erase(vect.begin() + i);
599  break;
600  }
601  }
602  }
std::vector< const_iterator_safe *> __safe_iterators
The list of "safe" iterators attached to the list.
Definition: list.h:1311
const List< Val, std::allocator< Val > > * __list
The list the iterator is pointing to.
Definition: list.h:2253
+ Here is the call graph for this function:
+ Here is the caller 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 709 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::__bucket, gum::ListConstIteratorSafe< Val >::__list, gum::ListConstIteratorSafe< Val >::__null_pointing, and gum::ListConstIteratorSafe< Val >::__removeFromSafeList().

Referenced by gum::ListConstIteratorSafe< Val >::setToEnd().

709  {
710  // remove the iterator src the list's iterator list
712 
713  // set its list as well as the element it points to to nullptr
714  __list = nullptr;
715  __bucket = nullptr;
716  __null_pointing = false;
717  }
bool __null_pointing
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2267
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2256
void __removeFromSafeList() const
Remove the iterator for its list&#39; safe iterators list.
Definition: list_tpl.h:592
const List< Val, std::allocator< Val > > * __list
The list the iterator is pointing to.
Definition: list.h:2253
+ Here is the call graph for this function:
+ Here is the caller 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 728 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::__bucket, gum::ListConstIteratorSafe< Val >::__next_current_bucket, gum::ListConstIteratorSafe< Val >::__null_pointing, gum::ListConstIteratorSafe< Val >::__prev_current_bucket, and gum::ListConstIteratorSafe< Val >::operator++().

728  {
729  return __null_pointing ? (__next_current_bucket == nullptr)
730  && (__prev_current_bucket == nullptr)
731  : (__bucket == nullptr);
732  }
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:2260
bool __null_pointing
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2267
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2256
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:2264
+ 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 925 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::__bucket, gum::ListConstIteratorSafe< Val >::__next_current_bucket, gum::ListConstIteratorSafe< Val >::__null_pointing, gum::ListConstIteratorSafe< Val >::__prev_current_bucket, and gum::ListConstIteratorSafe< Val >::operator==().

Referenced by gum::ListConstIteratorSafe< Val >::operator-().

925  {
926  return __null_pointing
927  ? (__next_current_bucket != src.__next_current_bucket)
928  || (__prev_current_bucket != src.__prev_current_bucket)
929  : (__bucket != src.__bucket);
930  }
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:2260
bool __null_pointing
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2267
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2256
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:2264
+ Here is the call graph for this function:
+ Here is the caller 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 954 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::__bucket, and GUM_ERROR.

Referenced by gum::ListIteratorSafe< Val >::operator*().

954  {
955  if (__bucket != nullptr)
956  return __bucket->__val;
957  else {
958  GUM_ERROR(UndefinedIteratorValue, "Accessing a NULL object");
959  }
960  }
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2256
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller 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 911 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::operator-().

Referenced by gum::ListConstIteratorSafe< Val >::operator-=().

911  {
912  return ListConstIteratorSafe< Val >(*this) += i;
913  }
+ Here is the call graph for this function:
+ Here is the caller 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 737 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::__bucket, gum::ListConstIteratorSafe< Val >::__next_current_bucket, gum::ListConstIteratorSafe< Val >::__null_pointing, and gum::ListConstIteratorSafe< Val >::__prev_current_bucket.

Referenced by gum::ListConstIteratorSafe< Val >::isEnd(), and gum::ListIteratorSafe< Val >::operator++().

737  {
738  // check if we are pointing to something that has been deleted
739  if (__null_pointing) {
740  __null_pointing = false;
741 
742  // if we are pointing to an element of the chained list that has been
743  // deleted
744  // but that has a next element, just point on the latter
745  if (__next_current_bucket != nullptr) {
747  return *this;
748  }
749 
750  // here we were pointing on an extremity of the list (either end or rend)
751  // if prev_current_bucket is not null, then we are at rend and doing
752  // a ++ shall now point to the beginning of the list
753  if (__prev_current_bucket != nullptr) {
755  return *this;
756  }
757 
758  // here, we are at the end of the chained list, hence we shall remain at
759  // end
760  __bucket = nullptr;
761  return *this;
762  } else {
763  // if we are pointing to an element of the chained list, just
764  // point on the next bucket in this list
765  if (__bucket != nullptr) { __bucket = __bucket->__next; }
766 
767  return *this;
768  }
769  }
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:2260
bool __null_pointing
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2267
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2256
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:2264
+ Here is the caller 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 849 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::__opMinus(), gum::ListConstIteratorSafe< Val >::__opPlus(), and gum::ListConstIteratorSafe< Val >::operator--().

Referenced by gum::ListIteratorSafe< Val >::operator+=().

850  {
851  if (!i) return *this;
852 
853  if (i < 0)
854  return __opMinus(-i);
855  else
856  return __opPlus(i);
857  }
ListConstIteratorSafe< Val > & __opPlus(Size i) noexcept
Makes the iterator point to the next element in the List.
Definition: list_tpl.h:812
ListConstIteratorSafe< Val > & __opMinus(Size i) noexcept
Makes the iterator point to i elements before in the List.
Definition: list_tpl.h:774
+ Here is the call graph for this function:
+ Here is the caller 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 918 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::operator!=().

Referenced by gum::ListConstIteratorSafe< Val >::operator+().

918  {
919  return ListConstIteratorSafe< Val >(*this) -= i;
920  }
+ Here is the call graph for this function:
+ Here is the caller 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 862 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::__bucket, gum::ListConstIteratorSafe< Val >::__next_current_bucket, gum::ListConstIteratorSafe< Val >::__null_pointing, and gum::ListConstIteratorSafe< Val >::__prev_current_bucket.

Referenced by gum::ListConstIteratorSafe< Val >::operator+=(), and gum::ListIteratorSafe< Val >::operator--().

862  {
863  // check if we are pointing to something that has been deleted
864  if (__null_pointing) {
865  __null_pointing = false;
866 
867  // if we are pointing to an element of the chained list that has been
868  // deleted
869  // but that has a preceding element, just point on the latter
870  if (__prev_current_bucket != nullptr) {
872  return *this;
873  }
874 
875  // here we were pointing on an extremity of the list (either end or rend)
876  // if next_current_bucket is not null, then we are at end and doing
877  // a -- shall now point to the beginning of the list
878  if (__next_current_bucket != nullptr) {
880  return *this;
881  }
882 
883  // here, we are at the rend of the chained list, hence we shall remain
884  // at rend
885  __bucket = nullptr;
886  return *this;
887  } else {
888  // if we are pointing to an element of the chained list, just
889  // point on the preceding bucket in this list
890  if (__bucket != nullptr) { __bucket = __bucket->__prev; }
891 
892  return *this;
893  }
894  }
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:2260
bool __null_pointing
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2267
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2256
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:2264
+ Here is the caller 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 898 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::__opMinus(), gum::ListConstIteratorSafe< Val >::__opPlus(), and gum::ListConstIteratorSafe< Val >::operator+().

Referenced by gum::ListIteratorSafe< Val >::operator-=().

899  {
900  if (!i) return *this;
901 
902  if (i < 0)
903  return __opPlus(-i);
904  else
905  return __opMinus(i);
906  }
ListConstIteratorSafe< Val > & __opPlus(Size i) noexcept
Makes the iterator point to the next element in the List.
Definition: list_tpl.h:812
ListConstIteratorSafe< Val > & __opMinus(Size i) noexcept
Makes the iterator point to i elements before in the List.
Definition: list_tpl.h:774
+ Here is the call graph for this function:
+ Here is the caller 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 944 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::__bucket, and GUM_ERROR.

Referenced by gum::ListIteratorSafe< Val >::operator->().

944  {
945  if (__bucket != nullptr)
946  return &(__bucket->__val);
947  else {
948  GUM_ERROR(UndefinedIteratorValue, "Accessing a NULL object");
949  }
950  }
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2256
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller 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 607 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::__bucket, gum::ListConstIteratorSafe< Val >::__list, gum::ListConstIteratorSafe< Val >::__next_current_bucket, gum::ListConstIteratorSafe< Val >::__null_pointing, gum::ListConstIteratorSafe< Val >::__prev_current_bucket, gum::ListConstIteratorSafe< Val >::__removeFromSafeList(), and gum::List< Val, Alloc >::__safe_iterators.

Referenced by gum::ListConstIteratorSafe< Val >::__removeFromSafeList(), and gum::ListIteratorSafe< Val >::operator=().

607  {
608  // avoid self assignment
609  if (this != &src) {
610  // for debugging purposes
611  GUM_OP_CPY(ListConstIteratorSafe);
612 
613  // check if src and this belong to the same list. If this is not
614  // the case, we shall remove this from its iterator's list and
615  // put it into src's list one.
616  if (__list && (src.__list != __list)) {
618  __list = nullptr;
619  }
620 
621  // if necessary, put this into the same list of safe iterators as src
622  if (src.__list && (src.__list != __list)) {
623  try {
624  src.__list->__safe_iterators.push_back(this);
625  } catch (...) {
626  __list = nullptr;
627  __bucket = nullptr;
628  __null_pointing = false;
629  throw;
630  }
631  }
632 
633  __list = src.__list;
634  __bucket = src.__bucket;
635  __prev_current_bucket = src.__prev_current_bucket;
636  __next_current_bucket = src.__next_current_bucket;
637  __null_pointing = src.__null_pointing;
638  }
639 
640  return *this;
641  }
ListConstIteratorSafe() noexcept
Default constructor.
Definition: list_tpl.h:492
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:2260
bool __null_pointing
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2267
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2256
std::vector< const_iterator_safe *> __safe_iterators
The list of "safe" iterators attached to the list.
Definition: list.h:1311
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:2264
void __removeFromSafeList() const
Remove the iterator for its list&#39; safe iterators list.
Definition: list_tpl.h:592
const List< Val, std::allocator< Val > > * __list
The list the iterator is pointing to.
Definition: list.h:2253
+ Here is the call graph for this function:
+ Here is the caller 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 646 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::__bucket, gum::ListConstIteratorSafe< Val >::__list, gum::ListConstIteratorSafe< Val >::__next_current_bucket, gum::ListConstIteratorSafe< Val >::__null_pointing, gum::ListConstIteratorSafe< Val >::__prev_current_bucket, gum::ListConstIteratorSafe< Val >::__removeFromSafeList(), and gum::List< Val, Alloc >::__safe_iterators.

646  {
647  // avoid self assignment
648  if (this != &src) {
649  // for debugging purposes
650  GUM_OP_MOV(ListConstIteratorSafe);
651 
652  // if the two iterators do not point to the same list, remove
653  // the current iterator from its safe iterators list
654  if ((__list != nullptr) && (src.__list != __list)) {
656  __list = nullptr;
657  }
658 
659  // now if src points to a list, put this at its location
660  if ((src.__list != nullptr)) {
661  std::vector< ListConstIteratorSafe< Val >* >& vect =
662  src.__list->__safe_iterators;
663  Idx index_src = Size(vect.size()) - 1;
664 
665  for (;; --index_src) {
666  if (vect[index_src] == &src) { break; }
667  }
668 
669  if (__list == nullptr) {
670  vect[index_src] = this;
671  } else {
672  vect.erase(vect.begin() + index_src);
673  }
674  }
675 
676  __list = src.__list;
677  __bucket = src.__bucket;
678  __prev_current_bucket = src.__prev_current_bucket;
679  __next_current_bucket = src.__next_current_bucket;
680  __null_pointing = src.__null_pointing;
681 
682  src.__list = nullptr;
683  src.__bucket = nullptr;
684  src.__null_pointing = false;
685  }
686 
687  return *this;
688  }
ListConstIteratorSafe() noexcept
Default constructor.
Definition: list_tpl.h:492
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:2260
bool __null_pointing
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2267
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2256
std::vector< const_iterator_safe *> __safe_iterators
The list of "safe" iterators attached to the list.
Definition: list.h:1311
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:2264
void __removeFromSafeList() const
Remove the iterator for its list&#39; safe iterators list.
Definition: list_tpl.h:592
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
const List< Val, std::allocator< Val > > * __list
The list the iterator is pointing to.
Definition: list.h:2253
+ 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 935 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::__bucket, gum::ListConstIteratorSafe< Val >::__next_current_bucket, gum::ListConstIteratorSafe< Val >::__null_pointing, and gum::ListConstIteratorSafe< Val >::__prev_current_bucket.

Referenced by gum::ListConstIteratorSafe< Val >::operator!=().

935  {
936  return __null_pointing
937  ? (__next_current_bucket == src.__next_current_bucket)
938  && (__prev_current_bucket == src.__prev_current_bucket)
939  : (__bucket == src.__bucket);
940  }
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:2260
bool __null_pointing
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2267
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2256
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:2264
+ Here is the caller 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 721 of file list_tpl.h.

References gum::ListConstIteratorSafe< Val >::clear().

721  {
722  clear();
723  }
void clear()
Makes the iterator point toward nothing.
Definition: list_tpl.h:709
+ 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 2248 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 2249 of file list.h.

Member Data Documentation

◆ __bucket

◆ __list

◆ __next_current_bucket

◆ __null_pointing

◆ __prev_current_bucket


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