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

Safe const iterators for Lists. More...

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

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

Public Types

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

Public Member Functions

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

Private Member Functions

ListBucket< Val > * _getBucket_ () const noexcept
 Returns the bucket the iterator is pointing to.
void _removeFromSafeList_ () const
 Remove the iterator for its list' safe iterators list.
ListConstIteratorSafe< Val > & _opPlus_ (Size i) noexcept
 Makes the iterator point to the next element in the List.
ListConstIteratorSafe< Val > & _opMinus_ (Size i) noexcept
 Makes the iterator point to i elements before in the List.

Private Attributes

const List< Val > * _list_ {nullptr}
 The list the iterator is pointing to.
ListBucket< Val > * _bucket_ {nullptr}
 The bucket in the chained list pointed to by the iterator.
ListBucket< Val > * _next_current_bucket_ {nullptr}
 The bucket we should start from when we are pointing on a deleted bucket and we decide to do a ++.
ListBucket< Val > * _prev_current_bucket_ {nullptr}
 The bucket we should start from when we are pointing on a deleted bucket and we decide to do a –.
bool _null_pointing_ {false}
 Indicates whether the bucket the iterator points to has been deleted.

Friends

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

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.pushBack ("toto"); list.pushBack ("titi");
// parse all the elements of a list
iter != list.cendSafe (); ++iter )
cerr << *iter << endl;
iter != list.cendSafe (); iter += 2 ) // step = 2
cerr << *iter << endl;
iter != list.cendSafe (); iter = iter + 2 ) // step = 2
cerr << *iter << endl;
iter != list.crendSafe (); --iter )
cerr << *iter << endl;
// use member size() of the strings
iter != list.cendSafe (); ++iter )
cerr << iter->size() << endl;
Generic doubly linked lists.
Definition list.h:379
ListConstIteratorSafe< Val > const_iterator_safe
Types for STL compliance.
Definition list.h:393
const const_iterator_safe & crendSafe() const noexcept
Return a safe const iterator pointing just before the beginning of the List.
Definition list_tpl.h:1312
const_iterator_safe crbeginSafe() const
Returns a safe const iterator pointing to the last element of the List.
Definition list_tpl.h:1372
const const_iterator_safe & cendSafe() const noexcept
Returns a safe const iterator pointing to the end of the List.
Definition list_tpl.h:1282
const_iterator_safe cbeginSafe() const
Returns a safe const iterator pointing to the beginning of the List.
Definition list_tpl.h:1342
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition list_tpl.h:1488
Template Parameters
ValThe gum::List values type.

Definition at line 2006 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 2015 of file list.h.

◆ const_reference

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

Types for STL compliance.

Definition at line 2013 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 2016 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 2010 of file list.h.

◆ pointer

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

Types for STL compliance.

Definition at line 2014 of file list.h.

◆ reference

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

Types for STL compliance.

Definition at line 2012 of file list.h.

◆ value_type

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

Types for STL compliance.

Definition at line 2011 of file list.h.

Constructor & Destructor Documentation

◆ ListConstIteratorSafe() [1/5]

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

Default constructor.

Returns an iterator pointing toward nothing.

Definition at line 509 of file list_tpl.h.

509 {
510 // for debugging purposes
512 }
Safe const iterators for Lists.
Definition list.h:2006
ListConstIteratorSafe() noexcept
Default constructor.
Definition list_tpl.h:509

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

Here is the caller graph for this function:

◆ ListConstIteratorSafe() [2/5]

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

Constructor for a begin.

Definition at line 516 of file list_tpl.h.

516 :
517 _list_{&theList}, _bucket_{theList._deb_list_} {
518 // for debugging purposes
520
521 // add the iterator to the list of safe iterators
522 theList._safe_iterators_.push_back(this);
523 }
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
Definition list.h:2233
const List< Val > * _list_
The list the iterator is pointing to.
Definition list.h:2230

References ListConstIteratorSafe(), _bucket_, _list_, and List< Val >.

Here is the call graph for this function:

◆ ListConstIteratorSafe() [3/5]

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

Copy constructor.

Parameters
srcThe gum::ListConstIteratorSafe to copy.

Definition at line 528 of file list_tpl.h.

