STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
__gnu_debug::_Safe_local_iterator< _Iterator, _Sequence > Class Template Reference

Safe iterator wrapper. More...

#include <debug/formatter.h>

Inheritance diagram for __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >:
__gnu_debug::_Safe_local_iterator_base __gnu_debug::_Safe_iterator_base

Public Types

typedef _Iterator iterator_type
 
typedef _Traits::iterator_category iterator_category
 
typedef _Traits::value_type value_type
 
typedef _Traits::difference_type difference_type
 
typedef _Traits::reference reference
 
typedef _Traits::pointer pointer
 

Public Member Functions

 _Safe_local_iterator ()
 
 _Safe_local_iterator (const _Iterator &__i, size_type __bucket, const _Sequence *__seq)
 Safe iterator construction from an unsafe iterator and its sequence. More...
 
 _Safe_local_iterator (const _Safe_local_iterator &__x)
 Copy construction. More...
 
template<typename _MutableIterator >
 _Safe_local_iterator (const _Safe_local_iterator< _MutableIterator, typename __gnu_cxx::__enable_if< std::__are_same< _MutableIterator, typename _Sequence::local_iterator::iterator_type >::__value, _Sequence >::__type > &__x)
 Converting constructor from a mutable iterator to a constant iterator. More...
 
_Safe_local_iteratoroperator= (const _Safe_local_iterator &__x)
 Copy assignment. More...
 
reference operator* () const
 Iterator dereference. More...
 
pointer operator-> () const
 Iterator dereference. More...
 
_Safe_local_iteratoroperator++ ()
 Iterator preincrement. More...
 
_Safe_local_iterator operator++ (int)
 Iterator postincrement. More...
 
_Iterator base () const
 Return the underlying iterator. More...
 
size_type bucket () const
 Return the bucket. More...
 
 operator _Iterator () const
 Conversion to underlying non-debug iterator to allow better interaction with non-debug containers. More...
 
void _M_attach (_Safe_sequence_base *__seq)
 
void _M_attach_single (_Safe_sequence_base *__seq)
 
bool _M_dereferenceable () const
 Is the iterator dereferenceable? More...
 
bool _M_incrementable () const
 Is the iterator incrementable? More...
 
template<typename _Other >
bool _M_valid_range (const _Safe_local_iterator< _Other, _Sequence > &__rhs) const
 
const _Sequence * _M_get_sequence () const
 
bool _M_is_begin () const
 Is this iterator equal to the sequence's begin() iterator? More...
 
bool _M_is_end () const
 Is this iterator equal to the sequence's end() iterator? More...
 
template<typename _Other >
bool _M_in_same_bucket (const _Safe_local_iterator< _Other, _Sequence > &__other) const
 Is this iterator part of the same bucket as the other one? More...
 
- Public Member Functions inherited from __gnu_debug::_Safe_local_iterator_base
void _M_attach (_Safe_sequence_base *__seq, bool __constant)
 
void _M_attach_single (_Safe_sequence_base *__seq, bool __constant) throw ()
 
void _M_detach ()
 
void _M_detach_single () throw ()
 
- Public Member Functions inherited from __gnu_debug::_Safe_iterator_base
void _M_attach (_Safe_sequence_base *__seq, bool __constant)
 
void _M_attach_single (_Safe_sequence_base *__seq, bool __constant) throw ()
 
void _M_detach ()
 
void _M_detach_single () throw ()
 
bool _M_attached_to (const _Safe_sequence_base *__seq) const
 
_GLIBCXX_PURE bool _M_singular () const throw ()
 
_GLIBCXX_PURE bool _M_can_compare (const _Safe_iterator_base &__x) const throw ()
 
void _M_invalidate ()
 
void _M_reset () throw ()
 
void _M_unlink () throw ()
 

Private Types

typedef _Safe_local_iterator _Self
 
typedef _Sequence::size_type size_type
 
typedef std::iterator_traits
< _Iterator > 
_Traits
 

Private Member Functions

bool _M_constant () const
 Determine if this is a constant iterator. More...
 

Private Attributes

_Iterator _M_current
 The underlying iterator. More...
 
size_type _M_bucket
 The bucket this local iterator belongs to. More...
 

Additional Inherited Members

- Public Attributes inherited from __gnu_debug::_Safe_iterator_base
_Safe_sequence_base_M_sequence
 
unsigned int _M_version
 
