[Rcpp-commits] r3895 - in pkg/Rcpp: inst/include/Rcpp inst/include/Rcpp/module src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Nov 5 13:32:18 CET 2012


Author: romain
Date: 2012-11-05 13:32:18 +0100 (Mon, 05 Nov 2012)
New Revision: 3895

Modified:
   pkg/Rcpp/inst/include/Rcpp/Module.h
   pkg/Rcpp/inst/include/Rcpp/module/Module.h
   pkg/Rcpp/src/Module.cpp
Log:
trying something

Modified: pkg/Rcpp/inst/include/Rcpp/Module.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Module.h	2012-11-04 19:57:04 UTC (rev 3894)
+++ pkg/Rcpp/inst/include/Rcpp/Module.h	2012-11-05 12:32:18 UTC (rev 3895)
@@ -422,6 +422,17 @@
         CppObject( Module* p, class_Base*, SEXP xp ) ;
     } ;
 
+    class FunctionProxy{
+    public:
+        FunctionProxy( DL_FUNC p_fun_ ): p_fun(p_fun_){}
+        
+        template <typename T> operator T() const { return (T)p_fun ; }
+        
+    private:
+        DL_FUNC p_fun ;
+    } ;
+    
+    FunctionProxy GetCppCallable( const std::string& mod, const std::string& fun) ;
 }
 
 #define RCPP_MODULE_BOOT(name) _rcpp_module_boot_##name

Modified: pkg/Rcpp/inst/include/Rcpp/module/Module.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/module/Module.h	2012-11-04 19:57:04 UTC (rev 3894)
+++ pkg/Rcpp/inst/include/Rcpp/module/Module.h	2012-11-05 12:32:18 UTC (rev 3895)
@@ -90,6 +90,7 @@
         DL_FUNC get_function_ptr( const std::string& ) ;
         
         inline void Add( const char* name_ , CppFunction* ptr){
+            R_RegisterCCallable( prefix.c_str(), name_, ptr->get_function_ptr() ) ;
             functions.insert( FUNCTION_PAIR( name_ , ptr ) ) ;
         }
                 
@@ -115,6 +116,7 @@
     private:
         MAP functions ;
         CLASS_MAP classes ;
+        std::string prefix ;
                            
     };
 

Modified: pkg/Rcpp/src/Module.cpp
===================================================================
--- pkg/Rcpp/src/Module.cpp	2012-11-04 19:57:04 UTC (rev 3894)
+++ pkg/Rcpp/src/Module.cpp	2012-11-05 12:32:18 UTC (rev 3895)
@@ -269,8 +269,10 @@
 
 namespace Rcpp{
 	
-	Module::Module() : name(), functions(), classes() {}
-	Module::Module(const char* name_) : name(name_), functions(), classes() {}
+	Module::Module() : name(), functions(), classes(), prefix() {}
+	Module::Module(const char* name_) : name(name_), functions(), classes(), prefix("Rcpp_module_") {
+	    prefix += name ;
+	}
 	
 	SEXP Module::invoke( const std::string& name_, SEXP* args, int nargs){
 		BEGIN_RCPP
@@ -461,5 +463,12 @@
 	        return R_ExternalPtrAddr(xp );
 	    }
 	}
+	
+	FunctionProxy GetCppCallable( const std::string& mod, const std::string& fun){
+        std::string pack( "Rcpp_module_" ) ;
+        pack += mod ;
+        return R_GetCCallable( pack.c_str(), fun.c_str() ) ;     
+    }
+	
 }
 



More information about the Rcpp-commits mailing list