[Rcpp-commits] r3880 - in pkg/Rcpp: . inst/include/Rcpp/sugar/logical
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Nov 1 09:03:18 CET 2012
Author: romain
Date: 2012-11-01 09:03:18 +0100 (Thu, 01 Nov 2012)
New Revision: 3880
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/inst/include/Rcpp/sugar/logical/or.h
Log:
(Logical sugar expression) | (Logical sugar expression)
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2012-11-01 03:10:05 UTC (rev 3879)
+++ pkg/Rcpp/ChangeLog 2012-11-01 08:03:18 UTC (rev 3880)
@@ -1,3 +1,8 @@
+2012-11-01 Romain Francois <romain at r-enthusiasts.com>
+
+ * include/Rcpp/sugar/logical/or.h : implementing x | y where x and y are
+ Logical sugar expressions
+
2012-10-31 JJ Allaire <jj at rstudio.org>
* R/Attributes.R: add cppFunction for inline-style definitions;
Modified: pkg/Rcpp/inst/include/Rcpp/sugar/logical/or.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/logical/or.h 2012-11-01 03:10:05 UTC (rev 3879)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/logical/or.h 2012-11-01 08:03:18 UTC (rev 3880)
@@ -2,7 +2,7 @@
//
// or.h: Rcpp R/C++ interface class library --
//
-// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
//
// This file is part of Rcpp.
//
@@ -197,9 +197,91 @@
} ;
-}
-}
+// (LogicalExpression) | (LogicalExpression)
+template <bool LHS_NA, typename LHS_T, bool RHS_NA, typename RHS_T>
+class Or_LogicalExpression_LogicalExpression : public Rcpp::VectorBase< LGLSXP, true, Or_LogicalExpression_LogicalExpression<LHS_NA,LHS_T,RHS_NA,RHS_T> >{
+public:
+ typedef typename Rcpp::VectorBase<LGLSXP,LHS_NA,LHS_T> LHS_TYPE ;
+ typedef typename Rcpp::VectorBase<LGLSXP,RHS_NA,RHS_T> RHS_TYPE ;
+
+ Or_LogicalExpression_LogicalExpression( const LHS_TYPE& lhs_, const RHS_TYPE& rhs_ ) : lhs(lhs_), rhs(rhs_){}
+
+ inline int operator[]( int i ) const{
+ if( lhs[i] == TRUE || rhs[i] == TRUE ) return TRUE ;
+ if( lhs[i] == FALSE && rhs[i] == FALSE ) return FALSE ;
+ return NA_LOGICAL;
+ }
+ inline int size() const { return lhs.size(); }
+
+private:
+ const LHS_TYPE& lhs ;
+ const RHS_TYPE& rhs ;
+} ;
+template <typename LHS_T, bool RHS_NA, typename RHS_T>
+class Or_LogicalExpression_LogicalExpression<false,LHS_T,RHS_NA,RHS_T>
+ : public Rcpp::VectorBase< LGLSXP, true, Or_LogicalExpression_LogicalExpression<false,LHS_T,RHS_NA,RHS_T> >{
+public:
+ typedef typename Rcpp::VectorBase<LGLSXP,false,LHS_T> LHS_TYPE ;
+ typedef typename Rcpp::VectorBase<LGLSXP,RHS_NA,RHS_T> RHS_TYPE ;
+
+ Or_LogicalExpression_LogicalExpression( const LHS_TYPE& lhs_, const RHS_TYPE& rhs_ ) : lhs(lhs_), rhs(rhs_){}
+
+ inline int operator[]( int i ) const{
+ if( lhs[i] == TRUE || rhs[i] == TRUE ) return TRUE ;
+ if( rhs[i] == NA_LOGICAL ) return NA_LOGICAL ;
+ return FALSE ;
+ }
+ inline int size() const { return lhs.size(); }
+
+private:
+ const LHS_TYPE& lhs ;
+ const RHS_TYPE& rhs ;
+} ;
+template <bool LHS_NA, typename LHS_T, typename RHS_T>
+class Or_LogicalExpression_LogicalExpression<LHS_NA,LHS_T,false,RHS_T>
+ : public Rcpp::VectorBase< LGLSXP, true, Or_LogicalExpression_LogicalExpression<LHS_NA,LHS_T,false,RHS_T> >{
+public:
+ typedef typename Rcpp::VectorBase<LGLSXP,LHS_NA,LHS_T> LHS_TYPE ;
+ typedef typename Rcpp::VectorBase<LGLSXP,false,RHS_T> RHS_TYPE ;
+
+ Or_LogicalExpression_LogicalExpression( const LHS_TYPE& lhs_, const RHS_TYPE& rhs_ ) : lhs(lhs_), rhs(rhs_){}
+
+ inline int operator[]( int i ) const{
+ if( lhs[i] == TRUE || rhs[i] == TRUE ) return TRUE ;
+ if( lhs[i] == NA_LOGICAL ) return NA_LOGICAL ;
+ return FALSE;
+ }
+ inline int size() const { return lhs.size(); }
+
+private:
+ const LHS_TYPE& lhs ;
+ const RHS_TYPE& rhs ;
+} ;
+template <typename LHS_T, typename RHS_T>
+class Or_LogicalExpression_LogicalExpression<false,LHS_T,false,RHS_T>
+ : public Rcpp::VectorBase< LGLSXP, false, Or_LogicalExpression_LogicalExpression<false,LHS_T,false,RHS_T> >{
+public:
+ typedef typename Rcpp::VectorBase<LGLSXP,false,LHS_T> LHS_TYPE ;
+ typedef typename Rcpp::VectorBase<LGLSXP,false,RHS_T> RHS_TYPE ;
+
+ Or_LogicalExpression_LogicalExpression( const LHS_TYPE& lhs_, const RHS_TYPE& rhs_ ) : lhs(lhs_), rhs(rhs_){}
+
+ inline int operator[]( int i ) const{
+ if( lhs[i] == TRUE || rhs[i] == TRUE ) return TRUE ;
+ return FALSE;
+ }
+ inline int size() const { return lhs.size(); }
+
+private:
+ const LHS_TYPE& lhs ;
+ const RHS_TYPE& rhs ;
+} ;
+
+
+} // sugar
+} // Rcpp
+
template <bool LHS_NA, typename LHS_T, bool RHS_NA, typename RHS_T>
inline Rcpp::sugar::Or_SingleLogicalResult_SingleLogicalResult<LHS_NA,LHS_T,RHS_NA,RHS_T>
operator||(
@@ -226,5 +308,16 @@
){
return Rcpp::sugar::Or_SingleLogicalResult_bool<LHS_NA,LHS_T>( lhs, rhs ) ;
}
+
+// (logical expression) | (logical expression)
+template <bool LHS_NA, typename LHS_T, bool RHS_NA, typename RHS_T>
+inline Rcpp::sugar::Or_LogicalExpression_LogicalExpression<LHS_NA,LHS_T,RHS_NA,RHS_T>
+operator|(
+ const Rcpp::VectorBase<LGLSXP,LHS_NA,LHS_T>& lhs,
+ const Rcpp::VectorBase<LGLSXP,RHS_NA,RHS_T>& rhs
+){
+ return Rcpp::sugar::Or_LogicalExpression_LogicalExpression<LHS_NA,LHS_T,RHS_NA,RHS_T>( lhs, rhs ) ;
+}
+
#endif
More information about the Rcpp-commits
mailing list