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 ////////////////////////////////////////////////////////////////////////////////
10 // can be excluded to break the dependency on the portability library
11 #ifndef NO_STLPLUS_INF
13 #include "persistent_int.hpp"
14 #include "persistent_string.hpp"
15 #include "persistent_inf.hpp"
17 ////////////////////////////////////////////////////////////////////////////////
19 void stlplus::dump_inf(stlplus::dump_context
& context
, const stlplus::inf
& data
)
20 throw(stlplus::persistent_dump_failed
)
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());
29 ////////////////////////////////////////////////////////////////////////////////
31 void stlplus::restore_inf(stlplus::restore_context
& context
, stlplus::inf
& data
)
32 throw(stlplus::persistent_restore_failed
)
34 if (context
.version() < 1)
35 throw stlplus::persistent_restore_failed(std::string("stlplus::inf::restore: wrong version"));
36 if (context
.version() == 1)
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
42 stlplus::restore_unsigned(context
,bits
);
43 unsigned words
= (bits
+7)/32;
44 // inf was dumped msB first
45 for (unsigned i
= words
; i
--; )
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
]);
55 data
.set_bytes(value
);
59 // new-style dump just uses the string persistence
61 stlplus::restore_string(context
,value
);
62 data
.set_bytes(value
);
65 ////////////////////////////////////////////////////////////////////////////////