aGrUM  0.14.2
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 2027 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 2036 of file list.h.

◆ const_reference

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

Types for STL compliance.

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

◆ pointer

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

Types for STL compliance.

Definition at line 2035 of file list.h.

◆ reference

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

Types for STL compliance.

Definition at line 2033 of file list.h.

◆ value_type

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

Types for STL compliance.

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

489  {
490  // for debugging purposes
491  GUM_CONSTRUCTOR(ListConstIteratorSafe);
492  }
ListConstIteratorSafe() noexcept
Default constructor.
Definition: list_tpl.h:489

◆ 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 511 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.

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

◆ 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 528 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.

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

◆ 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 560 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.

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

◆ ~ListConstIteratorSafe()

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

Class Desctructor.

Definition at line 689 of file list_tpl.h.

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

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

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

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

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 699 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().

700  {
701  return __bucket;
702  }
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2253
+ 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 771 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-=().

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

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

589  {
590  // find where the iterator is
591  std::vector< ListConstIteratorSafe< Val >* >& vect = __list->__safe_iterators;
592 
593  for (auto i = vect.size() - 1; i >= 0; --i) {
594  if (vect[i] == this) {
595  vect.erase(vect.begin() + i);
596  break;
597  }
598  }
599  }
std::vector< const_iterator_safe *> __safe_iterators
The list of "safe" iterators attached to the list.
Definition: list.h:1308
const List< Val, std::allocator< Val > > * __list
The list the iterator is pointing to.
Definition: list.h:2250
+ 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 706 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().

706  {
707  // remove the iterator src the list's iterator list
709 
710  // set its list as well as the element it points to to nullptr
711  __list = nullptr;
712  __bucket = nullptr;
713  __null_pointing = false;
714  }
bool __null_pointing
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2264
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2253
void __removeFromSafeList() const
Remove the iterator for its list&#39; safe iterators list.
Definition: list_tpl.h:589
const List< Val, std::allocator< Val > > * __list
The list the iterator is pointing to.
Definition: list.h:2250
+ 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 725 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++().

725  {
726  return __null_pointing ? (__next_current_bucket == nullptr)
727  && (__prev_current_bucket == nullptr)
728  : (__bucket == nullptr);
729  }
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:2257
bool __null_pointing
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2264
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2253
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:2261
+ 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 922 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-().

922  {
923  return __null_pointing
924  ? (__next_current_bucket != src.__next_current_bucket)
925  || (__prev_current_bucket != src.__prev_current_bucket)
926  : (__bucket != src.__bucket);
927  }
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:2257
bool __null_pointing
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2264
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2253
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:2261
+ 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 951 of file list_tpl.h.

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

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

951  {
952  if (__bucket != nullptr)
953  return __bucket->__val;
954  else {
955  GUM_ERROR(UndefinedIteratorValue, "Accessing a NULL object");
956  }
957  }
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2253
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ 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 908 of file list_tpl.h.

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

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

908  {
909  return ListConstIteratorSafe< Val >(*this) += i;
910  }
+ 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 734 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++().

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

847  {
848  if (!i) return *this;
849 
850  if (i < 0)
851  return __opMinus(-i);
852  else
853  return __opPlus(i);
854  }
ListConstIteratorSafe< Val > & __opPlus(Size i) noexcept
Makes the iterator point to the next element in the List.
Definition: list_tpl.h:809
ListConstIteratorSafe< Val > & __opMinus(Size i) noexcept
Makes the iterator point to i elements before in the List.
Definition: list_tpl.h:771
+ 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 915 of file list_tpl.h.

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

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

915  {
916  return ListConstIteratorSafe< Val >(*this) -= i;
917  }
+ 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 859 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--().

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

896  {
897  if (!i) return *this;
898 
899  if (i < 0)
900  return __opPlus(-i);
901  else
902  return __opMinus(i);
903  }
ListConstIteratorSafe< Val > & __opPlus(Size i) noexcept
Makes the iterator point to the next element in the List.
Definition: list_tpl.h:809
ListConstIteratorSafe< Val > & __opMinus(Size i) noexcept
Makes the iterator point to i elements before in the List.
Definition: list_tpl.h:771
+ 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 941 of file list_tpl.h.

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

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

941  {
942  if (__bucket != nullptr)
943  return &(__bucket->__val);
944  else {
945  GUM_ERROR(UndefinedIteratorValue, "Accessing a NULL object");
946  }
947  }
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2253
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ 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 604 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=().

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

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

932  {
933  return __null_pointing
934  ? (__next_current_bucket == src.__next_current_bucket)
935  && (__prev_current_bucket == src.__prev_current_bucket)
936  : (__bucket == src.__bucket);
937  }
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:2257
bool __null_pointing
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2264
ListBucket< Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2253
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:2261
+ 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 718 of file list_tpl.h.

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

718  {
719  clear();
720  }
void clear()
Makes the iterator point toward nothing.
Definition: list_tpl.h:706
+ 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 2245 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 2246 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: