FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTpythonpickle.h
Go to the documentation of this file.
1/*
2Copyright (c) 2019 Gouvernement du Qu�bec
3
4SPDX-License-Identifier: LiLiQ-R-1.1
5License-Filename: LICENSES/EN/LiLiQ-R11unicode.txt
6*/
7
8#ifndef FMTPYTHONPICKLE_Hm_included
9#define FMTPYTHONPICKLE_Hm_included
10 #include <boost/serialization/serialization.hpp>
11 #include <boost/serialization/export.hpp>
12 #include <boost/iostreams/stream.hpp>
13 #include <boost/iostreams/filtering_streambuf.hpp>
14 #include <boost/iostreams/filter/zlib.hpp>
15 #include <boost/iostreams/copy.hpp>
16 #include "FMTModel.h"
17 #include "FMTLpModel.h"
18 #include "FMTSesModel.h"
20 #include <typeinfo>
21
22#if defined FMTWITHPYTHON
23
24 #include <boost/python.hpp>
25
26namespace Python {
27
28
29 // DocString: Python::FMT_pickle_suite
34 template<typename T>
35 class FMT_pickle_suite : public boost::python::pickle_suite
36 {
37 public:
38 // DocString: Python::FMT_pickle_suite::getName
43 static const char* getName()
44 {
45 return typeid(T).name();
46 }
47 // Noms imposés par Boost.Python (protocole pickle) : NE PAS passer en camelCase,
48 // sinon boost::python::pickle_suite ne les détecte plus (voir pickle_support.hpp).
49 // DocString: Python::FMT_pickle_suite::getinitargs
54 static boost::python::tuple getinitargs(const T&)
55 {
56 return(boost::python::make_tuple());
57 }
58 // DocString: Python::FMT_pickle_suite::getstate
64 static boost::python::object getstate(const T& target)
65 {
66 std::stringstream os;
67 {
68 boost::archive::binary_oarchive oa(os);
69 oa << boost::serialization::make_nvp(getName(), target);
70 }
71 std::stringstream compressed;
72 boost::iostreams::filtering_streambuf<boost::iostreams::input> out;
73 out.push(boost::iostreams::zlib_compressor());
74 out.push(os);
75 boost::iostreams::copy(out, compressed);
76 return boost::python::make_tuple(compressed.str());
77 }
78 // DocString: Python::FMT_pickle_suite::setstate
84 static void setstate(T& target, boost::python::tuple state)
85 {
86 boost::python::extract<std::string> input(state[0]);
87 std::stringstream compressed(input);
88 std::stringstream decompressed;
89 boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
90 in.push(boost::iostreams::zlib_decompressor());
91 in.push(compressed);
92 boost::iostreams::copy(in, decompressed);
93 {
94 boost::archive::binary_iarchive ia(decompressed);
95 ia >> boost::serialization::make_nvp(getName(), target);
96 }
97 }
98 };
99
100 #endif
101
102
103 /*BOOST_CLASS_EXPORT(FMTMask)
104 BOOST_CLASS_EXPORT(FMTTheme)
105 BOOST_CLASS_EXPORT(FMTDevelopment)
106 BOOST_CLASS_EXPORT(FMTActualDevelopment)
107 BOOST_CLASS_EXPORT(FMTFuturDevelopment)
108 BOOST_CLASS_EXPORT(FMTAction)
109 BOOST_CLASS_EXPORT(FMTTransition)
110 BOOST_CLASS_EXPORT(FMTYields)
111 BOOST_CLASS_EXPORT(FMTOutput)
112 BOOST_CLASS_EXPORT(FMTConstraint)
113 BOOST_CLASS_EXPORT(FMTSchedule)
114 BOOST_CLASS_EXPORT(FMTModel)
115 BOOST_CLASS_EXPORT(FMTLpModel)
116 BOOST_CLASS_EXPORT(FMTSesModel)*/
117
118}
119
120#endif
Definition: PYdefinitions.h:14