]> Dogcows Code - chaz/yoink/blobdiff - src/stlplus/persistence/persistent_vector.cpp
testing new non-autotools build system
[chaz/yoink] / src / stlplus / persistence / persistent_vector.cpp
diff --git a/src/stlplus/persistence/persistent_vector.cpp b/src/stlplus/persistence/persistent_vector.cpp
new file mode 100644 (file)
index 0000000..b983d37
--- /dev/null
@@ -0,0 +1,56 @@
+////////////////////////////////////////////////////////////////////////////////\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
+#include "persistent_vector.hpp"\r
+\r
+////////////////////////////////////////////////////////////////////////////////\r
+// specialisation for a vector of bool which has a different implementation to a vector of anything else\r
+\r
+void stlplus::dump_vector_bool(stlplus::dump_context& context, const std::vector<bool>& data)\r
+  throw(stlplus::persistent_dump_failed)\r
+{\r
+  stlplus::dump_unsigned(context,data.size());\r
+  unsigned size = data.size();\r
+  unsigned bytes = ((size + 7) / 8);\r
+  for (unsigned b = 0; b < bytes; b++)\r
+  {\r
+    unsigned char byte = 0;\r
+    unsigned char mask = 1;\r
+    for (unsigned e = 0; e < 8; e++)\r
+    {\r
+      unsigned i = b*8 + e;\r
+      if (i >= size) break;\r
+      if (data[i]) byte |= mask;\r
+      mask <<= 1;\r
+    }\r
+    context.put(byte);\r
+  }\r
+}\r
+\r
+void stlplus::restore_vector_bool(stlplus::restore_context& context, std::vector<bool>& data)\r
+  throw(stlplus::persistent_restore_failed)\r
+{\r
+  unsigned size = 0;\r
+  stlplus::restore_unsigned(context,size);\r
+  data.resize(size);\r
+  unsigned bytes = ((size + 7) / 8);\r
+  for (unsigned b = 0; b < bytes; b++)\r
+  {\r
+    unsigned char byte = context.get();\r
+    unsigned char mask = 1;\r
+    for (unsigned e = 0; e < 8; e++)\r
+    {\r
+      unsigned i = b*8 + e;\r
+      if (i >= size) break;\r
+      data[i] = ((byte & mask) != 0);\r
+      mask <<= 1;\r
+    }\r
+  }\r
+}\r
+\r
+////////////////////////////////////////////////////////////////////////////////\r
This page took 0.025338 seconds and 4 git commands to generate.