2template <>
struct binary< std::vector<bool> >
4 typedef std::vector< bool > value_type;
5 typedef value_type::value_type elem_type;
7 static const bool is_streamable =
true;
9 static size_t size_of(
bool =
true) {
return UnknownSize; }
10 static size_t size_of(
const value_type& _v,
bool _store_size =
true)
12 size_t size = _v.size() / 8 + ((_v.size() % 8)!=0);
14 size += binary<unsigned int>::size_of();
17 static std::string type_identifier(
void) {
return "std::vector<bool>"; }
19 size_t store( std::ostream& _ostr,
const value_type& _v,
bool _swap,
bool _store_size =
true)
23 size_t N = _v.size() / 8;
24 size_t R = _v.size() % 8;
28 unsigned int size_N =
static_cast<unsigned int>(_v.size());
29 bytes += binary<unsigned int>::store( _ostr, size_N, _swap );
36 for (bidx=idx=0; idx < N; ++idx, bidx+=8)
38 bits =
static_cast<unsigned char>(_v[bidx])
39 | (
static_cast<unsigned char>(_v[bidx+1]) << 1)
40 | (
static_cast<unsigned char>(_v[bidx+2]) << 2)
41 | (
static_cast<unsigned char>(_v[bidx+3]) << 3)
42 | (
static_cast<unsigned char>(_v[bidx+4]) << 4)
43 | (
static_cast<unsigned char>(_v[bidx+5]) << 5)
44 | (
static_cast<unsigned char>(_v[bidx+6]) << 6)
45 | (
static_cast<unsigned char>(_v[bidx+7]) << 7);
53 for (idx=0; idx < R; ++idx)
54 bits |=
static_cast<unsigned char>(_v[bidx+idx]) << idx;
58 assert( bytes == size_of(_v, _store_size) );
64 size_t restore( std::istream& _istr, value_type& _v,
bool _swap,
bool _restore_size =
true)
70 unsigned int size_of_vec;
71 bytes += binary<unsigned int>::restore(_istr, size_of_vec, _swap);
72 _v.resize(size_of_vec);
75 size_t N = _v.size() / 8;
76 size_t R = _v.size() % 8;
82 for (bidx=idx=0; idx < N; ++idx, bidx+=8)
85 _v[bidx+0] = (bits & 0x01) != 0;
86 _v[bidx+1] = (bits & 0x02) != 0;
87 _v[bidx+2] = (bits & 0x04) != 0;
88 _v[bidx+3] = (bits & 0x08) != 0;
89 _v[bidx+4] = (bits & 0x10) != 0;
90 _v[bidx+5] = (bits & 0x20) != 0;
91 _v[bidx+6] = (bits & 0x40) != 0;
92 _v[bidx+7] = (bits & 0x80) != 0;
99 for (idx=0; idx < R; ++idx)
100 _v[bidx+idx] = (bits & (1<<idx)) != 0;