aGrUM  0.20.2
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 2034 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 2043 of file list.h.

◆ const_reference

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

Types for STL compliance.

Definition at line 2041 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 2044 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 2038 of file list.h.

◆ pointer

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

Types for STL compliance.

Definition at line 2042 of file list.h.

◆ reference

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

Types for STL compliance.

Definition at line 2040 of file list.h.

◆ value_type

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

Types for STL compliance.

Definition at line 2039 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.

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

492  {
493  // for debugging purposes
494  GUM_CONSTRUCTOR(ListConstIteratorSafe);
495  }
ListConstIteratorSafe() noexcept
Default constructor.
Definition: list_tpl.h:492
+ 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 514 of file list_tpl.h.

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

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  }
const List< Val, std::allocator< Val > > * list__
The list the iterator is pointing to.
Definition: list.h:2257
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:2260
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:2264
bool null_pointing__
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2271
std::vector< const_iterator_safe *> safe_iterators__
The list of "safe" iterators attached to the list.
Definition: list.h:1315
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:2268
+ 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 531 of file list_tpl.h.

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

533  :
534  list__{
535  reinterpret_cast< const List< Val, std::allocator< Val > >* >(&theList)} {
536  // for debugging purposes
537  GUM_CONSTRUCTOR(ListConstIteratorSafe);
538 
539  // check if the index ind_elt passed as parameter is valid
540  if (ind_elt >= list__->nb_elements__) {
541  GUM_ERROR(UndefinedIteratorValue, "Not enough elements in the list");
542  }
543 
544  // check if it is faster to find the indexth element src the start or
545  // src the end of the list
546  if (ind_elt < (list__->nb_elements__ >> 1)) {
547  // find the element we shall point to src the start of the list
548  for (bucket__ = list__->deb_list__; ind_elt;
549  --ind_elt, bucket__ = bucket__->next__) {}
550  } else {
551  // find the element we shall point to src the end of the list
552  for (bucket__ = list__->end_list__,
553  ind_elt = list__->nb_elements__ - ind_elt - 1;
554  ind_elt;
555  --ind_elt, bucket__ = bucket__->prev__) {}
556  }
557 
558  // add the iterator to the list of safe iterators
559  theList.safe_iterators__.push_back(this);
560  }
Size nb_elements__
The number of elements in the list.
Definition: list.h:1312
const List< Val, std::allocator< Val > > * list__
The list the iterator is pointing to.
Definition: list.h:2257
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:2260
ListBucket< Val > * end_list__
A pointer on the last element of the chained list.
Definition: list.h:1309
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
ListBucket< Val > * deb_list__
A pointer on the first element of the chained list.
Definition: list.h:1306
+ 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 564 of file list_tpl.h.

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

565  :
566  list__{src.list__},
567  bucket__{src.bucket__}, next_current_bucket__{src.next_current_bucket__},
568  prev_current_bucket__{src.prev_current_bucket__}, null_pointing__{
569  src.null_pointing__} {
570  // for debugging purposes
571  GUM_CONS_MOV(ListConstIteratorSafe);
572 
573  if (list__ != nullptr) {
574  // substitute src by this in the list of safe iterators
575  std::vector< ListConstIteratorSafe< Val >* >& vect
577 
578  for (auto ptr = vect.rbegin(); ptr != vect.rend(); --ptr) {
579  if (*ptr == &src) {
580  *ptr = this;
581  break;
582  }
583  }
584 
585  src.list__ = nullptr;
586  src.bucket__ = nullptr;
587  src.null_pointing__ = false;
588  }
589  }
const List< Val, std::allocator< Val > > * list__
The list the iterator is pointing to.
Definition: list.h:2257
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:2260
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:2264
bool null_pointing__
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2271
std::vector< const_iterator_safe *> safe_iterators__
The list of "safe" iterators attached to the list.
Definition: list.h:1315
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:2268
+ Here is the call graph for this function:

