X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fstlplus%2Fpersistence%2Fpersistent_inf.cpp;fp=src%2Fstlplus%2Fpersistence%2Fpersistent_inf.cpp;h=29637c913ea05ccba4eba683b7aa6a9256cce7df;hb=6b0a0d0efafe34d48ab344fca3b479553bd4e62c;hp=0000000000000000000000000000000000000000;hpb=85783316365181491a3e3c0c63659972477cebba;p=chaz%2Fyoink diff --git a/src/stlplus/persistence/persistent_inf.cpp b/src/stlplus/persistence/persistent_inf.cpp new file mode 100644 index 0000000..29637c9 --- /dev/null +++ b/src/stlplus/persistence/persistent_inf.cpp @@ -0,0 +1,66 @@ +//////////////////////////////////////////////////////////////////////////////// + +// Author: Andy Rushton +// Copyright: (c) Southampton University 1999-2004 +// (c) Andy Rushton 2004-2009 +// License: BSD License, see ../docs/license.html + +//////////////////////////////////////////////////////////////////////////////// + +// can be excluded to break the dependency on the portability library +#ifndef NO_STLPLUS_INF + +#include "persistent_int.hpp" +#include "persistent_string.hpp" +#include "persistent_inf.hpp" + +//////////////////////////////////////////////////////////////////////////////// + +void stlplus::dump_inf(stlplus::dump_context& context, const stlplus::inf& data) + throw(stlplus::persistent_dump_failed) +{ + // don't support dumping of old versions + if (context.version() < 2) + throw stlplus::persistent_dump_failed(std::string("stlplus::inf::dump: wrong version")); + // just dump the string + stlplus::dump_string(context,data.get_bytes()); +} + +//////////////////////////////////////////////////////////////////////////////// + +void stlplus::restore_inf(stlplus::restore_context& context, stlplus::inf& data) + throw(stlplus::persistent_restore_failed) +{ + if (context.version() < 1) + throw stlplus::persistent_restore_failed(std::string("stlplus::inf::restore: wrong version")); + if (context.version() == 1) + { + // old-style restore relies on the word size being the same - 32-bits - on all platforms + // this can be restored on such machines but is not portable to 64-bit machines + std::string value; + unsigned bits = 0; + stlplus::restore_unsigned(context,bits); + unsigned words = (bits+7)/32; + // inf was dumped msB first + for (unsigned i = words; i--; ) + { + // restore a word + unsigned word = 0; + stlplus::restore_unsigned(context,word); + // now extract the bytes + unsigned char* byte_ptr = (unsigned char*)(&word); + for (unsigned b = 4; b--; ) + value.insert(value.begin(),byte_ptr[context.little_endian() ? b : 3 - b]); + } + data.set_bytes(value); + } + else + { + // new-style dump just uses the string persistence + std::string value; + stlplus::restore_string(context,value); + data.set_bytes(value); + } +} +//////////////////////////////////////////////////////////////////////////////// +#endif