[Rcpp-commits] r296 - in pkg: inst/unitTests src/Rcpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jan 7 14:03:10 CET 2010


Author: romain
Date: 2010-01-07 14:03:10 +0100 (Thu, 07 Jan 2010)
New Revision: 296

Modified:
   pkg/inst/unitTests/runit.GenericVector.R
   pkg/src/Rcpp/CharacterVector.h
   pkg/src/Rcpp/GenericVector.h
Log:
improve the Proxy class in Rcpp::GenericVector with a templated operator= so that we get wrap to work for us, see the test.List.template unit test

Modified: pkg/inst/unitTests/runit.GenericVector.R
===================================================================
--- pkg/inst/unitTests/runit.GenericVector.R	2010-01-07 12:51:29 UTC (rev 295)
+++ pkg/inst/unitTests/runit.GenericVector.R	2010-01-07 13:03:10 UTC (rev 296)
@@ -30,6 +30,20 @@
 	checkEquals( funx(), as.list( 2*0:9), msg = "GenericVector" )
 }
 
+test.List.template <- function(){
+	funx <- cfunction(signature(), '
+	List x(4) ;
+	x[0] = "foo"  ;
+	x[1] = 10 ;
+	x[2] = 10.2 ;
+	x[3] = false; 
+	return x ;', 
+		Rcpp=TRUE, verbose=FALSE, includes = "using namespace Rcpp;" )
+	checkEquals( funx(), 
+		list( "foo", 10L, 10.2, FALSE), 
+		msg = "GenericVector" )
+}
+
 test.List.VECSXP <- function(){
 	funx <- cfunction(signature(vec = "list" ), '
 	List x(vec) ;

Modified: pkg/src/Rcpp/CharacterVector.h
===================================================================
--- pkg/src/Rcpp/CharacterVector.h	2010-01-07 12:51:29 UTC (rev 295)
+++ pkg/src/Rcpp/CharacterVector.h	2010-01-07 13:03:10 UTC (rev 296)
@@ -84,6 +84,8 @@
 	
 } ;
 
+typedef CharacterVector StringVector ;
+
 } // namespace
 
 #endif

Modified: pkg/src/Rcpp/GenericVector.h
===================================================================
--- pkg/src/Rcpp/GenericVector.h	2010-01-07 12:51:29 UTC (rev 295)
+++ pkg/src/Rcpp/GenericVector.h	2010-01-07 13:03:10 UTC (rev 296)
@@ -44,6 +44,11 @@
 		Proxy& operator=(const Proxy& rhs) ;
 		Proxy& operator=(SEXP rhs) ;
 		
+		template <typename T>
+		Proxy& operator=( const T& rhs){
+			SET_VECTOR_ELT( parent, index, wrap(rhs) ) ;
+		}
+		
 		/* rvalue use */
 		operator SEXP() const ;
 		



More information about the Rcpp-commits mailing list