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