_Safe_iterator_base_M_prior
 
_Safe_iterator_base_M_next
 
- Protected Member Functions inherited from __gnu_debug::_Safe_local_iterator_base
 _Safe_local_iterator_base ()
 
 _Safe_local_iterator_base (const _Safe_sequence_base *__seq, bool __constant)
 
 _Safe_local_iterator_base (const _Safe_local_iterator_base &__x, bool __constant)
 
_Safe_local_iterator_baseoperator= (const _Safe_local_iterator_base &)
 
 _Safe_local_iterator_base (const _Safe_local_iterator_base &)
 
 ~_Safe_local_iterator_base ()
 
_Safe_unordered_container_base_M_get_container () const _GLIBCXX_NOEXCEPT
 
- Protected Member Functions inherited from __gnu_debug::_Safe_iterator_base
 _Safe_iterator_base ()
 
 _Safe_iterator_base (const _Safe_sequence_base *__seq, bool __constant)
 
 _Safe_iterator_base (const _Safe_iterator_base &__x, bool __constant)
 
_Safe_iterator_baseoperator= (const _Safe_iterator_base &)
 
 _Safe_iterator_base (const _Safe_iterator_base &)
 
 ~_Safe_iterator_base ()
 
__gnu_cxx::__mutex & _M_get_mutex () throw ()
 

Detailed Description

template<typename _Iterator, typename _Sequence>
class __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >

Safe iterator wrapper.

The class template _Safe_local_iterator is a wrapper around an iterator that tracks the iterator's movement among sequences and checks that operations performed on the "safe" iterator are legal. In additional to the basic iterator operations (which are validated, and then passed to the underlying iterator), _Safe_local_iterator has member functions for iterator invalidation, attaching/detaching the iterator from sequences, and querying the iterator's state.

Member Typedef Documentation

template<typename _Iterator, typename _Sequence>
typedef _Safe_local_iterator __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::_Self
private
template<typename _Iterator, typename _Sequence>
typedef std::iterator_traits<_Iterator> __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::_Traits
private
template<typename _Iterator, typename _Sequence>
typedef _Traits::difference_type __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::difference_type
template<typename _Iterator, typename _Sequence>
typedef _Traits::iterator_category __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::iterator_category
template<typename _Iterator, typename _Sequence>
typedef _Iterator __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::iterator_type
template<typename _Iterator, typename _Sequence>
typedef _Traits::pointer __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::pointer
template<typename _Iterator, typename _Sequence>
typedef _Traits::reference __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::reference
template<typename _Iterator, typename _Sequence>
typedef _Sequence::size_type __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::size_type
private
template<typename _Iterator, typename _Sequence>
typedef _Traits::value_type __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::value_type

Constructor & Destructor Documentation

template<typename _Iterator, typename _Sequence>
__gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::_Safe_local_iterator ( )
inline
Postcondition
the iterator is singular and unattached
82 : _M_current() { }
_Iterator _M_current
The underlying iterator.
Definition: safe_local_iterator.h:58
template<typename _Iterator, typename _Sequence>
__gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::_Safe_local_iterator ( const _Iterator &  __i,
size_type  __bucket,
const _Sequence *  __seq 
)
inline

Safe iterator construction from an unsafe iterator and its sequence.

Precondition
seq is not NULL
Postcondition
this is not singular
94  _M_bucket(__bucket)
95  {
97  _M_message(__msg_init_singular)
98  ._M_iterator(*this, "this"));
99  }
_Iterator _M_current
The underlying iterator.
Definition: safe_local_iterator.h:58
size_type _M_bucket
The bucket this local iterator belongs to.
Definition: safe_local_iterator.h:61
_Safe_local_iterator_base()
Definition: safe_unordered_base.h:54
bool _M_constant() const
Determine if this is a constant iterator.
Definition: safe_local_iterator.h:65
Definition: formatter.h:81
_GLIBCXX_PURE bool _M_singular() const
#define _GLIBCXX_DEBUG_VERIFY(_Condition, _ErrorMessage)
Definition: macros.h:49
template<typename _Iterator, typename _Sequence>
__gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::_Safe_local_iterator ( const _Safe_local_iterator< _Iterator, _Sequence > &  __x)
inline

Copy construction.

