|
75 | 75 | template <typename OUT, typename... Args> |
76 | 76 | class CppFunction_Impl : public CppFunction { |
77 | 77 | public: |
78 | | - CppFunction_Impl(OUT (*fun)(Args...), const char* docstring = 0 ) : |
| 78 | + typedef OUT (*Fun)(Args...) ; |
| 79 | + |
| 80 | + CppFunction_Impl(Fun fun, const char* docstring = 0 ) : |
79 | 81 | CppFunction(docstring), ptr_fun(fun){} |
80 | 82 |
|
81 | | - SEXP operator()(SEXP* args) { |
82 | | - return function_invoke<OUT,Args...>( typename traits::number_to_type<sizeof...(Args)>(), ptr_fun, args ) ; |
| 83 | + inline SEXP operator()(SEXP* args) { |
| 84 | + return FunctionInvoker<OUT,Args...>( ptr_fun, args ).invoke() ; |
83 | 85 | } |
84 | 86 |
|
85 | 87 | inline int nargs(){ return sizeof...(Args); } |
86 | 88 | inline void signature(std::string& s, const char* name){ Rcpp::signature<OUT, Args...>(s, name) ; } |
87 | 89 | inline DL_FUNC get_function_ptr(){ return (DL_FUNC)ptr_fun ; } |
88 | 90 |
|
89 | 91 | private: |
90 | | - OUT (*ptr_fun)(Args...) ; |
| 92 | + Fun ptr_fun ; |
91 | 93 | } ; |
92 | 94 |
|
93 | | - template <typename... Args> |
94 | | - class CppFunction_Impl<void,Args...> : public CppFunction { |
95 | | - public: |
96 | | - CppFunction_Impl(void (*fun)(Args...), const char* docstring = 0 ) : |
97 | | - CppFunction(docstring), ptr_fun(fun){} |
98 | | - |
99 | | - SEXP operator()(SEXP* args) { |
100 | | - void_function_invoke( typename traits::number_to_type<sizeof...(Args)>(), ptr_fun, args ) ; |
101 | | - return R_NilValue ; |
102 | | - } |
103 | | - |
104 | | - inline int nargs(){ return sizeof...(Args); } |
105 | | - inline void signature(std::string& s, const char* name){ Rcpp::signature<void, Args...>(s, name) ; } |
106 | | - inline DL_FUNC get_function_ptr(){ return (DL_FUNC)ptr_fun ; } |
107 | | - inline bool is_void(){ return true; } |
108 | | - |
109 | | - private: |
110 | | - void (*ptr_fun)(Args...) ; |
111 | | - } ; |
112 | | - |
113 | 95 | template <typename OUT, typename... Args> |
114 | 96 | class CppFunction_WithFormals_Impl : public CppFunction { |
115 | 97 | public: |
116 | | - CppFunction_WithFormals_Impl(OUT (*fun)(Args...), Rcpp::List formals_, const char* docstring = 0 ) : CppFunction(docstring), formals(formals_), ptr_fun(fun){} |
117 | | - SEXP operator()(SEXP* args) { |
118 | | - return function_invoke<OUT, Args...>( typename traits::number_to_type<sizeof...(Args)>(), ptr_fun, args) ; |
119 | | - } |
120 | | - |
121 | | - inline int nargs(){ return sizeof...(Args) ; } |
122 | | - inline void signature(std::string& s, const char* name){ Rcpp::signature<OUT,Args...>(s, name) ; } |
123 | | - inline DL_FUNC get_function_ptr(){ return (DL_FUNC)ptr_fun ; } |
124 | | - inline SEXP get_formals(){ return formals; } |
| 98 | + typedef OUT (*Fun)(Args...) ; |
125 | 99 |
|
126 | | - private: |
127 | | - Rcpp::List formals ; |
128 | | - OUT (*ptr_fun)(void) ; |
129 | | - } ; |
130 | | - |
131 | | - template <typename... Args> |
132 | | - class CppFunction_WithFormals_Impl<void,Args...> : public CppFunction { |
133 | | - public: |
134 | | - CppFunction_WithFormals_Impl(void (*fun)(Args...), Rcpp::List formals_, const char* docstring = 0 ) : CppFunction(docstring), formals(formals_), ptr_fun(fun){} |
135 | | - SEXP operator()(SEXP* args) { |
136 | | - void_function_invoke( typename traits::number_to_type<sizeof...(Args)>(), ptr_fun, args) ; |
137 | | - return R_NilValue ; |
| 100 | + CppFunction_WithFormals_Impl(Fun fun, Rcpp::List formals_, const char* docstring = 0 ) : |
| 101 | + CppFunction(docstring), formals(formals_), ptr_fun(fun){} |
| 102 | + |
| 103 | + inline SEXP operator()(SEXP* args) { |
| 104 | + return FunctionInvoker<OUT,Args...>( ptr_fun, args ).invoke() ; |
138 | 105 | } |
139 | 106 |
|
140 | 107 | inline int nargs(){ return sizeof...(Args) ; } |
141 | | - inline void signature(std::string& s, const char* name){ Rcpp::signature<void,Args...>(s, name) ; } |
| 108 | + inline void signature(std::string& s, const char* name){ Rcpp::signature<OUT,Args...>(s, name) ; } |
142 | 109 | inline DL_FUNC get_function_ptr(){ return (DL_FUNC)ptr_fun ; } |
143 | 110 | inline SEXP get_formals(){ return formals; } |
144 | | - inline bool is_void(){ return true; } |
145 | 111 |
|
146 | 112 | private: |
147 | 113 | Rcpp::List formals ; |
148 | | - void (*ptr_fun)(Args...) ; |
| 114 | + Fun ptr_fun ; |
149 | 115 | } ; |
150 | | - |
151 | | - |
152 | 116 |
|
153 | 117 | #endif |
0 commit comments