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

Base class for constructing a safe sequence type that tracks iterators that reference it. More...

#include <debug/formatter.h>

Inheritance diagram for __gnu_debug::_Safe_sequence< _Sequence >:
__gnu_debug::_Safe_sequence_base

Public Member Functions

template<typename _Predicate >
void _M_invalidate_if (_Predicate __pred)
 
template<typename _Predicate >
void _M_transfer_from_if (_Safe_sequence &__from, _Predicate __pred)
 
- Public Member Functions inherited from __gnu_debug::_Safe_sequence_base
void _M_invalidate_all () const
 
void _M_attach (_Safe_iterator_base *__it, bool __constant)
 
void _M_attach_single (_Safe_iterator_base *__it, bool __constant) throw ()
 
void _M_detach (_Safe_iterator_base *__it)
 
void _M_detach_single (_Safe_iterator_base *__it) throw ()
 

Additional Inherited Members

- Public Attributes inherited from __gnu_debug::_Safe_sequence_base
_Safe_iterator_base_M_iterators
 The list of mutable iterators that reference this container. More...
 
_Safe_iterator_base_M_const_iterators
 The list of constant iterators that reference this container. More...
 
unsigned int _M_version
 The container version number. This number may never be 0. More...
 
- Protected Member Functions inherited from __gnu_debug::_Safe_sequence_base
 _Safe_sequence_base ()
 
 ~_Safe_sequence_base ()
 
void _M_detach_all ()
 
void _M_detach_singular ()
 
void _M_revalidate_singular ()
 
void _M_swap (_Safe_sequence_base &__x)
 
__gnu_cxx::__mutex & _M_get_mutex () throw ()
 

Detailed Description

template<typename _Sequence>
class __gnu_debug::_Safe_sequence< _Sequence >

Base class for constructing a safe sequence type that tracks iterators that reference it.

The class template _Safe_sequence simplifies the construction of safe sequences that track the iterators that reference the sequence, so that the iterators are notified of changes in the sequence that may affect their operation, e.g., if the container invalidates its iterators or is destructed. This class template may only be used by deriving from it and passing the name of the derived class as its template parameter via the curiously recurring template pattern. The derived class must have iterator and const_iterator types that are instantiations of class template _Safe_iterator for this sequence. Iterators will then be tracked automatically.

Member Function Documentation

template<typename _Sequence >
template<typename _Predicate >
void __gnu_debug::_Safe_sequence< _Sequence >::_M_invalidate_if ( _Predicate  __pred)

Invalidates all iterators x that reference this sequence, are not singular, and for which __pred(x) returns true. __pred will be invoked with the normal iterators nested in the safe ones.

39  {
40  typedef typename _Sequence::iterator iterator;
41  typedef typename _Sequence::const_iterator const_iterator;
42 
43  __gnu_cxx::__scoped_lock sentry(this->_M_get_mutex());
44  for (_Safe_iterator_base* __iter = _M_iterators; __iter;)
45  {
46  iterator* __victim = static_cast<iterator*>(__iter);
47  __iter = __iter->_M_next;
48  if (!__victim->_M_singular() && __pred(__victim->base()))
49  {
50  __victim->_M_invalidate();
51  }
52  }
53 
54  for (_Safe_iterator_base* __iter2 = _M_const_iterators; __iter2;)
55  {
56  const_iterator* __victim = static_cast<const_iterator*>(__iter2);
57  __iter2 = __iter2->_M_next;
58  if (!__victim->_M_singular() && __pred(__victim->base()))
59  {
60  __victim->_M_invalidate();
61  }
62  }
63  }
_Safe_iterator_base * _M_const_iterators
The list of constant iterators that reference this container.
Definition: safe_base.h:184
_Safe_iterator_base * _M_iterators
The list of mutable iterators that reference this container.
Definition: safe_base.h:181
__gnu_cxx::__mutex & _M_get_mutex()
template<typename _Sequence >
template<typename _Predicate >
void __gnu_debug::_Safe_sequence< _Sequence >::_M_transfer_from_if ( _Safe_sequence< _Sequence > &  __from,
_Predicate  __pred 
)

Transfers all iterators x that reference from sequence, are not singular, and for which __pred(x) returns true. __pred will be invoked with the normal iterators nested in the safe ones.

70  {
71  typedef typename _Sequence::iterator iterator;
72  typedef typename _Sequence::const_iterator const_iterator;
73 
74  _Safe_iterator_base* __transfered_iterators = 0;
75  _Safe_iterator_base* __transfered_const_iterators = 0;
76  _Safe_iterator_base* __last_iterator = 0;
77  _Safe_iterator_base* __last_const_iterator = 0;
78  {
79  // We lock __from first and detach iterator(s) to transfer
80  __gnu_cxx::__scoped_lock sentry(__from._M_get_mutex());
81 
82  for (_Safe_iterator_base* __iter = __from._M_iterators; __iter;)
83  {
84  iterator* __victim = static_cast<iterator*>(__iter);
85  __iter = __iter->_M_next;
86  if (!__victim->_M_singular() && __pred(__victim->base()))
87  {
88  __victim->_M_detach_single();
89  if (__transfered_iterators)
90  {
91  __victim->_M_next = __transfered_iterators;
92  __transfered_iterators->_M_prior = __victim;
93  }
94  else
95  __last_iterator = __victim;
96  __victim->_M_sequence = this;
97  __victim->_M_version = this->_M_version;
98  __transfered_iterators = __victim;
99  }
100  }
101 
102  for (_Safe_iterator_base* __iter2 = __from._M_const_iterators;
103  __iter2;)
104  {
105  const_iterator* __victim = static_cast<const_iterator*>(__iter2);
106  __iter2 = __iter2->_M_next;
107  if (!__victim->_M_singular() && __pred(__victim->base()))
108  {
109  __victim->_M_detach_single();
110  if (__transfered_const_iterators)
111  {
112  __victim->_M_next = __transfered_const_iterators;
113  __transfered_const_iterators->_M_prior = __victim;
114  }
115  else
116  __last_const_iterator = __victim;
117  __victim->_M_sequence = this;
118  __victim->_M_version = this->_M_version;
119  __transfered_const_iterators = __victim;
120  }
121  }
122  }
123 
124  // Now we can lock *this and add the transfered iterators if any
125  if (__last_iterator || __last_const_iterator)
126  {
127  __gnu_cxx::__scoped_lock sentry(this->_M_get_mutex());
128  if (__last_iterator)
129  {
130  if (this->_M_iterators)
131  {
132  this->_M_iterators->_M_prior = __last_iterator;
133  __last_iterator->_M_next = this->_M_iterators;
134  }
135  this->_M_iterators = __transfered_iterators;
136  }
137  if (__last_const_iterator)
138  {
139  if (this->_M_const_iterators)
140  {
141  this->_M_const_iterators->_M_prior = __last_const_iterator;
142  __last_const_iterator->_M_next = this->_M_const_iterators;
143  }
144  this->_M_const_iterators = __transfered_const_iterators;
145  }
146  }
147  }
_Safe_iterator_base * _M_const_iterators
The list of constant iterators that reference this container.
Definition: safe_base.h:184
_Safe_iterator_base * _M_iterators
The list of mutable iterators that reference this container.
Definition: safe_base.h:181
__gnu_cxx::__mutex & _M_get_mutex()
_Safe_iterator_base * _M_prior
Definition: safe_base.h:68
_Safe_iterator_base * _M_next
Definition: safe_base.h:72
unsigned int _M_version
The container version number. This number may never be 0.
Definition: safe_base.h:187

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