1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/tools/stlport/stl/_bitset.c Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,235 @@
1.4 +/*
1.5 + * Copyright (c) 1998
1.6 + * Silicon Graphics Computer Systems, Inc.
1.7 + *
1.8 + * Copyright (c) 1999
1.9 + * Boris Fomitchev
1.10 + *
1.11 + * This material is provided "as is", with absolutely no warranty expressed
1.12 + * or implied. Any use is at your own risk.
1.13 + *
1.14 + * Permission to use or copy this software for any purpose is hereby granted
1.15 + * without fee, provided the above notices are retained on all copies.
1.16 + * Permission to modify the code and to distribute modified code is granted,
1.17 + * provided the above notices are retained, and a notice that the code was
1.18 + * modified is included with the above copyright notice.
1.19 + *
1.20 + */
1.21 +
1.22 +#ifndef _STLP_BITSET_C
1.23 +#define _STLP_BITSET_C
1.24 +
1.25 +#ifndef _STLP_BITSET_H
1.26 +# include <stl/_bitset.h>
1.27 +#endif
1.28 +
1.29 +#define __BITS_PER_WORD (CHAR_BIT * sizeof(unsigned long))
1.30 +
1.31 +_STLP_BEGIN_NAMESPACE
1.32 +
1.33 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.34 +//
1.35 +// Definitions of non-inline functions from _Base_bitset.
1.36 +//
1.37 +template<size_t _Nw>
1.38 +void _Base_bitset<_Nw>::_M_do_left_shift(size_t __shift) {
1.39 + if (__shift != 0) {
1.40 + const size_t __wshift = __shift / __BITS_PER_WORD;
1.41 + const size_t __offset = __shift % __BITS_PER_WORD;
1.42 +
1.43 + if (__offset == 0)
1.44 + for (size_t __n = _Nw - 1; __n >= __wshift; --__n)
1.45 + _M_w[__n] = _M_w[__n - __wshift];
1.46 +
1.47 + else {
1.48 + const size_t __sub_offset = __BITS_PER_WORD - __offset;
1.49 + for (size_t __n = _Nw - 1; __n > __wshift; --__n)
1.50 + _M_w[__n] = (_M_w[__n - __wshift] << __offset) |
1.51 + (_M_w[__n - __wshift - 1] >> __sub_offset);
1.52 + _M_w[__wshift] = _M_w[0] << __offset;
1.53 + }
1.54 +
1.55 + fill(_M_w + 0, _M_w + __wshift, __STATIC_CAST(_WordT,0));
1.56 + }
1.57 +}
1.58 +
1.59 +template<size_t _Nw>
1.60 +void _Base_bitset<_Nw>::_M_do_right_shift(size_t __shift) {
1.61 + if (__shift != 0) {
1.62 + const size_t __wshift = __shift / __BITS_PER_WORD;
1.63 + const size_t __offset = __shift % __BITS_PER_WORD;
1.64 + const size_t __limit = _Nw - __wshift - 1;
1.65 +
1.66 + if (__offset == 0)
1.67 + for (size_t __n = 0; __n <= __limit; ++__n)
1.68 + _M_w[__n] = _M_w[__n + __wshift];
1.69 +
1.70 + else {
1.71 + const size_t __sub_offset = __BITS_PER_WORD - __offset;
1.72 + for (size_t __n = 0; __n < __limit; ++__n)
1.73 + _M_w[__n] = (_M_w[__n + __wshift] >> __offset) |
1.74 + (_M_w[__n + __wshift + 1] << __sub_offset);
1.75 + _M_w[__limit] = _M_w[_Nw-1] >> __offset;
1.76 + }
1.77 +
1.78 + fill(_M_w + __limit + 1, _M_w + _Nw, __STATIC_CAST(_WordT,0));
1.79 + }
1.80 +}
1.81 +
1.82 +template<size_t _Nw>
1.83 +unsigned long _Base_bitset<_Nw>::_M_do_to_ulong() const {
1.84 + for (size_t __i = 1; __i < _Nw; ++__i)
1.85 + if (_M_w[__i])
1.86 + __stl_throw_overflow_error("bitset");
1.87 + return _M_w[0];
1.88 +} // End _M_do_to_ulong
1.89 +
1.90 +template<size_t _Nw>
1.91 +size_t _Base_bitset<_Nw>::_M_do_find_first(size_t __not_found) const {
1.92 + for ( size_t __i = 0; __i < _Nw; __i++ ) {
1.93 + _WordT __thisword = _M_w[__i];
1.94 + if ( __thisword != __STATIC_CAST(_WordT,0) ) {
1.95 + // find byte within word
1.96 + for ( size_t __j = 0; __j < sizeof(_WordT); __j++ ) {
1.97 + unsigned char __this_byte
1.98 + = __STATIC_CAST(unsigned char,(__thisword & (~(unsigned char)0)));
1.99 + if ( __this_byte )
1.100 + return __i*__BITS_PER_WORD + __j*CHAR_BIT +
1.101 + _Bs_G::_S_first_one(__this_byte);
1.102 +
1.103 + __thisword >>= CHAR_BIT;
1.104 + }
1.105 + }
1.106 + }
1.107 + // not found, so return an indication of failure.
1.108 + return __not_found;
1.109 +}
1.110 +
1.111 +template<size_t _Nw>
1.112 +size_t
1.113 +_Base_bitset<_Nw>::_M_do_find_next(size_t __prev,
1.114 + size_t __not_found) const {
1.115 + // make bound inclusive
1.116 + ++__prev;
1.117 +
1.118 + // check out of bounds
1.119 + if ( __prev >= _Nw * __BITS_PER_WORD )
1.120 + return __not_found;
1.121 +
1.122 + // search first word
1.123 + size_t __i = _S_whichword(__prev);
1.124 + _WordT __thisword = _M_w[__i];
1.125 +
1.126 + // mask off bits below bound
1.127 + __thisword &= (~__STATIC_CAST(_WordT,0)) << _S_whichbit(__prev);
1.128 +
1.129 + if ( __thisword != __STATIC_CAST(_WordT,0) ) {
1.130 + // find byte within word
1.131 + // get first byte into place
1.132 + __thisword >>= _S_whichbyte(__prev) * CHAR_BIT;
1.133 + for ( size_t __j = _S_whichbyte(__prev); __j < sizeof(_WordT); ++__j ) {
1.134 + unsigned char __this_byte
1.135 + = __STATIC_CAST(unsigned char,(__thisword & (~(unsigned char)0)));
1.136 + if ( __this_byte )
1.137 + return __i*__BITS_PER_WORD + __j*CHAR_BIT +
1.138 + _Bs_G::_S_first_one(__this_byte);
1.139 +
1.140 + __thisword >>= CHAR_BIT;
1.141 + }
1.142 + }
1.143 +
1.144 + // check subsequent words
1.145 + ++__i;
1.146 + for ( ; __i < _Nw; ++__i ) {
1.147 + /* _WordT */ __thisword = _M_w[__i];
1.148 + if ( __thisword != __STATIC_CAST(_WordT,0) ) {
1.149 + // find byte within word
1.150 + for ( size_t __j = 0; __j < sizeof(_WordT); ++__j ) {
1.151 + unsigned char __this_byte
1.152 + = __STATIC_CAST(unsigned char,(__thisword & (~(unsigned char)0)));
1.153 + if ( __this_byte )
1.154 + return __i*__BITS_PER_WORD + __j*CHAR_BIT +
1.155 + _Bs_G::_S_first_one(__this_byte);
1.156 +
1.157 + __thisword >>= CHAR_BIT;
1.158 + }
1.159 + }
1.160 + }
1.161 +
1.162 + // not found, so return an indication of failure.
1.163 + return __not_found;
1.164 +} // end _M_do_find_next
1.165 +
1.166 +_STLP_MOVE_TO_STD_NAMESPACE
1.167 +
1.168 +#if !defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
1.169 +
1.170 +# if !defined (_STLP_USE_NO_IOSTREAMS)
1.171 +
1.172 +_STLP_END_NAMESPACE
1.173 +
1.174 +#ifndef _STLP_STRING_IO_H
1.175 +# include <stl/_string_io.h> //includes _istream.h and _ostream.h
1.176 +#endif
1.177 +
1.178 +_STLP_BEGIN_NAMESPACE
1.179 +
1.180 +template <class _CharT, class _Traits, size_t _Nb>
1.181 +basic_istream<_CharT, _Traits>& _STLP_CALL
1.182 +operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x) {
1.183 + basic_string<_CharT, _Traits> __tmp;
1.184 + __tmp.reserve(_Nb);
1.185 +
1.186 + // Skip whitespace
1.187 + typename basic_istream<_CharT, _Traits>::sentry __sentry(__is);
1.188 + if (__sentry) {
1.189 + basic_streambuf<_CharT, _Traits>* __buf = __is.rdbuf();
1.190 + for (size_t __i = 0; __i < _Nb; ++__i) {
1.191 + static typename _Traits::int_type __eof = _Traits::eof();
1.192 +
1.193 + typename _Traits::int_type __c1 = __buf->sbumpc();
1.194 + if (_Traits::eq_int_type(__c1, __eof)) {
1.195 + __is.setstate(ios_base::eofbit);
1.196 + break;
1.197 + }
1.198 + else {
1.199 + typename _Traits::char_type __c2 = _Traits::to_char_type(__c1);
1.200 + char __c = __is.narrow(__c2, '*');
1.201 +
1.202 + if (__c == '0' || __c == '1')
1.203 + __tmp.push_back(__c);
1.204 + else if (_Traits::eq_int_type(__buf->sputbackc(__c2), __eof)) {
1.205 + __is.setstate(ios_base::failbit);
1.206 + break;
1.207 + }
1.208 + }
1.209 + }
1.210 +
1.211 + if (__tmp.empty())
1.212 + __is.setstate(ios_base::failbit);
1.213 + else
1.214 + __x._M_copy_from_string(__tmp, __STATIC_CAST(size_t,0), _Nb);
1.215 + }
1.216 +
1.217 + return __is;
1.218 +}
1.219 +
1.220 +template <class _CharT, class _Traits, size_t _Nb>
1.221 +basic_ostream<_CharT, _Traits>& _STLP_CALL
1.222 +operator<<(basic_ostream<_CharT, _Traits>& __os,
1.223 + const bitset<_Nb>& __x) {
1.224 + basic_string<_CharT, _Traits> __tmp;
1.225 + __x._M_copy_to_string(__tmp);
1.226 + return __os << __tmp;
1.227 +}
1.228 +
1.229 +# endif /* !_STLP_USE_NO_IOSTREAMS */
1.230 +
1.231 +#endif /* _STLP_NON_TYPE_TMPL_PARAM_BUG */
1.232 +
1.233 +_STLP_END_NAMESPACE
1.234 +
1.235 +#undef __BITS_PER_WORD
1.236 +#undef bitset
1.237 +
1.238 +#endif /* _STLP_BITSET_C */