]> Dogcows Code - chaz/yoink/blobdiff - src/stlplus/persistence/persistent_inf.cpp
testing new non-autotools build system
[chaz/yoink] / src / stlplus / persistence / persistent_inf.cpp
diff --git a/src/stlplus/persistence/persistent_inf.cpp b/src/stlplus/persistence/persistent_inf.cpp
new file mode 100644 (file)
index 0000000..29637c9
--- /dev/null
@@ -0,0 +1,66 @@
+////////////////////////////////////////////////////////////////////////////////\r
+\r
+//   Author:    Andy Rushton\r
+//   Copyright: (c) Southampton University 1999-2004\r
+//              (c) Andy Rushton           2004-2009\r
+//   License:   BSD License, see ../docs/license.html\r
+\r
+////////////////////////////////////////////////////////////////////////////////\r
+\r
+// can be excluded to break the dependency on the portability library\r
+#ifndef NO_STLPLUS_INF\r
+\r
+#include "persistent_int.hpp"\r
+#include "persistent_string.hpp"\r
+#include "persistent_inf.hpp"\r
+\r
+////////////////////////////////////////////////////////////////////////////////\r
+\r
+void stlplus::dump_inf(stlplus::dump_context& context, const stlplus::inf& data)\r
+  throw(stlplus::persistent_dump_failed)\r
+{\r
+  // don't support dumping of old versions\r
+  if (context.version() < 2)\r
+    throw stlplus::persistent_dump_failed(std::string("stlplus::inf::dump: wrong version"));\r
+  // just dump the string\r
+  stlplus::dump_string(context,data.get_bytes());\r
+}\r
+\r
+////////////////////////////////////////////////////////////////////////////////\r
+\r
+void stlplus::restore_inf(stlplus::restore_context& context, stlplus::inf& data)\r
+  throw(stlplus::persistent_restore_failed)\r
+{\r
+  if (context.version() < 1)\r
+    throw stlplus::persistent_restore_failed(std::string("stlplus::inf::restore: wrong version"));\r
+  if (context.version() == 1)\r
+  {\r
+    // old-style restore relies on the word size being the same - 32-bits - on all platforms\r
+    // this can be restored on such machines but is not portable to 64-bit machines\r
+    std::string value;\r
+    unsigned bits = 0;\r
+    stlplus::restore_unsigned(context,bits);\r
+    unsigned words = (bits+7)/32;\r
+    // inf was dumped msB first\r
+    for (unsigned i = words; i--; )\r
+    {\r
+      // restore a word\r
+      unsigned word = 0;\r
+      stlplus::restore_unsigned(context,word);\r
+      // now extract the bytes\r
+      unsigned char* byte_ptr = (unsigned char*)(&word);\r
+      for (unsigned b = 4; b--; )\r
+        value.insert(value.begin(),byte_ptr[context.little_endian() ? b : 3 - b]);\r
+    }\r
+    data.set_bytes(value);\r
+  }\r
+  else\r
+  {\r
+    // new-style dump just uses the string persistence\r
+    std::string value;\r
+    stlplus::restore_string(context,value);\r
+    data.set_bytes(value);\r
+  }\r
+}\r
+////////////////////////////////////////////////////////////////////////////////\r
+#endif\r
This page took 0.02171 seconds and 4 git commands to generate.