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_int.hpp"
14 ////////////////////////////////////////////////////////////////////////////////
15 // format: data msB first, packed into bytes with lowest index at the byte's lsb
17 // Note: the interface does not provide access to the internal storage and yet
18 // to be efficient the std::bitset must be packed as bytes. Thus I have to do it the
22 void dump_bitset(dump_context& context, const std::bitset<N>& data)
23 throw(persistent_dump_failed)
25 size_t bits = data.size();
26 size_t bytes = (bits+7)/8;
27 for (size_t B = bytes; B--; )
30 for (size_t b = 0; b < 8; b++)
33 if (bit < bits && data.test(bit))
36 dump_unsigned_char(context,ch);
41 void restore_bitset(restore_context& context, std::bitset<N>& data)
42 throw(persistent_restore_failed)
44 size_t bits = data.size();
45 size_t bytes = (bits+7)/8;
46 for (size_t B = bytes; B--; )
49 restore_unsigned_char(context,ch);
50 for (size_t b = 0; b < 8; b++)
53 if (bit >= bits) break;
54 data.set(bit, ch & (0x01 << b) ? true : false);
59 ////////////////////////////////////////////////////////////////////////////////
61 } // end namespace stlplus