106  _M_current(__x._M_current), _M_bucket(__x._M_bucket)
107  {
108  // _GLIBCXX_RESOLVE_LIB_DEFECTS
109  // DR 408. Is vector<reverse_iterator<char*> > forbidden?
110  _GLIBCXX_DEBUG_VERIFY(!__x._M_singular()
111  || __x._M_current == _Iterator(),
112  _M_message(__msg_init_copy_singular)
113  ._M_iterator(*this, "this")
114  ._M_iterator(__x, "other"));
115  }
_Iterator _M_current
The underlying iterator.
Definition: safe_local_iterator.h:58
size_type _M_bucket
The bucket this local iterator belongs to.
Definition: safe_local_iterator.h:61
_Safe_local_iterator_base()
Definition: safe_unordered_base.h:54
bool _M_constant() const
Determine if this is a constant iterator.
Definition: safe_local_iterator.h:65
#define _GLIBCXX_DEBUG_VERIFY(_Condition, _ErrorMessage)
Definition: macros.h:49
Definition: formatter.h:82
template<typename _Iterator, typename _Sequence>
template<typename _MutableIterator >
__gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::_Safe_local_iterator ( const _Safe_local_iterator< _MutableIterator, typename __gnu_cxx::__enable_if< std::__are_same< _MutableIterator, typename _Sequence::local_iterator::iterator_type >::__value, _Sequence >::__type > &  __x)
inline

Converting constructor from a mutable iterator to a constant iterator.

129  _M_current(__x.base()), _M_bucket(__x._M_bucket)
130  {
131  // _GLIBCXX_RESOLVE_LIB_DEFECTS
132  // DR 408. Is vector<reverse_iterator<char*> > forbidden?
133  _GLIBCXX_DEBUG_VERIFY(!__x._M_singular()
134  || __x.base() == _Iterator(),
135  _M_message(__msg_init_const_singular)
136  ._M_iterator(*this, "this")
137  ._M_iterator(__x, "other"));
138  }
_Iterator _M_current
The underlying iterator.
Definition: safe_local_iterator.h:58
size_type _M_bucket
The bucket this local iterator belongs to.
Definition: safe_local_iterator.h:61
Definition: formatter.h:83
_Safe_local_iterator_base()
Definition: safe_unordered_base.h:54
bool _M_constant() const
Determine if this is a constant iterator.
Definition: safe_local_iterator.h:65
#define _GLIBCXX_DEBUG_VERIFY(_Condition, _ErrorMessage)
Definition: macros.h:49

Member Function Documentation

template<typename _Iterator, typename _Sequence>
void __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::_M_attach ( _Safe_sequence_base __seq)
inline

Attach iterator to the given sequence.

void _M_attach(_Safe_sequence_base *__seq, bool __constant)
bool _M_constant() const
Determine if this is a constant iterator.
Definition: safe_local_iterator.h:65
template<typename _Iterator, typename _Sequence>
void __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::_M_attach_single ( _Safe_sequence_base __seq)
inline

Likewise, but not thread-safe.

void _M_attach_single(_Safe_sequence_base *__seq, bool __constant)
bool _M_constant() const
Determine if this is a constant iterator.
Definition: safe_local_iterator.h:65
template<typename _Iterator, typename _Sequence>
bool __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::_M_constant ( ) const
inlineprivate

Determine if this is a constant iterator.

66  {
67  typedef typename _Sequence::const_local_iterator const_iterator;
68  return std::__are_same<const_iterator, _Safe_local_iterator>::__value;
69  }
template<typename _Iterator, typename _Sequence>
bool __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::_M_dereferenceable ( ) const
inline

Is the iterator dereferenceable?

249  { return !this->_M_singular() && !_M_is_end(); }
_GLIBCXX_PURE bool _M_singular() const
bool _M_is_end() const
Is this iterator equal to the sequence's end() iterator?
Definition: safe_local_iterator.h:272
template<typename _Iterator, typename _Sequence>
const _Sequence* __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::_M_get_sequence ( ) const
inline
265  { return static_cast<const _Sequence*>(_M_sequence); }
_Safe_sequence_base * _M_sequence
Definition: safe_base.h:55
template<typename _Iterator, typename _Sequence>
template<typename _Other >
bool __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::_M_in_same_bucket ( const _Safe_local_iterator< _Other, _Sequence > &  __other) const
inline

Is this iterator part of the same bucket as the other one?

279  { return _M_bucket == __other.bucket(); }
size_type _M_bucket
The bucket this local iterator belongs to.
Definition: safe_local_iterator.h:61
template<typename _Iterator, typename _Sequence>
bool __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::_M_incrementable ( ) const
inline

