[Rcpp-commits] r3813 - scripts

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Oct 23 15:43:52 CEST 2012


Author: romain
Date: 2012-10-23 15:43:52 +0200 (Tue, 23 Oct 2012)
New Revision: 3813

Modified:
   scripts/generator_Module_CppMethod.R
   scripts/generator_Module_PointerCppMethod.R
Log:
generators for allowing methods for class Foo that returns a Foo*

Modified: scripts/generator_Module_CppMethod.R
===================================================================
--- scripts/generator_Module_CppMethod.R	2012-10-23 11:57:42 UTC (rev 3812)
+++ scripts/generator_Module_CppMethod.R	2012-10-23 13:43:52 UTC (rev 3813)
@@ -19,7 +19,7 @@
 		
 		CppMethod%d(Method m) : method_class(), met(m) {} 
 		SEXP operator()( Class* object, SEXP* args){
-			return Rcpp::wrap( (object->*met)( %s ) ) ;
+			return Rcpp::module_wrap<Class,OUT>( (object->*met)( %s ) ) ;
 		}
 		inline int nargs(){ return %d ; }
 		inline bool is_void(){ return false ; }
@@ -80,7 +80,7 @@
 		
 		const_CppMethod%d(Method m) : method_class(), met(m){} 
 		SEXP operator()( Class* object, SEXP* args){
-			return Rcpp::wrap( (object->*met)( %s ) ) ;
+			return Rcpp::module_wrap<Class,OUT>( (object->*met)( %s ) ) ;
 		}
 		inline int nargs(){ return %d ; }
 		inline bool is_void(){ return false ; }
@@ -193,7 +193,7 @@
 //
 // Module_generated_CppMethod.h: Rcpp R/C++ interface class library -- Rcpp modules
 //
-// Copyright (C) 2010	Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010-2012  Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -219,7 +219,7 @@
 		typedef CppMethod<Class> method_class ;
 		CppMethod0( Method m) : method_class(), met(m){} 
 		SEXP operator()( Class* object, SEXP*){
-			return Rcpp::wrap( (object->*met)( ) ) ;
+			return Rcpp::module_wrap<Class,OUT>( (object->*met)( ) ) ;
 		}
 		inline int nargs(){ return 0 ; }
 		inline bool is_void(){ return false ; }
@@ -276,7 +276,7 @@
 		typedef CppMethod<Class> method_class ;
 		const_CppMethod0( Method m) : method_class(), met(m){} 
 		SEXP operator()( Class* object, SEXP* ){
-			return Rcpp::wrap( (object->*met)( ) ) ;
+			return Rcpp::module_wrap<Class,OUT>( (object->*met)( ) ) ;
 		}
 		inline int nargs(){ return 0 ; }
 		inline bool is_void(){ return false ; }

Modified: scripts/generator_Module_PointerCppMethod.R
===================================================================
--- scripts/generator_Module_PointerCppMethod.R	2012-10-23 11:57:42 UTC (rev 3812)
+++ scripts/generator_Module_PointerCppMethod.R	2012-10-23 13:43:52 UTC (rev 3813)
@@ -30,6 +30,25 @@
 		Method met ;
 	} ;
 	
+	template < typename Class, typename T, %s > 
+	class Pointer_CppMethod%d<Class, result<T>, %s> : public CppMethod<Class> {
+	public:
+		typedef result<T> (*Method)(Class*, %s) ;
+		typedef CppMethod<Class> method_class ;
+		
+		Pointer_CppMethod%d(Method m) : method_class(), met(m){} 
+		SEXP operator()( Class* object, SEXP* args){
+			return Rcpp::wrap( met( object, %s ) ) ;
+		}
+		inline int nargs(){ return %d ; }
+		inline bool is_void(){ return false ; }
+		inline bool is_const(){ return false ; }
+		inline void signature(std::string& s, const char* name){ Rcpp::signature<result<T>,%s>(s, name) ; }
+		
+	private:
+		Method met ;
+	} ;
+
 	template < typename Class, %s > class Pointer_CppMethod%d<Class,void,%s> : public CppMethod<Class> {
 	public:
 		typedef void (*Method)(Class*, %s) ;
@@ -100,7 +119,16 @@
 U, 
 
 typenames,  # typename U0, ...
+i,           
+U,
+u,          # U0 u0, ...
 i, 
+as,         # Rcpp::as<U0>( args[0] ) , ...
+i,
+U, 
+
+typenames,  # typename U0, ...
+i, 
 U, 			# U0, ...
 u,          # U0 u0, ...
 i, 
@@ -175,6 +203,25 @@
 		Method met ;
 	} ;
 	
+	template <typename Class, typename T> 
+	class Pointer_CppMethod0< Class,result<T> > : public CppMethod<Class> {
+	public:
+		typedef result<T> (*Method)(Class*) ;
+		typedef CppMethod<Class> method_class ;
+		Pointer_CppMethod0( Method m) : method_class(), met(m){} 
+		SEXP operator()( Class* object, SEXP* ){
+		    T* ptr = met(object) ;
+			return internal::make_new_object<T>(ptr) ; 
+		}
+		inline int nargs(){ return 0 ; }
+		inline bool is_void(){ return false ; }
+		inline bool is_const(){ return false ; }
+		inline void signature(std::string& s, const char* name){ Rcpp::signature< result<T> >(s, name) ; }
+		
+	private:
+		Method met ;
+	} ;
+
 	template <typename Class> class Pointer_CppMethod0<Class,void> : public CppMethod<Class> {
 	public:
 		typedef void (*Method)(Class*) ;



More information about the Rcpp-commits mailing list