aGrUM 3.1.1
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:378
ListConstIteratorSafe< Val > const_iterator_safe
Types for STL compliance.
Definition list.h:392
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition list_tpl.h:1481
const_iterator_safe cbeginSafe() const
Returns a safe const iterator pointing to the beginning of the List.
Definition list_tpl.h:1335
const_iterator_safe crbeginSafe() const
Returns a safe const iterator pointing to the last element of the List.
Definition list_tpl.h:1365
const const_iterator_safe & cendSafe() const noexcept
Returns a safe const iterator pointing to the end of the List.
Definition list_tpl.h:1275
const const_iterator_safe & crendSafe() const noexcept
Return a safe const iterator pointing just before the beginning of the List.
Definition list_tpl.h:1305
Template Parameters
ValThe gum::List values type.

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

◆ const_reference

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

Types for STL compliance.

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

◆ pointer

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

Types for STL compliance.

Definition at line 2013 of file list.h.

◆ reference

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

Types for STL compliance.

Definition at line 2011 of file list.h.

◆ value_type

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

Types for STL compliance.

Definition at line 2010 of file list.h.

Constructor & Destructor Documentation

◆ ListConstIteratorSafe() [1/5]

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

Default constructor.

Returns an iterator pointing toward nothing.

Definition at line 507 of file list_tpl.h.

507 {
508 // for debugging purposes
510 }
Safe const iterators for Lists.
Definition list.h:2005
ListConstIteratorSafe() noexcept
Default constructor.
Definition list_tpl.h:507

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=(), and operator==().

Here is the caller graph for this function:

◆ ListConstIteratorSafe() [2/5]

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

Constructor for a begin.

Definition at line 514 of file list_tpl.h.

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

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

Here is the call graph for this function:

◆ ListConstIteratorSafe() [3/5]

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

Copy constructor.

Parameters
srcThe gum::ListConstIteratorSafe to copy.

Definition at line 525 of file list_tpl.h.

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

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

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

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

Here is the call graph for this function:

◆ ListConstIteratorSafe() [5/5]

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

Move constructor.

Parameters
srcThe gum::ListConstIterator to move.

Definition at line 566 of file list_tpl.h.

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

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>
gum::ListConstIteratorSafe< Val >::~ListConstIteratorSafe ( )

Class Desctructor.

Definition at line 690 of file list_tpl.h.

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

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

Here is the call graph for this function:

Member Function Documentation

◆ _getBucket_()

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

Returns the bucket the iterator is pointing to.

Definition at line 700 of file list_tpl.h.

700 {
701 return _bucket_;
702 }

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>
ListConstIteratorSafe< Val > & gum::ListConstIteratorSafe< Val >::_opMinus_ ( Size i)
privatenoexcept

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

Definition at line 769 of file list_tpl.h.

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

References ListConstIteratorSafe(), and _null_pointing_.

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>
ListConstIteratorSafe< Val > & gum::ListConstIteratorSafe< Val >::_opPlus_ ( Size i)
privatenoexcept

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

Definition at line 806 of file list_tpl.h.

806 {
807 // check if we are pointing to something that has been deleted
808 if (_null_pointing_) {
809 _null_pointing_ = false;
810
811 // if we are pointing to an element of the chained list that has been
812 // deleted
813 // but that has a next element, just point on the latter
814 if (_next_current_bucket_ != nullptr) {
816 } else {
817 // here we were pointing on an extremity of the list (either end or
818 // rend)
819 // if prev_current_bucket is not null, then we are at rend and doing
820 // a ++ shall now point to the beginning of the list
821 if (_prev_current_bucket_ != nullptr) {
823 } else {
824 // here, we are at the end of the chained list, hence we shall
825 // remain at end
826 _bucket_ = nullptr;
827 return *this;
828 }
829 }
830 } else {
831 // if we are pointing to an element of the chained list, just
832 // point on the next bucket in this list
833 if (_bucket_ != nullptr) { _bucket_ = _bucket_->_next_; }
834 }
835
836 for (--i; i && (_bucket_ != nullptr); --i, _bucket_ = _bucket_->_next_) {}
837
838 return *this;
839 }

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>
void gum::ListConstIteratorSafe< Val >::_removeFromSafeList_ ( ) const
private

