|
| 1 | +// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- |
| 2 | +// |
| 3 | +// CppFunction.h: Rcpp R/C++ interface class library -- C++ exposed function |
| 4 | +// |
| 5 | +// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois |
| 6 | +// |
| 7 | +// This file is part of Rcpp. |
| 8 | +// |
| 9 | +// Rcpp is free software: you can redistribute it and/or modify it |
| 10 | +// under the terms of the GNU General Public License as published by |
| 11 | +// the Free Software Foundation, either version 2 of the License, or |
| 12 | +// (at your option) any later version. |
| 13 | +// |
| 14 | +// Rcpp is distributed in the hope that it will be useful, but |
| 15 | +// WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | +// GNU General Public License for more details. |
| 18 | +// |
| 19 | +// You should have received a copy of the GNU General Public License |
| 20 | +// along with Rcpp. If not, see <http://www.gnu.org/licenses/>. |
| 21 | + |
| 22 | +#ifndef Rcpp_Module_CppFunction_h |
| 23 | +#define Rcpp_Module_CppFunction_h |
| 24 | + |
| 25 | + /** |
| 26 | + * base class of all exported C++ functions. Template deduction in the |
| 27 | + * Module_generated_function.h file creates an instance of a class that |
| 28 | + * derives CppFunction (see Module_generated_CppFunction.h fr all the |
| 29 | + * definitions |
| 30 | + */ |
| 31 | + class CppFunction { |
| 32 | + public: |
| 33 | + CppFunction(const char* doc = 0) : docstring( doc == 0 ? "" : doc) {} |
| 34 | + |
| 35 | + /** |
| 36 | + * modules call the function with this interface. input: an array of SEXP |
| 37 | + * output: a SEXP. |
| 38 | + */ |
| 39 | + virtual SEXP operator()(SEXP*) { |
| 40 | + return R_NilValue ; |
| 41 | + } |
| 42 | + virtual ~CppFunction(){} ; |
| 43 | + |
| 44 | + /** |
| 45 | + * The number of arguments of the function |
| 46 | + */ |
| 47 | + virtual int nargs(){ return 0 ; } |
| 48 | + |
| 49 | + /** |
| 50 | + * voidness |
| 51 | + */ |
| 52 | + virtual bool is_void(){ return false ; } |
| 53 | + |
| 54 | + /** |
| 55 | + * Human readable function signature (demangled if possible) |
| 56 | + */ |
| 57 | + virtual void signature(std::string&, const char* ){} |
| 58 | + |
| 59 | + /** |
| 60 | + * formal arguments |
| 61 | + */ |
| 62 | + virtual SEXP get_formals(){ return R_NilValue; } |
| 63 | + |
| 64 | + /** |
| 65 | + * The actual function pointer, as a catch all function pointer |
| 66 | + * (see Rdynload.h for definition of DL_FUNC) |
| 67 | + */ |
| 68 | + virtual DL_FUNC get_function_ptr() ; |
| 69 | + |
| 70 | + /** |
| 71 | + * description of the function |
| 72 | + */ |
| 73 | + std::string docstring ; |
| 74 | + }; |
| 75 | + |
| 76 | +#endif |
0 commit comments