[Rcpp-commits] r1561 - in pkg/Rcpp/inst/include/Rcpp: sugar vector

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jun 17 11:46:58 CEST 2010


Author: romain
Date: 2010-06-17 11:46:57 +0200 (Thu, 17 Jun 2010)
New Revision: 1561

Added:
   pkg/Rcpp/inst/include/Rcpp/sugar/r_binary_op.h
Modified:
   pkg/Rcpp/inst/include/Rcpp/sugar/can_have_na.h
   pkg/Rcpp/inst/include/Rcpp/sugar/logical_operators.h
   pkg/Rcpp/inst/include/Rcpp/sugar/sugar.h
   pkg/Rcpp/inst/include/Rcpp/sugar/sugar_forward.h
   pkg/Rcpp/inst/include/Rcpp/vector/VectorBase.h
Log:
move r_binary_op in its own file

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/can_have_na.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/can_have_na.h	2010-06-17 09:25:43 UTC (rev 1560)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/can_have_na.h	2010-06-17 09:46:57 UTC (rev 1561)
@@ -25,9 +25,8 @@
 namespace Rcpp{
 
 template <typename T>
-struct can_have_na : Rcpp::traits::true_type {} ;
+struct can_have_na :  T::can_have_na::type {} ;
 
-
 } // Rcpp
 #endif
 

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/logical_operators.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/logical_operators.h	2010-06-17 09:25:43 UTC (rev 1560)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/logical_operators.h	2010-06-17 09:46:57 UTC (rev 1561)
@@ -25,40 +25,6 @@
 namespace Rcpp{
 namespace sugar{
 
-#undef RCPP_OP
-#define RCPP_OP(NAME,OP)   	                                     \
-template <int RTYPE>                                                \
-class NAME {                                                        \
-public:                                                             \
-	typedef typename traits::storage_type<RTYPE>::type STORAGE ;    \
-	inline bool compare_one( STORAGE lhs, STORAGE rhs) const {      \
-		return lhs OP rhs ;                                         \
-	}                                                               \
-} ;
-RCPP_OP(less,<)
-RCPP_OP(greater,>)
-RCPP_OP(less_or_equal,<=)
-RCPP_OP(greater_or_equal,>=)
-RCPP_OP(equal,==)
-RCPP_OP(not_equal,!=)
-#undef RCPP_OP
-
-	
-template <int RTYPE, typename T>
-class r_binary_op : public T {
-public:
-	typedef typename traits::storage_type<RTYPE>::type STORAGE ;
-	
-	r_binary_op(){}
-	
-	inline int compare( STORAGE lhs, STORAGE rhs) const {
-		return ( traits::is_na<RTYPE>(lhs) || traits::is_na<RTYPE>(rhs) ) ? 
-		NA_LOGICAL : static_cast<int>( compare_one( lhs, rhs ) ) ;
-	}
-	
-} ;
-
-
 template <int RTYPE, typename Operator>
 class Comparator : public LogicalResult< Comparator<RTYPE,Operator> > {
 public:

Added: pkg/Rcpp/inst/include/Rcpp/sugar/r_binary_op.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/r_binary_op.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/r_binary_op.h	2010-06-17 09:46:57 UTC (rev 1561)
@@ -0,0 +1,64 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// LessThan.h: Rcpp R/C++ interface class library -- vector operators
+//                                                                      
+// 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__r_binary_op_h
+#define Rcpp__sugar__r_binary_op_h
+
+namespace Rcpp{
+namespace sugar{
+
+#undef RCPP_OP
+#define RCPP_OP(NAME,OP)   	                                     \
+template <int RTYPE>                                                \
+class NAME {                                                        \
+public:                                                             \
+	typedef typename traits::storage_type<RTYPE>::type STORAGE ;    \
+	inline bool compare_one( STORAGE lhs, STORAGE rhs) const {      \
+		return lhs OP rhs ;                                         \
+	}                                                               \
+} ;
+RCPP_OP(less,<)
+RCPP_OP(greater,>)
+RCPP_OP(less_or_equal,<=)
+RCPP_OP(greater_or_equal,>=)
+RCPP_OP(equal,==)
+RCPP_OP(not_equal,!=)
+#undef RCPP_OP
+
+	
+template <int RTYPE, typename T>
+class r_binary_op : public T {
+public:
+	typedef typename traits::storage_type<RTYPE>::type STORAGE ;
+	
+	r_binary_op(){}
+	
+	inline int compare( STORAGE lhs, STORAGE rhs) const {
+		return ( traits::is_na<RTYPE>(lhs) || traits::is_na<RTYPE>(rhs) ) ? 
+		NA_LOGICAL : static_cast<int>( compare_one( lhs, rhs ) ) ;
+	}
+	
+} ;
+
+} // sugar
+} // Rcpp
+
+#endif

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/sugar.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/sugar.h	2010-06-17 09:25:43 UTC (rev 1560)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/sugar.h	2010-06-17 09:46:57 UTC (rev 1561)
@@ -23,6 +23,7 @@
 #define RCPP_SUGAR_H
 
 // implementations
+#include <Rcpp/sugar/r_binary_op.h>
 #include <Rcpp/sugar/any.h>
 #include <Rcpp/sugar/all.h>
 #include <Rcpp/sugar/logical_operators.h>

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/sugar_forward.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/sugar_forward.h	2010-06-17 09:25:43 UTC (rev 1560)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/sugar_forward.h	2010-06-17 09:46:57 UTC (rev 1561)
@@ -23,6 +23,7 @@
 #define RCPP_SUGAR_FORWARD_H
 
 // traits
+#include <Rcpp/sugar/r_binary_op.h>
 #include <Rcpp/sugar/can_have_na.h>
 
 // abstractions

Modified: pkg/Rcpp/inst/include/Rcpp/vector/VectorBase.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/VectorBase.h	2010-06-17 09:25:43 UTC (rev 1560)
+++ pkg/Rcpp/inst/include/Rcpp/vector/VectorBase.h	2010-06-17 09:46:57 UTC (rev 1561)
@@ -27,7 +27,7 @@
 class VectorBase {
 public:
 	struct r_type : traits::integral_constant<int,RTYPE>{} ;
-	struct can_contain_na : traits::integral_constant<bool,na>{} ;
+	struct can_have_na : traits::integral_constant<bool,na>{} ;
 	
 	typedef typename traits::get_iterator<VECTOR>::type iterator ;
 	typedef typename traits::storage_type<RTYPE>::type stored_type ;
@@ -40,6 +40,7 @@
 
 	inline stored_type operator[]( int i) const { return static_cast<VECTOR*>(this)->operator[](i) ; }
 	
+	inline int size() const { return static_cast<VECTOR*>(this)->size() ; }
 } ;
 
 #endif



More information about the Rcpp-commits mailing list