528 :
531 // for debugging purposes
533
534 // add the iterator to the list of safe iterators
535 if (_list_ != nullptr) _list_->_safe_iterators_.push_back(this);
536 }
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:2237
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:2241
bool _null_pointing_
Indicates whether the bucket the iterator points to has been deleted.
Definition list.h:2244

References ListConstIteratorSafe(), _bucket_, _list_, _next_current_bucket_, _null_pointing_, and _prev_current_bucket_.

Here is the call graph for this function:

◆ ListConstIteratorSafe() [4/5]

template<typename Val>
gum::ListConstIteratorSafe< Val >::ListConstIteratorSafe ( const List< Val > & 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 542 of file list_tpl.h.

542 :
543 _list_{&theList} {
544 // for debugging purposes
546
547 // check if the index ind_elt passed as parameter is valid
548 if (ind_elt >= _list_->_nb_elements_) {
549 GUM_ERROR(UndefinedIteratorValue, "Not enough elements in the list")
550 }
551
552 // check if it is faster to find the indexth element src the start or
553 // src the end of the list
554 if (ind_elt < (_list_->_nb_elements_ >> 1)) {
555 // find the element we shall point to src the start of the list
556 for (_bucket_ = _list_->_deb_list_; ind_elt; --ind_elt, _bucket_ = _bucket_->_next_) {}
557 } else {
558 // find the element we shall point to src the end of the list
559 for (_bucket_ = _list_->_end_list_, ind_elt = _list_->_nb_elements_ - ind_elt - 1; ind_elt;
560 --ind_elt, _bucket_ = _bucket_->_prev_) {}
561 }
562
563 // add the iterator to the list of safe iterators
564 theList._safe_iterators_.push_back(this);
565 }
#define GUM_ERROR(type, msg)
Definition exceptions.h:72

References ListConstIteratorSafe(), _list_, and List< Val >.

Here is the call graph for this function:

◆ ListConstIteratorSafe() [5/5]

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

Move constructor.

Parameters
srcThe gum::ListConstIterator to move.

Definition at line 569 of file list_tpl.h.

569 :
572 // for debugging purposes
574
575 if (_list_ != nullptr) {
576 // substitute src by this in the list of safe iterators
578
579 for (auto ptr = vect.rbegin(); ptr != vect.rend(); --ptr) {
580 if (*ptr == &src) {
581 *ptr = this;
582 break;
583 }
584 }
585
586 src._list_ = nullptr;
587 src._bucket_ = nullptr;
588 src._null_pointing_ = false;
589 }
590 }

References ListConstIteratorSafe(), _bucket_, _list_, _next_current_bucket_, _null_pointing_, and _prev_current_bucket_.

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.

693 {
694 // for debugging purposes
696
697 // remove the iterator src the table's iterator list
699 }
void _removeFromSafeList_() const
Remove the iterator for its list' safe iterators list.
Definition list_tpl.h:594

References ListConstIteratorSafe(), _list_, and _removeFromSafeList_().

Here is the call graph for this function:

Member Function Documentation

◆ _getBucket_()

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

Returns the bucket the iterator is pointing to.

Definition at line 703 of file list_tpl.h.

703 {
704 return _bucket_;
705 }

References _bucket_.

Referenced by gum::List< Val >::_insert_(), gum::List< Val >::erase(), and gum::List< Val >::erase().

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

772 {
773 // check if we are pointing to something that has been deleted
774 if (_null_pointing_) {
775 _null_pointing_ = false;
776
777 // if we are pointing to an element of the chained list that has been
778 // deleted
779 // but that has a preceding element, just point on the latter
780 if (_prev_current_bucket_ != nullptr) {
782 } else {
783 // here we were pointing on an extremity of the list (either end or
784 // rend)
785 // if next_current_bucket is not null, then we are at end and doing
786 // a -- shall now point to the beginning of the list
787 if (_next_current_bucket_ != nullptr) {
789 } else {
790 // here, we are at the rend of the chained list, hence we shall remain
791 // at rend
792 _bucket_ = nullptr;
793 return *this;
794 }
795 }
796 } else {
797 // if we are pointing to an element of the chained list, just
798 // point on the preceding bucket in this list
799 if (_bucket_ != nullptr) { _bucket_ = _bucket_->_prev_; }
800 }
801
802 for (--i; i && (_bucket_ != nullptr); --i, _bucket_ = _bucket_->_prev_) {}
803
804 return *this;
805 }

