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

Safe iterators for the Set class. More...

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

Collaboration diagram for gum::SetIteratorSafe< Key >:

Public Types

enum  Position { BEGIN , END }
 An enumeration to position the iterator at the beginning or the end of the set. More...
using iterator_category = std::forward_iterator_tag
 Types for STL compliance.
using value_type = Key
 Types for STL compliance.
using reference = value_type&
 Types for STL compliance.
using const_reference = const value_type&
 Types for STL compliance.
using pointer = value_type*
 Types for STL compliance.
using const_pointer = const value_type*
 Types for STL compliance.
using difference_type = std::ptrdiff_t
 Types for STL compliance.

Public Member Functions

Constructors / Destructors
 SetIteratorSafe ()
 Default constructor: the iterator points toward nothing.
 SetIteratorSafe (const Set< Key > &from, Position pos=BEGIN)
 Creates an iterator for a given set.
 SetIteratorSafe (const SetIteratorSafe< Key > &from)
 Copy constructor.
 SetIteratorSafe (const SetIterator< Key > &from)
 Copy constructor.
 SetIteratorSafe (SetIteratorSafe< Key > &&from)
 Move constructor.
 ~SetIteratorSafe () noexcept
 Class destructor.
Operators
SetIteratorSafe< Key > & operator= (const SetIteratorSafe< Key > &from)
 Assignment operator.
SetIteratorSafe< Key > & operator= (const SetIterator< Key > &from)
 Assignment operator.
SetIteratorSafe< Key > & operator= (SetIteratorSafe< Key > &&from) noexcept
 Assignment operator.
SetIteratorSafe< Key > & operator++ () noexcept
 Increments the iterator.
SetIteratorSafe< Key > & operator+= (Size i) noexcept
 Makes the iterator point to i elements further in the set.
SetIteratorSafe< Key > operator+ (Size i) const
 Returns a new iterator.
bool operator!= (const SetIteratorSafe< Key > &from) const noexcept
 Indicates whether two iterators point to different elements or sets.
bool operator== (const SetIteratorSafe< Key > &from) const noexcept
 Indicates whether two iterators point toward the same element of a same set.
const Key & operator* () const
 Returns the element pointed to by the iterator.
const Key * operator-> () const
 Returns a pointer to the element pointed to by the iterator.
Accessors / Modifiers
void clear () noexcept
 makes the iterator point toward nothing (in particular, it is not related anymore to its current set).

Private Attributes

HashTableConstIteratorSafe< Key, bool_ht_iter_
 The underlying iterator for the set's hash table containing the data.

Friends

class Set< Key >
 For efficiency, Set should be able to modify the hash table iterator.

Detailed Description

template<typename Key>
class gum::SetIteratorSafe< Key >

Safe iterators for the Set class.

Developers may consider using Set<x>::iterator_safe instead of SetIteratorSafe<x>.

Usage example:
// creation of a set with 10 elements
for (int i = 0; i< 10; ++i)
set<<i;
// parse the set
for (const auto iter = table.beginSafe (); iter != table.endSafe (); ++iter) {
// display the values
cerr << *iter << endl;
}
// check whether two iterators point toward the same element
Set<int>::iterator_safe iter1 = table1.beginSafe();
Set<int>::iterator_safe iter2 = table1.endSafe();
if (iter1 != iter)
cerr << "iter1 and iter2 point toward different elements";
Representation of a set.
Definition set.h:131
SetIteratorSafe< Key > iterator_safe
Types for STL compliance.
Definition set.h:144
Template Parameters
KeyThe elements type.

Definition at line 601 of file set.h.

Member Typedef Documentation

◆ const_pointer

template<typename Key>
using gum::SetIteratorSafe< Key >::const_pointer = const value_type*

Types for STL compliance.

Definition at line 610 of file set.h.

◆ const_reference

template<typename Key>
using gum::SetIteratorSafe< Key >::const_reference = const value_type&

Types for STL compliance.

Definition at line 608 of file set.h.

◆ difference_type

template<typename Key>
using gum::SetIteratorSafe< Key >::difference_type = std::ptrdiff_t

Types for STL compliance.

Definition at line 611 of file set.h.

◆ iterator_category

template<typename Key>
using gum::SetIteratorSafe< Key >::iterator_category = std::forward_iterator_tag

Types for STL compliance.

Definition at line 605 of file set.h.

◆ pointer

template<typename Key>
using gum::SetIteratorSafe< Key >::pointer = value_type*

Types for STL compliance.

Definition at line 609 of file set.h.

◆ reference

template<typename Key>
using gum::SetIteratorSafe< Key >::reference = value_type&

Types for STL compliance.

Definition at line 607 of file set.h.

◆ value_type

template<typename Key>
using gum::SetIteratorSafe< Key >::value_type = Key

Types for STL compliance.

Definition at line 606 of file set.h.

