Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RExports.h
Go to the documentation of this file.
1// @(#)root/r:$Id$
2// Author: Omar Zapata Omar.Zapata@cern.ch 29/05/2013
3
4
5/*************************************************************************
6 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12#ifndef ROOT_R_RExports
13#define ROOT_R_RExports
14//ROOT headers
15#include <Rtypes.h>
16
17#include <TString.h>
18
19#include <TVector.h>
20
21#include <TMatrixT.h>
22
23#include <TArrayD.h>
24
25#include <TArrayF.h>
26
27#include <TArrayI.h>
28
29//std headers
30#include<string>
31#include<vector>
32//support for std c++11 classes
33#include<array>
34
35//pragma to disable warnings on Rcpp which have
36//so many noise compiling
37#if defined(__GNUC__)
38#pragma GCC diagnostic ignored "-Wunknown-pragmas"
39#pragma GCC diagnostic ignored "-Wshadow"
40#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
41#pragma GCC diagnostic ignored "-Wunused-parameter"
42#pragma GCC diagnostic ignored "-Woverloaded-virtual"
43#pragma GCC diagnostic ignored "-Wextra"
44#pragma GCC diagnostic ignored "-Wignored-qualifiers"
45#endif
46
47
48//Some useful typedefs
49typedef std::vector<TString> TVectorString;
50
51#include<RcppCommon.h>
52namespace ROOT {
53 namespace R {
54 class TRFunctionExport;
55 class TRFunctionImport;
56 class TRDataFrame;
57 class TRObject;
58 }
59}
60
61namespace Rcpp {
62
63//TString
64 template<> inline SEXP wrap(const TString &s)
65 {
66 return wrap(std::string(s.Data()));
67 }
68 template<> inline TString as(SEXP s)
69 {
70 return TString(::Rcpp::as<std::string>(s).c_str());
71 }
72
73//TVectorT
74 template<> SEXP wrap(const TVectorT<Double_t> &v);
75 template<> TVectorT<Double_t> as(SEXP v);
76
77 template<> SEXP wrap(const TVectorT<Float_t> &v);
78 template<> TVectorT<Float_t> as(SEXP v);
79
80//TMatrixT
81 template<> SEXP wrap(const TMatrixT<Double_t> &m);
82 template<> TMatrixT<Double_t> as(SEXP) ;
83 template<> SEXP wrap(const TMatrixT<Float_t> &m);
84 template<> TMatrixT<Float_t> as(SEXP) ;
85
86//TRDataFrame
87 template<> SEXP wrap(const ROOT::R::TRDataFrame &o);
88 template<> ROOT::R::TRDataFrame as(SEXP) ;
89
90//TRObject
91 template<> SEXP wrap(const ROOT::R::TRObject &o);
92 template<> ROOT::R::TRObject as(SEXP) ;
93
94//TRFunctionImport
95 template<> SEXP wrap(const ROOT::R::TRFunctionImport &o);
96 template<> ROOT::R::TRFunctionImport as(SEXP) ;
97
98 template<class T, size_t i> std::array<T, i> as(SEXP &obj)
99 {
100 std::vector<T> v = Rcpp::as<std::vector<T> >(obj);
101 std::array<T, i> a;
102 std::copy(v.begin(), v.end(), a.begin());
103 return a;
104 }
105
106 namespace traits {
107 template <typename T, size_t i>
108 class Exporter<std::array<T, i> > {
109 public:
110 Exporter(SEXP x)
111 {
112 t = Rcpp::as<T, i>(x);
113 }
114 std::array<T, i> get()
115 {
116 return t;
117 }
118 private:
119 std::array<T, i> t;
120 } ;
121 }
122}
123
124//added to fix bug in last version of Rcpp on mac
125#if !defined(R_Version)
126#define R_Version(v,p,s) ((v * 65536) + (p * 256) + (s))
127#endif
128
129#include<Rcpp.h>//this headers should be called after templates definitions
130#include<Rcpp/Named.h>
131#undef HAVE_UINTPTR_T
132#include<RInside.h>
133
134#ifdef Free
135// see https://sft.its.cern.ch/jira/browse/ROOT-9258
136# undef Free
137#endif
138
139namespace ROOT {
140 namespace R {
141 //reference to internal ROOTR's Module that call ROOT's classes in R
142 extern VARIABLE_IS_NOT_USED SEXP ModuleSymRef;
143 template<class T> class class_: public Rcpp::class_<T> {
144 public:
145 class_(const Char_t *name_, const Char_t *doc = 0) : Rcpp::class_<T>(name_, doc) {}
146 };
147
148 //________________________________________________________________________________________________________
149 template <class T>
150 void function(const Char_t *name_, T fun, const Char_t *docstring = 0)
151 {
152 //template function required to create modules using the macro ROOTR_MODULE
153 Rcpp::function(name_, fun, docstring);
154 }
155
156 extern const Rcpp::internal::NamedPlaceHolder &Label;
157 }
158}
159
160
161//macros redifined to be accord with the namespace
162#define ROOTR_MODULE RCPP_MODULE
163#define ROOTR_EXPOSED_CLASS RCPP_EXPOSED_CLASS
164
165//modified definiton to support ROOTR namespace
166#define ROOTR_EXPOSED_CLASS_INTERNAL(CLASS)\
167 namespace ROOT{ \
168 namespace R{ \
169 class CLASS; \
170 }} \
171 RCPP_EXPOSED_CLASS_NODECL(ROOT::R::CLASS)
172
173
174
175//modified macro for ROOTR global Module Object Symbol Reference ROOT::R::ModuleSymRef
176#define LOAD_ROOTR_MODULE(NAME) Rf_eval( Rf_lang2( ( ROOT::R::ModuleSymRef == NULL ? ROOT::R::ModuleSymRef = Rf_install("Module") : ROOT::R::ModuleSymRef ), _rcpp_module_boot_##NAME() ), R_GlobalEnv )
177#endif
std::vector< TString > TVectorString
Definition RExports.h:49
#define a(i)
Definition RSha256.hxx:99
char Char_t
Definition RtypesCore.h:37
This is a class to create DataFrames from ROOT to R.
This is a class to pass functions from ROOT to R.
This is a class to pass functions from ROOT to R.
This is a class to get ROOT's objects from R's objects.
Definition TRObject.h:70
class_(const Char_t *name_, const Char_t *doc=0)
Definition RExports.h:145
TMatrixT.
Definition TMatrixT.h:39
Basic string class.
Definition TString.h:136
const char * Data() const
Definition TString.h:369
TVectorT.
Definition TVectorT.h:27
Double_t x[n]
Definition legend1.C:17
const Rcpp::internal::NamedPlaceHolder & Label
VARIABLE_IS_NOT_USED SEXP ModuleSymRef
Definition RExports.cxx:117
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition RExports.h:150
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
This is a class to support deprecated method to pass function to R's Environment, based in Rcpp::Inte...
Definition RExports.h:61
SEXP wrap(const TString &s)
Definition RExports.h:64
TString as(SEXP s)
Definition RExports.h:68
auto * m
Definition textangle.C:8