[Rcpp-commits] r3292 - scripts

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Nov 6 18:09:09 CET 2011


Author: romain
Date: 2011-11-06 18:09:09 +0100 (Sun, 06 Nov 2011)
New Revision: 3292

Modified:
   scripts/generator_Module_PointerCppMethod.R
   scripts/generator_Module_Pointer_method.R
Log:
more code in generators to deal with const free methods

Modified: scripts/generator_Module_PointerCppMethod.R
===================================================================
--- scripts/generator_Module_PointerCppMethod.R	2011-11-06 16:42:48 UTC (rev 3291)
+++ scripts/generator_Module_PointerCppMethod.R	2011-11-06 17:09:09 UTC (rev 3292)
@@ -49,7 +49,47 @@
 		Method met ;
 	} ;
 
+	
+	// const
+	
+	template < typename Class, typename OUT, %s > class Const_Pointer_CppMethod%d : public CppMethod<Class> {
+	public:
+		typedef OUT (*Method)(const Class*, %s) ;
+		typedef CppMethod<Class> method_class ;
+		
+		Const_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 true ; }
+		inline void signature(std::string& s, const char* name){ Rcpp::signature<OUT,%s>(s, name) ; }
+		
+	private:
+		Method met ;
+	} ;
+	
+	template < typename Class, %s > class Const_Pointer_CppMethod%d<Class,void,%s> : public CppMethod<Class> {
+	public:
+		typedef void (*Method)(const Class*, %s) ;
+		typedef CppMethod<Class> method_class ;
+		
+		Const_Pointer_CppMethod%d( Method m) : method_class(), met(m){} 
+		SEXP operator()( Class* object, SEXP* args){
+			met( object, %s ) ;
+			return R_NilValue ;
+		}
+		inline int nargs(){ return %d ; }
+		inline bool is_void(){ return true ; }
+		inline bool is_const(){ return true ; }
+		inline void signature(std::string& s, const char* name){ Rcpp::signature<void_type,%s>(s, name) ; }
+		
+	private:
+		Method met ;
+	} ;
 
+
 ', 
 typenames,  # typename U0, ...
 i,           
@@ -66,8 +106,28 @@
 i, 
 as, 
 i,
+U, 
+
+
+# const 
+typenames,  # typename U0, ...
+i,           
+u,          # U0 u0, ...
+i, 
+as,         # Rcpp::as<U0>( args[0] ) , ...
+i,
+U, 
+
+typenames,  # typename U0, ...
+i, 
+U, 			# U0, ...
+u,          # U0 u0, ...
+i, 
+as, 
+i,
 U
 
+
 )   
 
 }
@@ -133,14 +193,54 @@
 	private:
 		Method met ;
 	} ;
-
+	
+	
+	
+	
+	template <typename Class, typename OUT> class Const_Pointer_CppMethod0 : public CppMethod<Class> {
+	public:
+		typedef OUT (*Method)(const Class*) ;
+		typedef CppMethod<Class> method_class ;
+		Const_Pointer_CppMethod0( Method m) : method_class(), met(m){} 
+		SEXP operator()( Class* object, SEXP* ){
+			return Rcpp::wrap( met(object) ) ;
+		}
+		inline int nargs(){ return 0 ; }
+		inline bool is_void(){ return false ; }
+		inline bool is_const(){ return true ; }
+		inline void signature(std::string& s, const char* name){ Rcpp::signature<OUT>(s, name) ; }
+		
+	private:
+		Method met ;
+	} ;
+	
+	template <typename Class> class Const_Pointer_CppMethod0<Class,void> : public CppMethod<Class> {
+	public:
+		typedef void (*Method)(const Class*) ;
+		typedef CppMethod<Class> method_class ;
+		Const_Pointer_CppMethod0( Method m) : method_class(), met(m){} 
+		SEXP operator()( Class* object, SEXP* ){
+			met( object ) ;
+			return R_NilValue ;
+		}
+		inline int nargs(){ return 0 ; }
+		inline bool is_void(){ return true ; }
+		inline bool is_const(){ return true ; }
+    
+		inline void signature(std::string& s, const char* name){ Rcpp::signature<void_type>(s, name) ; }
+		
+	private:
+		Method met ;
+	} ;
+	
+	
 %s
 
 #endif
 ', paste( sapply( 1:65 , fun), collapse = "\n" ) 
 )
 
-writeLines( file, "Rcpp/inst/include/Rcpp/module/Module_generated_Pointer_CppMethod.h" )
+writeLines( file, "../pkg/Rcpp/inst/include/Rcpp/module/Module_generated_Pointer_CppMethod.h" )
 
 
 

Modified: scripts/generator_Module_Pointer_method.R
===================================================================
--- scripts/generator_Module_Pointer_method.R	2011-11-06 16:42:48 UTC (rev 3291)
+++ scripts/generator_Module_Pointer_method.R	2011-11-06 17:09:09 UTC (rev 3292)
@@ -18,12 +18,25 @@
   		return *this ;
 	}
 	
-
+	template <typename OUT, %s>
+	self& const_method( const char* name_, OUT (*fun)(const Class*, %s), const char* docstring = 0, ValidMethod valid = &yes_arity<%d> ){
+		AddMethod( name_, new Const_Pointer_CppMethod%d<Class,OUT,%s>( fun ), valid, docstring ) ;
+  		return *this ;
+	}
+	
+	
+	
 ',
 typenames,   # typename U0, ...
 u,           # U0 u0, ...
 i,
 i,
+U,           # U0, ...
+
+typenames,   # typename U0, ...
+u,           # U0 u0, ...
+i,
+i,
 U            # U0, ...
 
 )   
@@ -61,14 +74,19 @@
   		return *this ;
 	}
 	
-
+	template <typename OUT>
+	self& const_method( const char* name_, OUT (*fun)(const Class*), const char* docstring = 0, ValidMethod valid = &yes ){
+		AddMethod( name_, new Const_Pointer_CppMethod0<Class,OUT>( fun ), valid, docstring ) ;
+  		return *this ;
+	}
+	
 %s
 
 #endif
 ', paste( sapply( 1:65, fun), collapse = "\n" ) 
 )
 
-writeLines( file, "Rcpp/inst/include/Rcpp/module/Module_generated_Pointer_method.h" )
+writeLines( file, "../pkg/Rcpp/inst/include/Rcpp/module/Module_generated_Pointer_method.h" )
 
 
 



More information about the Rcpp-commits mailing list