[Rcpp-commits] r2487 - scripts
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Nov 22 13:03:57 CET 2010
Author: romain
Date: 2010-11-22 13:03:56 +0100 (Mon, 22 Nov 2010)
New Revision: 2487
Added:
scripts/generator_Module_signature.R
Modified:
scripts/generator_Module_CppMethod.R
scripts/generator_Module_PointerCppMethod.R
Log:
grab method signatures
Modified: scripts/generator_Module_CppMethod.R
===================================================================
--- scripts/generator_Module_CppMethod.R 2010-11-21 22:56:02 UTC (rev 2486)
+++ scripts/generator_Module_CppMethod.R 2010-11-22 12:03:56 UTC (rev 2487)
@@ -17,12 +17,13 @@
typedef OUT (Class::*Method)(%s) ;
typedef CppMethod<Class> method_class ;
- CppMethod%d(Method m) : method_class(), met(m){}
+ CppMethod%d(Method m) : method_class(), met(m) {}
SEXP operator()( Class* object, SEXP* args){
return Rcpp::wrap( (object->*met)( %s ) ) ;
}
inline int nargs(){ return %d ; }
inline bool is_void(){ return false ; }
+ const char* signature(const char* name ){ return Rcpp::signature<OUT,%s>(name) ; }
private:
Method met ;
} ;
@@ -39,6 +40,7 @@
}
inline int nargs(){ return %d ; }
inline bool is_void(){ return true ; }
+ const char* signature(const char* name ){ return Rcpp::signature<void_type,%s>(name) ; }
private:
Method met ;
} ;
@@ -56,6 +58,8 @@
}
inline int nargs(){ return %d ; }
inline bool is_void(){ return false ; }
+ const char* signature(const char* name ){ return Rcpp::signature<OUT,%s>(name) ; }
+
private:
Method met ;
} ;
@@ -65,13 +69,15 @@
typedef void (Class::*Method)(%s) const ;
typedef CppMethod<Class> method_class ;
- const_CppMethod%d( Method m) : method_class(), met(m){}
+ const_CppMethod%d( Method m) : method_class(), met(m) {}
SEXP operator()( Class* object, SEXP* args){
(object->*met)( %s ) ;
return R_NilValue ;
}
inline int nargs(){ return %d ; }
inline bool is_void(){ return true ; }
+ const char* signature(const char* name ){ return Rcpp::signature<void_type,%s>(name) ; }
+
private:
Method met ;
} ;
@@ -83,14 +89,16 @@
i,
as, # Rcpp::as<U0>( args[0] ) , ...
i,
+U,
typenames, # typename U0, ...
i,
U, # U0, ...
u, # U0 u0, ...
-i,
+i,
as,
i,
+U,
typenames, # typename U0, ...
@@ -99,14 +107,16 @@
i,
as, # Rcpp::as<U0>( args[0] ) , ...
i,
+U,
typenames, # typename U0, ...
i,
-U, # U0, ...
+U, # U0, ...
u, # U0 u0, ...
i,
as,
-i
+i,
+U
)
@@ -148,6 +158,8 @@
}
inline int nargs(){ return 0 ; }
inline bool is_void(){ return false ; }
+ const char* signature(const char* name){ return Rcpp::signature<OUT>(name) ; }
+
private:
Method met ;
} ;
@@ -163,6 +175,8 @@
}
inline int nargs(){ return 0 ; }
inline bool is_void(){ return true ; }
+ const char* signature(const char* name){ return Rcpp::signature<void_type>(name) ; }
+
private:
Method met ;
} ;
@@ -177,6 +191,8 @@
}
inline int nargs(){ return 0 ; }
inline bool is_void(){ return false ; }
+ const char* signature(const char* name){ return Rcpp::signature<OUT>(name) ; }
+
private:
Method met ;
} ;
@@ -185,13 +201,15 @@
public:
typedef void (Class::*Method)(void) const ;
typedef CppMethod<Class> method_class ;
- const_CppMethod0( Method m) : method_class(), met(m){}
+ const_CppMethod0( Method m) : method_class(), met(m) {}
SEXP operator()( Class* object, SEXP* ){
(object->*met)( ) ;
return R_NilValue ;
}
inline int nargs(){ return 0 ; }
inline bool is_void(){ return true ; }
+ const char* signature(const char* name){ return Rcpp::signature<void_type>(name) ; }
+
private:
Method met ;
} ;
Modified: scripts/generator_Module_PointerCppMethod.R
===================================================================
--- scripts/generator_Module_PointerCppMethod.R 2010-11-21 22:56:02 UTC (rev 2486)
+++ scripts/generator_Module_PointerCppMethod.R 2010-11-22 12:03:56 UTC (rev 2487)
@@ -23,6 +23,8 @@
}
inline int nargs(){ return %d ; }
inline bool is_void(){ return false ; }
+ const char* signature(const char* name){ return Rcpp::signature<OUT,%s>(name) ; }
+
private:
Method met ;
} ;
@@ -39,6 +41,8 @@
}
inline int nargs(){ return %d ; }
inline bool is_void(){ return true ; }
+ const char* signature(const char* name){ return Rcpp::signature<void_type,%s>(name) ; }
+
private:
Method met ;
} ;
@@ -50,7 +54,8 @@
u, # U0 u0, ...
i,
as, # Rcpp::as<U0>( args[0] ) , ...
-i,
+i,
+U,
typenames, # typename U0, ...
i,
@@ -58,7 +63,8 @@
u, # U0 u0, ...
i,
as,
-i
+i,
+U
)
@@ -100,6 +106,8 @@
}
inline int nargs(){ return 0 ; }
inline bool is_void(){ return false ; }
+ const char* signature(const char* name){ return Rcpp::signature<OUT>(name) ; }
+
private:
Method met ;
} ;
@@ -115,6 +123,8 @@
}
inline int nargs(){ return 0 ; }
inline bool is_void(){ return true ; }
+ const char* signature(const char* name){ return Rcpp::signature<void_type>(name) ; }
+
private:
Method met ;
} ;
Added: scripts/generator_Module_signature.R
===================================================================
--- scripts/generator_Module_signature.R (rev 0)
+++ scripts/generator_Module_signature.R 2010-11-22 12:03:56 UTC (rev 2487)
@@ -0,0 +1,130 @@
+
+
+fun <- function( i ){
+
+ index <- 0:i
+ collapse <- function(x) paste( x, collapse = ", " )
+
+ typenames <- collapse( sprintf( "typename U%d", index ) )
+ demangles <- paste(
+ sprintf( ' s += ", " ; s+= get_return_type<U%d>();', 1:i),
+ collapse = "\n" )
+
+txt <- sprintf( '
+
+template <typename OUT,%s>
+inline const char* signature(const char* name){
+ std::string s ;
+ s += get_return_type<OUT>() ;
+ s += " " ;
+ s += name ;
+ s += "(" ;
+ s += get_return_type<U0>() ;
+%s
+ s += ")" ;
+ return s.c_str() ;
+}
+
+
+',
+typenames, # typename U0, ...
+demangles
+)
+txt
+}
+
+file <- sprintf(
+'// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
+//
+// Module_generated_get_signature.h: Rcpp R/C++ interface class library --
+//
+// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef Rcpp_Module_generated_get_signature_h
+#define Rcpp_Module_generated_get_signature_h
+
+struct void_type{} ;
+
+template <typename OUT>
+inline std::string get_return_type(){
+ return demangle( typeid(OUT).name() ).data() ;
+}
+template <>
+inline std::string get_return_type<void_type>(){
+ return "void" ;
+}
+template <>
+inline std::string get_return_type<Rcpp::IntegerVector>(){
+ return "Rcpp::IntegerVector" ;
+}
+template <>
+inline std::string get_return_type<Rcpp::NumericVector>(){
+ return "Rcpp::NumericVector" ;
+}
+template <>
+inline std::string get_return_type<Rcpp::RawVector>(){
+ return "Rcpp::RawVector" ;
+}
+template <>
+inline std::string get_return_type<Rcpp::ExpressionVector>(){
+ return "Rcpp::ExpressionVector" ;
+}
+template <>
+inline std::string get_return_type<Rcpp::List>(){
+ return "Rcpp::List" ;
+}
+template <>
+inline std::string get_return_type<Rcpp::CharacterVector>(){
+ return "Rcpp::CharacterVector" ;
+}
+
+
+template <typename OUT>
+inline const char* signature(const std::string& name){
+ std::string s ;
+ s += get_return_type<OUT>() ;
+ s += " " ;
+ s += name ;
+ s += "()" ;
+ return s.c_str() ;
+}
+
+
+template <typename OUT,typename U0>
+inline const char* signature(const std::string& name){
+ std::string s ;
+ s += get_return_type<OUT>() ;
+ s += " " ;
+ s += name ;
+ s += "(" ;
+ s += get_return_type<U0>() ;
+ s += ")" ;
+ return s.c_str() ;
+}
+
+%s
+
+#endif', paste( sapply( 1:65, fun), collapse = "\n" )
+)
+
+writeLines( file, "Rcpp/inst/include/Rcpp/module/Module_generated_get_signature.h" )
+
+
+
+
+
More information about the Rcpp-commits
mailing list