diff options
Diffstat (limited to 'share/swig/2.0.11/r')
24 files changed, 2840 insertions, 0 deletions
diff --git a/share/swig/2.0.11/r/boost_shared_ptr.i b/share/swig/2.0.11/r/boost_shared_ptr.i new file mode 100644 index 0000000..17e9cfe --- /dev/null +++ b/share/swig/2.0.11/r/boost_shared_ptr.i @@ -0,0 +1,307 @@ +%include <shared_ptr.i> + +// Language specific macro implementing all the customisations for handling the smart pointer +%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...) + +// %naturalvar is as documented for member variables +%naturalvar TYPE; +%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >; + +// destructor wrapper customisation +%feature("unref") TYPE +//"if (debug_shared) { cout << \"deleting use_count: \" << (*smartarg1).use_count() << \" [\" << (boost::get_deleter<SWIG_null_deleter>(*smartarg1) ? std::string(\"CANNOT BE DETERMINED SAFELY\") : ( (*smartarg1).get() ? (*smartarg1)->getValue() : std::string(\"NULL PTR\") )) << \"]\" << endl << flush; }\n" + "(void)arg1; delete smartarg1;" + +// Typemap customisations... + +// plain value +%typemap(in) CONST TYPE (void *argp, int res = 0) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (!argp) { + %argument_nullref("$type", $symname, $argnum); + } else { + $1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get()); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + } +} +%typemap(out) CONST TYPE { + %set_output(SWIG_NewPointerObj(new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) CONST TYPE { + void *argp = 0; + int newmem = 0; + int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %variable_fail(res, "$type", "$name"); + } + if (!argp) { + %argument_nullref("$type", $symname, $argnum); + } else { + $1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get()); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + } +} +%typemap(varout) CONST TYPE { + %set_varoutput(SWIG_NewPointerObj(new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +// plain pointer +// Note: $disown not implemented as it will lead to a memory leak of the shared_ptr instance +%typemap(in) CONST TYPE * (void *argp = 0, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (newmem & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast(tempshared.get(), $1_ltype); + } else { + smartarg = %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype); + } +} +%typemap(out, fragment="SWIG_null_deleter") CONST TYPE * { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), $owner | SWIG_POINTER_OWN)); +} + +%typemap(varin) CONST TYPE * { + void *argp = 0; + int newmem = 0; + int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %variable_fail(res, "$type", "$name"); + } + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared; + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0; + if (newmem & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast(tempshared.get(), $1_ltype); + } else { + smartarg = %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype); + } +} +%typemap(varout, fragment="SWIG_null_deleter") CONST TYPE * { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0; + %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +// plain reference +%typemap(in) CONST TYPE & (void *argp = 0, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (!argp) { %argument_nullref("$type", $symname, $argnum); } + if (newmem & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast(tempshared.get(), $1_ltype); + } else { + $1 = %const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype); + } +} +%typemap(out, fragment="SWIG_null_deleter") CONST TYPE & { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) CONST TYPE & { + void *argp = 0; + int newmem = 0; + int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %variable_fail(res, "$type", "$name"); + } + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared; + if (!argp) { %argument_nullref("$type", $symname, $argnum); } + if (newmem & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = *%const_cast(tempshared.get(), $1_ltype); + } else { + $1 = *%const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype); + } +} +%typemap(varout, fragment="SWIG_null_deleter") CONST TYPE & { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(&$1 SWIG_NO_NULL_DELETER_0); + %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +// plain pointer by reference +// Note: $disown not implemented as it will lead to a memory leak of the shared_ptr instance +%typemap(in) TYPE *CONST& (void *argp = 0, int res = 0, $*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (newmem & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + temp = %const_cast(tempshared.get(), $*1_ltype); + } else { + temp = %const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $*1_ltype); + } + $1 = &temp; +} +%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST& { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) TYPE *CONST& %{ +#error "varin typemap not implemented" +%} +%typemap(varout) TYPE *CONST& %{ +#error "varout typemap not implemented" +%} + +// shared_ptr by value +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (void *argp, int res = 0) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (argp) $1 = *(%reinterpret_cast(argp, $<ype)); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $<ype); +} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { + int newmem = 0; + void *argp = 0; + int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %variable_fail(res, "$type", "$name"); + } + $1 = argp ? *(%reinterpret_cast(argp, $<ype)) : SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE >(); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $<ype); +} +%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; + %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +// shared_ptr by reference +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & (void *argp, int res = 0, $*1_ltype tempshared) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (newmem & SWIG_CAST_NEW_MEMORY) { + if (argp) tempshared = *%reinterpret_cast(argp, $ltype); + delete %reinterpret_cast(argp, $ltype); + $1 = &tempshared; + } else { + $1 = (argp) ? %reinterpret_cast(argp, $ltype) : &tempshared; + } +} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{ +#error "varin typemap not implemented" +%} +%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{ +#error "varout typemap not implemented" +%} + +// shared_ptr by pointer +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * (void *argp, int res = 0, $*1_ltype tempshared) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (newmem & SWIG_CAST_NEW_MEMORY) { + if (argp) tempshared = *%reinterpret_cast(argp, $ltype); + delete %reinterpret_cast(argp, $ltype); + $1 = &tempshared; + } else { + $1 = (argp) ? %reinterpret_cast(argp, $ltype) : &tempshared; + } +} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 && *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); + if ($owner) delete $1; +} + +%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{ +#error "varin typemap not implemented" +%} +%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{ +#error "varout typemap not implemented" +%} + +// shared_ptr by pointer reference +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& (void *argp, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, $*1_ltype temp = 0) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (argp) tempshared = *%reinterpret_cast(argp, $*ltype); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $*ltype); + temp = &tempshared; + $1 = &temp; +} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 && **$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(**$1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{ +#error "varin typemap not implemented" +%} +%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{ +#error "varout typemap not implemented" +%} + +// Typecheck typemaps +// Note: SWIG_ConvertPtr with void ** parameter set to 0 instead of using SWIG_ConvertPtrAndOwn, so that the casting +// function is not called thereby avoiding a possible smart pointer copy constructor call when casting up the inheritance chain. +%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) + TYPE CONST, + TYPE CONST &, + TYPE CONST *, + TYPE *CONST&, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& { + int res = SWIG_ConvertPtr($input, 0, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), 0); + $1 = SWIG_CheckState(res); +} + + +// various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug +%typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ +#error "typemaps for $1_type not available" +%} +%typemap(out) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ +#error "typemaps for $1_type not available" +%} + + +%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >; +%enddef + diff --git a/share/swig/2.0.11/r/cdata.i b/share/swig/2.0.11/r/cdata.i new file mode 100644 index 0000000..3679659 --- /dev/null +++ b/share/swig/2.0.11/r/cdata.i @@ -0,0 +1 @@ +%include <typemaps/cdata.swg> diff --git a/share/swig/2.0.11/r/exception.i b/share/swig/2.0.11/r/exception.i new file mode 100644 index 0000000..39cb095 --- /dev/null +++ b/share/swig/2.0.11/r/exception.i @@ -0,0 +1,8 @@ +%include <typemaps/exception.swg> + + +%insert("runtime") { + %define_as(SWIG_exception(code, msg), +%block(switch (code) {case SWIG_IndexError: return Rf_ScalarLogical(NA_LOGICAL); default: %error(code, msg); SWIG_fail;} )) +} + diff --git a/share/swig/2.0.11/r/r.swg b/share/swig/2.0.11/r/r.swg new file mode 100644 index 0000000..126611d --- /dev/null +++ b/share/swig/2.0.11/r/r.swg @@ -0,0 +1,272 @@ +/* */ + + +%insert("header") "swiglabels.swg" + +%insert("header") "swigerrors.swg" +%insert("init") "swiginit.swg" +%insert("runtime") "swigrun.swg" +%insert("runtime") "rrun.swg" + +%init %{ +SWIGEXPORT void SWIG_init(void) { +%} + +%include <rkw.swg> + +#define %Rruntime %insert("s") + +#define SWIG_Object SEXP +#define VOID_Object R_NilValue + +#define %append_output(obj) SET_VECTOR_ELT($result, $n, obj) + +%define %set_constant(name, obj) %begin_block + SEXP _obj = obj; + assign(name, _obj); +%end_block %enddef + +%define %raise(obj,type,desc) +return R_NilValue; +%enddef + +%insert("sinit") "srun.swg" + +%insert("sinitroutine") %{ +SWIG_init(); +SWIG_InitializeModule(0); +%} + +%include <typemaps/swigmacros.swg> +%typemap(in) (double *x, int len) %{ + $1 = REAL(x); + $2 = Rf_length(x); +%} + +/* XXX + Need to worry about inheritance, e.g. if B extends A + and we are looking for an A[], then B elements are okay. +*/ +%typemap(scheck) SWIGTYPE[ANY] + %{ +# assert(length($input) > $1_dim0) + assert(all(sapply($input, class) == "$R_class")); + %} + +%typemap(out) void ""; + +%typemap(in) int *, int[ANY], + signed int *, signed int[ANY], + unsigned int *, unsigned int[ANY], + short *, short[ANY], + signed short *, signed short[ANY], + unsigned short *, unsigned short[ANY], + long *, long[ANY], + signed long *, signed long[ANY], + unsigned long *, unsigned long[ANY], + long long *, long long[ANY], + signed long long *, signed long long[ANY], + unsigned long long *, unsigned long long[ANY] + +{ +{ int _rswigi; + int _rswiglen = LENGTH($input); + $1 = %static_cast(calloc(sizeof($1_basetype), _rswiglen), $1_ltype); + for (_rswigi=0; _rswigi< _rswiglen; _rswigi++) { + $1[_rswigi] = INTEGER($input)[_rswigi]; + } +} +} + +%typemap(in) float *, float[ANY], + double *, double[ANY] + +{ +{ int _rswigi; + int _rswiglen = LENGTH($input); + $1 = %static_cast(calloc(sizeof($1_basetype), _rswiglen), $1_ltype); + for (_rswigi=0; _rswigi<_rswiglen; _rswigi++) { + $1[_rswigi] = REAL($input)[_rswigi]; + } +} +} + +%typemap(freearg,noblock=1) int *, int[ANY], + signed int *, signed int[ANY], + unsigned int *, unsigned int[ANY], + short *, short[ANY], + signed short *, signed short[ANY], + unsigned short *, unsigned short[ANY], + long *, long[ANY], + signed long *, signed long[ANY], + unsigned long *, unsigned long[ANY], + long long *, long long[ANY], + signed long long *, signed long long[ANY], + unsigned long long *, unsigned long long[ANY], + float *, float[ANY], + double *, double[ANY] +%{ + free($1); +%} + +%typemap(freearg, noblock=1) int *OUTPUT, +signed int *OUTPUT, +unsigned int *OUTPUT, +short *OUTPUT, +signed short *OUTPUT, +unsigned short *OUTPUT, +long *OUTPUT, +signed long *OUTPUT, +unsigned long *OUTPUT, +long long *OUTPUT, +signed long long *OUTPUT, +unsigned long long *OUTPUT, +float *OUTPUT, +double *OUTPUT, +char *OUTPUT, +signed char *OUTPUT, +unsigned char *OUTPUT +{} + + + +/* Should we recycle to make the length correct. + And warn if length() > the dimension. +*/ +%typemap(scheck) SWIGTYPE [ANY] %{ +# assert(length($input) >= $1_dim0) +%} + +/* Handling vector case to avoid warnings, + although we just use the first one. */ +%typemap(scheck) unsigned int %{ + assert(length($input) == 1 && $input >= 0, "All values must be non-negative"); +%} + + +%typemap(scheck) int, long %{ + if(length($input) > 1) { + warning("using only the first element of $input"); + }; +%} + +%include <typemaps/fragments.swg> +%include <rfragments.swg> +%include <ropers.swg> +%include <typemaps/swigtypemaps.swg> +%include <rtype.swg> + +%typemap(in,noblock=1) enum SWIGTYPE[ANY] { + $1 = %reinterpret_cast(INTEGER($input), $1_ltype); +} + +%typemap(in,noblock=1,fragment="SWIG_strdup") char * { + $1 = %reinterpret_cast(SWIG_strdup(CHAR(STRING_ELT($input, 0))), $1_ltype); +} + +%typemap(freearg,noblock=1) char * { + free($1); +} + +%typemap(in,noblock=1,fragment="SWIG_strdup") char *[ANY] { + $1 = %reinterpret_cast(SWIG_strdup(CHAR(STRING_ELT($input, 0))), $1_ltype); +} + +%typemap(freearg,noblock=1) char *[ANY] { + free($1); +} + +%typemap(in,noblock=1,fragment="SWIG_strdup") char[ANY] { + $1 = SWIG_strdup(CHAR(STRING_ELT($input, 0))); +} + +%typemap(freearg,noblock=1) char[ANY] { + free($1); +} + +%typemap(in,noblock=1,fragment="SWIG_strdup") char[] { + $1 = SWIG_strdup(CHAR(STRING_ELT($input, 0))); +} + +%typemap(freearg,noblock=1) char[] { + free($1); +} + + +%typemap(memberin) char[] %{ +if ($input) strcpy($1, $input); +else +strcpy($1, ""); +%} + +%typemap(globalin) char[] %{ +if ($input) strcpy($1, $input); +else +strcpy($1, ""); +%} + +%typemap(out,noblock=1) char * + { $result = $1 ? Rf_mkString(%reinterpret_cast($1,char *)) : R_NilValue; } + +%typemap(in,noblock=1) char { +$1 = %static_cast(CHAR(STRING_ELT($input, 0))[0],$1_ltype); +} + +%typemap(out) char + { + char tmp[2] = "x"; + tmp[0] = $1; + $result = Rf_mkString(tmp); + } + + +%typemap(in,noblock=1) int, long +{ + $1 = %static_cast(INTEGER($input)[0], $1_ltype); +} + +%typemap(out,noblock=1) int, long + "$result = Rf_ScalarInteger($1);"; + + +%typemap(in,noblock=1) bool + "$1 = LOGICAL($input)[0] ? true : false;"; + + +%typemap(out,noblock=1) bool + "$result = Rf_ScalarLogical($1);"; + +%typemap(in,noblock=1) + float, + double +{ + $1 = %static_cast(REAL($input)[0], $1_ltype); +} + +/* Why is this here ? */ +/* %typemap(out,noblock=1) unsigned int * + "$result = ScalarReal(*($1));"; */ + +%Rruntime %{ +setMethod('[', "ExternalReference", +function(x,i,j, ..., drop=TRUE) +if (!is.null(x$"__getitem__")) +sapply(i, function(n) x$"__getitem__"(i=as.integer(n-1)))) + +setMethod('[<-' , "ExternalReference", +function(x,i,j, ..., value) +if (!is.null(x$"__setitem__")) { +sapply(1:length(i), function(n) +x$"__setitem__"(i=as.integer(i[n]-1), x=value[n])) +x +}) + +setAs('ExternalReference', 'character', +function(from) {if (!is.null(from$"__str__")) from$"__str__"()}) + +setMethod('print', 'ExternalReference', +function(x) {print(as(x, "character"))}) +%} + + + diff --git a/share/swig/2.0.11/r/rcontainer.swg b/share/swig/2.0.11/r/rcontainer.swg new file mode 100644 index 0000000..54b31b3 --- /dev/null +++ b/share/swig/2.0.11/r/rcontainer.swg @@ -0,0 +1,198 @@ + +// +// Common fragments +// + + +/**** The python container methods ****/ + + + +%fragment("StdSequenceTraits","header",fragment="<stddef.h>") +{ +%#include <functional> +namespace swig { + inline size_t + check_index(ptrdiff_t i, size_t size, bool insert = false) { + if ( i < 0 ) { + if ((size_t) (-i) <= size) + return (size_t) (i + size); + } else if ( (size_t) i < size ) { + return (size_t) i; + } else if (insert && ((size_t) i == size)) { + return size; + } + + throw std::out_of_range("index out of range"); + } + + inline size_t + slice_index(ptrdiff_t i, size_t size) { + if ( i < 0 ) { + if ((size_t) (-i) <= size) { + return (size_t) (i + size); + } else { + throw std::out_of_range("index out of range"); + } + } else { + return ( (size_t) i < size ) ? ((size_t) i) : size; + } + } + + template <class Sequence, class Difference> + inline typename Sequence::iterator + getpos(Sequence* self, Difference i) { + typename Sequence::iterator pos = self->begin(); + std::advance(pos, check_index(i,self->size())); + return pos; + } + + template <class Sequence, class Difference> + inline typename Sequence::const_iterator + cgetpos(const Sequence* self, Difference i) { + typename Sequence::const_iterator pos = self->begin(); + std::advance(pos, check_index(i,self->size())); + return pos; + } + + template <class Sequence, class Difference> + inline Sequence* + getslice(const Sequence* self, Difference i, Difference j) { + typename Sequence::size_type size = self->size(); + typename Sequence::size_type ii = swig::check_index(i, size); + typename Sequence::size_type jj = swig::slice_index(j, size); + + if (jj > ii) { + typename Sequence::const_iterator vb = self->begin(); + typename Sequence::const_iterator ve = self->begin(); + std::advance(vb,ii); + std::advance(ve,jj); + return new Sequence(vb, ve); + } else { + return new Sequence(); + } + } + + template <class Sequence, class Difference, class InputSeq> + inline void + setslice(Sequence* self, Difference i, Difference j, const InputSeq& v) { + typename Sequence::size_type size = self->size(); + typename Sequence::size_type ii = swig::check_index(i, size, true); + typename Sequence::size_type jj = swig::slice_index(j, size); + if (jj < ii) jj = ii; + size_t ssize = jj - ii; + if (ssize <= v.size()) { + typename Sequence::iterator sb = self->begin(); + typename InputSeq::const_iterator vmid = v.begin(); + std::advance(sb,ii); + std::advance(vmid, jj - ii); + self->insert(std::copy(v.begin(), vmid, sb), vmid, v.end()); + } else { + typename Sequence::iterator sb = self->begin(); + typename Sequence::iterator se = self->begin(); + std::advance(sb,ii); + std::advance(se,jj); + self->erase(sb,se); + self->insert(sb, v.begin(), v.end()); + } + } + + template <class Sequence, class Difference> + inline void + delslice(Sequence* self, Difference i, Difference j) { + typename Sequence::size_type size = self->size(); + typename Sequence::size_type ii = swig::check_index(i, size, true); + typename Sequence::size_type jj = swig::slice_index(j, size); + if (jj > ii) { + typename Sequence::iterator sb = self->begin(); + typename Sequence::iterator se = self->begin(); + std::advance(sb,ii); + std::advance(se,jj); + self->erase(sb,se); + } + } +} +} + +%define %swig_container_methods(Container...) + + %newobject __getslice__; + + %extend { + bool __nonzero__() const { + return !(self->empty()); + } + + size_type __len__() const { + return self->size(); + } + } +%enddef + +%define %swig_sequence_methods_common(Sequence...) +// %swig_sequence_iterator(%arg(Sequence)) + %swig_container_methods(%arg(Sequence)) + + %fragment("StdSequenceTraits"); + + %extend { + value_type pop() throw (std::out_of_range) { + if (self->size() == 0) + throw std::out_of_range("pop from empty container"); + Sequence::value_type x = self->back(); + self->pop_back(); + return x; + } + + Sequence* __getslice__(difference_type i, difference_type j) throw (std::out_of_range) { + return swig::getslice(self, i, j); + } + + void __setslice__(difference_type i, difference_type j, const Sequence& v) + throw (std::out_of_range, std::invalid_argument) { + swig::setslice(self, i, j, v); + } + + void __delslice__(difference_type i, difference_type j) throw (std::out_of_range) { + swig::delslice(self, i, j); + } + + void __delitem__(difference_type i) throw (std::out_of_range) { + self->erase(swig::getpos(self,i)); + } + } +%enddef + +%define %swig_sequence_methods(Sequence...) + %swig_sequence_methods_common(%arg(Sequence)) + %extend { + const value_type& __getitem__(difference_type i) const throw (std::out_of_range) { + return *(swig::cgetpos(self, i)); + } + + void __setitem__(difference_type i, const value_type& x) throw (std::out_of_range) { + *(swig::getpos(self,i)) = x; + } + + void append(const value_type& x) { + self->push_back(x); + } + } +%enddef + +%define %swig_sequence_methods_val(Sequence...) + %swig_sequence_methods_common(%arg(Sequence)) + %extend { + value_type __getitem__(difference_type i) throw (std::out_of_range) { + return *(swig::cgetpos(self, i)); + } + + void __setitem__(difference_type i, value_type x) throw (std::out_of_range) { + *(swig::getpos(self,i)) = x; + } + + void append(value_type x) { + self->push_back(x); + } + } +%enddef diff --git a/share/swig/2.0.11/r/rfragments.swg b/share/swig/2.0.11/r/rfragments.swg new file mode 100644 index 0000000..afb75c3 --- /dev/null +++ b/share/swig/2.0.11/r/rfragments.swg @@ -0,0 +1,183 @@ +#define SWIG_Error(code, msg) Rf_warning(msg); return Rf_ScalarLogical(NA_LOGICAL) + +#define SWIG_fail return Rf_ScalarLogical(NA_LOGICAL) + +/* for raw pointers */ +#define SWIG_ConvertPtr(oc, ptr, ty, flags) SWIG_R_ConvertPtr(oc, ptr, ty, flags) +#define SWIG_ConvertFunctionPtr(oc, ptr, ty) SWIG_R_ConvertPtr(oc, ptr, ty, 0) +#define SWIG_NewPointerObj(ptr, ty, flags) SWIG_R_NewPointerObj(ptr, ty, flags) +#define SWIG_NewFunctionPtrObj(ptr, ty) SWIG_R_NewPointerObj(ptr, ty, 0) + +/* for raw packed data */ +#define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_R_ConvertPacked(obj, ptr, sz, ty) +#define SWIG_NewPackedObj(ptr, sz, ty) SWIG_R_NewPackedObj(ptr, sz, ty) + +/* for class or struct pointers */ +#define SWIG_ConvertInstance(obj, pptr, ty, flags) SWIG_ConvertPtr(obj, pptr, ty, flags) +#define SWIG_NewInstanceObj(ptr, ty, flags) SWIG_NewPointerObj(ptr, ty, flags) + +/* for C++ member pointers, ie, member methods */ +#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_R_ConvertPacked(obj, ptr, sz, ty) +#define SWIG_NewMemberObj(ptr, sz, ty) SWIG_R_NewPackedObj(ptr, sz, ty) + + +/* Runtime API */ + +#define SWIG_GetModule(clientdata) SWIG_R_GetModule() +#define SWIG_SetModule(clientdata, pointer) SWIG_R_SetModule(pointer) + +%fragment(SWIG_From_frag(long),"header") { +SWIGINTERNINLINE SEXP +SWIG_From_dec(long)(long value) +{ + return Rf_ScalarInteger((int)value); +} +} + +%fragment(SWIG_AsVal_frag(long),"header") { +SWIGINTERNINLINE int +SWIG_AsVal_dec(long)(SEXP obj, long *val) +{ + if (val) *val = Rf_asInteger(obj); + return SWIG_OK; +} +} + + +%fragment(SWIG_From_frag(long long),"header") { +SWIGINTERNINLINE SEXP +SWIG_From_dec(long long)(long long value) +{ + return Rf_ScalarInteger((int)value); +} +} + +%fragment(SWIG_AsVal_frag(long long),"header") { +SWIGINTERNINLINE int +SWIG_AsVal_dec(long long)(SEXP obj, long long *val) +{ + if (val) *val = Rf_asInteger(obj); + return SWIG_OK; +} +} + +%fragment(SWIG_From_frag(unsigned long),"header") { +SWIGINTERNINLINE SEXP +SWIG_From_dec(unsigned long)(unsigned long value) +{ + return Rf_ScalarInteger((int)value); +} +} + + +%fragment(SWIG_AsVal_frag(unsigned long),"header") { +SWIGINTERNINLINE int +SWIG_AsVal_dec(unsigned long)(SEXP obj, unsigned long *val) +{ + if (val) *val = Rf_asInteger(obj); + return SWIG_OK; +} +} + + +%fragment(SWIG_From_frag(unsigned long long),"header") { +SWIGINTERNINLINE SEXP +SWIG_From_dec(unsigned long long)(unsigned long long value) +{ + return Rf_ScalarInteger((int)value); +} +} + + +%fragment(SWIG_AsVal_frag(unsigned long long),"header") { +SWIGINTERNINLINE int +SWIG_AsVal_dec(unsigned long long)(SEXP obj, unsigned long long *val) +{ + if (val) *val = Rf_asInteger(obj); + return SWIG_OK; +} +} + +%fragment(SWIG_From_frag(double),"header") { +SWIGINTERNINLINE SEXP +SWIG_From_dec(double)(double value) +{ + return Rf_ScalarReal(value); +} +} + + +%fragment(SWIG_AsVal_frag(double),"header") { +SWIGINTERNINLINE int +SWIG_AsVal_dec(double)(SEXP obj, double *val) +{ + if (val) *val = Rf_asReal(obj); + return SWIG_OK; +} +} + +%fragment("SWIG_AsCharPtrAndSize", "header") +{ +SWIGINTERN int +SWIG_AsCharPtrAndSize(SEXP obj, char** cptr, size_t* psize, int *alloc) +{ + if (cptr && Rf_isString(obj)) { + char *cstr = %const_cast(CHAR(STRING_ELT(obj, 0)), char *); + int len = strlen(cstr); + + if (alloc) { + if (*alloc == SWIG_NEWOBJ) { + *cptr = %new_copy_array(cstr, len + 1, char); + *alloc = SWIG_NEWOBJ; + } else { + *cptr = cstr; + } + } else { + *cptr = %reinterpret_cast(malloc(len + 1), char *); + *cptr = strcpy(*cptr, cstr); + } + if (psize) *psize = len + 1; + return SWIG_OK; + } + return SWIG_TypeError; +} +} + +%fragment("SWIG_strdup","header") +{ +SWIGINTERN char * +SWIG_strdup(const char *str) +{ + char *newstr = %reinterpret_cast(malloc(strlen(str) + 1), char *); + return strcpy(newstr, str); +} +} + +# This is modified from the R header files + +%fragment("SWIG_FromCharPtrAndSize","header") +{ +SWIGINTERN SEXP +SWIG_FromCharPtrAndSize(const char* carray, size_t size) +{ + SEXP t, c; + if (!carray) return R_NilValue; +/* See R internals document 1.10. + MkCharLen was introduced in 2.7.0. Use that instead of hand + creating vector. + + Starting in 2.8.0 creating strings via vectors was deprecated in + order to allow for use of CHARSXP caches. */ + + Rf_protect(t = Rf_allocVector(STRSXP, 1)); +%#if R_VERSION >= R_Version(2,7,0) + c = Rf_mkCharLen(carray, size); +%#else + c = Rf_allocVector(CHARSXP, size); + strncpy((char *)CHAR(c), carray, size); +%#endif + SET_STRING_ELT(t, 0, c); + Rf_unprotect(1); + return t; +} +} diff --git a/share/swig/2.0.11/r/rkw.swg b/share/swig/2.0.11/r/rkw.swg new file mode 100644 index 0000000..2c181fa --- /dev/null +++ b/share/swig/2.0.11/r/rkw.swg @@ -0,0 +1,32 @@ +/* + Warnings for R keywords, built-in names and bad names. +*/ + +#define RKW(x) %keywordwarn("'" `x` "' is a R keyword, renaming to '_" `x`"'", rename="_%s") `x` + +/* + Warnings for R reserved words taken from + http://cran.r-project.org/doc/manuals/R-lang.html#Reserved-words +*/ + +RKW(if); +RKW(else); +RKW(repeat); +RKW(while); +RKW(function); +RKW(for); +RKW(in); +RKW(next); +RKW(break); +RKW(TRUE); +RKW(FALSE); +RKW(NULL); +RKW(Inf); +RKW(NaN); +RKW(NA); +RKW(NA_integer_); +RKW(NA_real_); +RKW(NA_complex_); +RKW(NA_character_); + +#undef RKW diff --git a/share/swig/2.0.11/r/ropers.swg b/share/swig/2.0.11/r/ropers.swg new file mode 100644 index 0000000..c02f7b2 --- /dev/null +++ b/share/swig/2.0.11/r/ropers.swg @@ -0,0 +1,70 @@ +#ifdef __cplusplus + +// These are auto-supported by the Perl-module +%rename(__plusplus__) *::operator++; +%rename(__minmin__) *::operator--; +%rename(__add__) *::operator+; +%rename(__sub__) *::operator-; +%rename(__neg__) *::operator-(); +%rename(__neg__) *::operator-() const; +%rename(__mul__) *::operator*; +%rename(__div__) *::operator/; +%rename(__eq__) *::operator==; +%rename(__ne__) *::operator!=; +%rename(__mod__) *::operator%; +%rename(__gt__) *::operator>; +%rename(__lt__) *::operator<; +%rename(__not__) *::operator!; + +// These are renamed, but no 'use overload...' is added +%rename(__lshift__) *::operator<<; +%rename(__rshift__) *::operator>>; +%rename(__and__) *::operator&; +%rename(__or__) *::operator|; +%rename(__xor__) *::operator^; +%rename(__invert__) *::operator~; +%rename(__le__) *::operator<=; +%rename(__ge__) *::operator>=; +%rename(__call__) *::operator(); +%rename(__getitem__) *::operator[]; + +%rename(__seteq__) *::operator=; + + +%rename(__land__) operator&&; +%rename(__lor__) operator||; +%rename(__plusplus__) *::operator++; +%rename(__minusminus__) *::operator--; +%rename(__arrowstar__) *::operator->*; +%rename(__index__) *::operator[]; + +%rename(Equal) operator =; +%rename(PlusEqual) operator +=; +%rename(MinusEqual) operator -=; +%rename(MultiplyEqual) operator *=; +%rename(DivideEqual) operator /=; +%rename(PercentEqual) operator %=; +%rename(Plus) operator +; +%rename(Minus) operator -; +%rename(Multiply) operator *; +%rename(Divide) operator /; +%rename(Percent) operator %; +%rename(Not) operator !; +%rename(IndexIntoConst) operator[](unsigned idx) const; +%rename(IndexInto) operator[](unsigned idx); +%rename(Functor) operator (); +%rename(EqualEqual) operator ==; +%rename(NotEqual) operator !=; +%rename(LessThan) operator <; +%rename(LessThanEqual) operator <=; +%rename(GreaterThan) operator >; +%rename(GreaterThanEqual) operator >=; +%rename(And) operator &&; +%rename(Or) operator ||; +%rename(PlusPlusPrefix) operator++(); +%rename(PlusPlusPostfix) operator++(int); +%rename(MinusMinusPrefix) operator--(); +%rename(MinusMinusPostfix) operator--(int); + + +#endif diff --git a/share/swig/2.0.11/r/rrun.swg b/share/swig/2.0.11/r/rrun.swg new file mode 100644 index 0000000..f8bc9f4 --- /dev/null +++ b/share/swig/2.0.11/r/rrun.swg @@ -0,0 +1,380 @@ + +#ifdef __cplusplus +extern "C" { +#endif + +/* for raw pointer */ +#define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_R_ConvertPtr(obj, pptr, type, flags) +#define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_R_ConvertPtr(obj, pptr, type, flags) +#define SWIG_NewPointerObj(ptr, type, flags) SWIG_R_NewPointerObj(ptr, type, flags) + + +/* Remove global namespace pollution */ +#if !defined(SWIG_NO_R_NO_REMAP) +# define R_NO_REMAP +#endif +#if !defined(SWIG_NO_STRICT_R_HEADERS) +# define STRICT_R_HEADERS +#endif + +#include <Rdefines.h> +#include <Rversion.h> +#include <stdlib.h> +#include <assert.h> + +#if R_VERSION >= R_Version(2,6,0) +#define VMAXTYPE void * +#else +#define VMAXTYPE char * +#endif + +/* + This is mainly a way to avoid having lots of local variables that may + conflict with those in the routine. + + Change name to R_SWIG_Callb.... +*/ +typedef struct RCallbackFunctionData { + + SEXP fun; + SEXP userData; + + + SEXP expr; + SEXP retValue; + int errorOccurred; + + SEXP el; /* Temporary pointer used in the construction of the expression to call the R function. */ + + struct RCallbackFunctionData *previous; /* Stack */ + +} RCallbackFunctionData; + +static RCallbackFunctionData *callbackFunctionDataStack; + + +SWIGRUNTIME SEXP +R_SWIG_debug_getCallbackFunctionData() +{ + int n, i; + SEXP ans; + RCallbackFunctionData *p = callbackFunctionDataStack; + + n = 0; + while(p) { + n++; + p = p->previous; + } + + Rf_protect(ans = Rf_allocVector(VECSXP, n)); + for(p = callbackFunctionDataStack, i = 0; i < n; p = p->previous, i++) + SET_VECTOR_ELT(ans, i, p->fun); + + Rf_unprotect(1); + + return(ans); +} + + + +SWIGRUNTIME RCallbackFunctionData * +R_SWIG_pushCallbackFunctionData(SEXP fun, SEXP userData) +{ + RCallbackFunctionData *el; + el = (RCallbackFunctionData *) calloc(1, sizeof(RCallbackFunctionData)); + el->fun = fun; + el->userData = userData; + el->previous = callbackFunctionDataStack; + + callbackFunctionDataStack = el; + + return(el); +} + + +SWIGRUNTIME SEXP +R_SWIG_R_pushCallbackFunctionData(SEXP fun, SEXP userData) +{ + R_SWIG_pushCallbackFunctionData(fun, userData); + return R_NilValue; +} + +SWIGRUNTIME RCallbackFunctionData * +R_SWIG_getCallbackFunctionData() +{ + if(!callbackFunctionDataStack) { + Rf_error("Supposedly impossible error occurred in the SWIG callback mechanism." + " No callback function data set."); + } + + return callbackFunctionDataStack; +} + +SWIGRUNTIME void +R_SWIG_popCallbackFunctionData(int doFree) +{ + RCallbackFunctionData *el = NULL; + if(!callbackFunctionDataStack) + return ; /* Error !!! */ + + el = callbackFunctionDataStack ; + callbackFunctionDataStack = callbackFunctionDataStack->previous; + + if(doFree) + free(el); +} + + +/* + Interface to S function + is(obj, type) + which is to be used to determine if an + external pointer inherits from the right class. + + Ideally, we would like to be able to do this without an explicit call to the is() function. + When the S4 class system uses its own SEXP types, then we will hopefully be able to do this + in the C code. + + Should we make the expression static and preserve it to avoid the overhead of + allocating each time. +*/ +SWIGRUNTIME int +R_SWIG_checkInherits(SEXP obj, SEXP tag, const char *type) +{ + SEXP e, val; + int check_err = 0; + + Rf_protect(e = Rf_allocVector(LANGSXP, 3)); + SETCAR(e, Rf_install("extends")); + + SETCAR(CDR(e), Rf_mkString(CHAR(PRINTNAME(tag)))); + SETCAR(CDR(CDR(e)), Rf_mkString(type)); + + val = R_tryEval(e, R_GlobalEnv, &check_err); + Rf_unprotect(1); + if(check_err) + return(0); + + + return(LOGICAL(val)[0]); +} + + +SWIGRUNTIME void * +R_SWIG_resolveExternalRef(SEXP arg, const char * const type, const char * const argName, Rboolean nullOk) +{ + void *ptr; + SEXP orig = arg; + + if(TYPEOF(arg) != EXTPTRSXP) + arg = GET_SLOT(arg, Rf_mkString("ref")); + + + if(TYPEOF(arg) != EXTPTRSXP) { + Rf_error("argument %s must be an external pointer (from an ExternalReference)", argName); + } + + + ptr = R_ExternalPtrAddr(arg); + + if(ptr == NULL && nullOk == (Rboolean) FALSE) { + Rf_error("the external pointer (of type %s) for argument %s has value NULL", argName, type); + } + + if(type[0] && R_ExternalPtrTag(arg) != Rf_install(type) && strcmp(type, "voidRef") + && !R_SWIG_checkInherits(orig, R_ExternalPtrTag(arg), type)) { + Rf_error("the external pointer for argument %s has tag %s, not the expected value %s", + argName, CHAR(PRINTNAME(R_ExternalPtrTag(arg))), type); + } + + + return(ptr); +} + +SWIGRUNTIME void +R_SWIG_ReferenceFinalizer(SEXP el) +{ + void *ptr = R_SWIG_resolveExternalRef(el, "", "<finalizer>", (Rboolean) 1); + fprintf(stderr, "In R_SWIG_ReferenceFinalizer for %p\n", ptr); + Rf_PrintValue(el); + + if(ptr) { + if(TYPEOF(el) != EXTPTRSXP) + el = GET_SLOT(el, Rf_mkString("ref")); + + if(TYPEOF(el) == EXTPTRSXP) + R_ClearExternalPtr(el); + + free(ptr); + } + + return; +} + +typedef enum {R_SWIG_EXTERNAL, R_SWIG_OWNER } R_SWIG_Owner; + +SWIGRUNTIME SEXP +SWIG_MakePtr(void *ptr, const char *typeName, R_SWIG_Owner owner) +{ + SEXP external, r_obj; + const char *p = typeName; + + if(typeName[0] == '_') + p = typeName + 1; + + Rf_protect(external = R_MakeExternalPtr(ptr, Rf_install(typeName), R_NilValue)); + Rf_protect(r_obj = NEW_OBJECT(MAKE_CLASS((char *) typeName))); + + if(owner) + R_RegisterCFinalizer(external, R_SWIG_ReferenceFinalizer); + + r_obj = SET_SLOT(r_obj, Rf_mkString((char *) "ref"), external); + SET_S4_OBJECT(r_obj); + Rf_unprotect(2); + + return(r_obj); +} + + +SWIGRUNTIME SEXP +R_SWIG_create_SWIG_R_Array(const char *typeName, SEXP ref, int len) +{ + SEXP arr; + +/*XXX remove the char * cast when we can. MAKE_CLASS should be declared appropriately. */ + Rf_protect(arr = NEW_OBJECT(MAKE_CLASS((char *) typeName))); + Rf_protect(arr = R_do_slot_assign(arr, Rf_mkString("ref"), ref)); + Rf_protect(arr = R_do_slot_assign(arr, Rf_mkString("dims"), Rf_ScalarInteger(len))); + + Rf_unprotect(3); + SET_S4_OBJECT(arr); + return arr; +} + +#define ADD_OUTPUT_ARG(result, pos, value, name) r_ans = AddOutputArgToReturn(pos, value, name, OutputValues); + +SWIGRUNTIME SEXP +AddOutputArgToReturn(int pos, SEXP value, const char *name, SEXP output) +{ + SET_VECTOR_ELT(output, pos, value); + + return(output); +} + +/* Create a new pointer object */ +SWIGRUNTIMEINLINE SEXP +SWIG_R_NewPointerObj(void *ptr, swig_type_info *type, int flags) { + SEXP rptr = R_MakeExternalPtr(ptr, + R_MakeExternalPtr(type, R_NilValue, R_NilValue), R_NilValue); + SET_S4_OBJECT(rptr); + return rptr; +} + + +/* Convert a pointer value */ +SWIGRUNTIMEINLINE int +SWIG_R_ConvertPtr(SEXP obj, void **ptr, swig_type_info *ty, int flags) { + void *vptr; + if (!obj) return SWIG_ERROR; + if (obj == R_NilValue) { + if (ptr) *ptr = NULL; + return SWIG_OK; + } + + vptr = R_ExternalPtrAddr(obj); + if (ty) { + swig_type_info *to = (swig_type_info*) + R_ExternalPtrAddr(R_ExternalPtrTag(obj)); + if (to == ty) { + if (ptr) *ptr = vptr; + } else { + swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); + int newmemory = 0; + if (ptr) *ptr = SWIG_TypeCast(tc,vptr,&newmemory); + assert(!newmemory); /* newmemory handling not yet implemented */ + } + } else { + if (ptr) *ptr = vptr; + } + return SWIG_OK; +} + +SWIGRUNTIME swig_module_info * +SWIG_GetModule(void *SWIGUNUSEDPARM(clientdata)) { + static void *type_pointer = (void *)0; + return (swig_module_info *) type_pointer; +} + +SWIGRUNTIME void +SWIG_SetModule(void *v, swig_module_info *swig_module) { +} + +typedef struct { + void *pack; + swig_type_info *ty; + size_t size; +} RSwigPacked; + +/* Create a new packed object */ + +SWIGRUNTIMEINLINE SEXP RSwigPacked_New(void *ptr, size_t sz, + swig_type_info *ty) { + SEXP rptr; + RSwigPacked *sobj = + (RSwigPacked*) malloc(sizeof(RSwigPacked)); + if (sobj) { + void *pack = malloc(sz); + if (pack) { + memcpy(pack, ptr, sz); + sobj->pack = pack; + sobj->ty = ty; + sobj->size = sz; + } else { + sobj = 0; + } + } + rptr = R_MakeExternalPtr(sobj, R_NilValue, R_NilValue); + return rptr; +} + +SWIGRUNTIME swig_type_info * +RSwigPacked_UnpackData(SEXP obj, void *ptr, size_t size) +{ + RSwigPacked *sobj = + (RSwigPacked *)R_ExternalPtrAddr(obj); + if (sobj->size != size) return 0; + memcpy(ptr, sobj->pack, size); + return sobj->ty; +} + +SWIGRUNTIMEINLINE SEXP +SWIG_R_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { + return ptr ? RSwigPacked_New((void *) ptr, sz, type) : R_NilValue; +} + +/* Convert a packed value value */ + +SWIGRUNTIME int +SWIG_R_ConvertPacked(SEXP obj, void *ptr, size_t sz, swig_type_info *ty) { + swig_type_info *to = RSwigPacked_UnpackData(obj, ptr, sz); + if (!to) return SWIG_ERROR; + if (ty) { + if (to != ty) { + /* check type cast? */ + swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); + if (!tc) return SWIG_ERROR; + } + } + return SWIG_OK; +} + +#ifdef __cplusplus +#include <exception> +#define SWIG_exception_noreturn(code, msg) do { throw std::runtime_error(msg); } while(0) +#else +#define SWIG_exception_noreturn(code, msg) do { return result; } while(0) +#endif + +#ifdef __cplusplus +} +#endif diff --git a/share/swig/2.0.11/r/rstdcommon.swg b/share/swig/2.0.11/r/rstdcommon.swg new file mode 100644 index 0000000..b11cf67 --- /dev/null +++ b/share/swig/2.0.11/r/rstdcommon.swg @@ -0,0 +1,210 @@ +%fragment("StdTraits","header",fragment="StdTraitsCommon") +{ +namespace swig { + /* + Traits that provides the from method + */ + + template <class Type> struct traits_from_ptr { + static SWIG_Object from(Type *val, int owner = 0) { + return SWIG_NewPointerObj(val, type_info<Type>(), owner); + } + }; + + template <class Type> struct traits_from { + static SWIG_Object from(const Type& val) { + return traits_from_ptr<Type>::from(new Type(val), 1); + } + }; + + template <class Type> struct traits_from<Type *> { + static SWIG_Object from(Type* val) { + return traits_from_ptr<Type>::from(val, 0); + } + }; + + template <class Type> + inline SWIG_Object from(const Type& val) { + return traits_from<Type>::from(val); + } + + template <class Type> + inline SWIG_Object from_ptr(Type* val, int owner) { + return traits_from_ptr<Type>::from(val, owner); + } + + /* + Traits that provides the asval/as/check method + */ + template <class Type> + struct traits_asptr { + static int asptr(SWIG_Object obj, Type **val) { + Type *p; + int res = SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0); + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + return res; + } + }; + + template <class Type> + inline int asptr(SWIG_Object obj, Type **vptr) { + return traits_asptr<Type>::asptr(obj, vptr); + } + + template <class Type> + struct traits_asval { + static int asval(SWIG_Object obj, Type *val) { + if (val) { + Type *p = 0; + int res = traits_asptr<Type>::asptr(obj, &p); + if (!SWIG_IsOK(res)) return res; + if (p) { + typedef typename noconst_traits<Type>::noconst_type noconst_type; + *(const_cast<noconst_type*>(val)) = *p; + if (SWIG_IsNewObj(res)){ + %delete(p); + res = SWIG_DelNewMask(res); + } + return res; + } else { + return SWIG_ERROR; + } + } else { + return traits_asptr<Type>::asptr(obj, (Type **)(0)); + } + } + }; + + template <class Type> struct traits_asval<Type*> { + static int asval(SWIG_Object obj, Type **val) { + if (val) { + typedef typename noconst_traits<Type>::noconst_type noconst_type; + noconst_type *p = 0; + int res = traits_asptr<noconst_type>::asptr(obj, &p); + if (SWIG_IsOK(res)) { + *(const_cast<noconst_type**>(val)) = p; + } + return res; + } else { + return traits_asptr<Type>::asptr(obj, (Type **)(0)); + } + } + }; + + template <class Type> + inline int asval(SWIG_Object obj, Type *val) { + return traits_asval<Type>::asval(obj, val); + } + + template <class Type> + struct traits_as<Type, value_category> { + static Type as(SWIG_Object obj, bool throw_error) { + Type v; + int res = asval(obj, &v); + if (!obj || !SWIG_IsOK(res)) { + if (throw_error) + throw std::invalid_argument("bad type"); + } + return v; + } + }; + + template <class Type> + struct traits_as<Type, pointer_category> { + static Type as(SWIG_Object obj, bool throw_error) { + Type *v = 0; + int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR); + if (SWIG_IsOK(res) && v) { + if (SWIG_IsNewObj(res)) { + Type r(*v); + %delete(v); + return r; + } else { + return *v; + } + } else { + // Uninitialized return value, no Type() constructor required. + static Type *v_def = (Type*) malloc(sizeof(Type)); + if (throw_error) + throw std::invalid_argument("bad type"); + memset(v_def,0,sizeof(Type)); + return *v_def; + } + } + }; + + template <class Type> + struct traits_as<Type*, pointer_category> { + static Type* as(SWIG_Object obj, bool throw_error) { + Type *v = 0; + int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR); + if (SWIG_IsOK(res)) { + return v; + } else { + if (throw_error) + throw std::invalid_argument("bad type"); + return 0; + } + } + }; + + template <class Type> + inline Type as(SWIG_Object obj, bool te = false) { + return traits_as<Type, typename traits<Type>::category>::as(obj, te); + } + + template <class Type> + struct traits_check<Type, value_category> { + static bool check(SWIG_Object obj) { + int res = obj ? asval(obj, (Type *)(0)) : SWIG_ERROR; + return SWIG_IsOK(res) ? true : false; + } + }; + + template <class Type> + struct traits_check<Type, pointer_category> { + static bool check(SWIG_Object obj) { + int res = obj ? asptr(obj, (Type **)(0)) : SWIG_ERROR; + return SWIG_IsOK(res) ? true : false; + } + }; + + template <class Type> + inline bool check(SWIG_Object obj) { + return traits_check<Type, typename traits<Type>::category>::check(obj); + } +} +} + +%define %specialize_std_container(Type,Check,As,From) +%{ +namespace swig { + template <> struct traits_asval<Type > { + typedef Type value_type; + static int asval(SWIG_Object obj, value_type *val) { + if (Check(obj)) { + if (val) *val = As(obj); + return SWIG_OK; + } + return SWIG_ERROR; + } + }; + template <> struct traits_from<Type > { + typedef Type value_type; + static SWIG_Object from(const value_type& val) { + return From(val); + } + }; + + template <> + struct traits_check<Type, value_category> { + static int check(SWIG_Object obj) { + int res = Check(obj); + return obj && res ? res : 0; + } + }; +} +%} +%enddef diff --git a/share/swig/2.0.11/r/rtype.swg b/share/swig/2.0.11/r/rtype.swg new file mode 100644 index 0000000..b86a618 --- /dev/null +++ b/share/swig/2.0.11/r/rtype.swg @@ -0,0 +1,316 @@ + +/* These map the primitive C types to the appropriate R type + for use in class representations. + */ + +%typemap("rtype") int, int *, int & "integer"; +%typemap("rtype") long, long *, long & "integer"; +%typemap("rtype") float, float*, float & "numeric"; +%typemap("rtype") double, double*, double & "numeric"; +%typemap("rtype") char *, char ** "character"; +%typemap("rtype") char "character"; +%typemap("rtype") string, string *, string & "character"; +%typemap("rtype") std::string, std::string *, std::string & "character"; +%typemap("rtype") bool, bool * "logical"; +%typemap("rtype") enum SWIGTYPE "character"; +%typemap("rtype") enum SWIGTYPE * "character"; +%typemap("rtype") enum SWIGTYPE *const "character"; +%typemap("rtype") enum SWIGTYPE & "character"; +%typemap("rtype") SWIGTYPE * "$R_class"; +%typemap("rtype") SWIGTYPE *const "$R_class"; +%typemap("rtype") SWIGTYPE & "$R_class"; +%typemap("rtype") SWIGTYPE "$&R_class"; + +%typemap("rtypecheck") int, int &, long, long & + %{ (is.integer($arg) || is.numeric($arg)) && length($arg) == 1 %} +%typemap("rtypecheck") int *, long * + %{ is.integer($arg) || is.numeric($arg) %} + + +%typemap("rtypecheck") float, double + %{ is.numeric($arg) && length($arg) == 1 %} +%typemap("rtypecheck") float *, double * + %{ is.numeric($arg) %} + +%typemap("rtypecheck") bool, bool & + %{ is.logical($arg) && length($arg) == 1 %} +%typemap("rtypecheck") bool * + %{ is.logical($arg) %} + +/* + Set up type checks to insure overloading precedence. + We would like non pointer items to shadow pointer items, so that + they get called if length = 1 +*/ + +%typecheck(SWIG_TYPECHECK_BOOL) bool {} +%typecheck(SWIG_TYPECHECK_UINT32) unsigned int {} +%typecheck(SWIG_TYPECHECK_INTEGER) int {} +%typecheck(SWIG_TYPECHECK_FLOAT) float {} +%typecheck(SWIG_TYPECHECK_DOUBLE) double {} + +%typecheck(SWIG_TYPECHECK_BOOL_PTR) bool * {} +%typecheck(SWIG_TYPECHECK_INT32_PTR) int * {} +%typecheck(SWIG_TYPECHECK_FLOAT_PTR) float * {} +%typecheck(SWIG_TYPECHECK_DOUBLE_PTR) double * {} +%typecheck(SWIG_TYPECHECK_CHAR_PTR) char * {} + +%typecheck(SWIG_TYPECHECK_INT32_ARRAY) int[ANY] {} +%typecheck(SWIG_TYPECHECK_FLOAT_ARRAY) float[ANY] {} +%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY) double [ANY] {} + +/* Have to be careful that as(x, "numeric") is different from as.numeric(x). + The latter makes a REALSXP, whereas the former leaves an INTSXP as an + INTSXP. +*/ + +/* Force coercion of integer, since by default R sets all constants to + numeric, which means that you can't directly call a function with an + integer using an R numercal literal */ + +%typemap(scoercein) int, int *, int & + %{ $input = as.integer($input); %} +%typemap(scoercein) long, long *, long & + %{ $input = as.integer($input); %} +%typemap(scoercein) float, float*, float &, + double, double *, double & + %{ %} +%typemap(scoercein) char, char *, char & + %{ $input = as($input, "character"); %} +%typemap(scoercein) string, string *, string & + %{ $input = as($input, "character"); %} +%typemap(scoercein) std::string, std::string *, std::string & + %{ $input = as($input, "character"); %} +%typemap(scoercein) enum SWIGTYPE + %{ $input = enumToInteger($input, "$R_class"); %} +%typemap(scoercein) enum SWIGTYPE & + %{ $input = enumToInteger($input, "$R_class"); %} +%typemap(scoercein) enum SWIGTYPE * + %{ $input = enumToInteger($input, "$R_class"); %} +%typemap(scoercein) enum SWIGTYPE *const + %{ $input = enumToInteger($input, "$R_class"); %} + +%typemap(scoercein) SWIGTYPE, SWIGTYPE *, SWIGTYPE *const, SWIGTYPE & + %{ if (inherits($input, "ExternalReference")) $input = slot($input,"ref") %} + +/* +%typemap(scoercein) SWIGTYPE *, SWIGTYPE *const + %{ $input = coerceIfNotSubclass($input, "$R_class") %} + +%typemap(scoercein) SWIGTYPE & + %{ $input = coerceIfNotSubclass($input, "$R_class") %} + +%typemap(scoercein) SWIGTYPE + %{ $input = coerceIfNotSubclass($input, "$&R_class") %} +*/ + +%typemap(scoercein) SWIGTYPE[ANY] + %{ + if(is.list($input)) + assert(all(sapply($input, class) == "$R_class")); + %} + + +/* **************************************************************** */ + +%typemap(scoercein) bool, bool *, bool & + "$input = as.logical($input);"; +%typemap(scoercein) int, + int *, + int &, + long, + long *, + long & + "$input = as.integer($input);"; + +%typemap(scoercein) char *, string, std::string, +string &, std::string & +%{ $input = as($input, "character"); %} + +%typemap(scoerceout) enum SWIGTYPE + %{ $result = enumFromInteger($result, "$R_class"); %} + +%typemap(scoerceout) enum SWIGTYPE & + %{ $result = enumFromInteger($result, "$R_class"); %} + +%typemap(scoerceout) enum SWIGTYPE * + %{ $result = enumToInteger($result, "$R_class"); %} + +%typemap(scoerceout) enum SWIGTYPE *const + %{ $result = enumToInteger($result, "$R_class"); %} + +#%typemap(scoerceout) SWIGTYPE +# %{ class($result) <- "$&R_class"; %} + +#%typemap(scoerceout) SWIGTYPE & +# %{ class($result) <- "$R_class"; %} + +#%typemap(scoerceout) SWIGTYPE * +# %{ class($result) <- "$R_class"; %} + +#%typemap(scoerceout) SWIGTYPE *const +# %{ class($result) <- "$R_class"; %} + + %typemap(scoerceout) SEXP %{ %} + + %typemap(scoerceout) SWIGTYPE + %{ $result <- new("$&R_class", ref=$result); %} + + %typemap(scoerceout) SWIGTYPE & + %{ $result <- new("$R_class", ref=$result) ; %} + + %typemap(scoerceout) SWIGTYPE * + %{ $result <- new("$R_class", ref=$result) ; %} + + %typemap(scoerceout) SWIGTYPE *const + %{ $result <- new("$R_class", ref=$result) ; %} + + +/* Override the SWIGTYPE * above. */ +%typemap(scoerceout) char, + char *, + char &, + float, + double, + float*, + double*, + float &, + double &, + int, + int &, + long, + long &, + bool, + bool &, + string, + std::string, + string &, + std::string &, + void, + signed int, + signed int &, + unsigned int, + unsigned int &, + short, + short &, + unsigned short, + unsigned short &, + long long, + signed long long, + signed long long &, + unsigned long long, + unsigned long long &, + signed long, + signed long &, + unsigned long, + unsigned long &, + signed char, + signed char &, + unsigned char, + unsigned char & + %{ %} + +%apply int {size_t, +std::size_t, +ptrdiff_t, +std::ptrdiff_t, +signed int, +unsigned int, +short, +unsigned short, +signed char, +unsigned char} + +%apply int* {size_t[], +std::size_t[], +ptrdiff_t[], +std::ptrdiff_t[], +signed int[], +unsigned int[], +short[], +unsigned short[], +signed char[], +unsigned char[]} + +%apply int* {size_t[ANY], +std::size_t[ANY], +ptrdiff_t[ANY], +std::ptrdiff_t[ANY], +signed int[ANY], +unsigned int[ANY], +short[ANY], +unsigned short[ANY], +signed char[ANY], +unsigned char[ANY]} + +%apply int* {size_t*, +std::size_t*, +ptrdiff_t*, +std::ptrdiff_t*, +signed int*, +unsigned int*, +short*, +unsigned short*, +signed char*, +unsigned char*} + +%apply long { + long long, + signed long long, + unsigned long long, + signed long, + unsigned long} + +%apply long* { + long long*, + signed long long*, + unsigned long long*, + signed long*, + unsigned long*, + long long[], + signed long long[], + unsigned long long[], + signed long[], + unsigned long[], + long long[ANY], + signed long long[ANY], + unsigned long long[ANY], + signed long[ANY], + unsigned long[ANY]} + +%apply float* { + float[], + float[ANY] +} +%apply double * { + double[], + double[ANY] +} + +%apply bool* { + bool[], + bool[ANY] +} + +#if 0 + Just examining the values for a SWIGTYPE. + +%typemap(scoerceout) SWIGTYPE %{ + + name = $1_name + type = $1_type + ltype = $1_ltype + + mangle = $1_mangle + descriptor = $1_descriptor + + pointer type = $*1_type + pointer ltype = $*1_ltype + + pointer descriptor = $*1_descriptor + basetype = $*_basetype + +%} +#endif + + diff --git a/share/swig/2.0.11/r/srun.swg b/share/swig/2.0.11/r/srun.swg new file mode 100644 index 0000000..71a508d --- /dev/null +++ b/share/swig/2.0.11/r/srun.swg @@ -0,0 +1,150 @@ +# srun.swg # +# +# This is the basic code that is needed at run time within R to +# provide and define the relevant classes. It is included +# automatically in the generated code by copying the contents of +# srun.swg into the newly created binding code. + + +# This could be provided as a separate run-time library but this +# approach allows the code to to be included directly into the +# generated bindings and so removes the need to have and install an +# additional library. We may however end up with multiple copies of +# this and some confusion at run-time as to which class to use. This +# is an issue when we use NAMESPACES as we may need to export certain +# classes. + +###################################################################### + +if(length(getClassDef("RSWIGStruct")) == 0) + setClass("RSWIGStruct", representation("VIRTUAL")) + + + +if(length(getClassDef("ExternalReference")) == 0) +# Should be virtual but this means it loses its slots currently +#representation("VIRTUAL") + setClass("ExternalReference", representation( ref = "externalptr")) + + + +if(length(getClassDef("NativeRoutinePointer")) == 0) + setClass("NativeRoutinePointer", + representation(parameterTypes = "character", + returnType = "character", + "VIRTUAL"), + contains = "ExternalReference") + +if(length(getClassDef("CRoutinePointer")) == 0) + setClass("CRoutinePointer", contains = "NativeRoutinePointer") + + +if(length(getClassDef("EnumerationValue")) == 0) + setClass("EnumerationValue", contains = "integer") + + +if(!isGeneric("copyToR")) + setGeneric("copyToR", + function(value, obj = new(gsub("Ref$", "", class(value)))) + standardGeneric("copyToR" + )) + +setGeneric("delete", function(obj) standardGeneric("delete")) + + +SWIG_createNewRef = +function(className, ..., append = TRUE) +{ + f = get(paste("new", className, sep = "_"), mode = "function") + + f(...) +} + +if(!isGeneric("copyToC")) + setGeneric("copyToC", + function(value, obj = RSWIG_createNewRef(class(value))) + standardGeneric("copyToC" + )) + + +# +defineEnumeration = +function(name, .values, where = topenv(parent.frame()), suffix = "Value") +{ + # Mirror the class definitions via the E analogous to .__C__ + defName = paste(".__E__", name, sep = "") + assign(defName, .values, envir = where) + + if(nchar(suffix)) + name = paste(name, suffix, sep = "") + + setClass(name, contains = "EnumerationValue", where = where) +} + +enumToInteger <- function(name,type) +{ + if (is.character(name)) { + ans <- as.integer(get(paste(".__E__", type, sep = ""))[name]) + if (is.na(ans)) {warning("enum not found ", name, " ", type)} + ans + } +} + +enumFromInteger = +function(i,type) +{ + itemlist <- get(paste(".__E__", type, sep="")) + names(itemlist)[match(i, itemlist)] +} + +coerceIfNotSubclass = +function(obj, type) +{ + if(!is(obj, type)) {as(obj, type)} else obj +} + + +setClass("SWIGArray", representation(dims = "integer"), contains = "ExternalReference") + +setMethod("length", "SWIGArray", function(x) x@dims[1]) + + +defineEnumeration("SCopyReferences", + .values = c( "FALSE" = 0, "TRUE" = 1, "DEEP" = 2)) + +assert = +function(condition, message = "") +{ + if(!condition) + stop(message) + + TRUE +} + + +if(FALSE) { +print.SWIGFunction = +function(x, ...) + { + } +} + + +####################################################################### + +R_SWIG_getCallbackFunctionStack = +function() +{ + # No PACKAGE argument as we don't know what the DLL is. + .Call("R_SWIG_debug_getCallbackFunctionData") +} + +R_SWIG_addCallbackFunctionStack = +function(fun, userData = NULL) +{ + # No PACKAGE argument as we don't know what the DLL is. + .Call("R_SWIG_R_pushCallbackFunctionData", fun, userData) +} + + +#######################################################################
\ No newline at end of file diff --git a/share/swig/2.0.11/r/std_alloc.i b/share/swig/2.0.11/r/std_alloc.i new file mode 100644 index 0000000..87fa8d4 --- /dev/null +++ b/share/swig/2.0.11/r/std_alloc.i @@ -0,0 +1 @@ +%include <std/std_alloc.i>
\ No newline at end of file diff --git a/share/swig/2.0.11/r/std_common.i b/share/swig/2.0.11/r/std_common.i new file mode 100644 index 0000000..8e97521 --- /dev/null +++ b/share/swig/2.0.11/r/std_common.i @@ -0,0 +1,73 @@ +%include <rstdcommon.swg> + + +/* + Generate the traits for a 'primitive' type, such as 'double', + for which the SWIG_AsVal and SWIG_From methods are already defined. +*/ + +%define %traits_ptypen(Type...) + %fragment(SWIG_Traits_frag(Type),"header", + fragment=SWIG_AsVal_frag(Type), + fragment=SWIG_From_frag(Type), + fragment="StdTraits") { +namespace swig { + template <> struct traits<Type > { + typedef value_category category; + static const char* type_name() { return #Type; } + }; + template <> struct traits_asval<Type > { + typedef Type value_type; + static int asval(SEXP obj, value_type *val) { + return SWIG_AsVal(Type)(obj, val); + } + }; + template <> struct traits_from<Type > { + typedef Type value_type; + static SEXP from(const value_type& val) { + return SWIG_From(Type)(val); + } + }; +} +} +%enddef + +/* Traits for enums. This is bit of a sneaky trick needed because a generic template specialization of enums + is not possible (unless using template meta-programming which SWIG doesn't support because of the explicit + instantiations required using %template). The STL containers define the 'front' method and the typemap + below is used whenever the front method is wrapped returning an enum. This typemap simply picks up the + standard enum typemap, but additionally drags in a fragment containing the traits_asval and traits_from + required in the generated code for enums. */ + +%define %traits_enum(Type...) + %fragment("SWIG_Traits_enum_"{Type},"header", + fragment=SWIG_AsVal_frag(int), + fragment=SWIG_From_frag(int), + fragment="StdTraits") { +namespace swig { + template <> struct traits_asval<Type > { + typedef Type value_type; + static int asval(SEXP obj, value_type *val) { + return SWIG_AsVal(int)(obj, (int *)val); + } + }; + template <> struct traits_from<Type > { + typedef Type value_type; + static SEXP from(const value_type& val) { + return SWIG_From(int)((int)val); + } + }; +} +} +%typemap(out, fragment="SWIG_Traits_enum_"{Type}) const enum SWIGTYPE& front %{$typemap(out, const enum SWIGTYPE&)%} +%enddef + + +%include <std/std_common.i> + +// +// Generates the traits for all the known primitive +// C++ types (int, double, ...) +// +%apply_cpptypes(%traits_ptypen); + diff --git a/share/swig/2.0.11/r/std_container.i b/share/swig/2.0.11/r/std_container.i new file mode 100644 index 0000000..076c1c6 --- /dev/null +++ b/share/swig/2.0.11/r/std_container.i @@ -0,0 +1,2 @@ +%include <rcontainer.swg> +%include <std/std_container.i> diff --git a/share/swig/2.0.11/r/std_deque.i b/share/swig/2.0.11/r/std_deque.i new file mode 100644 index 0000000..0c757ab --- /dev/null +++ b/share/swig/2.0.11/r/std_deque.i @@ -0,0 +1 @@ +%include<std/std_deque.i>
\ No newline at end of file diff --git a/share/swig/2.0.11/r/std_except.i b/share/swig/2.0.11/r/std_except.i new file mode 100644 index 0000000..af98428 --- /dev/null +++ b/share/swig/2.0.11/r/std_except.i @@ -0,0 +1 @@ +%include <typemaps/std_except.swg> diff --git a/share/swig/2.0.11/r/std_list.i b/share/swig/2.0.11/r/std_list.i new file mode 100644 index 0000000..d67ec02 --- /dev/null +++ b/share/swig/2.0.11/r/std_list.i @@ -0,0 +1,5 @@ +#define %swig_list_methods(Type...) %swig_sequence_methods(Type) +#define %swig_list_methods_val(Type...) %swig_sequence_methods_val(Type); + +%include <std/std_list.i> + diff --git a/share/swig/2.0.11/r/std_map.i b/share/swig/2.0.11/r/std_map.i new file mode 100644 index 0000000..5605751 --- /dev/null +++ b/share/swig/2.0.11/r/std_map.i @@ -0,0 +1,5 @@ +%fragment("StdMapTraits","header") +%{ +%} + +%include <std/std_map.i> diff --git a/share/swig/2.0.11/r/std_pair.i b/share/swig/2.0.11/r/std_pair.i new file mode 100644 index 0000000..e980344 --- /dev/null +++ b/share/swig/2.0.11/r/std_pair.i @@ -0,0 +1,5 @@ +%fragment("StdPairTraits","header") +%{ +%} + +%include<std/std_pair.i> diff --git a/share/swig/2.0.11/r/std_string.i b/share/swig/2.0.11/r/std_string.i new file mode 100644 index 0000000..dc1378a --- /dev/null +++ b/share/swig/2.0.11/r/std_string.i @@ -0,0 +1 @@ +%include <typemaps/std_string.swg> diff --git a/share/swig/2.0.11/r/std_vector.i b/share/swig/2.0.11/r/std_vector.i new file mode 100644 index 0000000..836c95b --- /dev/null +++ b/share/swig/2.0.11/r/std_vector.i @@ -0,0 +1,608 @@ +// R specific swig components +/* + Vectors +*/ + +%fragment("StdVectorTraits","header",fragment="StdSequenceTraits") +%{ + namespace swig { + // vectors of doubles + template <> + struct traits_from_ptr<std::vector<double> > { + static SEXP from (std::vector<double > *val, int owner = 0) { + SEXP result; + PROTECT(result = Rf_allocVector(REALSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + NUMERIC_POINTER(result)[pos] = ((*val)[pos]); + } + UNPROTECT(1); + return(result); + } + }; + // vectors of floats + template <> + struct traits_from_ptr<std::vector<float> > { + static SEXP from (std::vector<float > *val, int owner = 0) { + SEXP result; + PROTECT(result = Rf_allocVector(REALSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + NUMERIC_POINTER(result)[pos] = ((*val)[pos]); + } + UNPROTECT(1); + return(result); + } + }; + // vectors of unsigned int + template <> + struct traits_from_ptr<std::vector<unsigned int> > { + static SEXP from (std::vector<unsigned int > *val, int owner = 0) { + SEXP result; + PROTECT(result = Rf_allocVector(INTSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + INTEGER_POINTER(result)[pos] = ((*val)[pos]); + } + UNPROTECT(1); + return(result); + } + }; + // vectors of int + template <> + struct traits_from_ptr<std::vector<int> > { + static SEXP from (std::vector<int > *val, int owner = 0) { + SEXP result; + PROTECT(result = Rf_allocVector(INTSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + INTEGER_POINTER(result)[pos] = ((*val)[pos]); + } + UNPROTECT(1); + return(result); + } + }; + + // vectors of bool + template <> + struct traits_from_ptr<std::vector<bool> > { + static SEXP from (std::vector<bool> *val, int owner = 0) { + SEXP result; + PROTECT(result = Rf_allocVector(LGLSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + LOGICAL_POINTER(result)[pos] = ((*val)[pos]); + } + UNPROTECT(1); + return(result); + //return SWIG_R_NewPointerObj(val, type_info< std::vector<T > >(), owner); + } + }; + // vectors of strings + template <> + struct traits_from_ptr<std::vector<std::basic_string<char> > > { + static SEXP from (std::vector<std::basic_string<char> > *val, int owner = 0) { + SEXP result; + PROTECT(result = Rf_allocVector(STRSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + CHARACTER_POINTER(result)[pos] = Rf_mkChar(((*val)[pos]).c_str()); + } + UNPROTECT(1); + return(result); + //return SWIG_R_NewPointerObj(val, type_info< std::vector<T > >(), owner); + } + }; + + // catch all that does everything with vectors + template <typename T> + struct traits_from_ptr< std::vector< T > > { + static SEXP from (std::vector< T > *val, int owner = 0) { + return SWIG_R_NewPointerObj(val, type_info< std::vector< T > >(), owner); + } + }; + + template <> + struct traits_asptr < std::vector<double> > { + static int asptr(SEXP obj, std::vector<double> **val) { + std::vector<double> *p; + // not sure how to check the size of the SEXP obj is correct + unsigned int sexpsz = Rf_length(obj); + p = new std::vector<double>(sexpsz); + double *S = NUMERIC_POINTER(obj); + for (unsigned pos = 0; pos < p->size(); pos++) + { + (*p)[pos] = static_cast<double>(S[pos]); + } + int res = SWIG_OK; + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + return res; + } + }; + + template <> + struct traits_asptr < std::vector<float> > { + static int asptr(SEXP obj, std::vector<float> **val) { + std::vector<float> *p; + // not sure how to check the size of the SEXP obj is correct + unsigned int sexpsz = Rf_length(obj); + p = new std::vector<float>(sexpsz); + double *S = NUMERIC_POINTER(obj); + for (unsigned pos = 0; pos < p->size(); pos++) + { + (*p)[pos] = static_cast<double>(S[pos]); + } + int res = SWIG_OK; + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + return res; + } + }; + + template <> + struct traits_asptr < std::vector<unsigned int> > { + static int asptr(SEXP obj, std::vector<unsigned int> **val) { + std::vector<unsigned int> *p; + unsigned int sexpsz = Rf_length(obj); + p = new std::vector<unsigned int>(sexpsz); + SEXP coerced; + PROTECT(coerced = Rf_coerceVector(obj, INTSXP)); + int *S = INTEGER_POINTER(coerced); + for (unsigned pos = 0; pos < p->size(); pos++) + { + (*p)[pos] = static_cast<unsigned int>(S[pos]); + } + int res = SWIG_OK; + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + UNPROTECT(1); + return res; + } + }; + + template <> + struct traits_asptr < std::vector<int> > { + static int asptr(SEXP obj, std::vector<int> **val) { + std::vector<int> *p; + // not sure how to check the size of the SEXP obj is correct + int sexpsz = Rf_length(obj); + p = new std::vector<int>(sexpsz); + SEXP coerced; + PROTECT(coerced = Rf_coerceVector(obj, INTSXP)); + int *S = INTEGER_POINTER(coerced); + for (unsigned pos = 0; pos < p->size(); pos++) + { + (*p)[pos] = static_cast<int>(S[pos]); + } + int res = SWIG_OK; + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + UNPROTECT(1); + return res; + } + }; + + template <> + struct traits_asptr < std::vector<bool> > { + static int asptr(SEXP obj, std::vector<bool> **val) { + std::vector<bool> *p; + // not sure how to check the size of the SEXP obj is correct + int sexpsz = Rf_length(obj); + p = new std::vector<bool>(sexpsz); + SEXP coerced; + PROTECT(coerced = Rf_coerceVector(obj, LGLSXP)); + int *S = LOGICAL_POINTER(coerced); + for (unsigned pos = 0; pos < p->size(); pos++) + { + (*p)[pos] = static_cast<bool>(S[pos]); + } + int res = SWIG_OK; + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + UNPROTECT(1); + return res; + } + }; + + // catchall for R to vector conversion + template <typename T> + struct traits_asptr < std::vector<T> > { + static int asptr(SEXP obj, std::vector<T> **val) { + std::vector<T> *p; + Rprintf("my asptr\n"); + int res = SWIG_R_ConvertPtr(obj, (void**)&p, type_info< std::vector<T> >(), 0); + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + return res; + } + }; + + // now for vectors of vectors. These will be represented as lists of vectors on the + // catch all that does everything with vectors + template <> + struct traits_from_ptr<std::vector<std::vector<unsigned int> > > { + static SEXP from (std::vector< std::vector<unsigned int > > *val, int owner = 0) { + SEXP result; + // allocate the R list + PROTECT(result = Rf_allocVector(VECSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + // allocate the R vector + SET_VECTOR_ELT(result, pos, Rf_allocVector(INTSXP, val->at(pos).size())); + // Fill the R vector + for (unsigned vpos = 0; vpos < val->at(pos).size(); ++vpos) + { + INTEGER_POINTER(VECTOR_ELT(result, pos))[vpos] = static_cast<int>(val->at(pos).at(vpos)); + } + } + UNPROTECT(1); + return(result); + } + }; + + template <> + struct traits_from_ptr<std::vector<std::vector<int> > > { + static SEXP from (std::vector< std::vector<int > > *val, int owner = 0) { + SEXP result; + // allocate the R list + PROTECT(result = Rf_allocVector(VECSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + // allocate the R vector + SET_VECTOR_ELT(result, pos, Rf_allocVector(INTSXP, val->at(pos).size())); + // Fill the R vector + for (unsigned vpos = 0; vpos < val->at(pos).size(); ++vpos) + { + INTEGER_POINTER(VECTOR_ELT(result, pos))[vpos] = static_cast<int>(val->at(pos).at(vpos)); + } + } + UNPROTECT(1); + return(result); + } + }; + + template <> + struct traits_from_ptr<std::vector<std::vector<float> > > { + static SEXP from (std::vector< std::vector<float > > *val, int owner = 0) { + SEXP result; + // allocate the R list + PROTECT(result = Rf_allocVector(VECSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + // allocate the R vector + SET_VECTOR_ELT(result, pos, Rf_allocVector(REALSXP, val->at(pos).size())); + // Fill the R vector + for (unsigned vpos = 0; vpos < val->at(pos).size(); ++vpos) + { + NUMERIC_POINTER(VECTOR_ELT(result, pos))[vpos] = static_cast<double>(val->at(pos).at(vpos)); + } + } + UNPROTECT(1); + return(result); + } + }; + + template <> + struct traits_from_ptr<std::vector<std::vector<double> > > { + static SEXP from (std::vector< std::vector<double > > *val, int owner = 0) { + SEXP result; + // allocate the R list + PROTECT(result = Rf_allocVector(VECSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + // allocate the R vector + SET_VECTOR_ELT(result, pos, Rf_allocVector(REALSXP, val->at(pos).size())); + // Fill the R vector + for (unsigned vpos = 0; vpos < val->at(pos).size(); ++vpos) + { + NUMERIC_POINTER(VECTOR_ELT(result, pos))[vpos] = static_cast<double>(val->at(pos).at(vpos)); + } + } + UNPROTECT(1); + return(result); + } + }; + + template <> + struct traits_from_ptr<std::vector<std::vector<bool> > > { + static SEXP from (std::vector< std::vector<bool> > *val, int owner = 0) { + SEXP result; + // allocate the R list + PROTECT(result = Rf_allocVector(VECSXP, val->size())); + for (unsigned pos = 0; pos < val->size(); pos++) + { + // allocate the R vector + SET_VECTOR_ELT(result, pos, Rf_allocVector(LGLSXP, val->at(pos).size())); + // Fill the R vector + for (unsigned vpos = 0; vpos < val->at(pos).size(); ++vpos) + { + LOGICAL_POINTER(VECTOR_ELT(result, pos))[vpos] = (val->at(pos).at(vpos)); + } + } + UNPROTECT(1); + return(result); + } + }; + + template <typename T> + struct traits_from_ptr< std::vector < std::vector< T > > > { + static SEXP from (std::vector < std::vector< T > > *val, int owner = 0) { + return SWIG_R_NewPointerObj(val, type_info< std::vector < std::vector< T > > >(), owner); + } + }; + + // R side + template <> + struct traits_asptr < std::vector< std::vector<unsigned int> > > { + static int asptr(SEXP obj, std::vector< std::vector<unsigned int> > **val) { + std::vector <std::vector<unsigned int> > *p; + // this is the length of the list + unsigned int sexpsz = Rf_length(obj); + p = new std::vector< std::vector<unsigned int> > (sexpsz); + + for (unsigned listpos = 0; listpos < sexpsz; ++listpos) + { + unsigned vecsize = Rf_length(VECTOR_ELT(obj, listpos)); + for (unsigned vpos = 0; vpos < vecsize; ++vpos) + { + (*p)[listpos].push_back(static_cast<int>(INTEGER_POINTER(VECTOR_ELT(obj, listpos))[vpos])); + } + } + + int res = SWIG_OK; + + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + return res; + } + }; + + template <> + struct traits_asptr < std::vector< std::vector< int> > > { + static int asptr(SEXP obj, std::vector< std::vector< int> > **val) { + std::vector <std::vector< int> > *p; + // this is the length of the list + unsigned int sexpsz = Rf_length(obj); + p = new std::vector< std::vector< int> > (sexpsz); + + for (unsigned listpos = 0; listpos < sexpsz; ++listpos) + { + unsigned vecsize = Rf_length(VECTOR_ELT(obj, listpos)); + for (unsigned vpos = 0; vpos < vecsize; ++vpos) + { + (*p)[listpos].push_back(static_cast<int>(INTEGER_POINTER(VECTOR_ELT(obj, listpos))[vpos])); + } + } + + int res = SWIG_OK; + + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + return res; + } + }; + + template <> + struct traits_asptr < std::vector< std::vector< float> > > { + static int asptr(SEXP obj, std::vector< std::vector< float> > **val) { + std::vector <std::vector< float> > *p; + // this is the length of the list + unsigned int sexpsz = Rf_length(obj); + p = new std::vector< std::vector< float> > (sexpsz); + + for (unsigned listpos = 0; listpos < sexpsz; ++listpos) + { + unsigned vecsize = Rf_length(VECTOR_ELT(obj, listpos)); + for (unsigned vpos = 0; vpos < vecsize; ++vpos) + { + (*p)[listpos].push_back(static_cast<float>(NUMERIC_POINTER(VECTOR_ELT(obj, listpos))[vpos])); + } + } + + int res = SWIG_OK; + + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + return res; + } + }; + + template <> + struct traits_asptr < std::vector< std::vector< double> > > { + static int asptr(SEXP obj, std::vector< std::vector< double> > **val) { + std::vector <std::vector< double> > *p; + // this is the length of the list + unsigned int sexpsz = Rf_length(obj); + p = new std::vector< std::vector< double> > (sexpsz); + + for (unsigned listpos = 0; listpos < sexpsz; ++listpos) + { + unsigned vecsize = Rf_length(VECTOR_ELT(obj, listpos)); + for (unsigned vpos = 0; vpos < vecsize; ++vpos) + { + (*p)[listpos].push_back(static_cast<double>(NUMERIC_POINTER(VECTOR_ELT(obj, listpos))[vpos])); + } + } + + int res = SWIG_OK; + + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + return res; + } + }; + + template <> + struct traits_asptr < std::vector< std::vector< bool > > > { + static int asptr(SEXP obj, std::vector< std::vector< bool> > **val) { + std::vector <std::vector< bool > > *p; + // this is the length of the list + unsigned int sexpsz = Rf_length(obj); + p = new std::vector< std::vector< bool > > (sexpsz); + + for (unsigned listpos = 0; listpos < sexpsz; ++listpos) + { + unsigned vecsize = Rf_length(VECTOR_ELT(obj, listpos)); + for (unsigned vpos = 0; vpos < vecsize; ++vpos) + { + (*p)[listpos].push_back(static_cast<bool>(LOGICAL_POINTER(VECTOR_ELT(obj, listpos))[vpos])); + } + } + + int res = SWIG_OK; + + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + return res; + } + }; + + // catchall + template <typename T> + struct traits_asptr < std::vector< std::vector<T> > > { + static int asptr(SEXP obj, std::vector< std::vector<T> > **val) { + std::vector< std::vector<T> > *p; + Rprintf("vector of vectors - unsupported content\n"); + int res = SWIG_R_ConvertPtr(obj, (void**)&p, type_info< std::vector< std::vector<T> > > (), 0); + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + return res; + } + }; + + } +%} + +#define %swig_vector_methods(Type...) %swig_sequence_methods(Type) +#define %swig_vector_methods_val(Type...) %swig_sequence_methods_val(Type); + +%define %traits_type_name(Type...) +%fragment(SWIG_Traits_frag(Type), "header", + fragment="StdTraits",fragment="StdVectorTraits") { + namespace swig { + template <> struct traits< Type > { + typedef pointer_category category; + static const char* type_name() { + return #Type; + } + }; + } + } +%enddef + +%include <std/std_vector.i> + +%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<double>) +%traits_type_name(std::vector<double>) +%typemap("rtypecheck") std::vector<double>, std::vector<double> const, std::vector<double> const& + %{ is.numeric($arg) %} +%typemap("rtype") std::vector<double> "numeric" +%typemap("scoercein") std::vector<double>, std::vector<double> const, std::vector<double> const& ""; + +%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<float>) +%traits_type_name(std::vector<float>) +%typemap("rtypecheck") std::vector<float>, std::vector<float> const, std::vector<float> const& + %{ is.numeric($arg) %} +%typemap("rtype") std::vector<float> "numeric" +%typemap("scoercein") std::vector<double>, std::vector<float> const, std::vector<float> const& ""; + +%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<bool>); +%traits_type_name(std::vector<bool>); +%typemap("rtypecheck") std::vector<bool> , std::vector<bool> const, std::vector<bool> const& + %{ is.logical($arg) %} +%typemap("rtype") std::vector<bool> "logical" +%typemap("scoercein") std::vector<bool> , std::vector<bool> const, std::vector<bool> const& "$input = as.logical($input);"; + +%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<int>); +%traits_type_name(std::vector<int>); +%typemap("rtypecheck") std::vector<int> , std::vector<int> const, std::vector<int> const& + %{ is.integer($arg) || is.numeric($arg) %} +%typemap("rtype") std::vector<int> "integer" +%typemap("scoercein") std::vector<int> , std::vector<int> const, std::vector<int> const& "$input = as.integer($input);"; + +%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<unsigned int>); +%traits_type_name(std::vector<unsigned int>); +%typemap("rtypecheck") std::vector<unsigned int>, std::vector<unsigned int> const, std::vector<unsigned int> const& +%{ is.integer($arg) || is.numeric($arg) %} +%typemap("rtype") std::vector<unsigned int> "integer" +%typemap("scoercein") std::vector<unsigned int>, std::vector<unsigned int> const, std::vector<unsigned int> const& "$input = as.integer($input);"; + +%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<std::vector<unsigned int> >); +%traits_type_name(std::vector< std::vector<unsigned int> >); +%typemap("rtypecheck") std::vector<std::vector<unsigned int> >, std::vector<std::vector<unsigned int> > const, std::vector<std::vector<unsigned int> >const& + %{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %} +%typemap("rtype") std::vector<std::vector<unsigned int> > "list" +%typemap("scoercein") std::vector< std::vector<unsigned int> >, std::vector<std::vector<unsigned int> > const, std::vector<std::vector<unsigned int> >const& "$input = lapply($input, as.integer);"; + +%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<std::vector<int> >); +%traits_type_name(std::vector< std::vector<int> >); +%typemap("rtypecheck") std::vector<std::vector<int> >, std::vector<std::vector<int> > const, std::vector<std::vector<int> >const& + %{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %} +%typemap("rtype") std::vector<std::vector<int> > "list" +%typemap("scoercein") std::vector< std::vector<int> >, std::vector<std::vector<int> > const, std::vector<std::vector<int> >const& "$input = lapply($input, as.integer);"; + +%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<std::vector<float> >); +%traits_type_name(std::vector< std::vector<float> >); +%typemap("rtypecheck") std::vector<std::vector<float> >, std::vector<std::vector<float> > const, std::vector<std::vector<float> >const& + %{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %} +%typemap("rtype") std::vector<std::vector<float> > "list" +%typemap("scoercein") std::vector< std::vector<float> >, std::vector<std::vector<float> > const, std::vector<std::vector<float> >const& "$input = lapply($input, as.numeric);"; + +%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<std::vector<double> >); +%traits_type_name(std::vector< std::vector<double> >); +%typemap("rtypecheck") std::vector<std::vector<double> >, std::vector<std::vector<double> > const, std::vector<std::vector<double> >const& + %{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %} +%typemap("rtype") std::vector<std::vector<double> > "list" +%typemap("scoercein") std::vector< std::vector<double> >, std::vector<std::vector<double> > const, std::vector<std::vector<double> >const& + "$input = lapply($input, as.numeric);"; + +%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<std::vector<bool> >); +%traits_type_name(std::vector< std::vector<bool> >); +%typemap("rtypecheck") std::vector<std::vector<bool> >, std::vector<std::vector<bool> > const, std::vector<std::vector<bool> >const& + %{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %} +%typemap("rtype") std::vector<std::vector<bool> > "list" +%typemap("scoercein") std::vector< std::vector<bool> >, std::vector<std::vector<bool> > const, std::vector<std::vector<bool> >const& "$input = lapply($input, as.logical);"; + +// we don't want these to be given R classes as they +// have already been turned into R vectors. +%typemap(scoerceout) std::vector<double>, + std::vector<double> *, + std::vector<double> &, + std::vector<bool>, + std::vector<bool> *, + std::vector<bool> &, + std::vector<unsigned int>, + std::vector<unsigned int> *, + std::vector<unsigned int> &, + // vectors of vectors + std::vector< std::vector<unsigned int> >, + std::vector< std::vector<unsigned int> >*, + std::vector< std::vector<unsigned int> >&, + std::vector< std::vector<int> >, + std::vector< std::vector<int> >*, + std::vector< std::vector<int> >&, + std::vector< std::vector<float> >, + std::vector< std::vector<float> >*, + std::vector< std::vector<float> >&, + std::vector< std::vector<double> >, + std::vector< std::vector<double> >*, + std::vector< std::vector<double> >&, + std::vector< std::vector<bool> >, + std::vector< std::vector<bool> >*, + std::vector< std::vector<bool> >& + + + %{ %} diff --git a/share/swig/2.0.11/r/stl.i b/share/swig/2.0.11/r/stl.i new file mode 100644 index 0000000..37e2ccb --- /dev/null +++ b/share/swig/2.0.11/r/stl.i @@ -0,0 +1,10 @@ +/* initial STL definition. extended as needed in each language */ +%include std_common.i +%include std_vector.i +%include std_pair.i +%include std_string.i + + + + + diff --git a/share/swig/2.0.11/r/typemaps.i b/share/swig/2.0.11/r/typemaps.i new file mode 100644 index 0000000..1f9b9c4 --- /dev/null +++ b/share/swig/2.0.11/r/typemaps.i @@ -0,0 +1 @@ +%include <typemaps/typemaps.swg> |