Member Enumeration Documentation

◆ Position

template<typename Key>
enum gum::SetIteratorSafe::Position

An enumeration to position the iterator at the beginning or the end of the set.

Enumerator
BEGIN 
END 

Definition at line 619 of file set.h.

Constructor & Destructor Documentation

◆ SetIteratorSafe() [1/5]

template<typename Key>
INLINE gum::SetIteratorSafe< Key >::SetIteratorSafe ( )
explicit

Default constructor: the iterator points toward nothing.

Definition at line 60 of file set_tpl.h.

60 {
62 }
Safe iterators for the Set class.
Definition set.h:601
SetIteratorSafe()
Default constructor: the iterator points toward nothing.
Definition set_tpl.h:60

References SetIteratorSafe().

Referenced by SetIteratorSafe(), SetIteratorSafe(), SetIteratorSafe(), SetIteratorSafe(), SetIteratorSafe(), ~SetIteratorSafe(), operator!=(), operator+(), operator++(), operator+=(), operator=(), operator=(), operator=(), and operator==().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetIteratorSafe() [2/5]

template<typename Key>
INLINE gum::SetIteratorSafe< Key >::SetIteratorSafe ( const Set< Key > & from,
Position pos = BEGIN )

Creates an iterator for a given set.

By default, the iterator points to the beginning of the set, but, using optional argument pos, you can make it point to end().

Parameters
fromThe gum::Set to iterate over.
posWhere to start iterating.

Definition at line 66 of file set_tpl.h.

66 :
67 _ht_iter_{pos == SetIteratorSafe< Key >::END ? set._inside_.cendSafe()
68 : set._inside_.cbeginSafe()} {
70 }
HashTableConstIteratorSafe< Key, bool > _ht_iter_
The underlying iterator for the set's hash table containing the data.
Definition set.h:775

References SetIteratorSafe(), _ht_iter_, END, and Set< Key >.

Here is the call graph for this function:

◆ SetIteratorSafe() [3/5]

template<typename Key>
INLINE gum::SetIteratorSafe< Key >::SetIteratorSafe ( const SetIteratorSafe< Key > & from)

Copy constructor.

Parameters
fromThe iterator to copy.

Definition at line 74 of file set_tpl.h.

References SetIteratorSafe(), and _ht_iter_.

Here is the call graph for this function:

◆ SetIteratorSafe() [4/5]

template<typename Key>
INLINE gum::SetIteratorSafe< Key >::SetIteratorSafe ( const SetIterator< Key > & from)
explicit

Copy constructor.

Parameters
fromThe iterator to copy.

Definition at line 81 of file set_tpl.h.

References SetIteratorSafe(), and _ht_iter_.

Here is the call graph for this function:

◆ SetIteratorSafe() [5/5]

template<typename Key>
INLINE gum::SetIteratorSafe< Key >::SetIteratorSafe ( SetIteratorSafe< Key > && from)

Move constructor.

Parameters
fromThe iterator to move.

Definition at line 88 of file set_tpl.h.

References SetIteratorSafe(), and _ht_iter_.

Here is the call graph for this function:

◆ ~SetIteratorSafe()

template<typename Key>
INLINE gum::SetIteratorSafe< Key >::~SetIteratorSafe ( )
noexcept

Class destructor.

Definition at line 95 of file set_tpl.h.

References SetIteratorSafe().

Here is the call graph for this function:

Member Function Documentation

◆ clear()

template<typename Key>
INLINE void gum::SetIteratorSafe< Key >::clear ( )
noexcept

makes the iterator point toward nothing (in particular, it is not related anymore to its current set).

Definition at line 179 of file set_tpl.h.

179 {
180 _ht_iter_.clear();
181 }

References _ht_iter_.

◆ operator!=()

template<typename Key>
INLINE bool gum::SetIteratorSafe< Key >::operator!= ( const SetIteratorSafe< Key > & from) const
noexcept

Indicates whether two iterators point to different elements or sets.

Parameters
fromThe iterator to test for inequality.
Returns
Returns true if both iterator are not equal.

Definition at line 148 of file set_tpl.h.

148 {
149 return _ht_iter_ != from._ht_iter_;
150 }

References SetIteratorSafe(), and _ht_iter_.

Here is the call graph for this function:

◆ operator*()

template<typename Key>
INLINE const Key & gum::SetIteratorSafe< Key >::operator* ( ) const

Returns the element pointed to by the iterator.

Exceptions
UndefinedIteratorValueRaised if the iterator does not point to an element of the set (for instance if the set or the element previously pointed to by the iterator have been deleted).
Returns
Returns the element pointed to by the iterator.

Definition at line 162 of file set_tpl.h.

162 {
163 // note that, if the hashtable's iterator points toward nothing, it will
164 // raise an UndefinedIteratorValue exception
165 return _ht_iter_.key();
166 }

◆ operator+()