Is the iterator incrementable?

254  { return !this->_M_singular() && !_M_is_end(); }
_GLIBCXX_PURE bool _M_singular() const
bool _M_is_end() const
Is this iterator equal to the sequence's end() iterator?
Definition: safe_local_iterator.h:272
template<typename _Iterator, typename _Sequence>
bool __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::_M_is_begin ( ) const
inline

Is this iterator equal to the sequence's begin() iterator?

269  { return base() == _M_get_sequence()->_M_base().begin(_M_bucket); }
_Iterator base() const
Return the underlying iterator.
Definition: safe_local_iterator.h:222
size_type _M_bucket
The bucket this local iterator belongs to.
Definition: safe_local_iterator.h:61
const _Sequence * _M_get_sequence() const
Definition: safe_local_iterator.h:264
template<typename _Iterator, typename _Sequence>
bool __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::_M_is_end ( ) const
inline

Is this iterator equal to the sequence's end() iterator?

273  { return base() == _M_get_sequence()->_M_base().end(_M_bucket); }
_Iterator base() const
Return the underlying iterator.
Definition: safe_local_iterator.h:222
size_type _M_bucket
The bucket this local iterator belongs to.
Definition: safe_local_iterator.h:61
const _Sequence * _M_get_sequence() const
Definition: safe_local_iterator.h:264
template<typename _Iterator , typename _Sequence >
template<typename _Other >
bool __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::_M_valid_range ( const _Safe_local_iterator< _Other, _Sequence > &  __rhs) const
39  {
40  if (!_M_can_compare(__rhs))
41  return false;
42  if (_M_bucket != __rhs._M_bucket)
43  return false;
44 
45  /* Determine if we can order the iterators without the help of
46  the container */
47  std::pair<difference_type, _Distance_precision> __dist =
48  __get_distance(base(), __rhs.base());
49  switch (__dist.second)
50  {
51  case __dp_equality:
52  if (__dist.first == 0)
53  return true;
54  break;
55 
56  case __dp_sign:
57  case __dp_exact:
58  return __dist.first >= 0;
59  }
60 
61  /* We can only test for equality, but check if one of the
62  iterators is at an extreme. */
63  /* Optim for classic [begin, it) or [it, end) ranges, limit checks
64  * when code is valid. */
65  if (_M_is_begin() || __rhs._M_is_end())
66  return true;
67  if (_M_is_end() || __rhs._M_is_begin())
68  return false;
69 
70  // Assume that this is a valid range; we can't check anything else
71  return true;
72  }
_Iterator base() const
Return the underlying iterator.
Definition: safe_local_iterator.h:222
std::pair< typename std::iterator_traits< _Iterator1 >::difference_type, _Distance_precision > __get_distance(const _Iterator1 &__lhs, const _Iterator2 &__rhs, std::random_access_iterator_tag)
Definition: safe_iterator.h:83
bool _M_is_begin() const
Is this iterator equal to the sequence's begin() iterator?
Definition: safe_local_iterator.h:268
Definition: safe_iterator.h:73
_GLIBCXX_PURE bool _M_can_compare(const _Safe_iterator_base &__x) const
size_type _M_bucket
The bucket this local iterator belongs to.
Definition: safe_local_iterator.h:61
bool _M_is_end() const
Is this iterator equal to the sequence's end() iterator?
Definition: safe_local_iterator.h:272
Definition: safe_iterator.h:74
Definition: safe_iterator.h:72
template<typename _Iterator, typename _Sequence>
_Iterator __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::base ( ) const
inline

Return the underlying iterator.

222 { return _M_current; }
_Iterator _M_current
The underlying iterator.
Definition: safe_local_iterator.h:58
template<typename _Iterator, typename _Sequence>
size_type __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::bucket ( ) const
inline

Return the bucket.

228 { return _M_bucket; }
size_type _M_bucket
The bucket this local iterator belongs to.
Definition: safe_local_iterator.h:61
template<typename _Iterator, typename _Sequence>
__gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::operator _Iterator ( ) const
inline

Conversion to underlying non-debug iterator to allow better interaction with non-debug containers.

234 { return _M_current; }
_Iterator _M_current
The underlying iterator.
Definition: safe_local_iterator.h:58
template<typename _Iterator, typename _Sequence>
reference __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::operator* ( ) const
inline

