]> Dogcows Code - chaz/yoink/blobdiff - src/stlplus/persistence/persistent_xref.tpp
testing new non-autotools build system
[chaz/yoink] / src / stlplus / persistence / persistent_xref.tpp
diff --git a/src/stlplus/persistence/persistent_xref.tpp b/src/stlplus/persistence/persistent_xref.tpp
new file mode 100644 (file)
index 0000000..e12639d
--- /dev/null
@@ -0,0 +1,51 @@
+////////////////////////////////////////////////////////////////////////////////\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
+//   format: magic_key [ data ]\r
+\r
+////////////////////////////////////////////////////////////////////////////////\r
+#include "persistent_int.hpp"\r
+\r
+namespace stlplus\r
+{\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+\r
+  template<typename T>\r
+  void dump_xref(dump_context& context, const T* const data)\r
+    throw(persistent_dump_failed)\r
+  {\r
+    // register the address and get the magic key for it\r
+    std::pair<bool,unsigned> mapping = context.pointer_map(data);\r
+    // if this is the first view of this pointer, simply throw an exception\r
+    if (!mapping.first) throw persistent_dump_failed("tried to dump a cross-reference not seen before");\r
+    // otherwise, just dump the magic key\r
+    dump_unsigned(context,mapping.second);\r
+  }\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////>\r
+\r
+  template<typename T>\r
+  void restore_xref(restore_context& context, T*& data)\r
+    throw(persistent_restore_failed)\r
+  {\r
+    // Note: I do not try to delete the old data because this is a cross-reference\r
+    // get the magic key\r
+    unsigned magic = 0;\r
+    restore_unsigned(context,magic);\r
+    // now lookup the magic key to see if this pointer has already been restored\r
+    // null pointers are always flagged as already restored\r
+    std::pair<bool,void*> address = context.pointer_map(magic);\r
+    // if this is the first view of this pointer, simply throw an exception\r
+    if (!address.first) throw persistent_restore_failed("tried to restore a cross-reference not seen before");\r
+    // seen before, so simply assign the old address\r
+    data = (T*)address.second;\r
+  }\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+\r
+} // end namespace stlplus\r
This page took 0.02706 seconds and 4 git commands to generate.