FMT 0.9.8
Forest management tools for forest planning
Loading...
Searching...
No Matches
PYdefinitions.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 PYDEFINITIONS_H_INCLUDED
9#define PYDEFINITIONS_H_INCLUDED
10
11#include "boost/python.hpp"
12
13namespace Python
14{
15
16template<class T>
18{
19 boost::python::to_python_converter<std::vector<T, std::allocator<T>>, VecToList<T>>();
20 iterable_converter().from_python<std::vector<T>>();
21}
22
23template <class T>
25 {
26 py_pair<Core::FMTmask, T>();
27 py_pair<Core::FMTmask const, T>();
28 boost::python::class_<Core::FMTlist<T>>("FMTlist", "@DocString(FMTlist)")
29 .def("__iter__", boost::python::iterator<Core::FMTlist<T>>())
30 .def("update", &Core::FMTlist<T>::update,
31 "@DocString(FMTlist::update)")
32 .def("push_back",
34 "@DocString(FMTyieldhandler::APIpush_back)");
35 define_pylist<T>();
36 }
37
38template <class T>
40 {
41
42 boost::python::class_<Spatial::FMTlayer<T>>("FMTlayer", "@DocString(FMTlayer)")
43 .def("getXSize",&Spatial::FMTlayer<T>::GetXSize,
44 "@DocString(FMTlayer::GetXSize)")
45 .def("getYSize",&Spatial::FMTlayer<T>::GetYSize,
46 "@DocString(FMTlayer::GetYSize)")
47 .def("getgeotransform",&Spatial::FMTlayer<T>::getgeotransform,
48 "@DocString(FMTlayer::getgeotransform)")
49 .def("getprojection",&Spatial::FMTlayer<T>::getprojection,
50 "@DocString(FMTlayer::getprojection)")
51 .def("getmapping",&Spatial::FMTlayer<T>::getmapping,
52 "@DocString(FMTlayer::getmapping)")
53 .def("area",&Spatial::FMTlayer<T>::area,
54 "@DocString(FMTlayer::area)")
55 .def("getcellsize",&Spatial::FMTlayer<T>::getcellsize,
56 "@DocString(FMTlayer::getcellsize)")
57 .def("__len__",&Spatial::FMTlayer<T>::size,
58 "@DocString(FMTlayer::size)")
59 //const because begin and end return const iterator
60 .def("itercell", boost::python::iterator<Spatial::FMTlayer<T>>())
61 .def("__getitem__",&Spatial::FMTlayer<T>::at,boost::python::return_internal_reference<>(),"@DocString(FMTlayer::at)");
62 boost::python::to_python_converter<std::map<Spatial::FMTcoordinate,T>,MapToDict<Spatial::FMTcoordinate,T>>();
63 }
64
65template<class k,class v>
67 {
68 boost::python::to_python_converter<std::map<k,v>,MapToDict<k,v>>();
69 MapFrDict<k,v>();
70 }
71
72/*template<typename T1, typename T2>
73struct PairToPythonConverter {
74 static PyObject* convert(const std::pair<T1, T2>& pair)
75 {
76 return boost::python::incref(boost::python::make_tuple(pair.first, pair.second).ptr());
77 }
78};
79
80template<typename T1, typename T2>
81struct PythonToPairConverter {
82 PythonToPairConverter()
83 {
84 boost::python::converter::registry::push_back(&convertible, &construct, boost::python::type_id<std::pair<T1, T2> >());
85 }
86 static void* convertible(PyObject* obj)
87 {
88 if (!PyTuple_CheckExact(obj)) return 0;
89 if (PyTuple_Size(obj) != 2) return 0;
90 return obj;
91 }
92 static void construct(PyObject* obj, boost::python::converter::rvalue_from_python_stage1_data* data)
93 {
94 boost::python::tuple tuple(boost::python::borrowed(obj));
95 void* storage = ((boost::python::converter::rvalue_from_python_storage<std::pair<T1, T2> >*) data)->storage.bytes;
96 new (storage) std::pair<T1, T2>(boost::python::extract<T1>(tuple[0]), boost::python::extract<T2>(tuple[1]));
97 data->convertible = storage;
98 }
99};*/
100
101template<typename T1, typename T2>
103 boost::python::to_python_converter<std::pair<T1, T2>, PairToPythonConverter<T1, T2>>();
104 PythonToPairConverter<T1, T2>();
105 }
106
107
108}
109#endif // PYDEFINITIONS_H_INCLUDED
Definition: FMTlist.hpp:46
Definition: FMTlayer.hpp:29
Definition: PYdefinitions.hpp:14
void define_pypair()
Definition: PYdefinitions.hpp:102
void define_FMTlist()
Definition: PYdefinitions.hpp:24
void define_pydict()
Definition: PYdefinitions.hpp:66
void define_pylist()
Definition: PYdefinitions.hpp:17
void define_FMTlayer()
Definition: PYdefinitions.hpp:39