2 template <>
struct binary<
std::vector<bool> >
5 typedef std::vector< bool > value_type;
6 typedef value_type::value_type elem_type;
8 static const bool is_streamable =
true;
10 static size_t size_of(
void) {
return UnknownSize; }
11 static size_t size_of(
const value_type& _v)
13 return _v.size() / 8 + ((_v.size() % 8)!=0);
17 size_t store( std::ostream& _ostr,
const value_type& _v,
bool )
21 size_t N = _v.size() / 8;
22 size_t R = _v.size() % 8;
27 for (idx=0; idx < N; ++idx)
29 bits =
static_cast<unsigned char>(_v[idx])
30 | (static_cast<unsigned char>(_v[idx+1]) << 1)
31 | (static_cast<unsigned char>(_v[idx+2]) << 2)
32 | (static_cast<unsigned char>(_v[idx+3]) << 3)
33 | (static_cast<unsigned char>(_v[idx+4]) << 4)
34 | (static_cast<unsigned char>(_v[idx+5]) << 5)
35 | (static_cast<unsigned char>(_v[idx+6]) << 6)
36 | (static_cast<unsigned char>(_v[idx+7]) << 7);
46 case 7: bits |= (
static_cast<unsigned char>(_v[idx+6]) << 6);
47 case 6: bits |= (
static_cast<unsigned char>(_v[idx+5]) << 5);
48 case 5: bits |= (
static_cast<unsigned char>(_v[idx+4]) << 4);
49 case 4: bits |= (
static_cast<unsigned char>(_v[idx+3]) << 3);
50 case 3: bits |= (
static_cast<unsigned char>(_v[idx+2]) << 2);
51 case 2: bits |= (
static_cast<unsigned char>(_v[idx+1]) << 1);
52 case 1: bits |=
static_cast<unsigned char>(_v[idx+0]);
58 assert( bytes == size_of(_v) );
64 size_t restore( std::istream& _istr, value_type& _v,
bool )
68 size_t N = _v.size() / 8;
69 size_t R = _v.size() % 8;
74 for (idx=0; idx < N; ++idx)
77 _v[idx+0] = ((bits & 0x01)!=0);
78 _v[idx+1] = ((bits & 0x02)!=0);
79 _v[idx+2] = ((bits & 0x04)!=0);
80 _v[idx+3] = ((bits & 0x08)!=0);
81 _v[idx+4] = ((bits & 0x10)!=0);
82 _v[idx+5] = ((bits & 0x20)!=0);
83 _v[idx+6] = ((bits & 0x40)!=0);
84 _v[idx+7] = ((bits & 0x80)!=0);
91 for(; idx < _v.size(); ++idx)
92 _v[idx] = (bits & (1 << (idx%8)))!=0;