persistence/persistent_interface.hpp

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