|
1 |
| -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*- |
2 |
| -// |
3 |
| -// InternalFunction_with_std_function.h: Rcpp R/C++ interface class library -- exposing C++ std::function's |
4 |
| -// |
5 |
| -// Copyright (C) 2014 Christian Authmann |
6 |
| -// Copyright (C) 2015 Romain Francois |
7 |
| -// |
8 |
| -// This file is part of Rcpp. |
9 |
| -// |
10 |
| -// Rcpp is free software: you can redistribute it and/or modify it |
11 |
| -// under the terms of the GNU General Public License as published by |
12 |
| -// the Free Software Foundation, either version 2 of the License, or |
13 |
| -// (at your option) any later version. |
14 |
| -// |
15 |
| -// Rcpp is distributed in the hope that it will be useful, but |
16 |
| -// WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
| -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
| -// GNU General Public License for more details. |
19 |
| -// |
20 |
| -// You should have received a copy of the GNU General Public License |
21 |
| -// along with Rcpp. If not, see <http://www.gnu.org/licenses/>. |
22 |
| - |
23 |
| -#ifndef Rcpp_InternalFunctionWithStdFunction_h |
24 |
| -#define Rcpp_InternalFunctionWithStdFunction_h |
25 |
| - |
26 |
| -#include <functional> |
27 |
| - |
28 |
| -namespace Rcpp{ |
29 |
| - |
30 |
| - namespace InternalFunctionWithStdFunction { |
31 |
| - |
32 |
| - #include <Rcpp/generated/InternalFunctionWithStdFunction_call.h> |
33 |
| - |
34 |
| - template <typename RESULT_TYPE, typename... Args> |
35 |
| - class CppFunctionBaseFromStdFunction : public CppFunctionBase { |
36 |
| - public: |
37 |
| - CppFunctionBaseFromStdFunction(const std::function<RESULT_TYPE(Args...)> &fun) : fun(fun) {} |
38 |
| - virtual ~CppFunctionBaseFromStdFunction() {} |
39 |
| - |
40 |
| - SEXP operator()(SEXP* args) { |
41 |
| - auto result = call<RESULT_TYPE, Args...>(fun, args); |
42 |
| - return Rcpp::module_wrap<RESULT_TYPE>(result); |
43 |
| - } |
44 |
| - |
45 |
| - private: |
46 |
| - const std::function<RESULT_TYPE(Args...)> fun; |
47 |
| - }; |
48 |
| - |
49 |
| - template <typename... Args> |
50 |
| - class CppFunctionBaseFromStdFunction<void, Args...> : public CppFunctionBase { |
51 |
| - public: |
52 |
| - CppFunctionBaseFromStdFunction(const std::function<void(Args...)> &fun) : fun(fun) {} |
53 |
| - virtual ~CppFunctionBaseFromStdFunction() {} |
54 |
| - |
55 |
| - SEXP operator()(SEXP* args) { |
56 |
| - call<void, Args...>(fun, args); |
57 |
| - return R_NilValue; |
58 |
| - } |
59 |
| - |
60 |
| - private: |
61 |
| - const std::function<void(Args...)> fun; |
62 |
| - }; |
63 |
| - |
64 |
| - } // namespace InternalFunctionWithStdFunction |
65 |
| -} // namespace Rcpp |
66 |
| - |
67 |
| -#endif |
| 1 | +// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- |
| 2 | +// |
| 3 | +// InternalFunction_with_std_function.h: Rcpp R/C++ interface class library -- exposing C++ std::function's |
| 4 | +// |
| 5 | +// Copyright (C) 2014 Christian Authmann |
| 6 | +// Copyright (C) 2015 Romain Francois and Dirk Eddelbuettel |
| 7 | +// |
| 8 | +// This file is part of Rcpp. |
| 9 | +// |
| 10 | +// Rcpp is free software: you can redistribute it and/or modify it |
| 11 | +// under the terms of the GNU General Public License as published by |
| 12 | +// the Free Software Foundation, either version 2 of the License, or |
| 13 | +// (at your option) any later version. |
| 14 | +// |
| 15 | +// Rcpp is distributed in the hope that it will be useful, but |
| 16 | +// WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | +// GNU General Public License for more details. |
| 19 | +// |
| 20 | +// You should have received a copy of the GNU General Public License |
| 21 | +// along with Rcpp. If not, see <http://www.gnu.org/licenses/>. |
| 22 | + |
| 23 | +#ifndef Rcpp_InternalFunctionWithStdFunction_h |
| 24 | +#define Rcpp_InternalFunctionWithStdFunction_h |
| 25 | + |
| 26 | +#include <functional> |
| 27 | + |
| 28 | +namespace Rcpp { |
| 29 | + |
| 30 | + namespace InternalFunctionWithStdFunction { |
| 31 | + |
| 32 | + #include <Rcpp/generated/InternalFunctionWithStdFunction_call.h> |
| 33 | + |
| 34 | + template <typename RESULT_TYPE, typename... Args> |
| 35 | + class CppFunctionBaseFromStdFunction : public CppFunctionBase { |
| 36 | + public: |
| 37 | + CppFunctionBaseFromStdFunction(const std::function<RESULT_TYPE(Args...)> &fun) : fun(fun) {} |
| 38 | + virtual ~CppFunctionBaseFromStdFunction() {} |
| 39 | + |
| 40 | + SEXP operator()(SEXP* args) { |
| 41 | + auto result = call<RESULT_TYPE, Args...>(fun, args); |
| 42 | + return Rcpp::module_wrap<RESULT_TYPE>(result); |
| 43 | + } |
| 44 | + |
| 45 | + private: |
| 46 | + const std::function<RESULT_TYPE(Args...)> fun; |
| 47 | + }; |
| 48 | + |
| 49 | + template <typename... Args> |
| 50 | + class CppFunctionBaseFromStdFunction<void, Args...> : public CppFunctionBase { |
| 51 | + public: |
| 52 | + CppFunctionBaseFromStdFunction(const std::function<void(Args...)> &fun) : fun(fun) {} |
| 53 | + virtual ~CppFunctionBaseFromStdFunction() {} |
| 54 | + |
| 55 | + SEXP operator()(SEXP* args) { |
| 56 | + call<void, Args...>(fun, args); |
| 57 | + return R_NilValue; |
| 58 | + } |
| 59 | + |
| 60 | + private: |
| 61 | + const std::function<void(Args...)> fun; |
| 62 | + }; |
| 63 | + |
| 64 | + } // namespace InternalFunctionWithStdFunction |
| 65 | +} // namespace Rcpp |
| 66 | + |
| 67 | +#endif |
0 commit comments