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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Feb 23 13:08:03 CET 2010


Author: romain
Date: 2010-02-23 13:08:03 +0100 (Tue, 23 Feb 2010)
New Revision: 777

Added:
   pkg/Rcpp/src/Rcpp/internal/ListInitialization.h
Modified:
   pkg/Rcpp/inst/ChangeLog
   pkg/Rcpp/inst/unitTests/runit.CharacterVector.R
   pkg/Rcpp/inst/unitTests/runit.IntegerVector.R
   pkg/Rcpp/src/Rcpp/CharacterVector.h
   pkg/Rcpp/src/Rcpp/SimpleVector.h
   pkg/Rcpp/src/RcppCommon.h
   pkg/Rcpp/src/VectorBase.cpp
Log:
experimental support of operator, (inspired from blitz++)

Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog	2010-02-23 10:06:45 UTC (rev 776)
+++ pkg/Rcpp/inst/ChangeLog	2010-02-23 12:08:03 UTC (rev 777)
@@ -1,3 +1,9 @@
+2010-02-23  Romain Francois <romain at r-enthusiasts.com>
+
+	* src/Rcpp/internal/ListInitialization.h: new class that 
+	supports use of operator, (inspired from blitz) giving this 
+	notation: IntegerVector x(3); x = 0, 1, 2 ;
+
 2010-02-21  Romain Francois <romain at r-enthusiasts.com>
 
 	* src/Rcpp/as.h: more generic as implementation. primitive 

Modified: pkg/Rcpp/inst/unitTests/runit.CharacterVector.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.CharacterVector.R	2010-02-23 10:06:45 UTC (rev 776)
+++ pkg/Rcpp/inst/unitTests/runit.CharacterVector.R	2010-02-23 12:08:03 UTC (rev 777)
@@ -223,4 +223,12 @@
 	checkEquals( funx(x), "foo", msg = "CharacterVector names based indexing" )
 }
 
-
+test.CharacterVector.comma <- function(){
+	
+	funx <- cfunction(signature(), '
+        	CharacterVector x(3) ;
+        	x = "foo", "bar", "bling" ;
+        	return x ;',
+        Rcpp=TRUE, verbose=FALSE, includes = "using namespace Rcpp;" )
+        checkEquals( funx(), c("foo","bar", "bling" ), msg = "CharacterVector comma operator" )
+}

Modified: pkg/Rcpp/inst/unitTests/runit.IntegerVector.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.IntegerVector.R	2010-02-23 10:06:45 UTC (rev 776)
+++ pkg/Rcpp/inst/unitTests/runit.IntegerVector.R	2010-02-23 12:08:03 UTC (rev 777)
@@ -154,3 +154,12 @@
 	
 }
 
+test.IntegerVector.comma <- function(){
+	funx <- cfunction(signature(), '
+	IntegerVector x(4) ;
+	x = 0, 1, 2, 3 ;
+	return x ;', 
+		Rcpp=TRUE, verbose=FALSE, includes = "using namespace Rcpp;" )
+	checkEquals( funx(), 0:3, msg = "IntegerVector comma initialization" )
+}
+

Modified: pkg/Rcpp/src/Rcpp/CharacterVector.h
===================================================================
--- pkg/Rcpp/src/Rcpp/CharacterVector.h	2010-02-23 10:06:45 UTC (rev 776)
+++ pkg/Rcpp/src/Rcpp/CharacterVector.h	2010-02-23 12:08:03 UTC (rev 777)
@@ -147,6 +147,8 @@
 		StringProxy proxy ;
 	};
 	
+	typedef StringProxy value_type ;
+	
 	/**
 	 * Default constructor. Sets the underlying object to NULL
 	 */
@@ -164,6 +166,11 @@
 	 */
 	CharacterVector& operator=( const CharacterVector& other ) ;
 	
+	internal::ListInitialization<iterator,std::string> operator=( const std::string& x){
+		SET_STRING_ELT( m_sexp, 0, Rf_mkChar( x.c_str() ) ) ;
+		return internal::ListInitialization<iterator,std::string>( iterator(*this, 1) ) ; 
+	}
+	
 	/**
 	 * encapsulates an R object
 	 *

Modified: pkg/Rcpp/src/Rcpp/SimpleVector.h
===================================================================
--- pkg/Rcpp/src/Rcpp/SimpleVector.h	2010-02-23 10:06:45 UTC (rev 776)
+++ pkg/Rcpp/src/Rcpp/SimpleVector.h	2010-02-23 12:08:03 UTC (rev 777)
@@ -67,6 +67,11 @@
 		return *this ;
 	}
 	
+	internal::ListInitialization<iterator,value_type> operator=( value_type x){
+		*start = x ;
+		return internal::ListInitialization<iterator,value_type>( start + 1 ) ; ;
+	}
+	
 	template <typename InputIterator>
 	SimpleVector( InputIterator first, InputIterator last) : VectorBase(), start(){
 		assign( first, last ) ;

Added: pkg/Rcpp/src/Rcpp/internal/ListInitialization.h
===================================================================
--- pkg/Rcpp/src/Rcpp/internal/ListInitialization.h	                        (rev 0)
+++ pkg/Rcpp/src/Rcpp/internal/ListInitialization.h	2010-02-23 12:08:03 UTC (rev 777)
@@ -0,0 +1,44 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+/* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */
+//
+// ListInitialization.h: Rcpp R/C++ interface class library -- 
+//
+// 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__internal__ListInitialization__h
+#define Rcpp__internal__ListInitialization__h
+
+namespace Rcpp{
+namespace internal{
+	
+template <typename iterator, typename value_type> class ListInitialization {
+public:
+	ListInitialization( iterator iter_ ) : iter(iter_) {} ;
+	ListInitialization<iterator,value_type> operator,( value_type x ){
+		*iter = x ;
+		return ListInitialization<iterator,value_type>( iter + 1 );
+	}
+	
+private:	
+	iterator iter ;
+} ;
+
+} // internal
+} // Rcpp
+
+#endif

Modified: pkg/Rcpp/src/RcppCommon.h
===================================================================
--- pkg/Rcpp/src/RcppCommon.h	2010-02-23 10:06:45 UTC (rev 776)
+++ pkg/Rcpp/src/RcppCommon.h	2010-02-23 12:08:03 UTC (rev 777)
@@ -177,9 +177,10 @@
 #include <Rcpp/traits/Exporter.h>
 #include <Rcpp/internal/r_coerce.h>
 #include <Rcpp/as.h>
-
 #include <Rcpp/internal/wrap.h>
 
+#include <Rcpp/internal/ListInitialization.h>
+
 RcppExport SEXP RcppXPtrExample_create_external_pointer() ;
 RcppExport SEXP RcppXPtrExample_get_external_pointer(SEXP ); 
 

Modified: pkg/Rcpp/src/VectorBase.cpp
===================================================================
--- pkg/Rcpp/src/VectorBase.cpp	2010-02-23 10:06:45 UTC (rev 776)
+++ pkg/Rcpp/src/VectorBase.cpp	2010-02-23 12:08:03 UTC (rev 777)
@@ -21,6 +21,7 @@
 
 #include <RcppCommon.h>
 #include <Rcpp/VectorBase.h>
+#include <Rcpp/CharacterVector.h>
 
 namespace Rcpp{
 	



More information about the Rcpp-commits mailing list