Rcpp Version 1.0.14
Loading...
Searching...
No Matches
SugarBlock_2.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_2_H
23#define RCPP_SUGAR_BLOCK_2_H
24
25namespace Rcpp{
26namespace sugar{
27
28template <bool NA, typename RESULT_TYPE, typename U1, typename T1, typename U2, typename T2>
29class SugarBlock_2 : public Rcpp::VectorBase< Rcpp::traits::r_sexptype_traits<RESULT_TYPE>::rtype , NA, SugarBlock_2<NA,RESULT_TYPE,U1,T1,U2,T2> > {
30public:
31 typedef RESULT_TYPE (*FunPtr)(U1,U2) ;
32 SugarBlock_2( FunPtr ptr_, const T1 & x_, const T2& y_ ) :
33 ptr(ptr_), x(x_), y(y_){
34 // TODO: check that x and y have same size
35 }
36
37 inline RESULT_TYPE operator[]( R_xlen_t i) const {
38 return ptr( x[i], y[i] ) ;
39 }
40 inline R_xlen_t size() const { return x.size() ; }
41
42private:
44 const T1& x ;
45 const T2& y ;
46};
47
48
49template <bool NA, typename RESULT_TYPE, typename U1, typename T1, typename U2>
50class SugarBlock_2__VP : public Rcpp::VectorBase< Rcpp::traits::r_sexptype_traits<RESULT_TYPE>::rtype , NA, SugarBlock_2__VP<NA,RESULT_TYPE,U1,T1,U2> > {
51public:
52 typedef RESULT_TYPE (*FunPtr)(U1,U2) ;
54 ptr(ptr_), x(x_), y(u2){}
55
56 inline RESULT_TYPE operator[]( R_xlen_t i) const {
57 return ptr( x[i], y ) ;
58 }
59 inline R_xlen_t size() const { return x.size() ; }
60
61private:
63 const T1& x ;
64 U2 y ;
65};
66
67template <bool NA, typename RESULT_TYPE, typename U1, typename U2, typename T2>
68class SugarBlock_2__PV : public Rcpp::VectorBase< Rcpp::traits::r_sexptype_traits<RESULT_TYPE>::rtype , NA, SugarBlock_2__PV<NA,RESULT_TYPE,U1,U2,T2> > {
69public:
70 typedef RESULT_TYPE (*FunPtr)(U1,U2) ;
72 ptr(ptr_), x(u1), y(y_){}
73
74 inline RESULT_TYPE operator[]( R_xlen_t i) const {
75 return ptr( x, y[i] ) ;
76 }
77 inline R_xlen_t size() const { return y.size() ; }
78
79private:
81 U1 x ;
82 const T2& y ;
83};
84
85
86} // sugar
87} // Rcpp
88
89#define SB2_LHT VectorBase<REALSXP,LHS_NA,LHS_T>
90#define SB2_RHT VectorBase<REALSXP,RHS_NA,RHS_T>
91
92#define SUGAR_BLOCK_2(__NAME__,__SYMBOL__) \
93 namespace Rcpp{ \
94 template <bool LHS_NA, typename LHS_T, bool RHS_NA, typename RHS_T > \
95 inline sugar::SugarBlock_2< (LHS_NA||RHS_NA) ,double,double,SB2_LHT,double,SB2_RHT> \
96 __NAME__( \
97 const SB2_LHT& lhs, \
98 const SB2_RHT& rhs \
99 ){ \
100 return sugar::SugarBlock_2< (LHS_NA||RHS_NA) ,double,double,SB2_LHT,double,SB2_RHT >(\
101 __SYMBOL__ , lhs, rhs \
102 ) ; \
103 } \
104 template <bool LHS_NA, typename LHS_T> \
105 inline sugar::SugarBlock_2__VP<LHS_NA,double,double,SB2_LHT,double> \
106 __NAME__( \
107 const SB2_LHT& lhs, \
108 double rhs \
109 ){ \
110 return sugar::SugarBlock_2__VP<LHS_NA,double,double,SB2_LHT,double>( \
111 __SYMBOL__ , lhs, rhs \
112 ) ; \
113 } \
114 template <bool RHS_NA, typename RHS_T> \
115 inline sugar::SugarBlock_2__PV<RHS_NA,double,double,double,SB2_RHT> \
116 __NAME__( \
117 double lhs, \
118 const SB2_RHT& rhs \
119 ){ \
120 return sugar::SugarBlock_2__PV<RHS_NA,double,double,double,SB2_RHT >( \
121 __SYMBOL__ , lhs, rhs \
122 ) ; \
123 } \
124 }
125
126
127#define SUGAR_BLOCK_2_NA(__NAME__,__SYMBOL__,__NA__) \
128 namespace Rcpp{ \
129 template <bool LHS_NA, typename LHS_T, bool RHS_NA, typename RHS_T > \
130 inline sugar::SugarBlock_2< __NA__ ,double,double,SB2_LHT,double,SB2_RHT> \
131 __NAME__( \
132 const SB2_LHT& lhs, \
133 const SB2_RHT& rhs \
134 ){ \
135 return sugar::SugarBlock_2< __NA__ ,double,double,SB2_LHT,double,SB2_RHT \
136 >( \
137 __SYMBOL__ , lhs, rhs \
138 ) ; \
139 } \
140 template <bool LHS_NA, typename LHS_T> \
141 inline sugar::SugarBlock_2__VP<__NA__,double,double,SB2_LHT,double> \
142 __NAME__( \
143 const SB2_LHT& lhs, \
144 double rhs \
145 ){ \
146 return sugar::SugarBlock_2__VP<__NA__,double,double,SB2_LHT,double>( \
147 __SYMBOL__ , lhs, rhs \
148 ) ; \
149 } \
150 template <bool RHS_NA, typename RHS_T> \
151 inline sugar::SugarBlock_2__PV<__NA__,double,double,double,SB2_RHT> \
152 __NAME__( \
153 double lhs, \
154 const SB2_RHT& rhs \
155 ){ \
156 return sugar::SugarBlock_2__PV<__NA__,double,double,double,SB2_RHT \
157 >( \
158 __SYMBOL__ , lhs, rhs \
159 ) ; \
160 } \
161 }
162
163
164#endif
RESULT_TYPE operator[](R_xlen_t i) const
RESULT_TYPE(* FunPtr)(U1, U2)
SugarBlock_2__PV(FunPtr ptr_, U1 u1, const T2 &y_)
RESULT_TYPE(* FunPtr)(U1, U2)
SugarBlock_2__VP(FunPtr ptr_, const T1 &x_, U2 u2)
RESULT_TYPE operator[](R_xlen_t i) const
SugarBlock_2(FunPtr ptr_, const T1 &x_, const T2 &y_)
RESULT_TYPE operator[](R_xlen_t i) const
RESULT_TYPE(* FunPtr)(U1, U2)
R_xlen_t size() const
Rcpp API.
Definition algo.h:28
T as(SEXP x)
Definition as.h:151