[Rcpp-commits] r3827 - in pkg/Rcpp: . R inst/include/Rcpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Oct 23 20:36:14 CEST 2012


Author: romain
Date: 2012-10-23 20:36:13 +0200 (Tue, 23 Oct 2012)
New Revision: 3827

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/R/00_classes.R
   pkg/Rcpp/R/01_show.R
   pkg/Rcpp/R/Module.R
   pkg/Rcpp/inst/include/Rcpp/Module.h
Log:
handle methods with no arguments

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2012-10-23 18:29:57 UTC (rev 3826)
+++ pkg/Rcpp/ChangeLog	2012-10-23 18:36:13 UTC (rev 3827)
@@ -7,6 +7,16 @@
         simplified the code
         * include/Rcpp/traits/module_wrap_traits.h : new file. helping implementation of 
         module_wrap
+        
+        * R/00_classes.R: C++OverloadedMethods gets the field "nargs" to capture
+        the number of arguments
+        
+        * R/01_show.R: cleanup
+        
+        * R/Module.R: handle the case where a method has no argument. In that 
+        case, the ellipsis does not end up in the formals
+        
+        * include/Rcpp/Module.h: exposing nargs in C++OverloadedMethods
 
 2012-10-22  Romain Francois <romain at r-enthusiasts.com>
 

Modified: pkg/Rcpp/R/00_classes.R
===================================================================
--- pkg/Rcpp/R/00_classes.R	2012-10-23 18:29:57 UTC (rev 3826)
+++ pkg/Rcpp/R/00_classes.R	2012-10-23 18:36:13 UTC (rev 3827)
@@ -1,4 +1,4 @@
-# Copyright (C) 2010 - 2011 John Chambers, Dirk Eddelbuettel and Romain Francois
+# Copyright (C) 2010 - 2012 John Chambers, Dirk Eddelbuettel and Romain Francois
 #
 # This file is part of Rcpp.
 #
@@ -42,7 +42,8 @@
         void          = "logical",
         const         = "logical", 
         docstrings    = "character", 
