1 // Debugging bitset implementation -*- C++ -*-
3 // Copyright (C) 2003, 2004, 2005
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
31 #ifndef _GLIBCXX_DEBUG_BITSET
32 #define _GLIBCXX_DEBUG_BITSET
35 #include <debug/safe_sequence.h>
36 #include <debug/safe_iterator.h>
38 namespace __gnu_debug_def
42 : public _GLIBCXX_STD::bitset<_Nb>,
43 public __gnu_debug::_Safe_sequence_base
45 typedef _GLIBCXX_STD::bitset<_Nb> _Base;
46 typedef __gnu_debug::_Safe_sequence_base _Safe_base;
51 : private _Base::reference, public __gnu_debug::_Safe_iterator_base
53 typedef typename _Base::reference _Base_ref;
58 reference(const _Base_ref& __base, bitset* __seq)
59 : _Base_ref(__base), _Safe_iterator_base(__seq, false)
63 reference(const reference& __x)
64 : _Base_ref(__x), _Safe_iterator_base(__x, false)
70 _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(),
71 _M_message(::__gnu_debug::__msg_bad_bitset_write)
73 *static_cast<_Base_ref*>(this) = __x;
78 operator=(const reference& __x)
80 _GLIBCXX_DEBUG_VERIFY(! __x._M_singular(),
81 _M_message(::__gnu_debug::__msg_bad_bitset_read)
83 _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(),
84 _M_message(::__gnu_debug::__msg_bad_bitset_write)
86 *static_cast<_Base_ref*>(this) = __x;
93 _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(),
94 _M_message(::__gnu_debug::__msg_bad_bitset_read)
96 return ~(*static_cast<const _Base_ref*>(this));
101 _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(),
102 _M_message(::__gnu_debug::__msg_bad_bitset_read)
103 ._M_iterator(*this));
104 return *static_cast<const _Base_ref*>(this);
110 _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(),
111 _M_message(::__gnu_debug::__msg_bad_bitset_flip)
112 ._M_iterator(*this));
118 // 23.3.5.1 constructors:
119 bitset() : _Base() { }
121 bitset(unsigned long __val) : _Base(__val) { }
123 template<typename _CharT, typename _Traits, typename _Allocator>
125 bitset(const std::basic_string<_CharT,_Traits,_Allocator>& __str,
126 typename std::basic_string<_CharT,_Traits,_Allocator>::size_type
128 typename std::basic_string<_CharT,_Traits,_Allocator>::size_type
129 __n = (std::basic_string<_CharT,_Traits,_Allocator>::npos))
130 : _Base(__str, __pos, __n) { }
132 bitset(const _Base& __x) : _Base(__x), _Safe_base() { }
134 // 23.3.5.2 bitset operations:
136 operator&=(const bitset<_Nb>& __rhs)
143 operator|=(const bitset<_Nb>& __rhs)
150 operator^=(const bitset<_Nb>& __rhs)
157 operator<<=(size_t __pos)
164 operator>>=(size_t __pos)
177 // _GLIBCXX_RESOLVE_LIB_DEFECTS
178 // 186. bitset::set() second parameter should be bool
180 set(size_t __pos, bool __val = true)
182 _Base::set(__pos, __val);
200 bitset<_Nb> operator~() const { return bitset(~_M_base()); }
217 // _GLIBCXX_RESOLVE_LIB_DEFECTS
218 // 11. Bitset minor problems
220 operator[](size_t __pos)
222 __glibcxx_check_subscript(__pos);
223 return reference(_M_base()[__pos], this);
226 // _GLIBCXX_RESOLVE_LIB_DEFECTS
227 // 11. Bitset minor problems
229 operator[](size_t __pos) const
231 __glibcxx_check_subscript(__pos);
232 return _M_base()[__pos];
235 using _Base::to_ulong;
237 template <typename _CharT, typename _Traits, typename _Allocator>
238 std::basic_string<_CharT, _Traits, _Allocator>
240 { return _M_base().template to_string<_CharT, _Traits, _Allocator>(); }
242 // _GLIBCXX_RESOLVE_LIB_DEFECTS
243 // 434. bitset::to_string() hard to use.
244 template<typename _CharT, typename _Traits>
245 std::basic_string<_CharT, _Traits, std::allocator<_CharT> >
247 { return to_string<_CharT, _Traits, std::allocator<_CharT> >(); }
249 template<typename _CharT>
250 std::basic_string<_CharT, std::char_traits<_CharT>,
251 std::allocator<_CharT> >
254 return to_string<_CharT, std::char_traits<_CharT>,
255 std::allocator<_CharT> >();
258 std::basic_string<char, std::char_traits<char>, std::allocator<char> >
261 return to_string<char,std::char_traits<char>,std::allocator<char> >();
268 operator==(const bitset<_Nb>& __rhs) const
269 { return _M_base() == __rhs; }
272 operator!=(const bitset<_Nb>& __rhs) const
273 { return _M_base() != __rhs; }
280 operator<<(size_t __pos) const
281 { return bitset<_Nb>(_M_base() << __pos); }
284 operator>>(size_t __pos) const
285 { return bitset<_Nb>(_M_base() >> __pos); }
288 _M_base() { return *this; }
291 _M_base() const { return *this; }
296 operator&(const bitset<_Nb>& __x, const bitset<_Nb>& __y)
297 { return bitset<_Nb>(__x) &= __y; }
301 operator|(const bitset<_Nb>& __x, const bitset<_Nb>& __y)
302 { return bitset<_Nb>(__x) |= __y; }
306 operator^(const bitset<_Nb>& __x, const bitset<_Nb>& __y)
307 { return bitset<_Nb>(__x) ^= __y; }
309 template<typename _CharT, typename _Traits, size_t _Nb>
310 std::basic_istream<_CharT, _Traits>&
311 operator>>(std::basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x)
312 { return __is >> __x._M_base(); }
314 template<typename _CharT, typename _Traits, size_t _Nb>
315 std::basic_ostream<_CharT, _Traits>&
316 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
317 const bitset<_Nb>& __x)
318 { return __os << __x._M_base(); }
319 } // namespace __gnu_debug_def