template<typename Key>
INLINE SetIteratorSafe< Key > gum::SetIteratorSafe< Key >::operator+ ( Size i) const

Returns a new iterator.

Parameters
iThe number of increments.
Returns
Returns a new iterator.

Definition at line 141 of file set_tpl.h.

141 {
142 return SetIteratorSafe< Key >{*this} += nb;
143 }

References SetIteratorSafe().

Here is the call graph for this function:

◆ operator++()

template<typename Key>
INLINE SetIteratorSafe< Key > & gum::SetIteratorSafe< Key >::operator++ ( )
noexcept

Increments the iterator.

Returns
This iterator.

Definition at line 124 of file set_tpl.h.

124 {
125 // note that, if the hashtable's iterator points toward nothing, the
126 // hashtable's iterator incrementation will do nothing. In particular, it
127 // will not segfault.
128 ++_ht_iter_;
129 return *this;
130 }

References SetIteratorSafe(), and _ht_iter_.

Here is the call graph for this function:

◆ operator+=()

template<typename Key>
INLINE SetIteratorSafe< Key > & gum::SetIteratorSafe< Key >::operator+= ( Size i)
noexcept

Makes the iterator point to i elements further in the set.

Parameters
iThe number of increments.
Returns
Returns this iterator.

Definition at line 134 of file set_tpl.h.

134 {
135 _ht_iter_ += nb;
136 return *this;
137 }

References SetIteratorSafe(), and _ht_iter_.

Here is the call graph for this function:

◆ operator->()

template<typename Key>
INLINE const Key * gum::SetIteratorSafe< Key >::operator-> ( ) const

Returns a pointer to the element pointed to by the iterator.

Exceptions
UndefinedIteratorValueRaised if the iterator does not point to an element of the set (for instance if the set or the element previously pointed to by the iterator have been deleted).
Returns
Returns a pointer to the element pointed to by the iterator.

Definition at line 170 of file set_tpl.h.

170 {
171 // note that, if the hashtable's iterator points toward nothing, it will
172 // raise an UndefinedIteratorValue exception
173 return &(_ht_iter_.key());
174 }

References _ht_iter_.

◆ operator=() [1/3]

template<typename Key>
INLINE SetIteratorSafe< Key > & gum::SetIteratorSafe< Key >::operator= ( const SetIterator< Key > & from)

Assignment operator.

Parameters
fromThe iterator to copy.
Returns
Returns this iterator.

Definition at line 109 of file set_tpl.h.

109 {
111 return *this;
112 }

References SetIteratorSafe(), gum::SetIterator< Key >::_ht_iter_, and _ht_iter_.

Here is the call graph for this function:

◆ operator=() [2/3]

template<typename Key>
INLINE SetIteratorSafe< Key > & gum::SetIteratorSafe< Key >::operator= ( const SetIteratorSafe< Key > & from)

Assignment operator.

Parameters
fromThe iterator to copy.
Returns
Returns this iterator.

Definition at line 102 of file set_tpl.h.

102 {
104 return *this;
105 }

References SetIteratorSafe(), and _ht_iter_.

Here is the call graph for this function:

◆ operator=() [3/3]

template<typename Key>
INLINE SetIteratorSafe< Key > & gum::SetIteratorSafe< Key >::operator= ( SetIteratorSafe< Key > && from)
noexcept

Assignment operator.

Parameters
fromThe iterator to move.
Returns
Returns this iterator.

Definition at line 117 of file set_tpl.h.

117 {
119 return *this;
120 }

References SetIteratorSafe(), and _ht_iter_.

Here is the call graph for this function:

◆ operator==()

template<typename Key>
INLINE bool gum::SetIteratorSafe< Key >::operator== ( const SetIteratorSafe< Key > & from) const
noexcept

Indicates whether two iterators point toward the same element of a same set.

Parameters
fromThe iterator to test for equality.
Returns
Returns true if both iterator are equal.

Definition at line 156 of file set_tpl.h.

156 {
157 return _ht_iter_ == from._ht_iter_;
158 }

References SetIteratorSafe(), and _ht_iter_.

Here is the call graph for this function:

◆ Set< Key >

template<typename Key>
friend class Set< Key >
friend

For efficiency, Set should be able to modify the hash table iterator.

Definition at line 766 of file set.h.

Referenced by SetIteratorSafe().

Member Data Documentation

◆ _ht_iter_

template<typename Key>
HashTableConstIteratorSafe< Key, bool > gum::SetIteratorSafe< Key >::_ht_iter_
private

The underlying iterator for the set's hash table containing the data.

Definition at line 775 of file set.h.

Referenced by SetIteratorSafe(), SetIteratorSafe(), SetIteratorSafe(), SetIteratorSafe(), clear(), gum::Set< Key >::erase(), operator!=(), operator++(), operator+=(), operator->(), operator=(), operator=(), operator=(), and operator==().


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