[Rcpp-commits] r1538 - pkg/Rcpp/inst/include/Rcpp/sugar

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jun 14 19:24:51 CEST 2010


Author: romain
Date: 2010-06-14 19:24:50 +0200 (Mon, 14 Jun 2010)
New Revision: 1538

Added:
   pkg/Rcpp/inst/include/Rcpp/sugar/all.h
Modified:
   pkg/Rcpp/inst/include/Rcpp/sugar/sugar.h
Log:
added sugar all

Added: pkg/Rcpp/inst/include/Rcpp/sugar/all.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/all.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/all.h	2010-06-14 17:24:50 UTC (rev 1538)
@@ -0,0 +1,85 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// all.h: Rcpp R/C++ interface class library -- all
+//
+// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef Rcpp__sugar__all_h
+#define Rcpp__sugar__all_h
+
+namespace Rcpp{
+namespace sugar{
+
+template <typename T>
+class All : public SingleLogicalResult< All<T> >{
+public:
+	typedef SingleLogicalResult< All<T> > PARENT ;
+	All( const T& t ) : PARENT() , object(t) {}
+	
+	void apply(){
+		apply__impl( typename can_have_na<T>::type() ) ;
+	}	
+private:		
+	const T& object ;
+
+	// version that takes NA into account
+	void apply__impl( Rcpp::traits::true_type ){
+		int n = object.size() ;
+		int current = 0 ;
+		PARENT::reset() ;
+		for( int i=0 ; i<n ; i++){
+			current = object[i] ;
+			if( current == FALSE ) {
+				PARENT::set_false() ; 
+				return ;
+			}
+			if( Rcpp::traits::is_na<LGLSXP>(current)  ) {
+				PARENT::set_na();
+			}
+		}
+		if( PARENT::is_unresolved() ){
+			PARENT::set_true() ;
+		}
+	}
+	
+	// version to use when we know there is no NA
+	void apply__impl( Rcpp::traits::false_type ){
+		int n = object.size() ;
+		PARENT::set_true() ;
+		for( int i=0 ; i<n ; i++){
+			if( object[i] == TRUE ) {
+				PARENT::set_false() ; 
+				return ;
+			}
+		}
+	}
+	
+	
+private:
+} ;
+
+} // sugar
+
+template <typename T>
+inline sugar::All<T> all( const T& t){
+	return sugar::All<T>( t ) ;
+}
+
+} // Rcpp
+#endif
+

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/sugar.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/sugar.h	2010-06-14 17:12:37 UTC (rev 1537)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/sugar.h	2010-06-14 17:24:50 UTC (rev 1538)
@@ -24,6 +24,7 @@
 
 // implementations
 #include <Rcpp/sugar/any.h>
+#include <Rcpp/sugar/all.h>
 #include <Rcpp/sugar/logical_operators.h>
 
 #endif



More information about the Rcpp-commits mailing list