FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
Rdefinitions.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 RDEFINITIONS_H_INCLUDED
9#define RDEFINITIONS_H_INCLUDED
10
11#if defined FMTWITHR
12
13#include <Rcpp.h>
14#include <vector>
15#include <map>
16#include "FMTList.hpp"
17#include "FMTLayer.hpp"
18
19
20
21#define RCPP_DEFINEVECTOR(CLASS) namespace Rcpp{\
22template <> std::vector<CLASS> as(SEXP obj){\
23const int RTYPE = traits::r_sexptype_traits<CLASS>::rtype;\
24Vector<RTYPE> rcppVec(obj);\
25std::vector<CLASS>newvec;\
26newvec.reserve(rcppVec.size());\
27for(int index = 0; index < rcppVec.size();++index)\
28{\
29newvec.push_back(rcppVec[index]);\
30}\
31return newvec;}\
32template <> SEXP wrap(const std::vector<CLASS>& obj){\
33const int RTYPE=traits::r_sexptype_traits<CLASS>::rtype;\
34return Vector<RTYPE>(obj.begin(), obj.end());}}
35
36#define RCPP_DEFINELIST(CLASS) namespace Rcpp{\
37template <> std::vector<CLASS> as(SEXP obj){\
38List listObj(obj);\
39std::vector<CLASS>newvec;\
40newvec.reserve(listObj.size());\
41for(int index = 0; index < listObj.size();++index)\
42{\
43newvec.push_back(as<CLASS>(listObj[index]));\
44}\
45return newvec;}\
46template <> SEXP wrap(const std::vector<CLASS>& obj){\
47List listObj(obj.size());\
48for(int index = 0; index < listObj.size();++index)\
49{\
50listObj[index]=wrap<CLASS>(obj.at(index));\
51}\
52return listObj;}}
53
54#define RCPP_DEFINEPAIR(FIRST,SECOND)namespace Rcpp{\
55template <> std::pair<FIRST,SECOND> as(SEXP obj){\
56Rcpp::List rcppList(obj);\
57return std::pair<FIRST,SECOND>(as<FIRST>(rcppList["first"]), as<SECOND>(rcppList["second"]));}\
58template <> SEXP wrap(const std::pair<FIRST,SECOND>& obj){\
59return List::create(Named("first") = wrap<FIRST>(obj.first),Named("second") = wrap<SECOND>(obj.second));}}
60
61#define RCPP_DEFINEMAP(KEY,OBJECT)namespace Rcpp{\
62template <> std::map<KEY,OBJECT> as(SEXP obj){\
63List rcppList(obj);\
64std::map<KEY,OBJECT>newmap;\
65for(int index = 0; index < rcppList.size();++index)\
66{\
67newmap[as<KEY>(as<List>(rcppList[index])["first"])]=as<OBJECT>(as<List>(rcppList[index])["second"]);\
68}\
69return newmap;}\
70template <> SEXP wrap(const std::map<KEY,OBJECT>& obj){\
71List rcppList(obj.size());\
72size_t index = 0;\
73for(const auto& mapobject: obj)\
74{\
75rcppList[index]=List::create(Named("first")=wrap<KEY>(mapobject.first),Named("second")=wrap<OBJECT>(mapobject.second));\
76++index;\
77}\
78return rcppList;}}
79
80namespace R
81{
82 template <class T>
83 void define_FMTlist(const char* name)
84 {
85 Rcpp::class_< Core::FMTList<T> >(name, "@DocString(FMTList)")
86 .constructor("@DocString(FMTList())")
87 .method("update", &Core::FMTList<T>::update,
88 "@DocString(FMTList::update)")
89 .method("push_back",
91 "@DocString(FMTYieldHandler::APIpush_back)");
92
93 }
94
95 template <class T>
96 void define_FMTlayer(const char* name)
97 {
98 Rcpp::class_<Spatial::FMTLayer<T>>(name, "@DocString(FMTLayer)")
99 .constructor("@DocString(FMTLayer())")
100 .method("getXSize", &Spatial::FMTLayer<T>::getXSize,
101 "@DocString(FMTLayer::GetXSize)")
102 .method("getYSize", &Spatial::FMTLayer<T>::getYSize,
103 "@DocString(FMTLayer::GetYSize)")
104 .method("getgeotransform", &Spatial::FMTLayer<T>::getGeoTransform,
105 "@DocString(FMTLayer::getgeotransform)")
106 .method("getprojection", &Spatial::FMTLayer<T>::getProjection,
107 "@DocString(FMTLayer::getprojection)")
108 .method("getmapping", &Spatial::FMTLayer<T>::getMapping,
109 "@DocString(FMTLayer::getmapping)")
110 .method("area", &Spatial::FMTLayer<T>::area,
111 "@DocString(FMTLayer::area)")
112 .method("getcellsize", &Spatial::FMTLayer<T>::getCellSize,
113 "@DocString(FMTLayer::getcellsize)")
114 .method("size", &Spatial::FMTLayer<T>::size,
115 "@DocString(FMTLayer::size)");
116 }
117}
118
119
120
121#endif
122
123
124
125#endif // RDEFINITIONS_H_INCLUDED
Definition: FMTAreaParser.h:32
Definition: FMTParser.h:54
void define_FMTlist()
Definition: PYdefinitions.h:31
void define_FMTlayer()
Definition: PYdefinitions.h:46
Definition: RexportCore.h:153