[Rcpp-commits] r741 - pkg/Rcpp/src/Rcpp/internal

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Feb 19 13:00:51 CET 2010


Author: romain
Date: 2010-02-19 13:00:51 +0100 (Fri, 19 Feb 2010)
New Revision: 741

Modified:
   pkg/Rcpp/src/Rcpp/internal/wrap.h
Log:
handle Importer of std::string -> STRSXP and generic type -> VECSXP

Modified: pkg/Rcpp/src/Rcpp/internal/wrap.h
===================================================================
--- pkg/Rcpp/src/Rcpp/internal/wrap.h	2010-02-19 11:37:05 UTC (rev 740)
+++ pkg/Rcpp/src/Rcpp/internal/wrap.h	2010-02-19 12:00:51 UTC (rev 741)
@@ -446,12 +446,37 @@
 }
 
 template <typename T, typename elem_type>
-SEXP wrap_dispatch_importer__impl( const T& object, ::Rcpp::traits::wrap_type_primitive_tag ){
+SEXP wrap_dispatch_importer__impl( const T& object, ::Rcpp::traits::r_type_primitive_tag ){
 	return wrap_dispatch_importer__impl__prim<T,elem_type>( object, 
 		typename ::Rcpp::traits::r_sexptype_needscast<elem_type>() ) ;
 }
 
 template <typename T, typename elem_type>
+SEXP wrap_dispatch_importer__impl( const T& object, ::Rcpp::traits::r_type_string_tag ){
+	int size = object.size() ;
+	SEXP x = PROTECT( Rf_allocVector( STRSXP, size ) );
+	std::string buf ;
+	for( int i=0; i<size; i++){
+		buf = object.get(i) ;
+		SET_STRING_ELT( x, i, Rf_mkChar( buf.c_str() ) ) ;
+	}
+	UNPROTECT(1) ;
+	return x ;
+}
+
+template <typename T, typename elem_type>
+SEXP wrap_dispatch_importer__impl( const T& object, ::Rcpp::traits::r_type_generic_tag ){
+	int size = object.size() ;
+	SEXP x = PROTECT( Rf_allocVector( VECSXP, size ) );
+	for( int i=0; i<size; i++){
+		SET_VECTOR_ELT( x, i, wrap( object.get(i) ) ) ;
+	}
+	UNPROTECT(1) ;
+	return x ;
+}
+
+
+template <typename T, typename elem_type>
 SEXP wrap_dispatch_importer( const T& object ){
 	return wrap_dispatch_importer__impl<T,elem_type>( object, 
 		typename ::Rcpp::traits::r_type_traits<elem_type>::r_category() 



More information about the Rcpp-commits mailing list