[Rcpp-commits] r4401 - in pkg/Rcpp/inst/unitTests: . cpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jul 23 22:57:08 CEST 2013


Author: romain
Date: 2013-07-23 22:57:08 +0200 (Tue, 23 Jul 2013)
New Revision: 4401

Modified:
   pkg/Rcpp/inst/unitTests/cpp/Module.cpp
   pkg/Rcpp/inst/unitTests/runit.Module.R
Log:
more testing

Modified: pkg/Rcpp/inst/unitTests/cpp/Module.cpp
===================================================================
--- pkg/Rcpp/inst/unitTests/cpp/Module.cpp	2013-07-23 20:42:59 UTC (rev 4400)
+++ pkg/Rcpp/inst/unitTests/cpp/Module.cpp	2013-07-23 20:57:08 UTC (rev 4401)
@@ -74,7 +74,6 @@
     int y ;
 };
    
-RCPP_EXPOSED_CLASS(Number)
 class Number{
 public:
     Number() : x(0.0), y(0){} ;
@@ -98,17 +97,29 @@
     double min, max ;
 } ;
 
-double Number_get_x_const_ref( const Number& x){
-    return x.x ;    
+RCPP_EXPOSED_CLASS(Test)
+class Test{
+public:
+    double value ;
+    Test(double v) : value(v){}
+private:    
+    // hiding those on purpose
+    // we work by reference or pointers here. Not by copy. 
+    Test( const Test& other) ;
+    Test& operator=( const Test& ) ;
+} ;
+
+double Test_get_x_const_ref( const Test& x){
+    return x.value ;    
 }
-double Number_get_x_ref( Number& x){
-    return x.x ;    
+double Test_get_x_ref( Test& x){
+    return x.value;    
 }
-double Number_get_x_const_pointer( const Number* x){
-    return x->x ;    
+double Test_get_x_const_pointer( const Test* x){
+    return x->value ;    
 }
-double Number_get_x_pointer( Number* x){
-    return x->x ;    
+double Test_get_x_pointer( Test* x){
+    return x->value ;    
 }
 
 RCPP_MODULE(yada){
@@ -119,6 +130,10 @@
 	function( "bla1"  , &bla1   ) ;
 	function( "bla2"  , &bla2   ) ;
 
+	class_<Test>("Test")
+        .constructor<double>()
+    ;   
+    
 	class_<World>( "World" )
 
 	    .constructor()
@@ -148,10 +163,10 @@
         	// read only data member
         	.field_readonly( "y", &Number::y )
     ;
-    function( "Number_get_x_const_ref", Number_get_x_const_ref ); 
-    function( "Number_get_x_ref", Number_get_x_ref ); 
-    function( "Number_get_x_const_pointer", Number_get_x_const_pointer ); 
-    function( "Number_get_x_pointer", Number_get_x_pointer ); 
+    function( "Test_get_x_const_ref", Test_get_x_const_ref ); 
+    function( "Test_get_x_ref", Test_get_x_ref ); 
+    function( "Test_get_x_const_pointer", Test_get_x_const_pointer ); 
+    function( "Test_get_x_pointer", Test_get_x_pointer ); 
     
     
     class_<Randomizer>( "Randomizer" )
@@ -161,4 +176,25 @@
         .method( "get" , &Randomizer::get ) 
     ;
 }
+  
+// [[Rcpp::export]]
+double attr_Test_get_x_const_ref( const Test& x){
+    return x.value ;    
+}
 
+// [[Rcpp::export]]
+double attr_Test_get_x_ref( Test& x){
+    return x.value;    
+}
+
+// [[Rcpp::export]]
+double attr_Test_get_x_const_pointer( const Test* x){
+    return x->value ;    
+}
+
+// [[Rcpp::export]]
+double attr_Test_get_x_pointer( Test* x){
+    return x->value ;    
+}
+
+

Modified: pkg/Rcpp/inst/unitTests/runit.Module.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.Module.R	2013-07-23 20:42:59 UTC (rev 4400)
+++ pkg/Rcpp/inst/unitTests/runit.Module.R	2013-07-23 20:57:08 UTC (rev 4401)
@@ -42,11 +42,16 @@
 }
 
 test.Module.exposed.class <- function(){
-    num <- new( Number )
-    checkEquals( Number_get_x_const_ref(num), 0.0 )
-    checkEquals( Number_get_x_const_pointer(num), 0.0 )
-    checkEquals( Number_get_x_ref(num), 0.0 )
-    checkEquals( Number_get_x_pointer(num), 0.0 )
+    test <- new( Test, 3.0 )
+    checkEquals( Test_get_x_const_ref(test), 3.0 )
+    checkEquals( Test_get_x_const_pointer(test), 3.0 )
+    checkEquals( Test_get_x_ref(test), 3.0 )
+    checkEquals( Test_get_x_pointer(test), 3.0 )
+    
+    checkEquals( attr_Test_get_x_const_ref(test), 3.0 )
+    checkEquals( attr_Test_get_x_const_pointer(test), 3.0 )
+    checkEquals( attr_Test_get_x_ref(test), 3.0 )
+    checkEquals( attr_Test_get_x_pointer(test), 3.0 )
 }
 
 test.Module.property <- function(){



More information about the Rcpp-commits mailing list