Install gcc-4.4.0-tdm-1-core-2.tar.gz
[msysgit.git] / mingw / lib / gcc / mingw32 / 4.3.3 / include / c++ / debug / bitset
blobdb4b3c075d005b2054f81b23b5003834f4a90399
1 // Debugging bitset implementation -*- C++ -*-
3 // Copyright (C) 2003, 2004, 2005, 2006, 2007 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 2, or (at your option)
9 // any later version.
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.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING.  If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction.  Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License.  This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 /** @file debug/bitset
31  *  This file is a GNU debug extension to the Standard C++ Library.
32  */
34 #ifndef _GLIBCXX_DEBUG_BITSET
35 #define _GLIBCXX_DEBUG_BITSET
37 #include <bitset>
38 #include <debug/safe_sequence.h>
39 #include <debug/safe_iterator.h>
41 namespace std
43 namespace __debug
45   template<size_t _Nb>
46     class bitset
47     : public _GLIBCXX_STD_D::bitset<_Nb>, 
48       public __gnu_debug::_Safe_sequence_base
49     {
50       typedef _GLIBCXX_STD_D::bitset<_Nb> _Base;
51       typedef __gnu_debug::_Safe_sequence_base  _Safe_base;
53     public:
54       // bit reference:
55       class reference
56       : private _Base::reference, public __gnu_debug::_Safe_iterator_base
57       {
58         typedef typename _Base::reference _Base_ref;
60         friend class bitset;
61         reference();
63         reference(const _Base_ref& __base, bitset* __seq)
64         : _Base_ref(__base), _Safe_iterator_base(__seq, false)
65         { }
67       public:
68         reference(const reference& __x)
69         : _Base_ref(__x), _Safe_iterator_base(__x, false)
70         { }
72         reference&
73         operator=(bool __x)
74         {
75           _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(),
76                               _M_message(__gnu_debug::__msg_bad_bitset_write)
77                                 ._M_iterator(*this));
78           *static_cast<_Base_ref*>(this) = __x;
79           return *this;
80         }
82         reference&
83         operator=(const reference& __x)
84         {
85           _GLIBCXX_DEBUG_VERIFY(! __x._M_singular(),
86                                _M_message(__gnu_debug::__msg_bad_bitset_read)
87                                 ._M_iterator(__x));
88           _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(),
89                               _M_message(__gnu_debug::__msg_bad_bitset_write)
90                                 ._M_iterator(*this));
91           *static_cast<_Base_ref*>(this) = __x;
92           return *this;
93         }
95         bool
96         operator~() const
97         {
98           _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(),
99                                _M_message(__gnu_debug::__msg_bad_bitset_read)
100                                 ._M_iterator(*this));
101           return ~(*static_cast<const _Base_ref*>(this));
102         }
104         operator bool() const
105         {
106           _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(),
107                               _M_message(__gnu_debug::__msg_bad_bitset_read)
108                                 ._M_iterator(*this));
109           return *static_cast<const _Base_ref*>(this);
110         }
112         reference&
113         flip()
114         {
115           _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(),
116                               _M_message(__gnu_debug::__msg_bad_bitset_flip)
117                                 ._M_iterator(*this));
118           _Base_ref::flip();
119           return *this;
120         }
121       };
123       // 23.3.5.1 constructors:
124       bitset() : _Base() { }
126       bitset(unsigned long __val) : _Base(__val) { }
128       template<typename _CharT, typename _Traits, typename _Allocator>
129         explicit
130         bitset(const std::basic_string<_CharT,_Traits,_Allocator>& __str,
131                typename std::basic_string<_CharT,_Traits,_Allocator>::size_type
132                __pos = 0,
133                typename std::basic_string<_CharT,_Traits,_Allocator>::size_type
134                __n = (std::basic_string<_CharT,_Traits,_Allocator>::npos))
135         : _Base(__str, __pos, __n) { }
137       bitset(const _Base& __x) : _Base(__x), _Safe_base() { }
139       // 23.3.5.2 bitset operations:
140       bitset<_Nb>&
141       operator&=(const bitset<_Nb>& __rhs)
142       {
143         _M_base() &= __rhs;
144         return *this;
145       }
147       bitset<_Nb>&
148       operator|=(const bitset<_Nb>& __rhs)
149       {
150         _M_base() |= __rhs;
151         return *this;
152       }
154       bitset<_Nb>&
155       operator^=(const bitset<_Nb>& __rhs)
156       {
157         _M_base() ^= __rhs;
158         return *this;
159       }
161       bitset<_Nb>&
162       operator<<=(size_t __pos)
163       {
164         _M_base() <<= __pos;
165         return *this;
166       }
168       bitset<_Nb>&
169       operator>>=(size_t __pos)
170       {
171         _M_base() >>= __pos;
172         return *this;
173       }
175       bitset<_Nb>&
176       set()
177       {
178         _Base::set();
179         return *this;
180       }
182       // _GLIBCXX_RESOLVE_LIB_DEFECTS
183       // 186. bitset::set() second parameter should be bool
184       bitset<_Nb>&
185       set(size_t __pos, bool __val = true)
186       {
187         _Base::set(__pos, __val);
188         return *this;
189       }
191       bitset<_Nb>&
192       reset()
193       {
194         _Base::reset();
195         return *this;
196       }
198       bitset<_Nb>&
199       reset(size_t __pos)
200       {
201         _Base::reset(__pos);
202         return *this;
203       }
205       bitset<_Nb> operator~() const { return bitset(~_M_base()); }
207       bitset<_Nb>&
208       flip()
209       {
210         _Base::flip();
211         return *this;
212       }
214       bitset<_Nb>&
215       flip(size_t __pos)
216       {
217         _Base::flip(__pos);
218         return *this;
219       }
221       // element access:
222       // _GLIBCXX_RESOLVE_LIB_DEFECTS
223       // 11. Bitset minor problems
224       reference
225       operator[](size_t __pos)
226       {
227         __glibcxx_check_subscript(__pos);
228         return reference(_M_base()[__pos], this);
229       }
231       // _GLIBCXX_RESOLVE_LIB_DEFECTS
232       // 11. Bitset minor problems
233       bool
234       operator[](size_t __pos) const
235       {
236         __glibcxx_check_subscript(__pos);
237         return _M_base()[__pos];
238       }
240       using _Base::to_ulong;
242       template <typename _CharT, typename _Traits, typename _Allocator>
243         std::basic_string<_CharT, _Traits, _Allocator>
244         to_string() const
245         { return _M_base().template to_string<_CharT, _Traits, _Allocator>(); }
247       // _GLIBCXX_RESOLVE_LIB_DEFECTS
248       // 434. bitset::to_string() hard to use.
249       template<typename _CharT, typename _Traits>
250         std::basic_string<_CharT, _Traits, std::allocator<_CharT> >
251         to_string() const
252         { return to_string<_CharT, _Traits, std::allocator<_CharT> >(); }
254       template<typename _CharT>
255         std::basic_string<_CharT, std::char_traits<_CharT>,
256                           std::allocator<_CharT> >
257         to_string() const
258         {
259           return to_string<_CharT, std::char_traits<_CharT>,
260                            std::allocator<_CharT> >();
261         }
263       std::basic_string<char, std::char_traits<char>, std::allocator<char> >
264         to_string() const
265         {
266           return to_string<char,std::char_traits<char>,std::allocator<char> >();
267         }
269       using _Base::count;
270       using _Base::size;
272       bool
273       operator==(const bitset<_Nb>& __rhs) const
274       { return _M_base() == __rhs; }
276       bool
277       operator!=(const bitset<_Nb>& __rhs) const
278       { return _M_base() != __rhs; }
280       using _Base::test;
281       using _Base::all;
282       using _Base::any;
283       using _Base::none;
285       bitset<_Nb>
286       operator<<(size_t __pos) const
287       { return bitset<_Nb>(_M_base() << __pos); }
289       bitset<_Nb>
290       operator>>(size_t __pos) const
291       { return bitset<_Nb>(_M_base() >> __pos); }
293       _Base&
294       _M_base() { return *this; }
296       const _Base&
297       _M_base() const { return *this; }
298     };
300   template<size_t _Nb>
301     bitset<_Nb>
302     operator&(const bitset<_Nb>& __x, const bitset<_Nb>& __y)
303     { return bitset<_Nb>(__x) &= __y; }
305   template<size_t _Nb>
306     bitset<_Nb>
307     operator|(const bitset<_Nb>& __x, const bitset<_Nb>& __y)
308     { return bitset<_Nb>(__x) |= __y; }
310   template<size_t _Nb>
311     bitset<_Nb>
312     operator^(const bitset<_Nb>& __x, const bitset<_Nb>& __y)
313     { return bitset<_Nb>(__x) ^= __y; }
315   template<typename _CharT, typename _Traits, size_t _Nb>
316     std::basic_istream<_CharT, _Traits>&
317     operator>>(std::basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x)
318     { return __is >> __x._M_base(); }
320   template<typename _CharT, typename _Traits, size_t _Nb>
321     std::basic_ostream<_CharT, _Traits>&
322     operator<<(std::basic_ostream<_CharT, _Traits>& __os,
323                const bitset<_Nb>& __x)
324     { return __os << __x._M_base(); }
325 } // namespace __debug
326 } // namespace std
328 #endif