Iterator dereference.

Precondition
iterator is dereferenceable
165  {
167  _M_message(__msg_bad_deref)
168  ._M_iterator(*this, "this"));
169  return *_M_current;
170  }
bool _M_dereferenceable() const
Is the iterator dereferenceable?
Definition: safe_local_iterator.h:248
_Iterator _M_current
The underlying iterator.
Definition: safe_local_iterator.h:58
Definition: formatter.h:85
#define _GLIBCXX_DEBUG_VERIFY(_Condition, _ErrorMessage)
Definition: macros.h:49
template<typename _Iterator, typename _Sequence>
_Safe_local_iterator& __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::operator++ ( )
inline

Iterator preincrement.

Precondition
iterator is incrementable
194  {
196  _M_message(__msg_bad_inc)
197  ._M_iterator(*this, "this"));
198  ++_M_current;
199  return *this;
200  }
Definition: formatter.h:86
_Iterator _M_current
The underlying iterator.
Definition: safe_local_iterator.h:58
#define _GLIBCXX_DEBUG_VERIFY(_Condition, _ErrorMessage)
Definition: macros.h:49
bool _M_incrementable() const
Is the iterator incrementable?
Definition: safe_local_iterator.h:253
template<typename _Iterator, typename _Sequence>
_Safe_local_iterator __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::operator++ ( int  )
inline

Iterator postincrement.

Precondition
iterator is incrementable
208  {
210  _M_message(__msg_bad_inc)
211  ._M_iterator(*this, "this"));
212  _Safe_local_iterator __tmp(*this);
213  ++_M_current;
214  return __tmp;
215  }
Definition: formatter.h:86
_Iterator _M_current
The underlying iterator.
Definition: safe_local_iterator.h:58
_Safe_local_iterator()
Definition: safe_local_iterator.h:82
#define _GLIBCXX_DEBUG_VERIFY(_Condition, _ErrorMessage)
Definition: macros.h:49
bool _M_incrementable() const
Is the iterator incrementable?
Definition: safe_local_iterator.h:253
template<typename _Iterator, typename _Sequence>
pointer __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::operator-> ( ) const
inline

Iterator dereference.

Precondition
iterator is dereferenceable
Todo:

Make this correct w.r.t. iterators that return proxies

Use addressof() instead of & operator

180  {
182  _M_message(__msg_bad_deref)
183  ._M_iterator(*this, "this"));
184  return &*_M_current;
185  }
bool _M_dereferenceable() const
Is the iterator dereferenceable?
Definition: safe_local_iterator.h:248
_Iterator _M_current
The underlying iterator.
Definition: safe_local_iterator.h:58
Definition: formatter.h:85
#define _GLIBCXX_DEBUG_VERIFY(_Condition, _ErrorMessage)
Definition: macros.h:49
template<typename _Iterator, typename _Sequence>
_Safe_local_iterator& __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::operator= ( const _Safe_local_iterator< _Iterator, _Sequence > &  __x)
inline

Copy assignment.

145  {
146  // _GLIBCXX_RESOLVE_LIB_DEFECTS
147  // DR 408. Is vector<reverse_iterator<char*> > forbidden?
148  _GLIBCXX_DEBUG_VERIFY(!__x._M_singular()
149  || __x._M_current == _Iterator(),
150  _M_message(__msg_copy_singular)
151  ._M_iterator(*this, "this")
152  ._M_iterator(__x, "other"));
153  _M_current = __x._M_current;
154  _M_bucket = __x._M_bucket;
155  this->_M_attach(__x._M_sequence);
156  return *this;
157  }
Definition: formatter.h:84
_Iterator _M_current
The underlying iterator.
Definition: safe_local_iterator.h:58
size_type _M_bucket
The bucket this local iterator belongs to.
Definition: safe_local_iterator.h:61
#define _GLIBCXX_DEBUG_VERIFY(_Condition, _ErrorMessage)
Definition: macros.h:49
void _M_attach(_Safe_sequence_base *__seq)
Definition: safe_local_iterator.h:238

Member Data Documentation

template<typename _Iterator, typename _Sequence>
size_type __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::_M_bucket
private

The bucket this local iterator belongs to.

template<typename _Iterator, typename _Sequence>
_Iterator __gnu_debug::_Safe_local_iterator< _Iterator, _Sequence >::_M_current
private

The underlying iterator.


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