1 ////////////////////////////////////////////////////////////////////////////////
3 // Author: Andy Rushton
4 // Copyright: (c) Southampton University 1999-2004
5 // (c) Andy Rushton 2004-2009
6 // License: BSD License, see ../docs/license.html
8 ////////////////////////////////////////////////////////////////////////////////
9 #include "persistent_vector.hpp"
11 ////////////////////////////////////////////////////////////////////////////////
12 // specialisation for a vector of bool which has a different implementation to a vector of anything else
14 void stlplus::dump_vector_bool(stlplus::dump_context
& context
, const std::vector
<bool>& data
)
15 throw(stlplus::persistent_dump_failed
)
17 stlplus::dump_unsigned(context
,data
.size());
18 unsigned size
= data
.size();
19 unsigned bytes
= ((size
+ 7) / 8);
20 for (unsigned b
= 0; b
< bytes
; b
++)
22 unsigned char byte
= 0;
23 unsigned char mask
= 1;
24 for (unsigned e
= 0; e
< 8; e
++)
28 if (data
[i
]) byte
|= mask
;
35 void stlplus::restore_vector_bool(stlplus::restore_context
& context
, std::vector
<bool>& data
)
36 throw(stlplus::persistent_restore_failed
)
39 stlplus::restore_unsigned(context
,size
);
41 unsigned bytes
= ((size
+ 7) / 8);
42 for (unsigned b
= 0; b
< bytes
; b
++)
44 unsigned char byte
= context
.get();
45 unsigned char mask
= 1;
46 for (unsigned e
= 0; e
< 8; e
++)
50 data
[i
] = ((byte
& mask
) != 0);
56 ////////////////////////////////////////////////////////////////////////////////