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

Safe iterators for the Set classDevelopers may consider using Set<x>::iterator_safe instead of SetIteratorSafe<x>. More...

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

+ Collaboration diagram for gum::SetIteratorSafe< Key >:

Public Member Functions

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

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. More...
 
using value_type = Key
 Types for STL compliance. More...
 
using reference = value_type &
 Types for STL compliance. More...
 
using const_reference = const value_type &
 Types for STL compliance. More...
 
using pointer = value_type *
 Types for STL compliance. More...
 
using const_pointer = const value_type *
 Types for STL compliance. More...
 
using difference_type = std::ptrdiff_t
 Types for STL compliance. More...
 

Friends

template<typename K , typename A >
class Set
 For efficiency, Set should be able to modify the hash table iterator. More...
 

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
Set<int> set;
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";
Template Parameters
KeyThe elements type.

Definition at line 816 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 825 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 823 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 826 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 820 of file set.h.

◆ pointer

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

Types for STL compliance.

Definition at line 824 of file set.h.

◆ reference

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

Types for STL compliance.

Definition at line 822 of file set.h.

◆ value_type

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

Types for STL compliance.

Definition at line 821 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 833 of file set.h.

834  {
835  BEGIN,
836  END
837  };

Constructor & Destructor Documentation

◆ SetIteratorSafe() [1/6]

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

Default constructor: the iterator points toward nothing.

Definition at line 39 of file set_tpl.h.

39  {
40  GUM_CONSTRUCTOR(SetIteratorSafe);
41  }
SetIteratorSafe()
Default constructor: the iterator points toward nothing.
Definition: set_tpl.h:39

◆ SetIteratorSafe() [2/6]

template<typename Key>
template<typename Alloc >
gum::SetIteratorSafe< Key >::SetIteratorSafe ( const Set< Key, Alloc > &  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().

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

◆ SetIteratorSafe() [3/6]

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

Copy constructor.

Parameters
fromThe iterator to copy.

Definition at line 54 of file set_tpl.h.

54  :
55  _ht_iter_{iter._ht_iter_} {
56  GUM_CONS_CPY(SetIteratorSafe);
57  }
HashTableConstIteratorSafe< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:990
SetIteratorSafe()
Default constructor: the iterator points toward nothing.
Definition: set_tpl.h:39

◆ SetIteratorSafe() [4/6]

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

Copy constructor.

Parameters
fromThe iterator to copy.

Definition at line 61 of file set_tpl.h.

61  :
62  _ht_iter_{iter._ht_iter_} {
63  GUM_CONS_CPY(SetIteratorSafe);
64  }
HashTableConstIteratorSafe< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:990
SetIteratorSafe()
Default constructor: the iterator points toward nothing.
Definition: set_tpl.h:39

◆ SetIteratorSafe() [5/6]

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

Move constructor.

Parameters
fromThe iterator to move.

Definition at line 68 of file set_tpl.h.

68  :
69  _ht_iter_{std::move(from._ht_iter_)} {
70  GUM_CONS_MOV(SetIteratorSafe);
71  }
HashTableConstIteratorSafe< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:990
SetIteratorSafe()
Default constructor: the iterator points toward nothing.
Definition: set_tpl.h:39

◆ ~SetIteratorSafe()

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

Class destructor.

Definition at line 75 of file set_tpl.h.

75  {
76  GUM_DESTRUCTOR(SetIteratorSafe);
77  }
SetIteratorSafe()
Default constructor: the iterator points toward nothing.
Definition: set_tpl.h:39

◆ SetIteratorSafe() [6/6]

template<typename Key>
template<typename Alloc >
INLINE gum::SetIteratorSafe< Key >::SetIteratorSafe ( const Set< Key, Alloc > &  set,
Position  pos 
)

Definition at line 46 of file set_tpl.h.

46  :
47  _ht_iter_{pos == SetIteratorSafe< Key >::END ? set._inside_.cendSafe()
48  : set._inside_.cbeginSafe()} {
49  GUM_CONSTRUCTOR(SetIteratorSafe);
50  }
HashTableConstIteratorSafe< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:990
SetIteratorSafe()
Default constructor: the iterator points toward nothing.
Definition: set_tpl.h:39

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

159  {
160  _ht_iter_.clear();
161  }
HashTableConstIteratorSafe< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:990
void clear() noexcept
Makes the iterator point toward nothing (in particular, it is not related anymore to its current hash...

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

128  {
129  return _ht_iter_ != from._ht_iter_;
130  }
HashTableConstIteratorSafe< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:990

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

142  {
143  // note that, if the hashtable's iterator points toward nothing, it will
144  // raise an UndefinedIteratorValue exception
145  return _ht_iter_.key();
146  }
const key_type & key() const
Returns the key pointed to by the iterator.
HashTableConstIteratorSafe< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:990

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

121  {
122  return SetIteratorSafe< Key >{*this} += nb;
123  }

◆ operator++()

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

Increments the iterator.

Returns
This iterator.

Definition at line 104 of file set_tpl.h.

104  {
105  // note that, if the hashtable's iterator points toward nothing, the
106  // hashtable's iterator incrementation will do nothing. In particular, it
107  // will not segfault.
108  ++_ht_iter_;
109  return *this;
110  }
HashTableConstIteratorSafe< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:990

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

114  {
115  _ht_iter_ += nb;
116  return *this;
117  }
HashTableConstIteratorSafe< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:990

◆ 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 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  }
const key_type & key() const
Returns the key pointed to by the iterator.
HashTableConstIteratorSafe< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:990

◆ operator=() [1/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 82 of file set_tpl.h.

82  {
83  _ht_iter_ = from._ht_iter_;
84  return *this;
85  }
HashTableConstIteratorSafe< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:990

◆ operator=() [2/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 89 of file set_tpl.h.

89  {
90  _ht_iter_ = from._ht_iter_;
91  return *this;
92  }
HashTableConstIteratorSafe< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:990

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

97  {
98  _ht_iter_ = std::move(from._ht_iter_);
99  return *this;
100  }
HashTableConstIteratorSafe< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:990

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

136  {
137  return _ht_iter_ == from._ht_iter_;
138  }
HashTableConstIteratorSafe< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:990

Friends And Related Function Documentation

◆ Set

template<typename Key>
template<typename K , typename A >
friend class Set
friend

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

Definition at line 987 of file set.h.

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 990 of file set.h.


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