FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
PYdefinitions.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 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 boost::python::to_python_converter<std::set<T>, SetToList<T>>();
27 iterable_converter().from_python<std::set<T>>();
28}
29
30template <class T>
32 {
33 py_pair<Core::FMTMask, T>();
34 py_pair<Core::FMTMask const, T>();
35 boost::python::class_<Core::FMTList<T>>("FMTlist", "@DocString(FMTList)")
36 .def("__iter__", boost::python::iterator<Core::FMTList<T>>())
37 .def("update", &Core::FMTList<T>::update,
38 "@DocString(FMTList::update)")
39 .def("push_back",
41 "@DocString(FMTYieldHandler::APIpush_back)");
42 definePyList<T>();
43 }
44
45template <class T>
47 {
48
49 boost::python::class_<Spatial::FMTLayer<T>>("FMTlayer", "@DocString(FMTLayer)")
50 .def("getXSize",&Spatial::FMTLayer<T>::getXSize,
51 "@DocString(FMTLayer::GetXSize)")
52 .def("getYSize",&Spatial::FMTLayer<T>::getYSize,
53 "@DocString(FMTLayer::GetYSize)")
54 .def("getgeotransform",&Spatial::FMTLayer<T>::getGeoTransform,
55 "@DocString(FMTLayer::getgeotransform)")
56 .def("getprojection",&Spatial::FMTLayer<T>::getProjection,
57 "@DocString(FMTLayer::getprojection)")
58 .def("getmapping",&Spatial::FMTLayer<T>::getMapping,
59 "@DocString(FMTLayer::getmapping)")
60 .def("area",&Spatial::FMTLayer<T>::area,
61 "@DocString(FMTLayer::area)")
62 .def("getcellsize",&Spatial::FMTLayer<T>::getCellSize,
63 "@DocString(FMTLayer::getcellsize)")
64 .def("__len__",&Spatial::FMTLayer<T>::size,
65 "@DocString(FMTLayer::size)")
66 //const because begin and end return const iterator
67 .def("itercell", boost::python::iterator<Spatial::FMTLayer<T>>())
68 .def("__getitem__",&Spatial::FMTLayer<T>::at,boost::python::return_internal_reference<>(),"@DocString(FMTLayer::at)");
69 boost::python::to_python_converter<std::map<Spatial::FMTCoordinate,T>,MapToDict<Spatial::FMTCoordinate,T>>();
70 }
71
72template<class k,class v>
74 {
75 boost::python::to_python_converter<std::map<k,v>,MapToDict<k,v>>();
76 MapFrDict<k,v>();
77 }
78
79/*template<typename T1, typename T2>
80struct PairToPythonConverter {
81 static PyObject* convert(const std::pair<T1, T2>& pair)
82 {
83 return boost::python::incref(boost::python::make_tuple(pair.first, pair.second).ptr());
84 }
85};
86
87template<typename T1, typename T2>
88struct PythonToPairConverter {
89 PythonToPairConverter()
90 {
91 boost::python::converter::registry::push_back(&convertible, &construct, boost::python::type_id<std::pair<T1, T2> >());
92 }
93 static void* convertible(PyObject* obj)
94 {
95 if (!PyTuple_CheckExact(obj)) return 0;
96 if (PyTuple_Size(obj) != 2) return 0;
97 return obj;
98 }
99 static void construct(PyObject* obj, boost::python::converter::rvalue_from_python_stage1_data* data)
100 {
101 boost::python::tuple tuple(boost::python::borrowed(obj));
102 void* storage = ((boost::python::converter::rvalue_from_python_storage<std::pair<T1, T2> >*) data)->storage.bytes;
103 new (storage) std::pair<T1, T2>(boost::python::extract<T1>(tuple[0]), boost::python::extract<T2>(tuple[1]));
104 data->convertible = storage;
105 }
106};*/
107
108template<typename T1, typename T2>
110 boost::python::to_python_converter<std::pair<T1, T2>, PairToPythonConverter<T1, T2>>();
111 PythonToPairConverter<T1, T2>();
112 }
113
114
115}
116#endif // PYDEFINITIONS_H_INCLUDED
Definition: FMTAreaParser.h:32
Definition: FMTParser.h:54
Definition: PYdefinitions.h:14
void definePySet()
Definition: PYdefinitions.h:24
void definePyPair()
Definition: PYdefinitions.h:109
void definePyDict()
Definition: PYdefinitions.h:73
void definePyList()
Definition: PYdefinitions.h:17
void define_FMTlist()
Definition: PYdefinitions.h:31
void define_FMTlayer()
Definition: PYdefinitions.h:46