aGrUM 3.1.1
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 class  Position : unsigned char { 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=Position::BEGIN)
 Creates an iterator for a given set.
 SetIteratorSafe (const SetIteratorSafe< Key > &from)
 Copy constructor.
 SetIteratorSafe (const SetIterator< Key > &iter)
 Copy constructor.
 SetIteratorSafe (SetIteratorSafe< Key > &&from) noexcept
 Move constructor.
 ~SetIteratorSafe () noexcept
 Class destructor.
Operators
SetIteratorSafe< Key > & operator= (const SetIteratorSafe< Key > &from)
 Assignment operator.
SetIteratorSafe< Key > & operator= (const SetIterator< Key > &iter)
 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 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:129
SetIteratorSafe< Key > iterator_safe
Types for STL compliance.
Definition set.h:142
Template Parameters
KeyThe elements type.

Definition at line 592 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 601 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 599 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 602 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 596 of file set.h.

◆ pointer

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

Types for STL compliance.

Definition at line 600 of file set.h.

◆ reference

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

Types for STL compliance.

Definition at line 598 of file set.h.

◆ value_type

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

Types for STL compliance.

Definition at line 597 of file set.h.

Member Enumeration Documentation

◆ Position

template<typename Key>
enum class gum::SetIteratorSafe::Position : unsigned char
strong

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

Enumerator
BEGIN 
END 

Definition at line 610 of file set.h.

610: unsigned char { BEGIN, END };

Constructor & Destructor Documentation

◆ SetIteratorSafe() [1/5]

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

Default constructor: the iterator points toward nothing.

Definition at line 61 of file set_tpl.h.

61 {
63 }
Safe iterators for the Set class.
Definition set.h:592
SetIteratorSafe()
Default constructor: the iterator points toward nothing.
Definition set_tpl.h:61

References SetIteratorSafe().

Referenced by SetIteratorSafe(), SetIteratorSafe(), SetIteratorSafe(), SetIteratorSafe(), SetIteratorSafe(), ~SetIteratorSafe(), 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>
gum::SetIteratorSafe< Key >::SetIteratorSafe ( const Set< Key > & from,
Position pos = Position::BEGIN )
explicit

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 67 of file set_tpl.h.

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

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

Here is the call graph for this function:

◆ SetIteratorSafe() [3/5]

template<typename Key>
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>
gum::SetIteratorSafe< Key >::SetIteratorSafe ( const SetIterator< Key > & iter)
explicit

Copy constructor.

Parameters
iterThe 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>
gum::SetIteratorSafe< Key >::SetIteratorSafe ( SetIteratorSafe< Key > && from)
noexcept

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>
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>
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 167 of file set_tpl.h.

167 {
168 _ht_iter_.clear();
169 }

References _ht_iter_.

◆ operator*()

template<typename Key>
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 150 of file set_tpl.h.

150 {
151 // note that, if the hashtable's iterator points toward nothing, it will
152 // raise an UndefinedIteratorValue exception
153 return _ht_iter_.key();
154 }

References _ht_iter_.

◆ operator+()

template<typename Key>
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 138 of file set_tpl.h.

138 {
139 return SetIteratorSafe< Key >{*this} += nb;
140 }

References SetIteratorSafe().

Here is the call graph for this function:

◆ operator++()

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

Increments the iterator.

Returns
This iterator.

Definition at line 121 of file set_tpl.h.

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

References SetIteratorSafe(), and _ht_iter_.

Here is the call graph for this function:

◆ operator+=()

template<typename Key>
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 131 of file set_tpl.h.

131 {
132 _ht_iter_ += nb;
133 return *this;
134 }

References SetIteratorSafe(), and _ht_iter_.

Here is the call graph for this function:

◆ operator->()

template<typename Key>
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 158 of file set_tpl.h.

158 {
159 // note that, if the hashtable's iterator points toward nothing, it will
160 // raise an UndefinedIteratorValue exception
161 return &(_ht_iter_.key());
162 }

References _ht_iter_.

◆ operator=() [1/3]

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

Assignment operator.

Parameters
iterThe iterator to copy.
Returns
Returns this iterator.

Definition at line 106 of file set_tpl.h.

106 {
108 return *this;
109 }

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

Here is the call graph for this function:

◆ operator=() [2/3]

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

Assignment operator.

Parameters
fromThe iterator to copy.
Returns
Returns this iterator.

◆ operator=() [3/3]

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

Assignment operator.

Parameters
fromThe iterator to move.
Returns
Returns this iterator.

Definition at line 114 of file set_tpl.h.

114 {
116 return *this;
117 }

References SetIteratorSafe(), and _ht_iter_.

Here is the call graph for this function:

◆ operator==()

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

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.

◆ 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 753 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 762 of file set.h.

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


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