]> Dogcows Code - chaz/yoink/blob - src/stlplus/persistence/persistent_xref.tpp
e12639d59e08ef89afda2e69a5b92146fbf7e935
[chaz/yoink] / src / stlplus / persistence / persistent_xref.tpp
1 ////////////////////////////////////////////////////////////////////////////////
2
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
7
8 // format: magic_key [ data ]
9
10 ////////////////////////////////////////////////////////////////////////////////
11 #include "persistent_int.hpp"
12
13 namespace stlplus
14 {
15
16 ////////////////////////////////////////////////////////////////////////////////
17
18 template<typename T>
19 void dump_xref(dump_context& context, const T* const data)
20 throw(persistent_dump_failed)
21 {
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);
28 }
29
30 ////////////////////////////////////////////////////////////////////////////////>
31
32 template<typename T>
33 void restore_xref(restore_context& context, T*& data)
34 throw(persistent_restore_failed)
35 {
36 // Note: I do not try to delete the old data because this is a cross-reference
37 // get the magic key
38 unsigned magic = 0;
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;
47 }
48
49 ////////////////////////////////////////////////////////////////////////////////
50
51 } // end namespace stlplus
This page took 0.030245 seconds and 3 git commands to generate.