FMT 0.9.8
Forest management tools for forest planning
Loading...
Searching...
No Matches
Rdefinitions.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 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: FMTlist.hpp:46
Definition: FMTlayer.hpp:29
void define_FMTlist()
Definition: PYdefinitions.hpp:24
void define_FMTlayer()
Definition: PYdefinitions.hpp:39
Definition: RexportCore.hpp:153