]> Dogcows Code - chaz/yoink/blobdiff - src/stlplus/persistence/persistent_contexts.hpp
testing new non-autotools build system
[chaz/yoink] / src / stlplus / persistence / persistent_contexts.hpp
diff --git a/src/stlplus/persistence/persistent_contexts.hpp b/src/stlplus/persistence/persistent_contexts.hpp
new file mode 100644 (file)
index 0000000..dfef17b
--- /dev/null
@@ -0,0 +1,156 @@
+#ifndef STLPLUS_PERSISTENT_CONTEXTS\r
+#define STLPLUS_PERSISTENT_CONTEXTS\r
+////////////////////////////////////////////////////////////////////////////////\r
+\r
+//   Author:    Andy Rushton\r
+//   Copyright: (c) Southampton University 1999-2004\r
+//              (c) Andy Rushton           2004-2009\r
+//   License:   BSD License, see ../docs/license.html\r
+\r
+//   Core context classes used to control the persistent dump/restore operations\r
+\r
+////////////////////////////////////////////////////////////////////////////////\r
+\r
+#include "persistence_fixes.hpp"\r
+#include "persistent.hpp"\r
+#include <iostream>\r
+#include <map>\r
+#include <typeinfo>\r
+\r
+////////////////////////////////////////////////////////////////////////////////\r
+\r
+namespace stlplus\r
+{\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+  // Internals\r
+\r
+  class dump_context_body;\r
+  class restore_context_body;\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+  // The format version number currently supported\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+\r
+  extern unsigned char PersistentVersion;\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+  // dump_context controls the formatting of a persistent dump\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+\r
+  class dump_context\r
+  {\r
+    friend class persistent;\r
+  public:\r
+    //////////////////////////////////////////////////////////////////////////////\r
+\r
+    // device must be in binary mode\r
+    dump_context(std::ostream& device, unsigned char version = PersistentVersion) throw(persistent_dump_failed);\r
+    ~dump_context(void);\r
+\r
+    // low level output used to dump a byte\r
+    void put(unsigned char data) throw(persistent_dump_failed);\r
+\r
+    // access the device, for example to check the error status\r
+    const std::ostream& device(void) const;\r
+\r
+    // recover the version number of the dumped output\r
+    unsigned char version(void) const;\r
+\r
+    // test whether the current platform uses little-endian or big-endian addressing of bytes\r
+    // this is used in dump/restore of integers and is exported so that other routines can use it\r
+    bool little_endian(void) const;\r
+\r
+    // Assist functions for Pointers\r
+    // the return pair value is a flag saying whether this is a new pointer and the magic key to dump to file\r
+    std::pair<bool,unsigned> pointer_map(const void* const pointer);\r
+\r
+    // Assist functions for Polymorphous classes (i.e. subclasses) using callback approach\r
+    typedef void (*dump_callback)(dump_context&,const void*);\r
+    unsigned register_callback(const std::type_info& info, dump_callback);\r
+    bool is_callback(const std::type_info& info) const;\r
+    typedef std::pair<unsigned,dump_callback> callback_data;\r
+    callback_data lookup_callback(const std::type_info&) const throw(persistent_illegal_type);\r
+\r
+    // Assist functions for Polymorphous classes (i.e. subclasses) using interface approach\r
+    unsigned register_interface(const std::type_info& info);\r
+    bool is_interface(const std::type_info& info) const;\r
+    unsigned lookup_interface(const std::type_info&) const throw(persistent_illegal_type);\r
+\r
+    // Register all Polymorphous classes using either approach by calling an installer callback\r
+    typedef void (*installer)(dump_context&);\r
+    void register_all(installer);\r
+\r
+  private:\r
+    friend class dump_context_body;\r
+    dump_context_body* m_body;\r
+\r
+    // disallow copying by making assignment and copy constructor private\r
+    dump_context(const dump_context&);\r
+    dump_context& operator=(const dump_context&);\r
+  };\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+  // restore_context controls the reading of the persistent data during a restore\r
+\r
+  class restore_context\r
+  {\r
+    friend class persistent;\r
+  public:\r
+    //////////////////////////////////////////////////////////////////////////////\r
+\r
+    // device must be in binary mode\r
+    restore_context(std::istream& device) throw(persistent_restore_failed);\r
+    ~restore_context(void);\r
+\r
+    // low level input used to restore a byte\r
+    int get(void) throw(persistent_restore_failed);\r
+\r
+    // access the device, for example to check the error status\r
+    const std::istream& device(void) const;\r
+\r
+    // access the version number of the input being restored\r
+    unsigned char version(void) const;\r
+\r
+    // test whether the current platform uses little-endian or big-endian addressing of bytes\r
+    // this is used in dump/restore of integers\r
+    bool little_endian(void) const;\r
+\r
+    // Assist functions for Pointers\r
+    std::pair<bool,void*> pointer_map(unsigned magic);\r
+    void pointer_add(unsigned magic, void* new_pointer);\r
+\r
+    // Assist functions for Polymorphous classes using the callback approach\r
+    typedef void* (*create_callback)(void);\r
+    typedef void (*restore_callback)(restore_context&,void*);\r
+    unsigned register_callback(create_callback,restore_callback);\r
+    bool is_callback(unsigned) const;\r
+    typedef std::pair<create_callback, restore_callback> callback_data;\r
+    callback_data lookup_callback(unsigned) const throw(persistent_illegal_type);\r
+\r
+    // Assist functions for Polymorphous classes using the interface approach\r
+    unsigned register_interface(persistent*);\r
+    bool is_interface(unsigned) const;\r
+    persistent* lookup_interface(unsigned) const throw(persistent_illegal_type);\r
+\r
+    // Register all Polymorphous classes using either approach by calling an installer callback\r
+    typedef void (*installer)(restore_context&);\r
+    void register_all(installer);\r
+\r
+  private:\r
+    friend class restore_context_body;\r
+    restore_context_body* m_body;\r
+\r
+    typedef std::pair<unsigned,persistent*> interface_data;\r
+\r
+    // disallow copying by making assignment and copy constructor private\r
+    restore_context(const restore_context&);\r
+    restore_context& operator=(const restore_context&);\r
+  };\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+\r
+} // end namespace stlplus\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+#endif\r
This page took 0.023406 seconds and 4 git commands to generate.