1 ////////////////////////////////////////////////////////////////////////////////
3 // Author: Andy Rushton
4 // Copyright: (c) Southampton University 1999-2004
5 // (c) Andy Rushton 2004-2009
6 // License: BSD License, see ../docs/license.html
8 // format: magic_key [ data ]
10 ////////////////////////////////////////////////////////////////////////////////
11 #include "persistent_int.hpp"
16 ////////////////////////////////////////////////////////////////////////////////
19 void dump_xref(dump_context& context, const T* const data)
20 throw(persistent_dump_failed)
22 // register the address and get the magic key for it
23 std::pair<bool,unsigned> mapping = context.pointer_map(data);
24 // if this is the first view of this pointer, simply throw an exception
25 if (!mapping.first) throw persistent_dump_failed("tried to dump a cross-reference not seen before");
26 // otherwise, just dump the magic key
27 dump_unsigned(context,mapping.second);
30 ////////////////////////////////////////////////////////////////////////////////>
33 void restore_xref(restore_context& context, T*& data)
34 throw(persistent_restore_failed)
36 // Note: I do not try to delete the old data because this is a cross-reference
39 restore_unsigned(context,magic);
40 // now lookup the magic key to see if this pointer has already been restored
41 // null pointers are always flagged as already restored
42 std::pair<bool,void*> address = context.pointer_map(magic);
43 // if this is the first view of this pointer, simply throw an exception
44 if (!address.first) throw persistent_restore_failed("tried to restore a cross-reference not seen before");
45 // seen before, so simply assign the old address
46 data = (T*)address.second;
49 ////////////////////////////////////////////////////////////////////////////////
51 } // end namespace stlplus