X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fstlplus%2Fpersistence%2Fpersistent_pointer.tpp;fp=src%2Fstlplus%2Fpersistence%2Fpersistent_pointer.tpp;h=0000000000000000000000000000000000000000;hb=5846afb00833cc72fe72422ca896d2387c712cb4;hp=c760b17c36b34ac9a946ed5a6d38920267c39e45;hpb=a97500609dc3c1b11f9786d32bc458eb00de4c36;p=chaz%2Fyoink diff --git a/src/stlplus/persistence/persistent_pointer.tpp b/src/stlplus/persistence/persistent_pointer.tpp deleted file mode 100644 index c760b17..0000000 --- a/src/stlplus/persistence/persistent_pointer.tpp +++ /dev/null @@ -1,68 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// - -// Author: Andy Rushton -// Copyright: (c) Southampton University 1999-2004 -// (c) Andy Rushton 2004-2009 -// License: BSD License, see ../docs/license.html - -// format: magic_key [ data ] - -//////////////////////////////////////////////////////////////////////////////// -#include "persistent_int.hpp" - -namespace stlplus -{ - - //////////////////////////////////////////////////////////////////////////////// - - template - void dump_pointer(dump_context& context, const T* const data, D dump_fn) - throw(persistent_dump_failed) - { - // register the address and get the magic key for it - std::pair mapping = context.pointer_map(data); - dump_unsigned(context,mapping.second); - // if the address is null, then that is all that we need to do - // however, if it is non-null and this is the first sight of the address, dump the contents - // note that the address is mapped before it is dumped so that self-referential structures dump correctly - if (data && !mapping.first) - dump_fn(context,*data); - } - - //////////////////////////////////////////////////////////////////////////////// - - template - void restore_pointer(restore_context& context, T*& data, R restore_fn) - throw(persistent_restore_failed) - { - if (data) - { - delete data; - data = 0; - } - // get the magic key - unsigned magic = 0; - restore_unsigned(context,magic); - // now lookup the magic key to see if this pointer has already been restored - // null pointers are always flagged as already restored - std::pair address = context.pointer_map(magic); - if (address.first) - { - // seen before, so simply assign the old address - data = (T*)address.second; - } - else - { - // this pointer has never been seen before and is non-null - data = new T(); - // add this pointer to the set of already seen objects - // do this before restoring the object so that self-referential structures restore correctly - context.pointer_add(magic,data); - // now restore it - restore_fn(context,*data); - } - } - - //////////////////////////////////////////////////////////////////////////////// - -} // end namespace stlplus