+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////\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_int.hpp"\r
-#include "persistent_pointer.hpp"\r
-#include "persistent_callback.hpp"\r
-#include "persistent_interface.hpp"\r
-\r
-namespace stlplus\r
-{\r
-\r
- ////////////////////////////////////////////////////////////////////////////////\r
-\r
- template<typename T, typename DE>\r
- void dump_smart_ptr(dump_context& context, const smart_ptr<T>& data,\r
- DE dump_element)\r
- throw(persistent_dump_failed)\r
- {\r
- // similar to the simple pointer routines, but use the address of the holder to tell which objects are aliases\r
- // Many smart pointers can point to the same object.\r
- // I could have used the address of the object to differentiate, \r
- // but that would not have differentiated between different null smart pointers\r
- // so I use the address of the substructure to differentiate between different objects.\r
- // get a magic key for the substructure - this also returns a flag saying whether its been seen before\r
- std::pair<bool,unsigned> mapping = context.pointer_map(data._handle());\r
- // dump the magic key\r
- dump_unsigned(context,mapping.second);\r
- // dump the contents but only if this is the first time this object has been seen\r
- // use the existing routines for ordinary pointers to dump the contents\r
- if (!mapping.first)\r
- dump_pointer(context,data.pointer(),dump_element);\r
- }\r
-\r
- template<typename T, typename RE>\r
- void restore_smart_ptr(restore_context& context, smart_ptr<T>& data,\r
- RE restore_element)\r
- throw(persistent_restore_failed)\r
- {\r
- // get the old substructure magic key\r
- unsigned magic = 0;\r
- restore_unsigned(context,magic);\r
- // lookup this magic number to see if we have seen this already\r
- std::pair<bool,void*> mapping = context.pointer_map(magic);\r
- if (mapping.first)\r
- {\r
- // this holder has already been restored\r
- // dealias the existing holder and replace it with the seen-before holder to make this object an alias of it\r
- data._make_alias((smart_ptr_holder<T>*)mapping.second);\r
- }\r
- else\r
- {\r
- // this is the first contact with this holder\r
- // make sure this smart pointer is unique to prevent side-effects\r
- data.clear_unique();\r
- // map the magic key onto this structure's holder\r
- // do this before restoring the object so that self-referential structures restore correctly\r
- context.pointer_add(magic,data._handle());\r
- // now restore the object\r
- T* value = 0;\r
- restore_pointer(context,value,restore_element);\r
- data.set(value);\r
- }\r
- }\r
-\r
- ////////////////////////////////////////////////////////////////////////////////\r
- // smart_ptr_clone using callbacks\r
-\r
- template<typename T>\r
- void dump_smart_ptr_clone_callback(dump_context& context, const smart_ptr_clone<T>& data)\r
- throw(persistent_dump_failed)\r
- {\r
- // similar to the simple pointer routines, but use the address of the holder to tell which objects are aliases\r
- // Many smart pointers can point to the same object.\r
- // I could have used the address of the object to differentiate, \r
- // but that would not have differentiated between different null smart pointers\r
- // so I use the address of the substructure to differentiate between different objects.\r
- // get a magic key for the substructure - this also returns a flag saying whether its been seen before\r
- std::pair<bool,unsigned> mapping = context.pointer_map(data._handle());\r
- // dump the magic key\r
- dump_unsigned(context,mapping.second);\r
- // dump the contents but only if this is the first time this object has been seen\r
- // use the existing routines for ordinary pointers to dump the contents\r
- if (!mapping.first)\r
- dump_callback(context,data.pointer());\r
- }\r
-\r
- template<typename T>\r
- void restore_smart_ptr_clone_callback(restore_context& context, smart_ptr_clone<T>& data)\r
- throw(persistent_restore_failed)\r
- {\r
- // get the old substructure magic key\r
- unsigned magic = 0;\r
- restore_unsigned(context,magic);\r
- // lookup this magic number to see if we have seen this already\r
- std::pair<bool,void*> mapping = context.pointer_map(magic);\r
- if (mapping.first)\r
- {\r
- // this holder has already been restored\r
- // dealias the existing holder and replace it with the seen-before holder to make this object an alias of it\r
- data._make_alias((smart_ptr_holder<T>*)mapping.second);\r
- }\r
- else\r
- {\r
- // this is the first contact with this holder\r
- // make sure this smart pointer is unique to prevent side-effects\r
- data.clear_unique();\r
- // map the magic key onto this structure's holder\r
- // do this before restoring the object so that self-referential structures restore correctly\r
- context.pointer_add(magic,data._handle());\r
- // now restore the object\r
- T* value = 0;\r
- restore_callback(context,value);\r
- data.set(value);\r
- }\r
- }\r
-\r
- ////////////////////////////////////////////////////////////////////////////////\r
- // smart_ptr_clone using interface\r
-\r
- template<typename T>\r
- void dump_smart_ptr_clone_interface(dump_context& context, const smart_ptr_clone<T>& data)\r
- throw(persistent_dump_failed)\r
- {\r
- // similar to the simple pointer routines, but use the address of the holder to tell which objects are aliases\r
- // Many smart pointers can point to the same object.\r
- // I could have used the address of the object to differentiate, \r
- // but that would not have differentiated between different null smart pointers\r
- // so I use the address of the substructure to differentiate between different objects.\r
- // get a magic key for the substructure - this also returns a flag saying whether its been seen before\r
- std::pair<bool,unsigned> mapping = context.pointer_map(data._handle());\r
- // dump the magic key\r
- dump_unsigned(context,mapping.second);\r
- // dump the contents but only if this is the first time this object has been seen\r
- // use the existing routines for ordinary pointers to dump the contents\r
- if (!mapping.first)\r
- dump_interface(context,data.pointer());\r
- }\r
-\r
- template<typename T>\r
- void restore_smart_ptr_clone_interface(restore_context& context, smart_ptr_clone<T>& data)\r
- throw(persistent_restore_failed)\r
- {\r
- // get the old substructure magic key\r
- unsigned magic = 0;\r
- restore_unsigned(context,magic);\r
- // lookup this magic number to see if we have seen this already\r
- std::pair<bool,void*> mapping = context.pointer_map(magic);\r
- if (mapping.first)\r
- {\r
- // this holder has already been restored\r
- // dealias the existing holder and replace it with the seen-before holder to make this object an alias of it\r
- data._make_alias((smart_ptr_holder<T>*)mapping.second);\r
- }\r
- else\r
- {\r
- // this is the first contact with this holder\r
- // make sure this smart pointer is unique to prevent side-effects\r
- data.clear_unique();\r
- // map the magic key onto this structure's holder\r
- // do this before restoring the object so that self-referential structures restore correctly\r
- context.pointer_add(magic,data._handle());\r
- // now restore the object\r
- T* value = 0;\r
- restore_interface(context,value);\r
- data.set(value);\r
- }\r
- }\r
-\r
- ////////////////////////////////////////////////////////////////////////////////\r
-\r
-} // end namespace stlplus\r