]> Dogcows Code - chaz/yoink/blob - src/stlplus/persistence/persistent_vector.cpp
archiving support for releases
[chaz/yoink] / src / stlplus / persistence / persistent_vector.cpp
1 ////////////////////////////////////////////////////////////////////////////////
2
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
7
8 ////////////////////////////////////////////////////////////////////////////////
9 #include "persistent_vector.hpp"
10
11 ////////////////////////////////////////////////////////////////////////////////
12 // specialisation for a vector of bool which has a different implementation to a vector of anything else
13
14 void stlplus::dump_vector_bool(stlplus::dump_context& context, const std::vector<bool>& data)
15 throw(stlplus::persistent_dump_failed)
16 {
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++)
21 {
22 unsigned char byte = 0;
23 unsigned char mask = 1;
24 for (unsigned e = 0; e < 8; e++)
25 {
26 unsigned i = b*8 + e;
27 if (i >= size) break;
28 if (data[i]) byte |= mask;
29 mask <<= 1;
30 }
31 context.put(byte);
32 }
33 }
34
35 void stlplus::restore_vector_bool(stlplus::restore_context& context, std::vector<bool>& data)
36 throw(stlplus::persistent_restore_failed)
37 {
38 unsigned size = 0;
39 stlplus::restore_unsigned(context,size);
40 data.resize(size);
41 unsigned bytes = ((size + 7) / 8);
42 for (unsigned b = 0; b < bytes; b++)
43 {
44 unsigned char byte = context.get();
45 unsigned char mask = 1;
46 for (unsigned e = 0; e < 8; e++)
47 {
48 unsigned i = b*8 + e;
49 if (i >= size) break;
50 data[i] = ((byte & mask) != 0);
51 mask <<= 1;
52 }
53 }
54 }
55
56 ////////////////////////////////////////////////////////////////////////////////
This page took 0.031585 seconds and 4 git commands to generate.