[Rcpp-commits] r3881 - 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 10:34:53 CET 2012


Author: romain
Date: 2012-11-01 10:34:53 +0100 (Thu, 01 Nov 2012)
New Revision: 3881

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/sugar/logical/and.h
Log:
x & y where x and y are logical sugar expressions

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2012-11-01 08:03:18 UTC (rev 3880)
+++ pkg/Rcpp/ChangeLog	2012-11-01 09:34:53 UTC (rev 3881)
@@ -2,6 +2,8 @@
 
         * include/Rcpp/sugar/logical/or.h : implementing x | y where x and y are
         Logical sugar expressions
+        * include/Rcpp/sugar/logical/and.h : implementing x & y where x and y are
+        Logical sugar expressions
 
 2012-10-31  JJ Allaire <jj at rstudio.org>
 

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/logical/and.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/logical/and.h	2012-11-01 08:03:18 UTC (rev 3880)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/logical/and.h	2012-11-01 09:34:53 UTC (rev 3881)
@@ -2,7 +2,7 @@
 //
 // and.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.
 //
@@ -199,6 +199,87 @@
 } ;
 
 
+
+// (LogicalExpression) & (LogicalExpression) 
+template <bool LHS_NA, typename LHS_T, bool RHS_NA, typename RHS_T>
+class And_LogicalExpression_LogicalExpression : public Rcpp::VectorBase< LGLSXP, true, And_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 ;
+    
+    And_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 || 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 <typename LHS_T, bool RHS_NA, typename RHS_T>
+class And_LogicalExpression_LogicalExpression<false,LHS_T,RHS_NA,RHS_T> 
+    : public Rcpp::VectorBase< LGLSXP, true, And_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 ;
+    
+    And_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 And_LogicalExpression_LogicalExpression<LHS_NA,LHS_T,false,RHS_T> 
+    : public Rcpp::VectorBase< LGLSXP, true, And_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 ;
+    
+    And_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 And_LogicalExpression_LogicalExpression<false,LHS_T,false,RHS_T>
+    : public Rcpp::VectorBase< LGLSXP, false, And_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 ;
+    
+    And_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 ;
+} ;
+
 }
 }
 
@@ -229,6 +310,15 @@
 	return Rcpp::sugar::And_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::And_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::And_LogicalExpression_LogicalExpression<LHS_NA,LHS_T,RHS_NA,RHS_T>( lhs, rhs ) ;
+}
 
 
 #endif



More information about the Rcpp-commits mailing list