Rcpp Version 1.0.9
SugarBlock_3.h
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 //
3 // SugarBlock.h: Rcpp R/C++ interface class library -- sugar functions
4 //
5 // Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
6 //
7 // This file is part of Rcpp.
8 //
9 // Rcpp is free software: you can redistribute it and/or modify it
10 // under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // Rcpp is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21 
22 #ifndef RCPP_SUGAR_BLOCK_3_H
23 #define RCPP_SUGAR_BLOCK_3_H
24 
25 namespace Rcpp{
26 namespace sugar{
27 
28 template <
29  bool NA, typename RESULT_TYPE,
30  typename U1, typename T1,
31  typename U2, typename T2,
32  typename U3, typename T3
33 >
35  Rcpp::traits::r_sexptype_traits<RESULT_TYPE>::rtype ,
36  NA,
37  SugarBlock_3_VVV<NA,RESULT_TYPE,U1,T1,U2,T2,U3,T3> > {
38 public:
39  typedef RESULT_TYPE (*FunPtr)(U1,U2,U3) ;
40  SugarBlock_3_VVV( FunPtr ptr_, const T1 & x_, const T2& y_, const T3& z_ ) :
41  ptr(ptr_), x(x_), y(y_), z(z_) {
42  // TODO: size checks, recycling, etc ...
43  }
44  inline RESULT_TYPE operator[]( R_xlen_t i) const {
45  return ptr( x[i], y[i], z[i] ) ;
46  }
47  inline R_xlen_t size() const { return x.size() ; }
48 
49 private:
51  const T1& x ;
52  const T2& y ;
53  const T2& z ;
54 };
55 
56 
57 // template <bool NA, typename RESULT_TYPE, typename U1, typename T1, typename U2>
58 // class SugarBlock_3__VP : public Rcpp::VectorBase< Rcpp::traits::r_sexptype_traits<RESULT_TYPE>::rtype , NA, SugarBlock_3__VP<NA,RESULT_TYPE,U1,T1,U2> > {
59 // public:
60 // typedef RESULT_TYPE (*FunPtr)(U1,U2) ;
61 // SugarBlock_3__VP( FunPtr ptr_, const T1 & x_, U2 u2 ) :
62 // ptr(ptr_), x(x_), y(u2){}
63 //
64 // inline RESULT_TYPE operator[]( int i) const {
65 // return ptr( x[i], y ) ;
66 // }
67 // inline int size() const { return x.size() ; }
68 //
69 // private:
70 // FunPtr ptr ;
71 // const T1& x ;
72 // U2 y ;
73 // };
74 //
75 // template <bool NA, typename RESULT_TYPE, typename U1, typename U2, typename T2>
76 // class SugarBlock_3__PV : public Rcpp::VectorBase< Rcpp::traits::r_sexptype_traits<RESULT_TYPE>::rtype , NA, SugarBlock_3__PV<NA,RESULT_TYPE,U1,U2,T2> > {
77 // public:
78 // typedef RESULT_TYPE (*FunPtr)(U1,U2) ;
79 // SugarBlock_3__PV( FunPtr ptr_, U1 u1, const T2& y_ ) :
80 // ptr(ptr_), x(u1), y(y_){}
81 //
82 // inline RESULT_TYPE operator[]( int i) const {
83 // return ptr( x, y[i] ) ;
84 // }
85 // inline int size() const { return y.size() ; }
86 //
87 // private:
88 // FunPtr ptr ;
89 // U1 x ;
90 // const T2& y ;
91 // };
92 
93 
94 } // sugar
95 } // Rcpp
96 
97 #define SB3_T1 VectorBase<REALSXP,T1_NA,T1>
98 #define SB3_T2 VectorBase<REALSXP,T2_NA,T2>
99 #define SB3_T3 VectorBase<REALSXP,T3_NA,T3>
100 
101 #define SUGAR_BLOCK_3(__NAME__,__SYMBOL__) \
102 namespace Rcpp{ \
103  template <bool T1_NA, typename T1, bool T2_NA, typename T2, bool T3_NA, typename T3> \
104  inline sugar::SugarBlock_3_VVV< \
105  (T1_NA||T2_NA||T3_NA) ,double, \
106  double,SB3_T1, \
107  double,SB3_T2, \
108  double,SB3_T3 \
109  > \
110  __NAME__( \
111  const SB3_T1& x1, \
112  const SB3_T2& x2, \
113  const SB3_T3& x3 \
114  ){ \
115  return sugar::SugarBlock_3_VVV< \
116  (T1_NA||T2_NA||T3_NA) , double, \
117  double,SB3_T1, \
118  double,SB3_T2, \
119  double,SB3_T3 \
120  >( \
121  __SYMBOL__ , x1, x2, x3 \
122  ) ; \
123  } \
124 }
125 
126 #endif
RESULT_TYPE operator[](R_xlen_t i) const
Definition: SugarBlock_3.h:44
SugarBlock_3_VVV(FunPtr ptr_, const T1 &x_, const T2 &y_, const T3 &z_)
Definition: SugarBlock_3.h:40
RESULT_TYPE(* FunPtr)(U1, U2, U3)
Definition: SugarBlock_3.h:39
Rcpp API.
Definition: algo.h:28
static Na_Proxy NA
Definition: Na_Proxy.h:52