References ListConstIteratorSafe(), _bucket_, _next_current_bucket_, _null_pointing_, and _prev_current_bucket_.

Referenced by operator+=(), and operator-=().

Here is the call graph for this function:
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.

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 }

References ListConstIteratorSafe(), _bucket_, _next_current_bucket_, _null_pointing_, and _prev_current_bucket_.

Referenced by operator+=(), and operator-=().

Here is the call graph for this function:
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 594 of file list_tpl.h.

594 {
595 // find where the iterator is
597
598 for (auto i = vect.size() - 1; i >= 0; --i) {
599 if (vect[i] == this) {
600 vect.erase(vect.begin() + i);
601 break;
602 }
603 }
604 }

References _list_.

Referenced by ~ListConstIteratorSafe(), clear(), and operator=().

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.

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 }

References _bucket_, _list_, _null_pointing_, and _removeFromSafeList_().

Referenced by setToEnd().

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.

728 {
729 return _null_pointing_
730 ? (_next_current_bucket_ == nullptr) && (_prev_current_bucket_ == nullptr)
731 : (_bucket_ == nullptr);
732 }

References _bucket_, _next_current_bucket_, _null_pointing_, and _prev_current_bucket_.

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

References ListConstIteratorSafe(), _bucket_, _next_current_bucket_, _null_pointing_, and _prev_current_bucket_.

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

941 {
942 if (_bucket_ != nullptr) return _bucket_->_val_;
943 else { GUM_ERROR(UndefinedIteratorValue, "Accessing a NULL object") }
944 }

References _bucket_, and GUM_ERROR.

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

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

903 {
904 return ListConstIteratorSafe< Val >(*this) += i;
905 }

References ListConstIteratorSafe().

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

736 {
737 // check if we are pointing to something that has been deleted
738 if (_null_pointing_) {
739 _null_pointing_ = false;
740
741 // if we are pointing to an element of the chained list that has been
742 // deleted
743 // but that has a next element, just point on the latter
744 if (_next_current_bucket_ != nullptr) {
746 return *this;
747 }
748
749 // here we were pointing on an extremity of the list (either end or rend)
750 // if prev_current_bucket is not null, then we are at rend and doing
751 // a ++ shall now point to the beginning of the list
752 if (_prev_current_bucket_ != nullptr) {
754 return *this;
755 }
756
757 // here, we are at the end of the chained list, hence we shall remain at
758 // end
759 _bucket_ = nullptr;
760 return *this;
761 } else {
762 // if we are pointing to an element of the chained list, just
763 // point on the next bucket in this list
764 if (_bucket_ != nullptr) { _bucket_ = _bucket_->_next_; }
765
766 return *this;
767 }
768 }

References ListConstIteratorSafe(), _bucket_, _next_current_bucket_, _null_pointing_, and _prev_current_bucket_.

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

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

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.

847 {
848 if (!i) return *this;
849
850 if (i < 0) return _opMinus_(-i);
851 else return _opPlus_(i);
852 }
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:772

References ListConstIteratorSafe(), _opMinus_(), and _opPlus_().

Referenced by gum::List< gum::Instantiation * >::eraseByVal().

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

910 {
911 return ListConstIteratorSafe< Val >(*this) -= i;
912 }

References ListConstIteratorSafe().

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

856 {
857 // check if we are pointing to something that has been deleted
858 if (_null_pointing_) {
859 _null_pointing_ = false;
860
861 // if we are pointing to an element of the chained list that has been
862 // deleted
863 // but that has a preceding element, just point on the latter
864 if (_prev_current_bucket_ != nullptr) {
866 return *this;
867 }
868
869 // here we were pointing on an extremity of the list (either end or rend)
870 // if next_current_bucket is not null, then we are at end and doing
871 // a -- shall now point to the beginning of the list
872 if (_next_current_bucket_ != nullptr) {
874 return *this;
875 }
876
877 // here, we are at the rend of the chained list, hence we shall remain
878 // at rend
879 _bucket_ = nullptr;
880 return *this;
881 } else {
882 // if we are pointing to an element of the chained list, just
883 // point on the preceding bucket in this list
884 if (_bucket_ != nullptr) { _bucket_ = _bucket_->_prev_; }
885
886 return *this;
887 }
888 }

