Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 #ifdef Free
136 // see https://sft.its.cern.ch/jira/browse/ROOT-9258
137 # undef Free
138 #endif
139 
140 namespace 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