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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Nov 21 18:25:07 CET 2010


Author: romain
Date: 2010-11-21 18:25:07 +0100 (Sun, 21 Nov 2010)
New Revision: 2478

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/NAMESPACE
   pkg/Rcpp/R/Module.R
   pkg/Rcpp/inst/include/Rcpp/Module.h
   pkg/Rcpp/inst/include/Rcpp/routines.h
   pkg/Rcpp/src/Module.cpp
   pkg/Rcpp/src/Rcpp_init.c
Log:
internal version of cpp_hasDefaultConstructor

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2010-11-20 18:48:05 UTC (rev 2477)
+++ pkg/Rcpp/ChangeLog	2010-11-21 17:25:07 UTC (rev 2478)
@@ -1,6 +1,14 @@
+2010-11-21  Romain Francois <romain at r-enthusiasts.com>
+
+	* R/Module.R: internal version of cpp_hasDefaultConstructor
+	
+	* src/Module.cpp: implementation (Class__has_default_constructor)
+	
+	* inst/include/Rcpp/Module.h: support (class_.has_default_constructor)
+
 2010-11-20  John M Chambers  <jmc at r-project.org>
 
-	* R/Module.R now checks for the existence of a default constructor
+	* R/Module.R: now checks for the existence of a default constructor
 	for a C++ class and generates a suitable $initialize() method accordingly.
 
 2010-11-20  Romain Francois <romain at r-enthusiasts.com>

Modified: pkg/Rcpp/NAMESPACE
===================================================================
--- pkg/Rcpp/NAMESPACE	2010-11-20 18:48:05 UTC (rev 2477)
+++ pkg/Rcpp/NAMESPACE	2010-11-21 17:25:07 UTC (rev 2478)
@@ -4,7 +4,7 @@
     
     CppField__get, CppField__set,
     
-    Class__name,
+    Class__name, Class__has_default_constructor,
     
     CppClass__complete, CppClass__methods,
     

Modified: pkg/Rcpp/R/Module.R
===================================================================
--- pkg/Rcpp/R/Module.R	2010-11-20 18:48:05 UTC (rev 2477)
+++ pkg/Rcpp/R/Module.R	2010-11-21 17:25:07 UTC (rev 2478)
@@ -269,11 +269,7 @@
 }
 
 cpp_hasDefaultConstructor <- function(CLASS) {
-    constrs <- CLASS at constructors
-    for(cc in constrs)
-        if(cc$nargs == 0)
-            return(TRUE)
-    FALSE
+    .Call( Class__has_default_constructor, CLASS at pointer )
 }
 
 binding_maker <- function( FIELD, where ){

Modified: pkg/Rcpp/inst/include/Rcpp/Module.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Module.h	2010-11-20 18:48:05 UTC (rev 2477)
+++ pkg/Rcpp/inst/include/Rcpp/Module.h	2010-11-21 17:25:07 UTC (rev 2478)
@@ -59,6 +59,7 @@
 	
 	virtual void run_finalizer(SEXP){ }
 	
+	virtual bool has_default_constructor(){ return false ; }
 	virtual bool has_method( const std::string& ){ 
 		return false ; 
 	}
@@ -343,6 +344,16 @@
 	    END_RCPP
 	}
 	
+	bool has_default_constructor(){ 
+	    int n = constructors.size() ;
+	    signed_constructor_class* p ;
+	    for( int i=0; i<n; i++ ){
+	        p = constructors[i];
+	        if( p->nargs() == 0 ) return true ;
+	    }
+	    return false ;
+    }
+	
 	SEXP invoke( SEXP method_xp, SEXP object, SEXP *args, int nargs ){ 
 		BEGIN_RCPP
 		
@@ -433,7 +444,7 @@
 #include <Rcpp/module/Module_generated_method.h>
 #include <Rcpp/module/Module_generated_Pointer_method.h>
 	
-	bool has_method( const std::string& m){
+    bool has_method( const std::string& m){
 		return vec_methods.find(m) != vec_methods.end() ;
 	}
 	bool has_property( const std::string& m){

Modified: pkg/Rcpp/inst/include/Rcpp/routines.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/routines.h	2010-11-20 18:48:05 UTC (rev 2477)
+++ pkg/Rcpp/inst/include/Rcpp/routines.h	2010-11-21 17:25:07 UTC (rev 2478)
@@ -41,6 +41,7 @@
 CALLFUN_3(CppField__get);
 CALLFUN_4(CppField__set);
 CALLFUN_1(Class__name);
+CALLFUN_1(Class__has_default_constructor) ;
 CALLFUN_1(CppClass__complete);
 CALLFUN_1(CppClass__methods);
 

Modified: pkg/Rcpp/src/Module.cpp
===================================================================
--- pkg/Rcpp/src/Module.cpp	2010-11-20 18:48:05 UTC (rev 2477)
+++ pkg/Rcpp/src/Module.cpp	2010-11-21 17:25:07 UTC (rev 2478)
@@ -29,6 +29,10 @@
 typedef Rcpp::XPtr<Rcpp::class_Base> XP_Class ; 
 typedef Rcpp::XPtr<Rcpp::CppFunction> XP_Function ; 
 
+RCPP_FUNCTION_1( bool, Class__has_default_constructor, XP_Class cl ){
+    return cl->has_default_constructor() ;
+}
+
 RCPP_FUNCTION_2( bool, Class__has_method, XP_Class cl, std::string m){
 	return cl->has_method(m) ;
 }
@@ -357,6 +361,7 @@
 	
 }
 
+
 #else
 /* quiet ranlib */ 
 void dummy(){}

Modified: pkg/Rcpp/src/Rcpp_init.c
===================================================================
--- pkg/Rcpp/src/Rcpp_init.c	2010-11-20 18:48:05 UTC (rev 2477)
+++ pkg/Rcpp/src/Rcpp_init.c	2010-11-21 17:25:07 UTC (rev 2478)
@@ -39,6 +39,7 @@
     CALLDEF(CppField__set,4),
     
     CALLDEF(Class__name,1),
+    CALLDEF(Class__has_default_constructor,1),
     
     CALLDEF(CppClass__complete,1),
     CALLDEF(CppClass__methods,1),



More information about the Rcpp-commits mailing list