◆ ~ListConstIteratorSafe()

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

Class Desctructor.

Definition at line 693 of file list_tpl.h.

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

693  {
694  // for debugging purposes
695  GUM_DESTRUCTOR(ListConstIteratorSafe);
696 
697  // remove the iterator src the table's iterator list
699  }
const List< Val, std::allocator< Val > > * list__
The list the iterator is pointing to.
Definition: list.h:2257
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:593
+ 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::Set< Key, Alloc >::emplace().

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  }
const List< Val, std::allocator< Val > > * list__
The list the iterator is pointing to.
Definition: list.h:2257
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:2260
+ Here is the call graph for this function:

Member Function Documentation

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

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

710  {
711  // remove the iterator src the list's iterator list
713 
714  // set its list as well as the element it points to to nullptr
715  list__ = nullptr;
716  bucket__ = nullptr;
717  null_pointing__ = false;
718  }
const List< Val, std::allocator< Val > > * list__
The list the iterator is pointing to.
Definition: list.h:2257
ListBucket< Val > * bucket__
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2260
bool null_pointing__
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2271
void removeFromSafeList__() const
Remove the iterator for its list&#39; safe iterators list.
Definition: list_tpl.h:593
+ Here is the call graph for this function:

◆ getBucket__()

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

Returns the bucket the iterator is pointing to.

Definition at line 704 of file list_tpl.h.

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

704  {
705  return bucket__;
706  }
ListBucket< Val > * bucket__
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2260
+ 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 729 of file list_tpl.h.

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

729  {
730  return null_pointing__ ? (next_current_bucket__ == nullptr)
731  && (prev_current_bucket__ == nullptr)
732  : (bucket__ == nullptr);
733  }
ListBucket< Val > * bucket__
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2260
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:2264
bool null_pointing__
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2271
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:2268
+ 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::Set< Key, Alloc >::emplace().

926  {
927  return null_pointing__
928  ? (next_current_bucket__ != src.next_current_bucket__)
929  || (prev_current_bucket__ != src.prev_current_bucket__)
930  : (bucket__ != src.bucket__);
931  }
ListBucket< Val > * bucket__
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2260
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:2264
bool null_pointing__
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2271
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:2268
+ 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 955 of file list_tpl.h.

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

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

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

912  {
913  return ListConstIteratorSafe< Val >(*this) += i;
914  }
+ 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 738 of file list_tpl.h.

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

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

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

851  {
852  if (!i) return *this;
853 
854  if (i < 0)
855  return opMinus__(-i);
856  else
857  return opPlus__(i);
858  }
ListConstIteratorSafe< Val > & opPlus__(Size i) noexcept
Makes the iterator point to the next element in the List.
Definition: list_tpl.h:813
ListConstIteratorSafe< Val > & opMinus__(Size i) noexcept
Makes the iterator point to i elements before in the List.
Definition: list_tpl.h:775
+ 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 918 of file list_tpl.h.

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

919  {
920  return ListConstIteratorSafe< Val >(*this) -= i;
921  }
+ 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 863 of file list_tpl.h.

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

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

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

900  {
901  if (!i) return *this;
902 
903  if (i < 0)
904  return opPlus__(-i);
905  else
906  return opMinus__(i);
907  }
ListConstIteratorSafe< Val > & opPlus__(Size i) noexcept
Makes the iterator point to the next element in the List.
Definition: list_tpl.h:813
ListConstIteratorSafe< Val > & opMinus__(Size i) noexcept
Makes the iterator point to i elements before in the List.
Definition: list_tpl.h:775
+ 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 945 of file list_tpl.h.

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

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

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

