1 // Debugging bitset implementation -*- C++ -*-
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
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 __gnu_norm::bitset<_Nb>, public __gnu_debug::_Safe_sequence_base
44 typedef __gnu_norm::bitset<_Nb> _Base;
45 typedef __gnu_debug::_Safe_sequence_base _Safe_base;
50 : private _Base::reference, public __gnu_debug::_Safe_iterator_base
52 typedef typename _Base::reference _Base_ref;
57 reference(const _Base_ref& __base, bitset* __seq)
58 : _Base_ref(__base), _Safe_iterator_base(__seq, false)
62 reference(const reference& __x)
63 : _Base_ref(__x), _Safe_iterator_base(__x, false)
69 _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(),
70 _M_message(::__gnu_debug::__msg_bad_bitset_write)
72 *static_cast<_Base_ref*>(this) = __x;
77 operator=(const reference& __x)
79 _GLIBCXX_DEBUG_VERIFY(! __x._M_singular(),
80 _M_message(::__gnu_debug::__msg_bad_bitset_read)
82 _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(),
83 _M_message(::__gnu_debug::__msg_bad_bitset_write)
85 *static_cast<_Base_ref*>(this) = __x;
92 _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(),
93 _M_message(::__gnu_debug::__msg_bad_bitset_read)
95 return ~(*static_cast<const _Base_ref*>(this));
100 _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(),
101 _M_message(::__gnu_debug::__msg_bad_bitset_read)
102 ._M_iterator(*this));
103 return *static_cast<const _Base_ref*>(this);
109 _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(),
110 _M_message(::__gnu_debug::__msg_bad_bitset_flip)
111 ._M_iterator(*this));
117 // 23.3.5.1 constructors:
118 bitset() : _Base() { }
120 bitset(unsigned long __val) : _Base(__val) { }
122 template<typename _CharT, typename _Traits, typename _Allocator>
124 bitset(const std::basic_string<_CharT,_Traits,_Allocator>& __str,
125 typename std::basic_string<_CharT,_Traits,_Allocator>::size_type
127 typename std::basic_string<_CharT,_Traits,_Allocator>::size_type
128 __n = (std::basic_string<_CharT,_Traits,_Allocator>::npos))
129 : _Base(__str, __pos, __n) { }
131 bitset(const _Base& __x) : _Base(__x), _Safe_base() { }
133 // 23.3.5.2 bitset operations:
135 operator&=(const bitset<_Nb>& __rhs)
142 operator|=(const bitset<_Nb>& __rhs)
149 operator^=(const bitset<_Nb>& __rhs)
156 operator<<=(size_t __pos)
163 operator>>=(size_t __pos)
176 // _GLIBCXX_RESOLVE_LIB_DEFECTS
177 // 186. bitset::set() second parameter should be bool
179 set(size_t __pos, bool __val = true)
181 _Base::set(__pos, __val);
199 bitset<_Nb> operator~() const { return bitset(~_M_base()); }
216 // _GLIBCXX_RESOLVE_LIB_DEFECTS
217 // 11. Bitset minor problems
219 operator[](size_t __pos)
221 __glibcxx_check_subscript(__pos);
222 return reference(_M_base()[__pos], this);
225 // _GLIBCXX_RESOLVE_LIB_DEFECTS
226 // 11. Bitset minor problems
228 operator[](size_t __pos) const
230 __glibcxx_check_subscript(__pos);
231 return _M_base()[__pos];
234 using _Base::to_ulong;
236 template <typename _CharT, typename _Traits, typename _Allocator>
237 std::basic_string<_CharT, _Traits, _Allocator>
239 { return _M_base().template to_string<_CharT, _Traits, _Allocator>(); }
245 operator==(const bitset<_Nb>& __rhs) const
246 { return _M_base() == __rhs; }
249 operator!=(const bitset<_Nb>& __rhs) const
250 { return _M_base() != __rhs; }
257 operator<<(size_t __pos) const
258 { return bitset<_Nb>(_M_base() << __pos); }
261 operator>>(size_t __pos) const
262 { return bitset<_Nb>(_M_base() >> __pos); }
265 _M_base() { return *this; }
268 _M_base() const { return *this; }
273 operator&(const bitset<_Nb>& __x, const bitset<_Nb>& __y)
274 { return bitset<_Nb>(__x) &= __y; }
278 operator|(const bitset<_Nb>& __x, const bitset<_Nb>& __y)
279 { return bitset<_Nb>(__x) |= __y; }
283 operator^(const bitset<_Nb>& __x, const bitset<_Nb>& __y)
284 { return bitset<_Nb>(__x) ^= __y; }
286 template<typename _CharT, typename _Traits, size_t _Nb>
287 std::basic_istream<_CharT, _Traits>&
288 operator>>(std::basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x)
289 { return __is >> __x._M_base(); }
291 template<typename _CharT, typename _Traits, size_t _Nb>
292 std::basic_ostream<_CharT, _Traits>&
293 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
294 const bitset<_Nb>& __x)
295 { return __os << __x._M_base(); }
296 } // namespace __gnu_debug_def