[Rcpp-commits] r4442 - in pkg/Rcpp: . inst inst/include/Rcpp/internal inst/unitTests inst/unitTests/cpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Aug 22 11:23:51 CEST 2013


Author: romain
Date: 2013-08-22 11:23:51 +0200 (Thu, 22 Aug 2013)
New Revision: 4442

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/NEWS.Rd
   pkg/Rcpp/inst/include/Rcpp/internal/wrap.h
   pkg/Rcpp/inst/unitTests/cpp/wrap.cpp
   pkg/Rcpp/inst/unitTests/runit.wrap.R
Log:
more wrap coverage

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2013-08-22 09:07:21 UTC (rev 4441)
+++ pkg/Rcpp/ChangeLog	2013-08-22 09:23:51 UTC (rev 4442)
@@ -6,7 +6,8 @@
         * include/Rcpp/traits/r_type_traits.h : new tag r_type_pair_tag to handle
         wrapping map<KEY, VALUE> where KEY can be converted to String and VALUE 
         can wrap itself
-        * include/Rcpp/internal/wrap.h : handling r_type_pair_tag
+        * include/Rcpp/internal/wrap.h : handling map<KEY, VALUE> and vector<T>
+        where T is a class handled by modules
         * include/Rcpp/api/meat/wrap.h : implementations to handle map<KEY, VALUE>
         * unitTests/cpp/wrap.cpp : more tests for map<KEY, VALUE> with KEY not a string
         * unitTests/runit.wrap.R : more tests for map<KEY, VALUE> with KEY not a string

Modified: pkg/Rcpp/inst/NEWS.Rd
===================================================================
--- pkg/Rcpp/inst/NEWS.Rd	2013-08-22 09:07:21 UTC (rev 4441)
+++ pkg/Rcpp/inst/NEWS.Rd	2013-08-22 09:23:51 UTC (rev 4442)
@@ -30,7 +30,11 @@
           a String from a double and \code{std::vector<double>} can wrap itself
       }
       Other examples of this are included at the end of the \code{wrap} unit test
-      file (\code{runit.wrap.R} and \code{wrap.cpp}) . 
+      file (\code{runit.wrap.R} and \code{wrap.cpp}).
+      \item \code{wrap} now handles containers of classes handled by modules. e.g.
+      if you expose a class \code{Foo} via modules, then you can wrap 
+      \code{vector<Foo>}, ... An example is included in the \code{wrap} unit test
+      file
     }
 
     \item Changes in Attributes:

Modified: pkg/Rcpp/inst/include/Rcpp/internal/wrap.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/internal/wrap.h	2013-08-22 09:07:21 UTC (rev 4441)
+++ pkg/Rcpp/inst/include/Rcpp/internal/wrap.h	2013-08-22 09:23:51 UTC (rev 4442)
@@ -185,7 +185,7 @@
  * This produces an unnamed generic vector (list)
  */
 template <typename InputIterator, typename T>
-inline SEXP range_wrap_dispatch___impl( InputIterator first, InputIterator last, ::Rcpp::traits::r_type_generic_tag ){ 
+inline SEXP range_wrap_dispatch___generic( InputIterator first, InputIterator last ){ 
 	size_t size = std::distance( first, last ) ;
 	SEXP x = PROTECT( Rf_allocVector( VECSXP, size ) );
 	size_t i =0 ;
@@ -198,6 +198,35 @@
 	return x ;
 }
 
+template <typename InputIterator, typename T>
+inline SEXP range_wrap_dispatch___impl( InputIterator first, InputIterator last, ::Rcpp::traits::r_type_generic_tag ){ 
+	return range_wrap_dispatch___generic<InputIterator, T>( first, last ) ;
+}
+
+// modules
+template <typename InputIterator, typename T>
+inline SEXP range_wrap_dispatch___impl( InputIterator first, InputIterator last, ::Rcpp::traits::r_type_module_object_pointer_tag ){ 
+	return range_wrap_dispatch___generic<InputIterator, T>( first, last ) ;
+}
+template <typename InputIterator, typename T>
+inline SEXP range_wrap_dispatch___impl( InputIterator first, InputIterator last, ::Rcpp::traits::r_type_module_object_const_pointer_tag ){ 
+	return range_wrap_dispatch___generic<InputIterator, T>( first, last ) ;
+}
+template <typename InputIterator, typename T>
+inline SEXP range_wrap_dispatch___impl( InputIterator first, InputIterator last, ::Rcpp::traits::r_type_module_object_tag ){ 
+	return range_wrap_dispatch___generic<InputIterator, T>( first, last ) ;
+}
+template <typename InputIterator, typename T>
+inline SEXP range_wrap_dispatch___impl( InputIterator first, InputIterator last, ::Rcpp::traits::r_type_module_object_reference_tag ){ 
+	return range_wrap_dispatch___generic<InputIterator, T>( first, last ) ;
+}
+template <typename InputIterator, typename T>
+inline SEXP range_wrap_dispatch___impl( InputIterator first, InputIterator last, ::Rcpp::traits::r_type_module_object_const_reference_tag ){ 
+	return range_wrap_dispatch___generic<InputIterator, T>( first, last ) ;
+}
+
+
+
 /**
  * Range based wrap implementation for iterators over std::string
  * 

Modified: pkg/Rcpp/inst/unitTests/cpp/wrap.cpp
===================================================================
--- pkg/Rcpp/inst/unitTests/cpp/wrap.cpp	2013-08-22 09:07:21 UTC (rev 4441)
+++ pkg/Rcpp/inst/unitTests/cpp/wrap.cpp	2013-08-22 09:23:51 UTC (rev 4442)
@@ -249,4 +249,11 @@
     return wrap( map ) ;
 }
 
+// [[Rcpp::export]]
+SEXP vector_Foo(){
+    std::vector<Foo> vec(2) ;
+    vec[0] = Foo( 2 ) ;
+    vec[1] = Foo( 3 ) ;
+    return wrap(vec) ;
+}
 

Modified: pkg/Rcpp/inst/unitTests/runit.wrap.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.wrap.R	2013-08-22 09:07:21 UTC (rev 4441)
+++ pkg/Rcpp/inst/unitTests/runit.wrap.R	2013-08-22 09:23:51 UTC (rev 4442)
@@ -181,5 +181,13 @@
     )    
 }
 
+test.wrap.vector.Foo <- function(){
+    checkEquals( 
+        sapply( vector_Foo(), function(.) .$get() ), 
+        c(2, 3), 
+        msg = "std::vector< MODULE EXPOSED CLASS >"
+    )    
 }
 
+}
+



More information about the Rcpp-commits mailing list