Skip to content

Commit a4028bf

Browse files
CppFunction gains get_function_ptr (implemented in all its child classes)
1 parent 3d0bd90 commit a4028bf

File tree

4 files changed

+612
-279
lines changed

4 files changed

+612
-279
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2012-11-02 Romain Francois <[email protected]>
2+
3+
* include/Rcpp/module/CppFunction.h : factored CppFunction in its own file
4+
and added the get_function_ptr virtual method. added documentation
5+
* include/Rcpp/module/Module_generated_CppFunction.h: implementation
6+
of get_function_ptr in classes that derive CppFunction
7+
18
2012-11-01 Dirk Eddelbuettel <[email protected]>
29

310
* inst/unitTests/runit.rmath.R: New unit test file added

inst/include/Rcpp/Module.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,7 @@ namespace Rcpp{
8181
}
8282
}
8383

84-
class CppFunction {
85-
public:
86-
CppFunction(const char* doc = 0) : docstring( doc == 0 ? "" : doc) {}
87-
virtual SEXP operator()(SEXP*) {
88-
return R_NilValue ;
89-
}
90-
virtual ~CppFunction(){} ;
91-
virtual int nargs(){ return 0 ; }
92-
virtual bool is_void(){ return false ; }
93-
virtual void signature(std::string&, const char* ){}
94-
virtual SEXP get_formals(){ return R_NilValue; }
95-
96-
std::string docstring ;
97-
};
98-
84+
#include <Rcpp/module/CppFunction.h>
9985
#include <Rcpp/module/Module_generated_get_return_type.h>
10086
#include <Rcpp/module/Module_generated_get_signature.h>
10187

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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

Comments
 (0)