Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RExports.cxx
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 2013-2014, Omar Andres Zapata Mesa *
3  * All rights reserved. *
4  * *
5  * For the licensing terms see $ROOTSYS/LICENSE. *
6  * For the list of contributors see $ROOTSYS/README/CREDITS. *
7  *************************************************************************/
8 #include<RExports.h>
9 #include<TRFunctionExport.h>
10 #include<TRObject.h>
11 #include<TRDataFrame.h>
12 #include<Rcpp/Vector.h>
13 
14 namespace ROOT {
15  namespace R {
16  const Rcpp::internal::NamedPlaceHolder &Label(Rcpp::_);
17  }
18 }
19 
20 namespace Rcpp {
21 //TVectorT
22  template<> SEXP wrap(const TVectorT<Double_t> &v)
23  {
24  std::vector<Double_t> vec(v.GetMatrixArray(), v.GetMatrixArray() + v.GetNoElements());
25  return wrap(vec);
26  }
27 
28  template<> TVectorT<Double_t> as(SEXP v)
29  {
30  std::vector<Double_t> vec =::Rcpp::as<std::vector<Double_t> >(v);
31  return TVectorT<Double_t>(vec.size(), vec.data());
32  }
33 
34  template<> SEXP wrap(const TVectorT<Float_t> &v)
35  {
36  std::vector<Float_t> vec(v.GetMatrixArray(), v.GetMatrixArray() + v.GetNoElements());
37  return wrap(vec);
38  }
39 
40  template<> TVectorT<Float_t> as(SEXP v)
41  {
42  std::vector<Float_t> vec =::Rcpp::as<std::vector<Float_t> >(v);
43  return TVectorT<Float_t>(vec.size(), vec.data());
44  }
45 
46 //TMatrixT
47  template<> SEXP wrap(const TMatrixT<Double_t> &m)
48  {
49  Int_t rows = m.GetNrows();
50  Int_t cols = m.GetNcols();
51  Double_t *data = new Double_t[rows * cols];
52  m.GetMatrix2Array(data, "F"); //ROOT has a bug here(Fixed)
53  NumericMatrix mat(rows, cols, data);
54  return wrap(mat);
55  }
56 
57  template<> TMatrixT<Double_t> as(SEXP m)
58  {
59  NumericMatrix mat =::Rcpp::as<NumericMatrix>(m);
60  return TMatrixT<Double_t>(mat.rows(), mat.cols(), mat.begin(), "F");
61  }
62 
63  template<> SEXP wrap(const TMatrixT<Float_t> &m)
64  {
65  Int_t rows = m.GetNrows();
66  Int_t cols = m.GetNcols();
67  Float_t *data = new Float_t[rows * cols];
68  m.GetMatrix2Array(data, "F"); //ROOT has a bug here(Fixed)
69  NumericMatrix mat(rows, cols, data);
70  return wrap(mat);
71  }
72 
73  template<> TMatrixT<Float_t> as(SEXP m)
74  {
75  NumericMatrix mat =::Rcpp::as<NumericMatrix>(m);
76  std::vector<Float_t> dat = Rcpp::as<std::vector<Float_t>>(mat);
77  return TMatrixT<Float_t>(mat.rows(), mat.cols(), &dat[0], "F");
78  }
79 
80 //TRObject
81  template<> SEXP wrap(const ROOT::R::TRObject &obj)
82  {
83  return obj.fObj;
84  }
85 
86  template<> ROOT::R::TRObject as(SEXP obj)
87  {
88  return ROOT::R::TRObject(obj);
89  }
90 //TRDataFrame
91  template<> SEXP wrap(const ROOT::R::TRDataFrame &obj)
92  {
93  return obj.df;
94  }
95 
96  template<> ROOT::R::TRDataFrame as(SEXP obj)
97  {
98  return ROOT::R::TRDataFrame(Rcpp::as<Rcpp::DataFrame>(obj));
99  }
100 
101 //TRFunctionImport
102  template<> SEXP wrap(const ROOT::R::TRFunctionImport &obj)
103  {
104  return *obj.f;
105  }
106 
107  template<> ROOT::R::TRFunctionImport as(SEXP obj)
108  {
109  return ROOT::R::TRFunctionImport(Rcpp::as<Rcpp::Function>(obj));
110  }
111 
112 }
113 namespace ROOT {
114  namespace R {
115  VARIABLE_IS_NOT_USED SEXP ModuleSymRef = NULL;
116  }
117 }