|
Rcpp Version 0.9.10
|
00001 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- 00002 // 00003 // SugarBlock.h: Rcpp R/C++ interface class library -- sugar functions 00004 // 00005 // Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois 00006 // 00007 // This file is part of Rcpp. 00008 // 00009 // Rcpp is free software: you can redistribute it and/or modify it 00010 // under the terms of the GNU General Public License as published by 00011 // the Free Software Foundation, either version 2 of the License, or 00012 // (at your option) any later version. 00013 // 00014 // Rcpp is distributed in the hope that it will be useful, but 00015 // WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with Rcpp. If not, see <http://www.gnu.org/licenses/>. 00021 00022 #ifndef RCPP_SUGAR_BLOCK_3_H 00023 #define RCPP_SUGAR_BLOCK_3_H 00024 00025 namespace Rcpp{ 00026 namespace sugar{ 00027 00028 template < 00029 bool NA, typename OUT, 00030 typename U1, typename T1, 00031 typename U2, typename T2, 00032 typename U3, typename T3 00033 > 00034 class SugarBlock_3_VVV : public Rcpp::VectorBase< 00035 Rcpp::traits::r_sexptype_traits<OUT>::rtype , 00036 NA, 00037 SugarBlock_3_VVV<NA,OUT,U1,T1,U2,T2,U3,T3> > { 00038 public: 00039 typedef OUT (*FunPtr)(U1,U2,U3) ; 00040 SugarBlock_3_VVV( FunPtr ptr_, const T1 & x_, const T2& y_, const T3& z_ ) : 00041 ptr(ptr_), x(x_), y(y_), z(z_) { 00042 // TODO: size checks, recycling, etc ... 00043 } 00044 inline OUT operator[]( int i) const { 00045 return ptr( x[i], y[i], z[i] ) ; 00046 } 00047 inline int size() const { return x.size() ; } 00048 00049 private: 00050 FunPtr ptr ; 00051 const T1& x ; 00052 const T2& y ; 00053 const T2& z ; 00054 }; 00055 00056 00057 // template <bool NA, typename OUT, typename U1, typename T1, typename U2> 00058 // class SugarBlock_3__VP : public Rcpp::VectorBase< Rcpp::traits::r_sexptype_traits<OUT>::rtype , NA, SugarBlock_3__VP<NA,OUT,U1,T1,U2> > { 00059 // public: 00060 // typedef OUT (*FunPtr)(U1,U2) ; 00061 // SugarBlock_3__VP( FunPtr ptr_, const T1 & x_, U2 u2 ) : 00062 // ptr(ptr_), x(x_), y(u2){} 00063 // 00064 // inline OUT operator[]( int i) const { 00065 // return ptr( x[i], y ) ; 00066 // } 00067 // inline int size() const { return x.size() ; } 00068 // 00069 // private: 00070 // FunPtr ptr ; 00071 // const T1& x ; 00072 // U2 y ; 00073 // }; 00074 // 00075 // template <bool NA, typename OUT, typename U1, typename U2, typename T2> 00076 // class SugarBlock_3__PV : public Rcpp::VectorBase< Rcpp::traits::r_sexptype_traits<OUT>::rtype , NA, SugarBlock_3__PV<NA,OUT,U1,U2,T2> > { 00077 // public: 00078 // typedef OUT (*FunPtr)(U1,U2) ; 00079 // SugarBlock_3__PV( FunPtr ptr_, U1 u1, const T2& y_ ) : 00080 // ptr(ptr_), x(u1), y(y_){} 00081 // 00082 // inline OUT operator[]( int i) const { 00083 // return ptr( x, y[i] ) ; 00084 // } 00085 // inline int size() const { return y.size() ; } 00086 // 00087 // private: 00088 // FunPtr ptr ; 00089 // U1 x ; 00090 // const T2& y ; 00091 // }; 00092 00093 00094 } // sugar 00095 } // Rcpp 00096 00097 #define SB3_T1 VectorBase<REALSXP,T1_NA,T1> 00098 #define SB3_T2 VectorBase<REALSXP,T2_NA,T2> 00099 #define SB3_T3 VectorBase<REALSXP,T3_NA,T3> 00100 00101 #define SUGAR_BLOCK_3(__NAME__,__SYMBOL__) \ 00102 namespace Rcpp{ \ 00103 template <bool T1_NA, typename T1, bool T2_NA, typename T2, bool T3_NA, typename T3> \ 00104 inline sugar::SugarBlock_3_VVV< \ 00105 (T1_NA||T2_NA||T3_NA) ,double, \ 00106 double,SB3_T1, \ 00107 double,SB3_T2, \ 00108 double,SB3_T3 \ 00109 > \ 00110 __NAME__( \ 00111 const SB3_T1& x1, \ 00112 const SB3_T2& x2, \ 00113 const SB3_T3& x3 \ 00114 ){ \ 00115 return sugar::SugarBlock_3_VVV< \ 00116 (T1_NA||T2_NA||T3_NA) , double, \ 00117 double,SB3_T1, \ 00118 double,SB3_T2, \ 00119 double,SB3_T3 \ 00120 >( \ 00121 __SYMBOL__ , x1, x2, x3 \ 00122 ) ; \ 00123 } \ 00124 } 00125 00126 #endif