[Rcpp-devel] [Rcpp-commits] r298 - in pkg: inst src src/Rcpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jan 7 14:25:46 CET 2010


Author: romain
Date: 2010-01-07 14:25:46 +0100 (Thu, 07 Jan 2010)
New Revision: 298

Modified:
   pkg/inst/ChangeLog
   pkg/src/CharacterVector.cpp
   pkg/src/Rcpp/CharacterVector.h
Log:
added constructors to CharacterVector

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2010-01-07 13:22:31 UTC (rev 297)
+++ pkg/inst/ChangeLog	2010-01-07 13:25:46 UTC (rev 298)
@@ -1,7 +1,8 @@
 2010-01-07  Romain Francois <francoisromain at free.fr>
 
 	* src/Rcpp/CharacterVector.h: new class Rcpp::CharacterVector
-	to manage character vectors (STRSXP)
+	to manage character vectors (STRSXP). StringVector is a 
+	convenience typedef equivalent to CharacterVector
 	* src/CharacterVector.cpp: implementation
 	* inst/unitTests/runit.CharacterVector.R: unit tests
 
@@ -14,8 +15,14 @@
 	USE_RINTERNALS, but defining it disables NO_R_REMAP)
 
 	* src/Rcpp/GenericVector.h : added begin and end to allow
-	stl type iteration over generic vectors.
+	stl type iteration over generic vectors. Now using the 
+	Proxy pattern (from Item 30 of More Effective C++) to 
+	allow getting and setting the elements of the list through
+	the operator[].
 
+	* int/unitTests/runit.GenericVector.R: examples are reworked
+	using [] where set and get were used.
+
 2010-01-06  Dirk Eddelbuettel  <edd at debian.org>
 
 	* src/RcppCommon.h: Protect definition of logTxt by #ifndef

Modified: pkg/src/CharacterVector.cpp
===================================================================
--- pkg/src/CharacterVector.cpp	2010-01-07 13:22:31 UTC (rev 297)
+++ pkg/src/CharacterVector.cpp	2010-01-07 13:25:46 UTC (rev 298)
@@ -45,7 +45,22 @@
 	CharacterVector::CharacterVector(int size) : RObject() {
 		setSEXP( Rf_allocVector(STRSXP, size) ) ;
 	}
-
+	
+	CharacterVector::CharacterVector( const std::string& x){
+		setSEXP( Rf_mkString(x.c_str()) ) ;
+	}
+	
+	CharacterVector::CharacterVector( const std::vector<std::string>& x){
+		SEXP y = PROTECT( Rf_allocVector( STRSXP, x.size() ) );
+		int n = x.size() ;
+		std::vector<std::string>::const_iterator iter = x.begin() ;
+		for( int i=0; i<n; i++, iter++){
+			SET_STRING_ELT( y, i, Rf_mkChar(iter->c_str()) ) ;
+		}
+		setSEXP(y) ;
+		UNPROTECT(1) ;
+	}
+	
 #ifdef HAS_INIT_LISTS
 	CharacterVector::CharacterVector( std::initializer_list<std::string> list ) {
 		SEXP x = PROTECT( Rf_allocVector( STRSXP, list.size() ) ) ;

Modified: pkg/src/Rcpp/CharacterVector.h
===================================================================
--- pkg/src/Rcpp/CharacterVector.h	2010-01-07 13:22:31 UTC (rev 297)
+++ pkg/src/Rcpp/CharacterVector.h	2010-01-07 13:25:46 UTC (rev 298)
@@ -56,6 +56,8 @@
 	
 	CharacterVector(SEXP x) throw(not_compatible);
 	CharacterVector(int size) ;
+	CharacterVector( const std::string& x );
+	CharacterVector( const std::vector<std::string>& x );
 	
 #ifdef HAS_INIT_LISTS
 	CharacterVector( std::initializer_list<std::string> list ) ;

_______________________________________________
Rcpp-commits mailing list
Rcpp-commits at lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-commits


More information about the Rcpp-devel mailing list