Logo ROOT   6.14/05
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
51 typedef std::vector<TString> TVectorString;
52 
53 
54 #include<RcppCommon.h>
55 namespace ROOT {
56  namespace R {
57  class TRFunctionExport;
58  class TRFunctionImport;
59  class TRDataFrame;
60  class TRObject;
61  }
62 }
63 
64 namespace 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 namespace ROOT {
136  namespace R {
137  //reference to internal ROOTR's Module that call ROOT's classes in R
138  extern VARIABLE_IS_NOT_USED SEXP ModuleSymRef;
139  template<class T> class class_: public Rcpp::class_<T> {
140  public:
141  class_(const Char_t *name_, const Char_t *doc = 0) : Rcpp::class_<T>(name_, doc) {}
142  };
143 
144  //________________________________________________________________________________________________________
145  template <class T>
146  void function(const Char_t *name_, T fun, const Char_t *docstring = 0)
147  {
148  //template function required to create modules using the macro ROOTR_MODULE
149  Rcpp::function(name_, fun, docstring);
150  }
151 
152  extern Rcpp::internal::NamedPlaceHolder Label;
153  }
154 }
155 
156 
157 //macros redifined to be accord with the namespace
158 #define ROOTR_MODULE RCPP_MODULE
159 #define ROOTR_EXPOSED_CLASS RCPP_EXPOSED_CLASS
160 
161 //modified definiton to support ROOTR namespace
162 #define ROOTR_EXPOSED_CLASS_INTERNAL(CLASS)\
163  namespace ROOT{ \
164  namespace R{ \
165  class CLASS; \
166  }} \
167  RCPP_EXPOSED_CLASS_NODECL(ROOT::R::CLASS)
168 
169 
170 
171 //modified macro for ROOTR global Module Object Symbol Reference ROOT::R::ModuleSymRef
172 #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 )
173 #endif
std::array< T, i > as(SEXP &obj)
Definition: RExports.h:101
auto * m
Definition: textangle.C:8
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
double T(double x)
Definition: ChebyshevPol.h:34
Basic string class.
Definition: TString.h:131
STL namespace.
#define R(a, b, c, d, e, f, g, h, i)
Definition: RSha256.hxx:110
Double_t x[n]
Definition: legend1.C:17
VARIABLE_IS_NOT_USED SEXP ModuleSymRef
Definition: RExports.cxx:111
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:146
This is a class to get ROOT&#39;s objects from R&#39;s objects
Definition: TRObject.h:71
This is a class to pass functions from ROOT to R.
SVector< double, 2 > v
Definition: Dict.h:5
auto * a
Definition: textangle.C:12
SEXP wrap(const ROOT::R::TRFunctionImport &o)
Definition: RExports.cxx:98
class_(const Char_t *name_, const Char_t *doc=0)
Definition: RExports.h:141
std::vector< TString > TVectorString
Definition: RExports.h:51
static constexpr double s
char Char_t
Definition: RtypesCore.h:29
This is a class to support deprecated method to pass function to R&#39;s Environment, based in Rcpp::Inte...
Definition: RExports.h:64
Rcpp::internal::NamedPlaceHolder Label
Definition: RExports.cxx:14
This is a class to pass functions from ROOT to R
This is a class to create DataFrames from ROOT to R
Definition: TRDataFrame.h:177
const char * Data() const
Definition: TString.h:364