[Rcpp-commits] r746 - pkg/Rcpp/src/Rcpp/traits

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Feb 19 16:43:33 CET 2010


Author: romain
Date: 2010-02-19 16:43:33 +0100 (Fri, 19 Feb 2010)
New Revision: 746

Modified:
   pkg/Rcpp/src/Rcpp/traits/Exporter.h
Log:
more Exporter, for RcppArmadillo and RProtoBuf support

Modified: pkg/Rcpp/src/Rcpp/traits/Exporter.h
===================================================================
--- pkg/Rcpp/src/Rcpp/traits/Exporter.h	2010-02-19 15:30:54 UTC (rev 745)
+++ pkg/Rcpp/src/Rcpp/traits/Exporter.h	2010-02-19 15:43:33 UTC (rev 746)
@@ -35,14 +35,14 @@
 	T t ;
 } ;
 
-template <typename T> class StdVectorExporter {
+template <typename T> class RangeExporter {
 public:
 	typedef typename T::value_type r_export_type ;
 	
-	StdVectorExporter( SEXP x ) : object(x){
+	RangeExporter( SEXP x ) : object(x){
 		// R_PreserveObject(object) ;
 	}
-	~StdVectorExporter(){
+	~RangeExporter(){
 		// R_ReleaseObject(object) ;
 	}
 	
@@ -56,9 +56,50 @@
 	SEXP object ;
 } ;
 
-template <typename T> class Exporter< std::vector<T> > : public StdVectorExporter< std::vector<T> > {
+template <typename T, typename value_type> class IndexingExporter {
+public:
+	typedef value_type r_export_type ;
+	
+	IndexingExporter( SEXP x) : object(x){}
+	~IndexingExporter(){}
+	
+	T get(){
+		T result( ::Rf_length(object) ) ;
+		::Rcpp::internal::export_indexing( object, result ) ;
+		return result ;
+	}
+	
+private:
+	SEXP object ;
+} ;
+
+template <typename T, typename value_type> class MatrixExporter {
+public:
+	typedef value_type r_export_type ;
+	
+	MatrixExporter( SEXP x) : object(x){}
+	~MatrixExporter(){}
+	
+	T get(){
+		SEXP dims = PROTECT( ::Rf_getAttrib( object, Rf_install("dim") ) ) ;
+		if( dims == R_NilValue || ::Rf_length(dims) != 2 ){
+			throw std::exception( "not a matrix" ) ;
+		}
+		int* dims_ = INTEGER(dims) ;
+		T result( dims[0], dims[1] ) ;
+		::Rcpp::internal::export_indexing( object, result ) ;
+		UNPROTECT(1) ;
+		return result ;
+	}
+	
+private:
+	SEXP object ;
+} ;
+
+
+template <typename T> class Exporter< std::vector<T> > : public RangeExporter< std::vector<T> > {
 	public:
-		Exporter(SEXP x) : StdVectorExporter< std::vector<T> >(x){}
+		Exporter(SEXP x) : RangeExporter< std::vector<T> >(x){}
 }; 
 
 



More information about the Rcpp-commits mailing list