]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // (C) Copyright R.W. Grosse-Kunstleve 2002. |
2 | // Distributed under the Boost Software License, Version 1.0. (See | |
3 | // accompanying file LICENSE_1_0.txt or copy at | |
4 | // http://www.boost.org/LICENSE_1_0.txt) | |
5 | #ifndef BOOST_PYTHON_OBJECT_PICKLE_SUPPORT_RWGK20020603_HPP | |
6 | # define BOOST_PYTHON_OBJECT_PICKLE_SUPPORT_RWGK20020603_HPP | |
7 | ||
8 | # include <boost/python/detail/prefix.hpp> | |
9 | ||
10 | namespace boost { namespace python { | |
11 | ||
12 | namespace api | |
13 | { | |
14 | class object; | |
15 | } | |
16 | using api::object; | |
17 | class tuple; | |
18 | ||
19 | BOOST_PYTHON_DECL object const& make_instance_reduce_function(); | |
20 | ||
21 | struct pickle_suite; | |
22 | ||
23 | namespace error_messages { | |
24 | ||
25 | template <class T> | |
26 | struct missing_pickle_suite_function_or_incorrect_signature {}; | |
27 | ||
28 | inline void must_be_derived_from_pickle_suite(pickle_suite const&) {} | |
29 | } | |
30 | ||
31 | namespace detail { struct pickle_suite_registration; } | |
32 | ||
33 | struct pickle_suite | |
34 | { | |
35 | private: | |
36 | struct inaccessible {}; | |
37 | friend struct detail::pickle_suite_registration; | |
38 | public: | |
39 | static inaccessible* getinitargs() { return 0; } | |
40 | static inaccessible* getstate() { return 0; } | |
41 | static inaccessible* setstate() { return 0; } | |
42 | static bool getstate_manages_dict() { return false; } | |
43 | }; | |
44 | ||
45 | namespace detail { | |
46 | ||
47 | struct pickle_suite_registration | |
48 | { | |
49 | typedef pickle_suite::inaccessible inaccessible; | |
50 | ||
51 | template <class Class_, class Tgetinitargs> | |
52 | static | |
53 | void | |
54 | register_( | |
55 | Class_& cl, | |
56 | tuple (*getinitargs_fn)(Tgetinitargs), | |
57 | inaccessible* (* /*getstate_fn*/)(), | |
58 | inaccessible* (* /*setstate_fn*/)(), | |
59 | bool) | |
60 | { | |
61 | cl.enable_pickling_(false); | |
62 | cl.def("__getinitargs__", getinitargs_fn); | |
63 | } | |
64 | ||
65 | template <class Class_, | |
66 | class Rgetstate, class Tgetstate, | |
67 | class Tsetstate, class Ttuple> | |
68 | static | |
69 | void | |
70 | register_( | |
71 | Class_& cl, | |
72 | inaccessible* (* /*getinitargs_fn*/)(), | |
73 | Rgetstate (*getstate_fn)(Tgetstate), | |
74 | void (*setstate_fn)(Tsetstate, Ttuple), | |
75 | bool getstate_manages_dict) | |
76 | { | |
77 | cl.enable_pickling_(getstate_manages_dict); | |
78 | cl.def("__getstate__", getstate_fn); | |
79 | cl.def("__setstate__", setstate_fn); | |
80 | } | |
81 | ||
82 | template <class Class_, | |
83 | class Tgetinitargs, | |
84 | class Rgetstate, class Tgetstate, | |
85 | class Tsetstate, class Ttuple> | |
86 | static | |
87 | void | |
88 | register_( | |
89 | Class_& cl, | |
90 | tuple (*getinitargs_fn)(Tgetinitargs), | |
91 | Rgetstate (*getstate_fn)(Tgetstate), | |
92 | void (*setstate_fn)(Tsetstate, Ttuple), | |
93 | bool getstate_manages_dict) | |
94 | { | |
95 | cl.enable_pickling_(getstate_manages_dict); | |
96 | cl.def("__getinitargs__", getinitargs_fn); | |
97 | cl.def("__getstate__", getstate_fn); | |
98 | cl.def("__setstate__", setstate_fn); | |
99 | } | |
100 | ||
101 | template <class Class_> | |
102 | static | |
103 | void | |
104 | register_( | |
105 | Class_&, | |
106 | ...) | |
107 | { | |
108 | typedef typename | |
109 | error_messages::missing_pickle_suite_function_or_incorrect_signature< | |
110 | Class_>::error_type error_type BOOST_ATTRIBUTE_UNUSED; | |
111 | } | |
112 | }; | |
113 | ||
114 | template <typename PickleSuiteType> | |
115 | struct pickle_suite_finalize | |
116 | : PickleSuiteType, | |
117 | pickle_suite_registration | |
118 | {}; | |
119 | ||
120 | } // namespace detail | |
121 | ||
122 | }} // namespace boost::python | |
123 | ||
124 | #endif // BOOST_PYTHON_OBJECT_PICKLE_SUPPORT_RWGK20020603_HPP |