![]() |
aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
|
Safe const iterators for Lists. More...
#include <agrum/base/core/list.h>
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. | |
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.
| Val | The gum::List values type. |
| using gum::ListConstIteratorSafe< Val >::const_pointer = const Val* |
| using gum::ListConstIteratorSafe< Val >::const_reference = const Val& |
| using gum::ListConstIteratorSafe< Val >::difference_type = std::ptrdiff_t |
| using gum::ListConstIteratorSafe< Val >::iterator_category = std::bidirectional_iterator_tag |
| using gum::ListConstIteratorSafe< Val >::pointer = Val* |
| using gum::ListConstIteratorSafe< Val >::reference = Val& |
| using gum::ListConstIteratorSafe< Val >::value_type = Val |
|
explicitnoexcept |
Default constructor.
Returns an iterator pointing toward nothing.
Definition at line 507 of file list_tpl.h.
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==().
| gum::ListConstIteratorSafe< Val >::ListConstIteratorSafe | ( | const List< Val > & | theList | ) |
Constructor for a begin.
Definition at line 514 of file list_tpl.h.
References ListConstIteratorSafe(), _bucket_, _list_, and List< Val >.
| gum::ListConstIteratorSafe< Val >::ListConstIteratorSafe | ( | const ListConstIteratorSafe< Val > & | src | ) |
Copy constructor.
| src | The gum::ListConstIteratorSafe to copy. |
Definition at line 525 of file list_tpl.h.
References ListConstIteratorSafe(), _bucket_, _list_, _next_current_bucket_, _null_pointing_, and _prev_current_bucket_.
| gum::ListConstIteratorSafe< Val >::ListConstIteratorSafe | ( | const List< Val > & | theList, |
| Size | ind_elt ) |
Constructor for an iterator pointing to the ind_eltth element of a List.
| theList | The list to iterate over. |
| ind_elt | The iterator starting position. |
| UndefinedIteratorValue | Raised if the element does not exist in the list. |
Definition at line 539 of file list_tpl.h.
References ListConstIteratorSafe(), _list_, GUM_ERROR, and List< Val >.
| gum::ListConstIteratorSafe< Val >::ListConstIteratorSafe | ( | ListConstIteratorSafe< Val > && | src | ) |
Move constructor.
| src | The gum::ListConstIterator to move. |
Definition at line 566 of file list_tpl.h.
References ListConstIteratorSafe(), _bucket_, _list_, _next_current_bucket_, _null_pointing_, and _prev_current_bucket_.
| gum::ListConstIteratorSafe< Val >::~ListConstIteratorSafe | ( | ) |
Class Desctructor.
Definition at line 690 of file list_tpl.h.
References ListConstIteratorSafe(), _list_, and _removeFromSafeList_().
|
privatenoexcept |
Returns the bucket the iterator is pointing to.
Definition at line 700 of file list_tpl.h.
Referenced by gum::List< Val >::_insert_(), gum::List< Val >::erase(), and gum::List< Val >::erase().
|
privatenoexcept |
Makes the iterator point to i elements before in the List.
Definition at line 769 of file list_tpl.h.
References ListConstIteratorSafe(), and _null_pointing_.
Referenced by operator+=(), and operator-=().
|
privatenoexcept |
Makes the iterator point to the next element in the List.
Definition at line 806 of file list_tpl.h.
References ListConstIteratorSafe(), _bucket_, _next_current_bucket_, _null_pointing_, and _prev_current_bucket_.
Referenced by operator+=(), and operator-=().
|
private |
Remove the iterator for its list' safe iterators list.
Definition at line 591 of file list_tpl.h.
References _list_.
Referenced by ~ListConstIteratorSafe(), and clear().
| void gum::ListConstIteratorSafe< Val >::clear | ( | ) |
Makes the iterator point toward nothing.
A method for detaching the iterator from the List it is attached to. It is mainly used by the List when the latter is deleted while the iterator is still alive. After being detached, the iterator does not point to any element, i.e., trying to access its content will raise an exception.
Definition at line 706 of file list_tpl.h.
References _bucket_, _list_, _null_pointing_, and _removeFromSafeList_().
Referenced by setToEnd().
| bool gum::ListConstIteratorSafe< Val >::isEnd | ( | ) | const |
Returns a bool indicating whether the iterator points to the end of the list.
Definition at line 725 of file list_tpl.h.
References _bucket_, _next_current_bucket_, _null_pointing_, and _prev_current_bucket_.
| bool gum::ListConstIteratorSafe< Val >::operator!= | ( | const ListConstIteratorSafe< Val > & | src | ) | const |
Checks whether two iterators point toward different elements.
list1.end() == list2.rend().| src | The gum::ListConstIteratorSafe to test for inequality. |
Definition at line 913 of file list_tpl.h.
References ListConstIteratorSafe(), _bucket_, _next_current_bucket_, _null_pointing_, and _prev_current_bucket_.
| const Val & gum::ListConstIteratorSafe< Val >::operator* | ( | ) | const |
Gives access to the content of the iterator.
| UndefinedIteratorValue | Raised if the iterator points to nothing. |
Definition at line 936 of file list_tpl.h.
References _bucket_, and GUM_ERROR.
Referenced by gum::ListIteratorSafe< Val >::operator*(), and gum::ListIteratorSafe< Val >::operator*().
|
noexcept |
Returns a new iterator pointing to i further elements in the gum::List.
| i | The number of steps to move the iterator. |
Definition at line 899 of file list_tpl.h.
References ListConstIteratorSafe().
|
noexcept |
Makes the iterator point to the next element in the List.
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.
Definition at line 733 of file list_tpl.h.
References ListConstIteratorSafe(), _bucket_, _next_current_bucket_, _null_pointing_, and _prev_current_bucket_.
Referenced by gum::ListIteratorSafe< Val >::operator++().
|
noexcept |
Makes the iterator point to i elements further in the List.
| i | The number of steps to move the iterator. |
Definition at line 843 of file list_tpl.h.
References ListConstIteratorSafe(), _opMinus_(), and _opPlus_().
Referenced by gum::ListIteratorSafe< Val >::operator+=().
|
noexcept |
Returns a new iterator pointing to i preceding elements in the gum::List.
| i | The number of steps to move the iterator. |
Definition at line 906 of file list_tpl.h.
References ListConstIteratorSafe().
|
noexcept |
Makes the iterator point to the preceding element in the List.
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.
Definition at line 853 of file list_tpl.h.
References ListConstIteratorSafe(), _bucket_, _next_current_bucket_, _null_pointing_, and _prev_current_bucket_.
Referenced by gum::ListIteratorSafe< Val >::operator--().
|
noexcept |
Makes the iterator point to i elements befor in the List.
| i | The number of steps to move the iterator. |
Definition at line 889 of file list_tpl.h.
References ListConstIteratorSafe(), _opMinus_(), and _opPlus_().
Referenced by gum::ListIteratorSafe< Val >::operator-=().
| const Val * gum::ListConstIteratorSafe< Val >::operator-> | ( | ) | const |
Dereferences the value pointed to by the iterator.
| UndefinedIteratorValue | Raised if the iterator points to nothing. |
Definition at line 929 of file list_tpl.h.
References _bucket_, and GUM_ERROR.
Referenced by gum::ListIteratorSafe< Val >::operator->(), and gum::ListIteratorSafe< Val >::operator->().
| ListConstIteratorSafe< Val > & gum::ListConstIteratorSafe< Val >::operator= | ( | const ListConstIteratorSafe< Val > & | src | ) |
Copy operator.
The current iterator now points to the same element as iterator from.
| src | The gum::ListConstIteratorSafe to copy. |
Definition at line 606 of file list_tpl.h.
Referenced by gum::ListIteratorSafe< Val >::operator=().
| ListConstIteratorSafe< Val > & gum::ListConstIteratorSafe< Val >::operator= | ( | ListConstIteratorSafe< Val > && | src | ) |
Move operator.
| src | The gum::ListConstIteratorSafe to move. |
Definition at line 645 of file list_tpl.h.
References ListConstIteratorSafe(), and _list_.
| bool gum::ListConstIteratorSafe< Val >::operator== | ( | const ListConstIteratorSafe< Val > & | src | ) | const |
Checks whether two iterators point toward the same elements.
list1.end() == list2.rend().| src | The gum::ListConstIteratorSafe to test for equality. |
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==().
| void gum::ListConstIteratorSafe< Val >::setToEnd | ( | ) |
Positions the iterator to the end of the list.
Definition at line 718 of file list_tpl.h.
References clear().
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().
|
friend |
|
private |
The bucket in the chained list pointed to by the iterator.
Definition at line 2232 of file list.h.
Referenced by ListConstIteratorSafe(), ListConstIteratorSafe(), ListConstIteratorSafe(), _opPlus_(), clear(), isEnd(), operator!=(), operator*(), operator++(), operator--(), operator->(), and operator==().
|
private |
The list the iterator is pointing to.
Definition at line 2229 of file list.h.
Referenced by ListConstIteratorSafe(), ListConstIteratorSafe(), ListConstIteratorSafe(), ListConstIteratorSafe(), ~ListConstIteratorSafe(), _removeFromSafeList_(), clear(), gum::List< gum::Instantiation * >::crend(), gum::List< Val >::insert(), gum::List< Val >::insert(), operator=(), and gum::List< gum::Instantiation * >::rend().
|
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.
Referenced by ListConstIteratorSafe(), ListConstIteratorSafe(), gum::List< Val >::_insert_(), _opPlus_(), isEnd(), operator!=(), operator++(), operator--(), and operator==().
|
private |
Indicates whether the bucket the iterator points to has been deleted.
Definition at line 2243 of file list.h.
Referenced by ListConstIteratorSafe(), ListConstIteratorSafe(), gum::List< Val >::_insert_(), _opMinus_(), _opPlus_(), clear(), isEnd(), operator!=(), operator++(), operator--(), and operator==().
|
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.
Referenced by ListConstIteratorSafe(), ListConstIteratorSafe(), gum::List< Val >::_insert_(), _opPlus_(), isEnd(), operator!=(), operator++(), operator--(), and operator==().