[Rcpp-commits] r2474 - pkg/Rcpp/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Nov 20 19:39:37 CET 2010
Author: jmc
Date: 2010-11-20 19:39:34 +0100 (Sat, 20 Nov 2010)
New Revision: 2474
Modified:
pkg/Rcpp/R/Module.R
Log:
dont require a default constructor for subclasses of C++ classes
Modified: pkg/Rcpp/R/Module.R
===================================================================
--- pkg/Rcpp/R/Module.R 2010-11-20 18:14:35 UTC (rev 2473)
+++ pkg/Rcpp/R/Module.R 2010-11-20 18:39:34 UTC (rev 2474)
@@ -166,7 +166,16 @@
)
# just to make codetools happy
.self <- .refClassDef <- NULL
- generator$methods(initialize = function(...) Rcpp:::cpp_object_initializer(.self,.refClassDef, ...))
+ generator$methods(initialize =
+ if(cpp_hasDefaultConstructor(CLASS))
+ function(...) Rcpp:::cpp_object_initializer(.self,.refClassDef, ...)
+ else
+ function(...) {
+ if(nargs()) Rcpp:::cpp_object_initializer(.self,.refClassDef, ...)
+ else .self
+ }
+ )
+
rm( .self, .refClassDef )
classDef <- getClass(clname)
@@ -259,6 +268,14 @@
mets
}
+cpp_hasDefaultConstructor <- function(CLASS) {
+ constrs <- CLASS at constructors
+ for(cc in constrs)
+ if(cc$nargs == 0)
+ return(TRUE)
+ FALSE
+}
+
binding_maker <- function( FIELD, where ){
f <- function( x ) NULL
body(f) <- substitute({
More information about the Rcpp-commits
mailing list