25#include <Rcpp/internal/call.h>
31 template <
typename FROM,
typename TO>
33 std::string method_name(
".___converter___" ) ;
36 method_name +=
"Rcpp_" ;
39 method_name +=
"___" ;
42 method_name +=
"Rcpp_" ;
59 operator T*(){
return ptr ; }
69 operator T*(){
return ptr ; }
76 template <
typename Class>
79 Function maker = Environment::Rcpp_namespace()[
"cpp_object_maker"] ;
80 return maker(
typeid(Class).name() , xp ) ;
90 template <
typename RESULT_TYPE,
typename... T>
91 inline void signature(std::string& s,
const char* name) {
97 (void)std::initializer_list<int>{
102 template <
typename RESULT_TYPE,
typename... T>
113 inline int nargs() {
return sizeof...(T); }
114 inline bool is_void() {
return std::is_void<RESULT_TYPE>::value; }
122 template <
typename RESULT_TYPE,
typename... T>
140 template <
typename Class>
146 virtual SEXP
operator()(Class* , SEXP* ) {
return R_NilValue ; }
151 virtual void signature(std::string& s,
const char* name ){ s = name ; }
154 template <
typename Class,
typename Parent>
176 template <
typename... T>
180 int n =
sizeof...(T);
183 (void)std::initializer_list<int>{
187 template <
typename Class>
195 template <
typename Class,
typename... T>
201 virtual int nargs(){
return sizeof...(T) ; }
202 virtual void signature(std::string& s,
const std::string& class_name ){
209 return new Class(
as<T>(args[Is])... ) ;
213 template <
typename Class>
221 template <
typename Class,
typename... T>
228 virtual int nargs(){
return sizeof...(T) ; }
237 Class* (*ptr_fun)(T...) ;
240 inline bool yes( SEXP* ,
int ){
252 template <
typename Class>
267 inline void signature(std::string& buffer,
const std::string& class_name){
268 ctor->signature(buffer, class_name) ;
272 template <
typename Class>
287 inline void signature(std::string& buffer,
const std::string& class_name){
288 fact->signature(buffer, class_name) ;
293 template <
typename Class>
306 inline void signature(std::string& s,
const char* name){
312 template <
typename Class>
320 RCPP_DEBUG(
"S4_CppConstructor( SignedConstructor<Class>* m, SEXP class_xp, const std::string& class_name, std::string& buffer" ) ;
322 field(
"class_pointer" ) = class_xp ;
325 field(
"signature" ) = buffer ;
333 template <
typename Class>
342 int n =
static_cast<int>(m->size()) ;
347 for(
int i=0; i<n; i++){
349 nargs[i] = met->
nargs() ;
354 signatures[i] = buffer ;
358 field(
"class_pointer" ) = class_xp ;
359 field(
"size" ) = n ;
360 field(
"void" ) = voidness ;
361 field(
"const" ) = constness ;
362 field(
"docstrings" ) = docstrings ;
363 field(
"signatures" ) = signatures ;
364 field(
"nargs" ) = nargs ;
373 template <
bool IsConst,
typename Class,
typename RESULT_TYPE,
typename... T>
376 typedef typename std::conditional<IsConst, RESULT_TYPE (Class::*)(T...)
const,
377 RESULT_TYPE (Class::*)(T...)>::type
Method;
389 inline int nargs() {
return sizeof...(T); }
390 inline bool is_void() {
return std::is_void<RESULT_TYPE>::value; }
397 template <
typename Class,
typename RESULT_TYPE,
typename... T>
400 template <
typename Class,
typename RESULT_TYPE,
typename... T>
403 template <
bool IsConst,
typename Class,
typename RESULT_TYPE,
typename... T>
406 typedef typename std::conditional<IsConst, RESULT_TYPE (*)(
const Class*, T...),
407 RESULT_TYPE (*)(Class*, T...)>::type
Method;
415 return met(
object, cpp_args...);
419 inline int nargs() {
return sizeof...(T); }
420 inline bool is_void() {
return std::is_void<RESULT_TYPE>::value; }
427 template <
typename Class,
typename RESULT_TYPE,
typename... T>
430 template <
typename Class,
typename RESULT_TYPE,
typename... T>
435 template <
typename Class>
442 virtual SEXP
get(Class* ) {
throw std::range_error(
"cannot retrieve property"); }
443 virtual void set(Class*, SEXP) {
throw std::range_error(
"cannot set property"); }
450 template <
typename Class,
typename Parent>
469 template <
typename Class>
473 virtual void run(Class* ){} ;
476 template <
typename Class>
482 virtual void run(Class*
object){
490 template <
typename Class>
496 RCPP_DEBUG(
"S4_field( CppProperty<Class>* p, const XP_Class& class_xp )" )
497 field(
"read_only" ) = p->is_readonly() ;
498 field(
"cpp_class" ) = p->get_class();
500 field(
"class_pointer" ) = class_xp ;
508#include <Rcpp/module/Module_Property.h>
512 template <
typename Enum,
typename Parent>
518 name(name_), values(), parent_typeinfo_name( typeid(Parent).
name() ){
522 module->add_enum( parent_typeinfo_name, name, values ) ;
526 values.insert(
PAIR( name_,
static_cast<int>( value_ ) ) ) ;
533 typedef std::map< std::string, int >
MAP ;
543 template <
typename RESULT_TYPE,
typename... T>
544 void function(
const char* name_, RESULT_TYPE (*fun)(T... t),
const char* docstring = 0) {
551 template <
typename RESULT_TYPE,
typename... T>
552 void function(
const char* name_, RESULT_TYPE (*fun)(T... t),
Rcpp::List formals,
const char* docstring = 0) {
563 template <
typename FROM,
typename TO>
564 void converter(
const char* from,
const char* to, TO (*fun)(FROM),
const char* docstring = 0 ){
566 function( fun_name.c_str(), fun, docstring ) ;
577 XP_Class clxp( cl,
false, R_NilValue, R_NilValue ) ;
578 slot(
"module" ) =
XP( p,
false ) ;
579 slot(
"pointer" ) = clxp ;
583 slot(
".Data" ) = buffer ;
585 slot(
"fields" ) = cl->
fields( clxp ) ;
587 slot(
"methods" ) = cl->
getMethods( clxp, buffer ) ;
591 slot(
"enums" ) = cl->
enums ;
592 slot(
"parents" ) = cl->
parents ;
604 slot(
"module" ) =
XP( p,
false ) ;
606 slot(
"pointer" ) = xp ;
613#define RCPP_MODULE_BOOT(name) _rcpp_module_boot_##name
615#define RCPP_MODULE(name) \
616 void _rcpp_module_##name##_init() ; \
617 static Rcpp::Module _rcpp_module_##name( # name ) ; \
618 extern "C" SEXP _rcpp_module_boot_##name(){ \
619 ::setCurrentScope( & _rcpp_module_##name ) ; \
620 _rcpp_module_##name##_init( ) ; \
621 Rcpp::XPtr<Rcpp::Module> mod_xp(& _rcpp_module_##name , false); \
622 ::setCurrentScope( 0 ) ; \
625 void _rcpp_module_##name##_init()
629#define VARIABLE_IS_NOT_USED __attribute__ ((unused))
631#define VARIABLE_IS_NOT_USED
639#define GET_MODULE_SYM ( moduleSym == NULL ? moduleSym = Rf_install("Module") : moduleSym )
642#define LOAD_RCPP_MODULE(NAME) \
643 Shield<SEXP> __load_module_call__( Rf_lang2( GET_MODULE_SYM, _rcpp_module_boot_##NAME() ) ); \
644 Rcpp_fast_eval( __load_module_call__, R_GlobalEnv );
#define VARIABLE_IS_NOT_USED
static VARIABLE_IS_NOT_USED SEXP moduleSym
self & field(const char *name_, T Class::*ptr, const char *docstring=0)
virtual Class * get_new(SEXP *args, int nargs)=0
virtual void signature(std::string &s, const std::string &class_name)=0
Class * get_new_impl(SEXP *args, int nargs, traits::index_sequence< Is... >)
virtual void signature(std::string &s, const std::string &class_name)
virtual Class * get_new(SEXP *args, int nargs)
Rcpp::XPtr< Rcpp::Module > XP
CppClass(Module *p, class_Base *cl, std::string &buffer)
XPtr< class_Base > XP_Class
virtual void run(Class *)
CppFunctionN(RESULT_TYPE(*fun)(T...), const char *docstring=0)
SEXP operator()(SEXP *args)
RESULT_TYPE(* ptr_fun)(T...)
DL_FUNC get_function_ptr()
void signature(std::string &s, const char *name)
CppFunction(const char *doc=0)
CppInheritedMethod(ParentMethod *parent_method_pointer_)
ParentMethod * parent_method_pointer
SEXP operator()(Class *object, SEXP *args)
CppMethod< Parent > ParentMethod
void signature(std::string &s, const char *name)
CppProperty< Class > Base
void set(Class *obj, SEXP s)
CppInheritedProperty(CppProperty< Parent > *parent_property_)
CppProperty< Parent > * parent_property
SEXP operator()(Class *object, SEXP *args)
std::conditional< IsConst, RESULT_TYPE(Class::*)(T...) const, RESULT_TYPE(Class::*)(T...)>::type Method
CppMethod< Class > method_class
Rcpp::traits::remove_const_and_reference< RESULT_TYPE >::type CLEANED_RESULT_TYPE
void signature(std::string &s, const char *name)
virtual void signature(std::string &s, const char *name)
virtual SEXP operator()(Class *, SEXP *)
CppObject(Module *p, class_Base *clazz, SEXP xp)
Rcpp::XPtr< Rcpp::Module > XP
CppProperty(const char *doc=0)
virtual SEXP get(Class *)
virtual bool is_readonly()
virtual std::string get_class()
virtual void set(Class *, SEXP)
virtual Class * get_new(SEXP *args, int nargs)=0
virtual void signature(std::string &s, const std::string &class_name)=0
virtual Class * get_new(SEXP *args, int nargs)
Class * get_new(SEXP *args, traits::index_sequence< I... >)
Factory(Class *(*fun)(T...))
virtual void signature(std::string &s, const std::string &class_name)
FunctionFinalizer(Pointer p)
virtual void run(Class *object)
void Add(const char *name_, CppFunction *ptr)
Pointer_CppMethodImplN(Method m)
CppMethod< Class > method_class
Rcpp::traits::remove_const_and_reference< RESULT_TYPE >::type CLEANED_RESULT_TYPE
void signature(std::string &s, const char *name)
std::conditional< IsConst, RESULT_TYPE(*)(constClass *, T...), RESULT_TYPE(*)(Class *, T...)>::type Method
SEXP operator()(Class *object, SEXP *args)
Reference::Storage Storage
XPtr< class_Base > XP_Class
S4_CppConstructor(SignedConstructor< Class > *m, const XP_Class &class_xp, const std::string &class_name, std::string &buffer)
S4_CppOverloadedMethods(vec_signed_method *m, const XP_Class &class_xp, const char *name, std::string &buffer)
std::vector< signed_method_class * > vec_signed_method
SignedMethod< Class > signed_method_class
Rcpp::XPtr< class_Base > XP_Class
XPtr< class_Base > XP_Class
S4_field(CppProperty< Class > *p, const XP_Class &class_xp)
void signature(std::string &buffer, const std::string &class_name)
Constructor_Base< Class > * ctor
SignedConstructor(Constructor_Base< Class > *ctor_, ValidConstructor valid_, const char *doc)
void signature(std::string &buffer, const std::string &class_name)
SignedFactory(Factory_Base< Class > *fact_, ValidConstructor valid_, const char *doc)
Factory_Base< Class > * fact
void signature(std::string &s, const char *name)
SignedMethod(METHOD *m, ValidMethod valid_, const char *doc)
CppMethod< Class > METHOD
virtual std::string get_typeinfo_name()
virtual Rcpp::List getConstructors(const XP_Class &, std::string &)
virtual Rcpp::List fields(const XP_Class &)
virtual Rcpp::List getMethods(const XP_Class &, std::string &)
std::vector< std::string > parents
self & field(const char *name_, T Class::*ptr, const char *docstring=0)
SignedMethod< Class > signed_method_class
self & method(const char *name_, RESULT_TYPE(Class::*fun)(T...), const char *docstring=0, ValidMethod valid=&yes_arity< sizeof...(T)>)
self & value(const char *name_, Enum value_)
std::map< std::string, int > MAP
std::string parent_typeinfo_name
enum_< Enum, Parent > self
#define RCPP_CTOR_ASSIGN_WITH_BASE(__CLASS__)
internal implementation details
SEXP make_new_object(Class *ptr)
std::string get_converter_name(const char *from, const char *to)
Pointer_CppMethodImplN< false, Class, RESULT_TYPE, T... > Pointer_CppMethodN
Function_Impl< PreserveStorage > Function
bool(* ValidConstructor)(SEXP *, int)
traits::remove_const_and_reference< T >::type bare_as(SEXP x)
void converter(const char *from, const char *to, TO(*fun)(FROM), const char *docstring=0)
bool(* ValidMethod)(SEXP *, int)
CppMethodImplN< false, Class, RESULT_TYPE, T... > CppMethodN
std::string get_return_type()
bool yes_arity(SEXP *, int nargs)
Vector< STRSXP > CharacterVector
Pointer_CppMethodImplN< true, Class, RESULT_TYPE, T... > Const_Pointer_CppMethodN
Vector< LGLSXP > LogicalVector
CppMethodImplN< true, Class, RESULT_TYPE, T... > const_CppMethodN
Vector< INTSXP > IntegerVector
Reference_Impl< PreserveStorage > Reference
void ctor_signature(std::string &s, const std::string &classname)
void function(const char *name_, RESULT_TYPE(*fun)(T... t), const char *docstring=0)
void signature(std::string &s, const char *name)
S4_Impl< PreserveStorage > S4
attribute_hidden Rcpp::Module * getCurrentScope()
remove_const< typenameremove_reference< T >::type >::type type