FMT 0.9.8
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTpythonpickle.hpp
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_H_INCLUDED
9#define FMTPYTHONPICKLE_H_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.hpp"
17 #include "FMTlpmodel.hpp"
18 #include "FMTsesmodel.hpp"
20 #include <typeinfo>
21
22#if defined FMTWITHPYTHON
23
24 #include <boost/python.hpp>
25
26namespace Python {
27
28
29 template<typename T>
30 class FMT_pickle_suite : public boost::python::pickle_suite
31 {
32 public:
33 static const char* getname()
34 {
35 return typeid(T).name();
36 }
37 static boost::python::tuple getinitargs(const T&)
38 {
39 return(boost::python::make_tuple());
40 }
41 static boost::python::object getstate(const T& target)
42 {
43 std::stringstream os;
44 {
45 boost::archive::binary_oarchive oa(os);
46 oa << boost::serialization::make_nvp(getname(), target);
47 }
48 std::stringstream compressed;
49 boost::iostreams::filtering_streambuf<boost::iostreams::input> out;
50 out.push(boost::iostreams::zlib_compressor());
51 out.push(os);
52 boost::iostreams::copy(out, compressed);
53 return boost::python::make_tuple(compressed.str());
54 }
55 static void setstate(T& target, boost::python::tuple state)
56 {
57 boost::python::extract<std::string> input(state[0]);
58 std::stringstream compressed(input);
59 std::stringstream decompressed;
60 boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
61 in.push(boost::iostreams::zlib_decompressor());
62 in.push(compressed);
63 boost::iostreams::copy(in, decompressed);
64 {
65 boost::archive::binary_iarchive ia(decompressed);
66 ia >> boost::serialization::make_nvp(getname(), target);
67 }
68 }
69 };
70
71 #endif
72
73
74 /*BOOST_CLASS_EXPORT(FMTmask)
75 BOOST_CLASS_EXPORT(FMTtheme)
76 BOOST_CLASS_EXPORT(FMTdevelopment)
77 BOOST_CLASS_EXPORT(FMTactualdevelopment)
78 BOOST_CLASS_EXPORT(FMTfuturdevelopment)
79 BOOST_CLASS_EXPORT(FMTaction)
80 BOOST_CLASS_EXPORT(FMTtransition)
81 BOOST_CLASS_EXPORT(FMTyields)
82 BOOST_CLASS_EXPORT(FMToutput)
83 BOOST_CLASS_EXPORT(FMTconstraint)
84 BOOST_CLASS_EXPORT(FMTschedule)
85 BOOST_CLASS_EXPORT(FMTmodel)
86 BOOST_CLASS_EXPORT(FMTlpmodel)
87 BOOST_CLASS_EXPORT(FMTsesmodel)*/
88
89}
90
91#endif
Definition: PYdefinitions.hpp:14