persistence/persistent_callback.hpp

    1: #ifndef STLPLUS_PERSISTENT_CALLBACK
    2: #define STLPLUS_PERSISTENT_CALLBACK
    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 polymorphic classes using the callback approach.
   10: 
   11: //   This works on a set of classes. Each subclass has a set of callback
   12: //   (non-method) functions that enable create/dump/restore operations. Each
   13: //   subclass must be registered with the persistence dump/restore context so
   14: //   that the system knows how to handle it.
   15: 
   16: //   This approach is suited to classes that cannot be modified to add
   17: //   persistence methods. See persistent_interface for a more C++-like way of
   18: //   handling polymorphism.
   19: 
   20: //   Objects are always dumped/restored as pointers to the superclass T.
   21: 
   22: //   Multiple pointers to the same object are handled in the same way as for
   23: //   simple pointers
   24: 
   25: //   Only classes registered with the context can be dumped and restored as
   26: //   polymorphic types - see dump_context::register_callback and
   27: //   restore_context::register_callback. Attempting to use any unrecognised class
   28: //   will throw an exception.
   29: 
   30: ////////////////////////////////////////////////////////////////////////////////
   31: 
   32: #include "persistence_fixes.hpp"
   33: #include "persistent_contexts.hpp"
   34: 
   35: ////////////////////////////////////////////////////////////////////////////////
   36: 
   37: namespace stlplus
   38: {
   39: 
   40:   template<typename T>
   41:   void dump_callback(dump_context&, const T* const data)
   42:     throw(persistent_dump_failed);
   43: 
   44:   template<typename T>
   45:   void restore_callback(restore_context&, T*& data)
   46:     throw(persistent_restore_failed);
   47: 
   48: } // end namespace stlplus
   49: 
   50:   ////////////////////////////////////////////////////////////////////////////////
   51: #include "persistent_callback.tpp"
   52: #endif