References ListConstIteratorSafe(), _bucket_, _next_current_bucket_, _null_pointing_, and _prev_current_bucket_.

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

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

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

893 {
894 if (!i) return *this;
895
896 if (i < 0) return _opPlus_(-i);
897 else return _opMinus_(i);
898 }

References ListConstIteratorSafe(), _opMinus_(), and _opPlus_().

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

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

934 {
935 if (_bucket_ != nullptr) return &(_bucket_->_val_);
936 else { GUM_ERROR(UndefinedIteratorValue, "Accessing a NULL object") }
937 }

References _bucket_, and GUM_ERROR.

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

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

609 {
610 // avoid self assignment
611 if (this != &src) {
612 // for debugging purposes
614
615 // check if src and this belong to the same list. If this is not
616 // the case, we shall remove this from its iterator's list and
617 // put it into src's list one.
618 if (_list_ && (src._list_ != _list_)) {
620 _list_ = nullptr;
621 }
622
623 // if necessary, put this into the same list of safe iterators as src
624 if (src._list_ && (src._list_ != _list_)) {
625 try {
626 src._list_->_safe_iterators_.push_back(this);
627 } catch (...) {
628 _list_ = nullptr;
629 _bucket_ = nullptr;
630 _null_pointing_ = false;
631 throw;
632 }
633 }
634
635 _list_ = src._list_;
640 }
641
642 return *this;
643 }

References ListConstIteratorSafe(), _list_, and _removeFromSafeList_().

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

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

648 {
649 // avoid self assignment
650 if (this != &src) {
651 // for debugging purposes
653
654 // if the two iterators do not point to the same list, remove
655 // the current iterator from its safe iterators list
656 if ((_list_ != nullptr) && (src._list_ != _list_)) {
658 _list_ = nullptr;
659 }
660
661 // now if src points to a list, put this at its location
662 if ((src._list_ != nullptr)) {
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_;
682
683 src._list_ = nullptr;
684 src._bucket_ = nullptr;
685 src._null_pointing_ = false;
686 }
687
688 return *this;
689 }

References ListConstIteratorSafe().

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

References ListConstIteratorSafe(), _bucket_, _next_current_bucket_, _null_pointing_, and _prev_current_bucket_.

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

Here is the call graph for this function:
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.

721 {
722 clear();
723 }
void clear()
Makes the iterator point toward nothing.
Definition list_tpl.h:709

References clear().

Here is the call graph for this function:

◆ List< Val >

template<typename Val>
friend class List< Val >
friend

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

Definition at line 2217 of file list.h.

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

◆ 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 2217 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 2233 of file list.h.

2233{nullptr};

Referenced by ListConstIteratorSafe(), ListConstIteratorSafe(), ListConstIteratorSafe(), _getBucket_(), _opMinus_(), _opPlus_(), clear(), isEnd(), operator!=(), operator*(), operator++(), operator--(), operator->(), and operator==().

◆ _list_

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

◆ _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 2237 of file list.h.

2237{nullptr};

Referenced by ListConstIteratorSafe(), ListConstIteratorSafe(), gum::List< Val >::_insert_(), _opMinus_(), _opPlus_(), isEnd(), operator!=(), operator++(), operator--(), and operator==().

◆ _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 2244 of file list.h.

2244{false};

Referenced by ListConstIteratorSafe(), ListConstIteratorSafe(), gum::List< Val >::_insert_(), _opMinus_(), _opPlus_(), clear(), isEnd(), operator!=(), operator++(), operator--(), and operator==().

◆ _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 2241 of file list.h.

2241{nullptr};

Referenced by ListConstIteratorSafe(), ListConstIteratorSafe(), gum::List< Val >::_insert_(), _opMinus_(), _opPlus_(), isEnd(), operator!=(), operator++(), operator--(), and operator==().


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