persistence/persistent_pointer.hpp

    1: #ifndef STLPLUS_PERSISTENT_POINTER
    2: #define STLPLUS_PERSISTENT_POINTER
    3: ////////////////////////////////////////////////////////////////////////////////
    4: 
    5: //   Author:    Andy Rushton
    6: //   Copyright: (c) Andy Rushton, 2007
    7: //   License:   BSD License, see ../docs/license.html
    8: 
    9: //   Persistence for pointers to persistent objects
   10: 
   11: //   Warning! The pointer must be a dynamically-allocated type, since the
   12: //   implementation uses new/delete
   13: 
   14: //   Multiple pointers to the same object *will* be restored as multiple pointers
   15: //   to the same object. The object is dumped only the first time it is
   16: //   encountered along with a "magic key". Subsequent pointers to the same object
   17: //   cause only the magic key to be dumped. On restore, the object is only
   18: //   restored once and the magic keys are matched up so that the other pointers
   19: //   now point to the restored object.
   20: 
   21: //   Supports null pointers too! If the data field to restore is null and the
   22: //   file format non-null, allocates a new T(). If the data field is non-null and
   23: //   the file format is null, deletes it and sets it null
   24: 
   25: ////////////////////////////////////////////////////////////////////////////////
   26: #include "persistence_fixes.hpp"
   27: #include "persistent_contexts.hpp"
   28: 
   29: ////////////////////////////////////////////////////////////////////////////////
   30: 
   31: namespace stlplus
   32: {
   33: 
   34:   template<typename T, typename D>
   35:   void dump_pointer(dump_context&, const T* const data, D dump_fn)
   36:     throw(persistent_dump_failed);
   37: 
   38:   template<typename T, typename R>
   39:   void restore_pointer(restore_context&, T*& data, R restore_fn)
   40:     throw(persistent_restore_failed);
   41: 
   42: } // end namespace stlplus
   43: 
   44:   ////////////////////////////////////////////////////////////////////////////////
   45: #include "persistent_pointer.tpp"
   46: #endif