-        signatures    = "character"
+        signatures    = "character", 
+        nargs         = "integer"
     ), 
     methods = list( 
         info = function(prefix = "    " ){

Modified: pkg/Rcpp/R/01_show.R
===================================================================
--- pkg/Rcpp/R/01_show.R	2012-10-23 18:29:57 UTC (rev 3826)
+++ pkg/Rcpp/R/01_show.R	2012-10-23 18:36:13 UTC (rev 3827)
@@ -1,4 +1,4 @@
-# Copyright (C) 2010 - 2011 John Chambers, Dirk Eddelbuettel and Romain Francois
+# Copyright (C) 2010 - 2012 John Chambers, Dirk Eddelbuettel and Romain Francois
 #
 # This file is part of Rcpp.
 #
@@ -18,14 +18,8 @@
 setMethod( "show", "C++Object", function(object){
     env <- as.environment(object)
     pointer <- get(".pointer", envir = env)
-    # FIXME: .emptyPointer is gone
-    # if(identical(pointer, .emptyPointer))
-    #     stop("Uninitialized C++ object")
     cppclass <- get(".cppclass", envir = env)
-    # FIXME: .emptyPointer is gone
-    # if(identical(cppclass, .emptyPointer))
-    #     stop("C++ object with unset C++ class pointer")
-	txt <- sprintf( "C++ object <%s> of class '%s' <%s>", 
+    txt <- sprintf( "C++ object <%s> of class '%s' <%s>", 
 		externalptr_address(pointer), 
 		.Call( Class__name, cppclass ), 
 		externalptr_address(cppclass)

Modified: pkg/Rcpp/R/Module.R
===================================================================
--- pkg/Rcpp/R/Module.R	2012-10-23 18:29:57 UTC (rev 3826)
+++ pkg/Rcpp/R/Module.R	2012-10-23 18:36:13 UTC (rev 3827)
@@ -1,4 +1,4 @@
-# Copyright (C) 2010 - 2011 John Chambers, Dirk Eddelbuettel and Romain Francois
+# Copyright (C) 2010 - 2012 John Chambers, Dirk Eddelbuettel and Romain Francois
 #
 # This file is part of Rcpp.
 #
@@ -276,7 +276,12 @@
 dealWith <- function( x ) if(isTRUE(x[[1]])) invisible(NULL) else x[[2]]
 
 method_wrapper <- function( METHOD, where ){
-        f <- function(...) NULL
+        noargs <- all( METHOD$nargs == 0 ) 
+        if( noargs ){
+            f <- function() NULL
+        } else { 
+            f <- function(...) NULL
+        }
 
         stuff <- list(
             class_pointer = METHOD$class_pointer,
@@ -287,31 +292,60 @@
             dealWith = dealWith,
             docstring = METHOD$info("")
         )
-
-        extCall <- if( all( METHOD$void ) ){
-            # all methods are void, so we know we want to return invisible(NULL)
-            substitute(
-            {
-                docstring
-                .External(CppMethod__invoke_void, class_pointer, pointer, .pointer, ...)
-                invisible(NULL)
-            } , stuff )
-        } else if( all( ! METHOD$void ) ){
-            # none of the methods are void so we always return the result of
-            # .External
-            substitute(
-            {
-                docstring
-               .External(CppMethod__invoke_notvoid, class_pointer, pointer, .pointer, ...)
-            } , stuff )
+                   
+        
+        extCall <- if( noargs ) { 
+            if( all( METHOD$void ) ){
+                # all methods are void, so we know we want to return invisible(NULL)
+                substitute(
+                {
+                    docstring
+                    .External(CppMethod__invoke_void, class_pointer, pointer, .pointer )
+                    invisible(NULL)
+                } , stuff )
+            } else if( all( ! METHOD$void ) ){
+                # none of the methods are void so we always return the result of
+                # .External
+                substitute(
+                {
+                    docstring
+                   .External(CppMethod__invoke_notvoid, class_pointer, pointer, .pointer )
+                } , stuff )
+            } else {
+                # some are void, some are not, so the voidness is part of the result
+                # we get from internally and we need to deal with it
+                substitute(
+	            {
+	                docstring
+	                dealWith( .External(CppMethod__invoke, class_pointer, pointer, .pointer ) )
+                } , stuff )
+            }
         } else {
-            # some are void, some are not, so the voidness is part of the result
-            # we get from internally and we need to deal with it
-            substitute(
-	        {
-	            docstring
-	            dealWith( .External(CppMethod__invoke, class_pointer, pointer, .pointer, ...) )
-            } , stuff )
+            if( all( METHOD$void ) ){
+                # all methods are void, so we know we want to return invisible(NULL)
+                substitute(
+                {
+                    docstring
+                    .External(CppMethod__invoke_void, class_pointer, pointer, .pointer, ...)
+                    invisible(NULL)
+                } , stuff )
+            } else if( all( ! METHOD$void ) ){
+                # none of the methods are void so we always return the result of
+                # .External
+                substitute(
+                {
+                    docstring
+                   .External(CppMethod__invoke_notvoid, class_pointer, pointer, .pointer, ...)
+                } , stuff )
+            } else {
+                # some are void, some are not, so the voidness is part of the result
+                # we get from internally and we need to deal with it
+                substitute(
+	            {
+	                docstring
+	                dealWith( .External(CppMethod__invoke, class_pointer, pointer, .pointer, ...) )
+                } , stuff )
+            }
         }
         body(f, where) <- extCall
         f

Modified: pkg/Rcpp/inst/include/Rcpp/Module.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Module.h	2012-10-23 18:29:57 UTC (rev 3826)
+++ pkg/Rcpp/inst/include/Rcpp/Module.h	2012-10-23 18:36:13 UTC (rev 3827)
@@ -283,9 +283,11 @@
             int n = m->size() ;
             Rcpp::LogicalVector voidness(n), constness(n) ;
             Rcpp::CharacterVector docstrings(n), signatures(n) ;
+            Rcpp::IntegerVector nargs(n) ;
             signed_method_class* met ;
             for( int i=0; i<n; i++){ 
                 met = m->at(i) ;
+                nargs[i] = met->nargs() ;
                 voidness[i] = met->is_void() ;
                 constness[i] = met->is_const() ;
                 docstrings[i] = met->docstring ;
@@ -300,6 +302,8 @@
             field( "const" )         = constness ;
             field( "docstrings" )    = docstrings ;
             field( "signatures" )    = signatures ;
+            field( "nargs" )         = nargs ;
+            
         }
     } ;
 



More information about the Rcpp-commits mailing list