Skip to content

Commit eae141b

Browse files
committed
updated header file generator script
1 parent 9af138e commit eae141b

File tree

2 files changed

+95
-88
lines changed

2 files changed

+95
-88
lines changed

scripts/generator_Module_method.R

100644100755
Lines changed: 95 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,82 @@
1+
#!/usr/bin/Rscript
2+
#
3+
# Generator for inst/include/Rcpp/module/Module_generated_method.h
4+
#
5+
# Copyright (C) 2010 - 2014 Dirk Eddelbuettel and Romain Francois
16

27

3-
fun <- function( i ){
8+
fun <- function(i) {
49

5-
index <- (1:i)-1
6-
collapse <- function(x) paste( x, collapse = ", " )
10+
index <- (1:i)-1
11+
collapse <- function(x) paste(x, collapse = ", ")
712

8-
typenames <- collapse( sprintf( "typename U%d", index ) )
9-
u <- collapse( sprintf( "U%d u%d", index, index ) )
10-
as <- collapse( sprintf( "Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U%d >::type >( args[%d] )", index, index ) )
11-
U <- collapse( sprintf( "U%d", index ) )
13+
typenames <- collapse(sprintf("typename U%d", index))
14+
u <- collapse(sprintf("U%d u%d", index, index))
15+
as <- collapse(sprintf("Rcpp::as< typename Rcpp::traits::remove_const_and_reference<U%d>::type>(args[%d])",
16+
index, index))
17+
U <- collapse(sprintf("U%d", index))
1218

13-
txt <- sprintf( '
19+
txt <- sprintf('
1420
15-
template <typename RESULT_TYPE, %s>
16-
self& method( const char* name_, RESULT_TYPE (Class::*fun)(%s), const char* docstring = 0, ValidMethod valid = &yes_arity<%d> ){
17-
AddMethod( name_, new CppMethod%d<Class,RESULT_TYPE,%s>( fun ), valid, docstring) ;
18-
return *this ;
19-
}
20-
21-
template <typename RESULT_TYPE, %s>
22-
self& method( const char* name_, RESULT_TYPE (Class::*fun)(%s) const, const char* docstring = 0, ValidMethod valid = &yes_arity<%d> ){
23-
AddMethod( name_, new const_CppMethod%d<Class,RESULT_TYPE,%s>( fun ), valid, docstring ) ;
24-
return *this ;
25-
}
26-
27-
template <typename RESULT_TYPE, %s>
28-
self& nonconst_method( const char* name_, RESULT_TYPE (Class::*fun)(%s), const char* docstring = 0, ValidMethod valid = &yes_arity<%d> ){
29-
AddMethod( name_, new CppMethod%d<Class,RESULT_TYPE,%s>( fun ), valid, docstring ) ;
30-
return *this ;
31-
}
32-
33-
template <typename RESULT_TYPE, %s>
34-
self& const_method( const char* name_, RESULT_TYPE (Class::*fun)(%s) const, const char* docstring = 0, ValidMethod valid = &yes_arity<%d>){
35-
AddMethod( name_, new const_CppMethod%d<Class,RESULT_TYPE,%s>( fun ), valid, docstring ) ;
36-
return *this ;
37-
}
38-
39-
',
40-
typenames, # typename U0, ...
41-
u, # U0 u0, ...
42-
i,
43-
i,
44-
U, # U0, ...
45-
46-
typenames, # typename U0, ...
47-
u, # U0 u0, ...
48-
i,
49-
i,
50-
U, # U0, ...
51-
52-
typenames, # typename U0, ...
53-
u, # U0 u0, ...
54-
i,
55-
i,
56-
U, # U0, ...
57-
58-
typenames, # typename U0, ...
59-
u, # U0 u0, ...
60-
i,
61-
i,
62-
U # U0, ...
21+
template <typename RESULT_TYPE, %s>
22+
self& method(const char* name_, RESULT_TYPE (Class::*fun)(%s),
23+
const char* docstring = 0, ValidMethod valid = &yes_arity<%d>) {
24+
AddMethod( name_, new CppMethod%d<Class,RESULT_TYPE,%s>(fun), valid, docstring);
25+
return *this;
26+
}
27+
28+
template <typename RESULT_TYPE, %s>
29+
self& method(const char* name_, RESULT_TYPE (Class::*fun)(%s) const,
30+
const char* docstring = 0, ValidMethod valid = &yes_arity<%d>) {
31+
AddMethod(name_, new const_CppMethod%d<Class,RESULT_TYPE,%s>(fun), valid, docstring);
32+
return *this ;
33+
}
6334
35+
template <typename RESULT_TYPE, %s>
36+
self& nonconst_method(const char* name_, RESULT_TYPE (Class::*fun)(%s),
37+
const char* docstring = 0, ValidMethod valid = &yes_arity<%d>) {
38+
AddMethod(name_, new CppMethod%d<Class,RESULT_TYPE,%s>( fun ), valid, docstring);
39+
return *this;
40+
}
41+
42+
template <typename RESULT_TYPE, %s>
43+
self& const_method(const char* name_, RESULT_TYPE (Class::*fun)(%s) const,
44+
const char* docstring = 0, ValidMethod valid = &yes_arity<%d>) {
45+
AddMethod(name_, new const_CppMethod%d<Class,RESULT_TYPE,%s>( fun ), valid, docstring);
46+
return *this;
47+
}',
48+
typenames, # typename U0, ...
49+
u, # U0 u0, ...
50+
i,
51+
i,
52+
U, # U0, ...
53+
54+
typenames, # typename U0, ...
55+
u, # U0 u0, ...
56+
i,
57+
i,
58+
U, # U0, ...
59+
60+
typenames, # typename U0, ...
61+
u, # U0 u0, ...
62+
i,
63+
i,
64+
U, # U0, ...
65+
66+
typenames, # typename U0, ...
67+
u, # U0 u0, ...
68+
i,
69+
i,
70+
U # U0, ...
6471
)
6572

6673
}
6774

6875
file <- sprintf(
69-
'// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
76+
'// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
7077
//
71-
// Module_generated_method.h: Rcpp R/C++ interface class library -- Rcpp modules
78+
// Module_generated_method.h: -- generated helper code for Modules
79+
// see rcpp-scripts repo for generator script
7280
//
7381
// Copyright (C) 2010 - 2014 Dirk Eddelbuettel and Romain Francois
7482
//
@@ -90,38 +98,42 @@ file <- sprintf(
9098
#ifndef Rcpp_Module_generated_method_h
9199
#define Rcpp_Module_generated_method_h
92100
93-
template <typename RESULT_TYPE>
94-
self& method( const char* name_, RESULT_TYPE (Class::*fun)(void), const char* docstring = 0, ValidMethod valid = &yes ){
95-
AddMethod( name_, new CppMethod0<Class,RESULT_TYPE>( fun ), valid, docstring) ;
96-
return *this ;
97-
}
98-
99-
template <typename RESULT_TYPE>
100-
self& method( const char* name_, RESULT_TYPE (Class::*fun)(void) const, const char* docstring = 0, ValidMethod valid = &yes ){
101-
AddMethod( name_, new const_CppMethod0<Class,RESULT_TYPE>( fun ), valid, docstring ) ;
102-
return *this ;
103-
}
101+
template <typename RESULT_TYPE>
102+
self& method(const char* name_, RESULT_TYPE (Class::*fun)(void),
103+
const char* docstring = 0, ValidMethod valid = &yes) {
104+
AddMethod(name_, new CppMethod0<Class,RESULT_TYPE>(fun), valid, docstring);
105+
return *this;
106+
}
107+
108+
template <typename RESULT_TYPE>
109+
self& method(const char* name_, RESULT_TYPE (Class::*fun)(void) const,
110+
const char* docstring = 0, ValidMethod valid = &yes) {
111+
AddMethod( name_, new const_CppMethod0<Class,RESULT_TYPE>(fun), valid, docstring);
112+
return *this;
113+
}
114+
115+
template <typename RESULT_TYPE>
116+
self& nonconst_method(const char* name_, RESULT_TYPE (Class::*fun)(void),
117+
const char* docstring = 0, ValidMethod valid = &yes ){
118+
AddMethod( name_, new CppMethod0<Class,RESULT_TYPE>( fun ) , valid, docstring ) ;
119+
return *this ;
120+
}
121+
122+
template <typename RESULT_TYPE>
123+
self& const_method(const char* name_, RESULT_TYPE (Class::*fun)(void) const,
124+
const char* docstring = 0, ValidMethod valid = &yes ){
125+
AddMethod( name_, new const_CppMethod0<Class,RESULT_TYPE>( fun ), valid, docstring ) ;
126+
return *this ;
127+
}
104128
105-
106-
template <typename RESULT_TYPE>
107-
self& nonconst_method( const char* name_, RESULT_TYPE (Class::*fun)(void), const char* docstring = 0, ValidMethod valid = &yes ){
108-
AddMethod( name_, new CppMethod0<Class,RESULT_TYPE>( fun ) , valid, docstring ) ;
109-
return *this ;
110-
}
111-
template <typename RESULT_TYPE>
112-
self& const_method( const char* name_, RESULT_TYPE (Class::*fun)(void) const, const char* docstring = 0, ValidMethod valid = &yes ){
113-
AddMethod( name_, new const_CppMethod0<Class,RESULT_TYPE>( fun ), valid, docstring ) ;
114-
return *this ;
115-
}
116-
117-
118129
%s
119130
120131
#endif
121132
', paste( sapply( 1:65, fun), collapse = "\n" )
122133
)
123134

124-
writeLines( file, "Rcpp/inst/include/Rcpp/module/Module_generated_method.h" )
135+
stopifnot(file.exists("inst/include/Rcpp/module/"))
136+
writeLines( file, "inst/include/Rcpp/module/Module_generated_method.h" )
125137

126138

127139

scripts/generator_Module_signature.R

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,3 @@ inline void signature(std::string& s, const char* name) {
8989

9090
stopifnot(file.exists("inst/include/Rcpp/module/"))
9191
writeLines(file, "inst/include/Rcpp/module/Module_generated_get_signature.h")
92-
93-
94-
95-
96-

0 commit comments

Comments
 (0)