STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
safe_base.h
Go to the documentation of this file.
1 // Safe sequence/iterator base implementation -*- C++ -*-
2 
3 // Copyright (C) 2003-2013 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24 
29 #ifndef _GLIBCXX_DEBUG_SAFE_BASE_H
30 #define _GLIBCXX_DEBUG_SAFE_BASE_H 1
31 
32 #include <ext/concurrence.h>
33 
34 namespace __gnu_debug
35 {
36  class _Safe_sequence_base;
37 
51  {
52  public:
56 
64  unsigned int _M_version;
65 
69 
73 
74  protected:
77  : _M_sequence(0), _M_version(0), _M_prior(0), _M_next(0)
78  { }
79 
87  _Safe_iterator_base(const _Safe_sequence_base* __seq, bool __constant)
88  : _M_sequence(0), _M_version(0), _M_prior(0), _M_next(0)
89  { this->_M_attach(const_cast<_Safe_sequence_base*>(__seq), __constant); }
90 
94  _Safe_iterator_base(const _Safe_iterator_base& __x, bool __constant)
95  : _M_sequence(0), _M_version(0), _M_prior(0), _M_next(0)
96  { this->_M_attach(__x._M_sequence, __constant); }
97 
100 
101  explicit
103 
105 
107  __gnu_cxx::__mutex& _M_get_mutex() throw ();
108 
109  public:
115  void _M_attach(_Safe_sequence_base* __seq, bool __constant);
116 
118  void _M_attach_single(_Safe_sequence_base* __seq, bool __constant) throw ();
119 
123  void _M_detach();
124 
126  void _M_detach_single() throw ();
127 
129  bool _M_attached_to(const _Safe_sequence_base* __seq) const
130  { return _M_sequence == __seq; }
131 
133  _GLIBCXX_PURE bool _M_singular() const throw ();
134 
138  _GLIBCXX_PURE bool _M_can_compare(const _Safe_iterator_base& __x) const throw ();
139 
141  void
143  { _M_version = 0; }
144 
146  void
147  _M_reset() throw ();
148 
150  void
151  _M_unlink() throw ()
152  {
153  if (_M_prior)
155  if (_M_next)
157  }
158  };
159 
178  {
179  public:
182 
185 
187  mutable unsigned int _M_version;
188 
189  protected:
190  // Initialize with a version number of 1 and no iterators
193  { }
194 
198  { this->_M_detach_all(); }
199 
201  void
202  _M_detach_all();
203 
208  void
210 
216  void
218 
224  void
226 
228  __gnu_cxx::__mutex& _M_get_mutex() throw ();
229 
230  public:
232  void
234  { if (++_M_version == 0) _M_version = 1; }
235 
237  void
238  _M_attach(_Safe_iterator_base* __it, bool __constant);
239 
241  void
242  _M_attach_single(_Safe_iterator_base* __it, bool __constant) throw ();
243 
245  void
247 
249  void
250  _M_detach_single(_Safe_iterator_base* __it) throw ();
251  };
252 } // namespace __gnu_debug
253 
254 #endif
_Safe_iterator_base & operator=(const _Safe_iterator_base &)
_Safe_sequence_base()
Definition: safe_base.h:191
~_Safe_sequence_base()
Definition: safe_base.h:197
__gnu_cxx::__mutex & _M_get_mutex()
bool _M_attached_to(const _Safe_sequence_base *__seq) const
Definition: safe_base.h:129
_Safe_iterator_base(const _Safe_sequence_base *__seq, bool __constant)
Definition: safe_base.h:87
_Safe_sequence_base * _M_sequence
Definition: safe_base.h:55
void _M_invalidate()
Definition: safe_base.h:142
void _M_swap(_Safe_sequence_base &__x)
_Safe_iterator_base * _M_const_iterators
The list of constant iterators that reference this container.
Definition: safe_base.h:184
_GLIBCXX_PURE bool _M_can_compare(const _Safe_iterator_base &__x) const
_Safe_iterator_base * _M_iterators
The list of mutable iterators that reference this container.
Definition: safe_base.h:181
void _M_attach(_Safe_sequence_base *__seq, bool __constant)
void _M_detach_single(_Safe_iterator_base *__it)
void _M_invalidate_all() const
Definition: safe_base.h:233
unsigned int _M_version
Definition: safe_base.h:64
void _M_attach_single(_Safe_iterator_base *__it, bool __constant)
_Safe_iterator_base(const _Safe_iterator_base &__x, bool __constant)
Definition: safe_base.h:94
void _M_attach_single(_Safe_sequence_base *__seq, bool __constant)
__gnu_cxx::__mutex & _M_get_mutex()
_GLIBCXX_PURE bool _M_singular() const
void _M_detach(_Safe_iterator_base *__it)
Basic functionality for a safe iterator.
Definition: safe_base.h:50
Base class that supports tracking of iterators that reference a sequence.
Definition: safe_base.h:177
_Safe_iterator_base * _M_prior
Definition: safe_base.h:68
_Safe_iterator_base * _M_next
Definition: safe_base.h:72
_Safe_iterator_base()
Definition: safe_base.h:76
void _M_attach(_Safe_iterator_base *__it, bool __constant)
~_Safe_iterator_base()
Definition: safe_base.h:104
unsigned int _M_version
The container version number. This number may never be 0.
Definition: safe_base.h:187
void _M_unlink()
Definition: safe_base.h:151