Remove the iterator for its list' safe iterators list.

Definition at line 591 of file list_tpl.h.

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

References _list_.

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

Here is the caller graph for this function:

◆ clear()

template<typename Val>
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.

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 }

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

725 {
726 return _null_pointing_
727 ? (_next_current_bucket_ == nullptr) && (_prev_current_bucket_ == nullptr)
728 : (_bucket_ == nullptr);
729 }

References _bucket_, _next_current_bucket_, _null_pointing_, and _prev_current_bucket_.

◆ operator!=()

template<typename Val>
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 913 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>
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 936 of file list_tpl.h.

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

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

900 {
901 return ListConstIteratorSafe< Val >(*this) += i;
902 }

References ListConstIteratorSafe().

Here is the call graph for this function:

◆ operator++()

template<typename Val>
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 733 of file list_tpl.h.

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

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

844 {
845 if (!i) return *this;
846
847 if (i < 0) return _opMinus_(-i);
848 else return _opPlus_(i);
849 }
ListConstIteratorSafe< Val > & _opMinus_(Size i) noexcept
Makes the iterator point to i elements before in the List.
Definition list_tpl.h:769
ListConstIteratorSafe< Val > & _opPlus_(Size i) noexcept
Makes the iterator point to the next element in the List.
Definition list_tpl.h:806

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

907 {
908 return ListConstIteratorSafe< Val >(*this) -= i;
909 }

References ListConstIteratorSafe().

Here is the call graph for this function:

◆ operator--()

template<typename Val>
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 853 of file list_tpl.h.

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

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

890 {
891 if (!i) return *this;
892
893 if (i < 0) return _opPlus_(-i);
894 else return _opMinus_(i);
895 }

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

929 {
930 if (_bucket_ != nullptr) return &(_bucket_->_val_);
931 else { GUM_ERROR(UndefinedIteratorValue, "Accessing a NULL object") }
932 }

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

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

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

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

645 {
646 // avoid self assignment
647 if (this != &src) {
648 // for debugging purposes
650
651 // if the two iterators do not point to the same list, remove
652 // the current iterator from its safe iterators list
653 if ((_list_ != nullptr) && (src._list_ != _list_)) {
655 _list_ = nullptr;
656 }
657
658 // now if src points to a list, put this at its location
659 if ((src._list_ != nullptr)) {
661 Idx index_src = Size(vect.size()) - 1;
662
663 for (;; --index_src) {
664 if (vect[index_src] == &src) { break; }
665 }
666
667 if (_list_ == nullptr) {
668 vect[index_src] = this;
669 } else {
670 vect.erase(vect.begin() + index_src);
671 }
672 }
673
674 _list_ = src._list_;
679
680 src._list_ = nullptr;
681 src._bucket_ = nullptr;
682 src._null_pointing_ = false;
683 }
684
685 return *this;
686 }

References ListConstIteratorSafe(), and _list_.

Here is the call graph for this function:

◆ operator==()

template<typename Val>
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 921 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>
void gum::ListConstIteratorSafe< Val >::setToEnd ( )

Positions the iterator to the end of the list.

Definition at line 718 of file list_tpl.h.

718 {
719 clear();
720 }
void clear()
Makes the iterator point toward nothing.
Definition list_tpl.h:706

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 2216 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 2216 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 2232 of file list.h.

2232{nullptr};

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

◆ _list_

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

2236{nullptr};

Referenced by ListConstIteratorSafe(), ListConstIteratorSafe(), gum::List< Val >::_insert_(), _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 2243 of file list.h.

2243{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 2240 of file list.h.

2240{nullptr};

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


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