]> Dogcows Code - chaz/yoink/blob - src/stlplus/persistence/persistent_contexts.hpp
testing new non-autotools build system
[chaz/yoink] / src / stlplus / persistence / persistent_contexts.hpp
1 #ifndef STLPLUS_PERSISTENT_CONTEXTS
2 #define STLPLUS_PERSISTENT_CONTEXTS
3 ////////////////////////////////////////////////////////////////////////////////
4
5 // Author: Andy Rushton
6 // Copyright: (c) Southampton University 1999-2004
7 // (c) Andy Rushton 2004-2009
8 // License: BSD License, see ../docs/license.html
9
10 // Core context classes used to control the persistent dump/restore operations
11
12 ////////////////////////////////////////////////////////////////////////////////
13
14 #include "persistence_fixes.hpp"
15 #include "persistent.hpp"
16 #include <iostream>
17 #include <map>
18 #include <typeinfo>
19
20 ////////////////////////////////////////////////////////////////////////////////
21
22 namespace stlplus
23 {
24
25 ////////////////////////////////////////////////////////////////////////////////
26 // Internals
27
28 class dump_context_body;
29 class restore_context_body;
30
31 ////////////////////////////////////////////////////////////////////////////////
32 // The format version number currently supported
33 ////////////////////////////////////////////////////////////////////////////////
34
35 extern unsigned char PersistentVersion;
36
37 ////////////////////////////////////////////////////////////////////////////////
38 // dump_context controls the formatting of a persistent dump
39 ////////////////////////////////////////////////////////////////////////////////
40
41 class dump_context
42 {
43 friend class persistent;
44 public:
45 //////////////////////////////////////////////////////////////////////////////
46
47 // device must be in binary mode
48 dump_context(std::ostream& device, unsigned char version = PersistentVersion) throw(persistent_dump_failed);
49 ~dump_context(void);
50
51 // low level output used to dump a byte
52 void put(unsigned char data) throw(persistent_dump_failed);
53
54 // access the device, for example to check the error status
55 const std::ostream& device(void) const;
56
57 // recover the version number of the dumped output
58 unsigned char version(void) const;
59
60 // test whether the current platform uses little-endian or big-endian addressing of bytes
61 // this is used in dump/restore of integers and is exported so that other routines can use it
62 bool little_endian(void) const;
63
64 // Assist functions for Pointers
65 // the return pair value is a flag saying whether this is a new pointer and the magic key to dump to file
66 std::pair<bool,unsigned> pointer_map(const void* const pointer);
67
68 // Assist functions for Polymorphous classes (i.e. subclasses) using callback approach
69 typedef void (*dump_callback)(dump_context&,const void*);
70 unsigned register_callback(const std::type_info& info, dump_callback);
71 bool is_callback(const std::type_info& info) const;
72 typedef std::pair<unsigned,dump_callback> callback_data;
73 callback_data lookup_callback(const std::type_info&) const throw(persistent_illegal_type);
74
75 // Assist functions for Polymorphous classes (i.e. subclasses) using interface approach
76 unsigned register_interface(const std::type_info& info);
77 bool is_interface(const std::type_info& info) const;
78 unsigned lookup_interface(const std::type_info&) const throw(persistent_illegal_type);
79
80 // Register all Polymorphous classes using either approach by calling an installer callback
81 typedef void (*installer)(dump_context&);
82 void register_all(installer);
83
84 private:
85 friend class dump_context_body;
86 dump_context_body* m_body;
87
88 // disallow copying by making assignment and copy constructor private
89 dump_context(const dump_context&);
90 dump_context& operator=(const dump_context&);
91 };
92
93 ////////////////////////////////////////////////////////////////////////////////
94 // restore_context controls the reading of the persistent data during a restore
95
96 class restore_context
97 {
98 friend class persistent;
99 public:
100 //////////////////////////////////////////////////////////////////////////////
101
102 // device must be in binary mode
103 restore_context(std::istream& device) throw(persistent_restore_failed);
104 ~restore_context(void);
105
106 // low level input used to restore a byte
107 int get(void) throw(persistent_restore_failed);
108
109 // access the device, for example to check the error status
110 const std::istream& device(void) const;
111
112 // access the version number of the input being restored
113 unsigned char version(void) const;
114
115 // test whether the current platform uses little-endian or big-endian addressing of bytes
116 // this is used in dump/restore of integers
117 bool little_endian(void) const;
118
119 // Assist functions for Pointers
120 std::pair<bool,void*> pointer_map(unsigned magic);
121 void pointer_add(unsigned magic, void* new_pointer);
122
123 // Assist functions for Polymorphous classes using the callback approach
124 typedef void* (*create_callback)(void);
125 typedef void (*restore_callback)(restore_context&,void*);
126 unsigned register_callback(create_callback,restore_callback);
127 bool is_callback(unsigned) const;
128 typedef std::pair<create_callback, restore_callback> callback_data;
129 callback_data lookup_callback(unsigned) const throw(persistent_illegal_type);
130
131 // Assist functions for Polymorphous classes using the interface approach
132 unsigned register_interface(persistent*);
133 bool is_interface(unsigned) const;
134 persistent* lookup_interface(unsigned) const throw(persistent_illegal_type);
135
136 // Register all Polymorphous classes using either approach by calling an installer callback
137 typedef void (*installer)(restore_context&);
138 void register_all(installer);
139
140 private:
141 friend class restore_context_body;
142 restore_context_body* m_body;
143
144 typedef std::pair<unsigned,persistent*> interface_data;
145
146 // disallow copying by making assignment and copy constructor private
147 restore_context(const restore_context&);
148 restore_context& operator=(const restore_context&);
149 };
150
151 ////////////////////////////////////////////////////////////////////////////////
152
153 } // end namespace stlplus
154
155 ////////////////////////////////////////////////////////////////////////////////
156 #endif
This page took 0.034937 seconds and 4 git commands to generate.