Rcpp Version 0.9.10
mapply_3.h
Go to the documentation of this file.
00001 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
00002 //
00003 // mapply_3.h: Rcpp R/C++ interface class library -- mapply_3
00004 //
00005 // Copyright (C) 2012 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__mapply_3_h
00023 #define Rcpp__sugar__mapply_3_h
00024 
00025 namespace Rcpp{
00026 namespace sugar{
00027 
00028 template <int RTYPE, 
00029     bool NA_1, typename T_1, 
00030     bool NA_2, typename T_2, 
00031     bool NA_3, typename T_3, 
00032     typename Function
00033 >
00034 class Mapply_3 : public VectorBase< 
00035         Rcpp::traits::r_sexptype_traits<
00036                 typename ::Rcpp::traits::result_of<Function>::type
00037         >::rtype , 
00038         true ,
00039         Mapply_3<RTYPE,NA_1,T_1,NA_2,T_2,NA_3,T_3,Function>
00040 > {
00041 public:         
00042         typedef typename ::Rcpp::traits::result_of<Function>::type result_type ;
00043         
00044     typedef Rcpp::VectorBase<RTYPE,NA_1,T_1> VEC_1 ;
00045         typedef Rcpp::VectorBase<RTYPE,NA_2,T_2> VEC_2 ;
00046         typedef Rcpp::VectorBase<RTYPE,NA_3,T_3> VEC_3 ;
00047         
00048         typedef typename Rcpp::traits::Extractor<RTYPE,NA_1,T_1>::type EXT_1 ;
00049         typedef typename Rcpp::traits::Extractor<RTYPE,NA_2,T_2>::type EXT_2 ;
00050         typedef typename Rcpp::traits::Extractor<RTYPE,NA_3,T_3>::type EXT_3 ;
00051         
00052         Mapply_3( const VEC_1& vec_1_, const VEC_2& vec_2_, const VEC_3& vec_3_, Function fun_ ) : 
00053                 vec_1(vec_1_.get_ref()), vec_2(vec_2_.get_ref()), vec_3(vec_3_.get_ref()), fun(fun_){}
00054         
00055         inline result_type operator[]( int i ) const {
00056                 return fun( vec_1[i], vec_2[i], vec_3[i] );
00057         }
00058         inline int size() const { return vec_1.size() ; }
00059                  
00060 private:
00061         const EXT_1& vec_1 ;
00062         const EXT_2& vec_2 ;
00063         const EXT_3& vec_3 ;
00064         Function fun ;
00065 } ;
00066         
00067 } // sugar
00068 
00069 template <int RTYPE, bool NA_1, typename T_1, bool NA_2, typename T_2, bool NA_3, typename T_3, typename Function >
00070 inline sugar::Mapply_3<RTYPE,NA_1,T_1,NA_2,T_2,NA_3,T_3,Function> 
00071 mapply( 
00072     const Rcpp::VectorBase<RTYPE,NA_1,T_1>& t1, 
00073     const Rcpp::VectorBase<RTYPE,NA_2,T_2>& t2, 
00074     const Rcpp::VectorBase<RTYPE,NA_3,T_3>& t3, 
00075     Function fun
00076 ){
00077         return sugar::Mapply_3<RTYPE,NA_1,T_1,NA_2,T_2,NA_3,T_3,Function>( t1, t2, t3, fun ) ;
00078 }
00079 
00080 } // Rcpp
00081 
00082 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Defines