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