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
15
16
17//ROOT headers
18#include <Rtypes.h>
19
20#include <TString.h>
21
22#include <TVector.h>
23
24#include <TMatrixT.h>
25
26#include <TArrayD.h>
27
28#include <TArrayF.h>
29
30#include <TArrayI.h>
31
32//std headers
33#include<string>
34#include<vector>
35//support for std c++11 classes
36#include<array>
37
38//pragma to disable warnings on Rcpp which have
39//so many noise compiling
40#if defined(__GNUC__)
41#pragma GCC diagnostic push
42#pragma GCC diagnostic ignored "-Wunknown-pragmas"
43#pragma GCC diagnostic ignored "-Wshadow"
44#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
45#pragma GCC diagnostic ignored "-Wunused-parameter"
46#pragma GCC diagnostic ignored "-Woverloaded-virtual"
47#pragma GCC diagnostic ignored "-Wextra"
48#pragma GCC diagnostic ignored "-Wignored-qualifiers"
49#pragma GCC diagnostic ignored "-Wsuggest-override"
50// disable warning for macos
51#if defined(__APPLE__)
52#pragma GCC diagnostic ignored "-Wnonportable-include-path"
53//This to fix conflict of RVersion.h from ROOT and Rversion.h from R
54#if !defined(R_Version)
55#define R_Version(v,p,s) ((v * 65536) + (p * 256) + (s))
56#endif
57// RAW is defined in a MacOS system header
58// but is defined as macro in RInternals.h
59#if defined(RAW)
60#undef RAW
61#endif
62#endif
63#endif
64
65#include<RcppCommon.h>
66
67
68//Some useful typedefs
69typedef std::vector<TString> TVectorString;
70
71namespace ROOT {
72 namespace R {
73 class TRFunctionExport;
74 class TRFunctionImport;
75 class TRDataFrame;
76 class TRObject;
77 }
78}
79
80namespace Rcpp {
81
82//TString
83 template<> inline SEXP wrap(const TString &s)
84 {
85 return wrap(std::string(s.Data()));
86 }
87 template<> inline TString as(SEXP s)
88 {
89 return TString(::Rcpp::as<std::string>(s).c_str());
90 }
91
92//TVectorT
93 template<> SEXP wrap(const TVectorT<Double_t> &v);
94 template<> TVectorT<Double_t> as(SEXP v);
95
96 template<> SEXP wrap(const TVectorT<Float_t> &v);
97 template<> TVectorT<Float_t> as(SEXP v);
98
99//TMatrixT
100 template<> SEXP wrap(const TMatrixT<Double_t> &m);
101 template<> TMatrixT<Double_t> as(SEXP) ;
102 template<> SEXP wrap(const TMatrixT<Float_t> &m);
103 template<> TMatrixT<Float_t> as(SEXP) ;
104
105//TRDataFrame
106 template<> SEXP wrap(const ROOT::R::TRDataFrame &o);
107 template<> ROOT::R::TRDataFrame as(SEXP) ;
108
109//TRObject
110 template<> SEXP wrap(const ROOT::R::TRObject &o);
111 template<> ROOT::R::TRObject as(SEXP) ;
112
113//TRFunctionImport
114 template<> SEXP wrap(const ROOT::R::TRFunctionImport &o);
115 template<> ROOT::R::TRFunctionImport as(SEXP) ;
116
117 template<class T, size_t i> std::array<T, i> as(SEXP &obj)
118 {
119 std::vector<T> v = Rcpp::as<std::vector<T> >(obj);
120 std::array<T, i> a;
121 std::copy(v.begin(), v.end(), a.begin());
122 return a;
123 }
124
125 namespace traits {
126 template <typename T, size_t i>
127 class Exporter<std::array<T, i> > {
128 public:
129 Exporter(SEXP x)
130 {
131 t = Rcpp::as<T, i>(x);
132 }
133 std::array<T, i> get()
134 {
135 return t;
136 }
137 private:
138 std::array<T, i> t;
139 } ;
140 }
141}
142
143#include<Rcpp.h>//this headers should be called after templates definitions
144#undef HAVE_UINTPTR_T
145#include<RInside.h>
146
147#ifdef Free
148// see https://sft.its.cern.ch/jira/browse/ROOT-9258
149# undef Free
150#endif
151
152// restore warning level of before
153#if defined(__GNUC__)
154#pragma GCC diagnostic pop
155#endif
156
157namespace ROOT {
158 namespace R {
159 //reference to internal ROOTR's Module that call ROOT's classes in R
161 template<class T> class class_: public Rcpp::class_<T> {
162 public:
163 class_(const Char_t *name_, const Char_t *doc = 0) : Rcpp::class_<T>(name_, doc) {}
164 };
165
166 //________________________________________________________________________________________________________
167 template <class T>
168 void function(const Char_t *name_, T fun, const Char_t *docstring = 0)
169 {
170 //template function required to create modules using the macro ROOTR_MODULE
171 Rcpp::function(name_, fun, docstring);
172 }
173
174 extern const Rcpp::internal::NamedPlaceHolder &Label;
175 }
176}
177
178
179//macros redifined to be accord with the namespace
180#define ROOTR_MODULE RCPP_MODULE
181#define ROOTR_EXPOSED_CLASS RCPP_EXPOSED_CLASS
182
183//modified definiton to support ROOTR namespace
184#define ROOTR_EXPOSED_CLASS_INTERNAL(CLASS)\
185 namespace ROOT{ \
186 namespace R{ \
187 class CLASS; \
188 }} \
189 RCPP_EXPOSED_CLASS_NODECL(ROOT::R::CLASS)
190
191
192
193//modified macro for ROOTR global Module Object Symbol Reference ROOT::R::ModuleSymRef
194#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 )
195#endif
std::vector< TString > TVectorString
Definition RExports.h:69
#define a(i)
Definition RSha256.hxx:99
char Char_t
Character 1 byte (char)
Definition RtypesCore.h:51
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:163
Basic string class.
Definition TString.h:138
const char * Data() const
Definition TString.h:384
Double_t x[n]
Definition legend1.C:17
const Rcpp::internal::NamedPlaceHolder & Label
VARIABLE_IS_NOT_USED SEXP ModuleSymRef
Definition RExports.cxx:116
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition RExports.h:168
This is a class to support deprecated method to pass function to R's Environment, based in Rcpp::Inte...
Definition RExports.h:80
SEXP wrap(const TString &s)
Definition RExports.h:83
TString as(SEXP s)
Definition RExports.h:87
TMarker m
Definition textangle.C:8