]> Dogcows Code - chaz/yoink/blob - src/stlplus/persistence/persistent_inf.cpp
archiving support for releases
[chaz/yoink] / src / stlplus / persistence / persistent_inf.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
10 // can be excluded to break the dependency on the portability library
11 #ifndef NO_STLPLUS_INF
12
13 #include "persistent_int.hpp"
14 #include "persistent_string.hpp"
15 #include "persistent_inf.hpp"
16
17 ////////////////////////////////////////////////////////////////////////////////
18
19 void stlplus::dump_inf(stlplus::dump_context& context, const stlplus::inf& data)
20 throw(stlplus::persistent_dump_failed)
21 {
22 // don't support dumping of old versions
23 if (context.version() < 2)
24 throw stlplus::persistent_dump_failed(std::string("stlplus::inf::dump: wrong version"));
25 // just dump the string
26 stlplus::dump_string(context,data.get_bytes());
27 }
28
29 ////////////////////////////////////////////////////////////////////////////////
30
31 void stlplus::restore_inf(stlplus::restore_context& context, stlplus::inf& data)
32 throw(stlplus::persistent_restore_failed)
33 {
34 if (context.version() < 1)
35 throw stlplus::persistent_restore_failed(std::string("stlplus::inf::restore: wrong version"));
36 if (context.version() == 1)
37 {
38 // old-style restore relies on the word size being the same - 32-bits - on all platforms
39 // this can be restored on such machines but is not portable to 64-bit machines
40 std::string value;
41 unsigned bits = 0;
42 stlplus::restore_unsigned(context,bits);
43 unsigned words = (bits+7)/32;
44 // inf was dumped msB first
45 for (unsigned i = words; i--; )
46 {
47 // restore a word
48 unsigned word = 0;
49 stlplus::restore_unsigned(context,word);
50 // now extract the bytes
51 unsigned char* byte_ptr = (unsigned char*)(&word);
52 for (unsigned b = 4; b--; )
53 value.insert(value.begin(),byte_ptr[context.little_endian() ? b : 3 - b]);
54 }
55 data.set_bytes(value);
56 }
57 else
58 {
59 // new-style dump just uses the string persistence
60 std::string value;
61 stlplus::restore_string(context,value);
62 data.set_bytes(value);
63 }
64 }
65 ////////////////////////////////////////////////////////////////////////////////
66 #endif
This page took 0.035729 seconds and 4 git commands to generate.