safe_base.h

Go to the documentation of this file.
00001 // Safe sequence/iterator base implementation  -*- C++ -*-
00002 
00003 // Copyright (C) 2003, 2004
00004 // Free Software Foundation, Inc.
00005 //
00006 // This file is part of the GNU ISO C++ Library.  This library is free
00007 // software; you can redistribute it and/or modify it under the
00008 // terms of the GNU General Public License as published by the
00009 // Free Software Foundation; either version 2, or (at your option)
00010 // any later version.
00011 
00012 // This library is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 
00017 // You should have received a copy of the GNU General Public License along
00018 // with this library; see the file COPYING.  If not, write to the Free
00019 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00020 // USA.
00021 
00022 // As a special exception, you may use this file as part of a free software
00023 // library without restriction.  Specifically, if other files instantiate
00024 // templates or use macros or inline functions from this file, or you compile
00025 // this file and link it with other files to produce an executable, this
00026 // file does not by itself cause the resulting executable to be covered by
00027 // the GNU General Public License.  This exception does not however
00028 // invalidate any other reasons why the executable file might be covered by
00029 // the GNU General Public License.
00030 
00031 #ifndef _GLIBCXX_DEBUG_SAFE_BASE_H
00032 #define _GLIBCXX_DEBUG_SAFE_BASE_H 1
00033 
00034 namespace __gnu_debug
00035 {
00036   class _Safe_sequence_base;
00037 
00050   class _Safe_iterator_base
00051   {
00052   public:
00055     _Safe_sequence_base* _M_sequence;
00056 
00064     unsigned int         _M_version;
00065 
00068     _Safe_iterator_base* _M_prior;
00069 
00072     _Safe_iterator_base* _M_next;
00073 
00074   protected:
00076     _Safe_iterator_base()
00077     : _M_sequence(0), _M_version(0), _M_prior(0), _M_next(0)
00078     { }
00079 
00087     _Safe_iterator_base(const _Safe_sequence_base* __seq, bool __constant)
00088     : _M_sequence(0), _M_version(0), _M_prior(0), _M_next(0)
00089     { this->_M_attach(const_cast<_Safe_sequence_base*>(__seq), __constant); }
00090 
00094     _Safe_iterator_base(const _Safe_iterator_base& __x, bool __constant)
00095     : _M_sequence(0), _M_version(0), _M_prior(0), _M_next(0)
00096     { this->_M_attach(__x._M_sequence, __constant); }
00097 
00098     _Safe_iterator_base&
00099     operator=(const _Safe_iterator_base&);
00100 
00101     explicit
00102     _Safe_iterator_base(const _Safe_iterator_base&);
00103 
00104     ~_Safe_iterator_base() { this->_M_detach(); }
00105 
00106   public:
00112     void _M_attach(_Safe_sequence_base* __seq, bool __constant);
00113 
00117     void _M_detach();
00118 
00120     bool _M_attached_to(const _Safe_sequence_base* __seq) const
00121     { return _M_sequence == __seq; }
00122 
00124     bool _M_singular() const;
00125 
00129     bool _M_can_compare(const _Safe_iterator_base& __x) const;
00130   };
00131 
00149   class _Safe_sequence_base
00150   {
00151   public:
00153     _Safe_iterator_base* _M_iterators;
00154 
00156     _Safe_iterator_base* _M_const_iterators;
00157 
00159     mutable unsigned int _M_version;
00160 
00161   protected:
00162     // Initialize with a version number of 1 and no iterators
00163     _Safe_sequence_base()
00164     : _M_iterators(0), _M_const_iterators(0), _M_version(1)
00165     { }
00166 
00169     ~_Safe_sequence_base()
00170     { this->_M_detach_all(); }
00171 
00173     void
00174     _M_detach_all();
00175 
00180     void
00181     _M_detach_singular();
00182 
00188     void
00189     _M_revalidate_singular();
00190 
00196     void
00197     _M_swap(_Safe_sequence_base& __x);
00198 
00199   public:
00201     void
00202     _M_invalidate_all() const
00203     { if (++_M_version == 0) _M_version = 1; }
00204   };
00205 } // namespace __gnu_debug
00206 
00207 #endif

Generated on Tue Jan 30 17:31:52 2007 for GNU C++ STL by doxygen 1.3.6