608  {
609  // avoid self assignment
610  if (this != &src) {
611  // for debugging purposes
612  GUM_OP_CPY(ListConstIteratorSafe);
613 
614  // check if src and this belong to the same list. If this is not
615  // the case, we shall remove this from its iterator's list and
616  // put it into src's list one.
617  if (list__ && (src.list__ != list__)) {
619  list__ = nullptr;
620  }
621 
622  // if necessary, put this into the same list of safe iterators as src
623  if (src.list__ && (src.list__ != list__)) {
624  try {
625  src.list__->safe_iterators__.push_back(this);
626  } catch (...) {
627  list__ = nullptr;
628  bucket__ = nullptr;
629  null_pointing__ = false;
630  throw;
631  }
632  }
633 
634  list__ = src.list__;
635  bucket__ = src.bucket__;
636  prev_current_bucket__ = src.prev_current_bucket__;
637  next_current_bucket__ = src.next_current_bucket__;
638  null_pointing__ = src.null_pointing__;
639  }
640 
641  return *this;
642  }
const List< Val, std::allocator< Val > > * list__
The list the iterator is pointing to.
Definition: list.h:2257
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:2260
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:2264
bool null_pointing__
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2271
void removeFromSafeList__() const
Remove the iterator for its list&#39; safe iterators list.
Definition: list_tpl.h:593
std::vector< const_iterator_safe *> safe_iterators__
The list of "safe" iterators attached to the list.
Definition: list.h:1315
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:2268
+ 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 647 of file list_tpl.h.

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

647  {
648  // avoid self assignment
649  if (this != &src) {
650  // for debugging purposes
651  GUM_OP_MOV(ListConstIteratorSafe);
652 
653  // if the two iterators do not point to the same list, remove
654  // the current iterator from its safe iterators list
655  if ((list__ != nullptr) && (src.list__ != list__)) {
657  list__ = nullptr;
658  }
659 
660  // now if src points to a list, put this at its location
661  if ((src.list__ != nullptr)) {
662  std::vector< ListConstIteratorSafe< Val >* >& vect
663  = src.list__->safe_iterators__;
664  Idx index_src = Size(vect.size()) - 1;
665 
666  for (;; --index_src) {
667  if (vect[index_src] == &src) { break; }
668  }
669 
670  if (list__ == nullptr) {
671  vect[index_src] = this;
672  } else {
673  vect.erase(vect.begin() + index_src);
674  }
675  }
676 
677  list__ = src.list__;
678  bucket__ = src.bucket__;
679  prev_current_bucket__ = src.prev_current_bucket__;
680  next_current_bucket__ = src.next_current_bucket__;
681  null_pointing__ = src.null_pointing__;
682 
683  src.list__ = nullptr;
684  src.bucket__ = nullptr;
685  src.null_pointing__ = false;
686  }
687 
688  return *this;
689  }
const List< Val, std::allocator< Val > > * list__
The list the iterator is pointing to.
Definition: list.h:2257
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:2260
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:2264
bool null_pointing__
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2271
void removeFromSafeList__() const
Remove the iterator for its list&#39; safe iterators list.
Definition: list_tpl.h:593
std::vector< const_iterator_safe *> safe_iterators__
The list of "safe" iterators attached to the list.
Definition: list.h:1315
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
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:2268
+ 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::Set< Key, Alloc >::emplace().

936  {
937  return null_pointing__
938  ? (next_current_bucket__ == src.next_current_bucket__)
939  && (prev_current_bucket__ == src.prev_current_bucket__)
940  : (bucket__ == src.bucket__);
941  }
ListBucket< Val > * bucket__
The bucket in the chained list pointed to by the iterator.
Definition: list.h:2260
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:2264
bool null_pointing__
Indicates whether the bucket the iterator points to has been deleted.
Definition: list.h:2271
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:2268
+ 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 775 of file list_tpl.h.

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

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

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

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

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

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

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

722  {
723  clear();
724  }
void clear()
Makes the iterator point toward nothing.
Definition: list_tpl.h:710
+ 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 2252 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 2253 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 2260 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 2257 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 2264 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 2271 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 2268 of file list.h.


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