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 - 2013 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 namespace Rcpp {
26 
27 	/**
28 	 * base class for a callable function. This limited functionality is
29 	 * just barely enough for an InternalFunction, nothing more.
30 	 */
31 	class CppFunctionBase {
32 	public:
CppFunctionBase()33 		CppFunctionBase() {}
~CppFunctionBase()34         virtual ~CppFunctionBase(){} ;
35 
36         /**
37          * modules call the function with this interface. input: an array of SEXP
38          * output: a SEXP.
39          */
operator()40         virtual SEXP operator()(SEXP*) {
41             return R_NilValue ;
42         }
43 
44 	};
45 
46     /**
47      * base class of all exported C++ functions. Template deduction in the
48      * Module_generated_function.h file creates an instance of a class that
49      * derives CppFunction (see Module_generated_CppFunction.h for all the
50      * definitions
51      */
52     class CppFunction : public CppFunctionBase {
53     public:
54         CppFunction(const char* doc = 0) : docstring( doc == 0 ? "" : doc) {}
~CppFunction()55         virtual ~CppFunction(){} ;
56 
57         /**
58          * The number of arguments of the function
59          */
nargs()60         virtual int nargs(){ return 0 ; }
61 
62         /**
63          * voidness
64          */
is_void()65         virtual bool is_void(){ return false ; }
66 
67         /**
68          * Human readable function signature (demangled if possible)
69          */
signature(std::string &,const char *)70         virtual void signature(std::string&, const char* ){}
71 
72         /**
73          * formal arguments
74          */
get_formals()75         virtual SEXP get_formals(){ return R_NilValue; }
76 
77         /**
78          * The actual function pointer, as a catch all function pointer
79          * (see Rdynload.h for definition of DL_FUNC)
80          */
81         virtual DL_FUNC get_function_ptr() = 0  ;
82 
83         /**
84          * description of the function
85          */
86         std::string docstring ;
87     };
88 
89 }
90 #endif
91