Merge branch 'master' into gsoc2009-matevz

parser.y still to be fixed up

Conflicts:
	Doc/Devel/engineering.html
	Examples/Makefile.in
	Lib/allegrocl/allegrocl.swg
	Lib/csharp/csharp.swg
	Lib/csharp/enums.swg
	Lib/csharp/enumsimple.swg
	Lib/csharp/enumtypesafe.swg
	Lib/java/java.swg
	Lib/python/pydocs.swg
	Lib/r/rtype.swg
	Source/Include/swigwarn.h
	Source/Modules/octave.cxx
	Source/Modules/python.cxx
	Source/Modules/ruby.cxx
	Source/Swig/scanner.c
	Source/Swig/stype.c
	Source/Swig/swig.h
	configure.ac
This commit is contained in:
William S Fulton 2013-01-28 07:01:37 +00:00
commit e805d5f925
1074 changed files with 54339 additions and 20134 deletions

View file

@ -16,6 +16,7 @@
float, double, long double, char *, void *,
enum SWIGTYPE "(cl::setq ACL_ffresult $body)";
%typemap(lout) void "$body";
#ifdef __cplusplus
%typemap(lout) SWIGTYPE[ANY], SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&
%{ (cl:let* ((address $body)
(new-inst (cl:make-instance '$lclass :foreign-address address)))
@ -24,6 +25,12 @@
(cl:setq ACL_ffresult new-inst)) %}
%typemap(lout) SWIGTYPE "(cl::let* ((address $body)\n (new-inst (cl::make-instance '$lclass :foreign-address address)))\n (cl::unless (cl::zerop address)\n (excl:schedule-finalization new-inst #'$ldestructor))\n (cl::setq ACL_ffresult new-inst))";
#else
%typemap(lout) SWIGTYPE[ANY], SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE
%{ (cl:let* ((address $body)
(new-inst (cl:make-instance '$lclass :foreign-address address)))
(cl:setq ACL_ffresult new-inst)) %}
#endif
%typemap(lisptype) bool, const bool "cl:boolean";
%typemap(lisptype) char, const char "cl:character";

View file

@ -7,27 +7,43 @@
* functions have been defined.
* ----------------------------------------------------------------------------- */
%typemap(in) long long, unsigned long long "$1 = $input;";
%typemap(out) long long, unsigned long long "$result = &$1;";
#ifdef Acl64Bit
%typemap(ctype) long long, unsigned long long "$1_ltype";
%typemap(out) long long, unsigned long long "$result = $1;";
%typemap(ffitype) long long ":nat";
%typemap(ffitype) unsigned long long ":unsigned-nat";
%typemap(lout) long long, unsigned long long " #+64bit (cl::setq ACL_ffresult $body)";
#else
%typemap(out) long long, unsigned long long "$result = &$1;";
%typemap(ffitype) long long "(:struct (l1 :long) (l2 :long))";
%typemap(ffitype) unsigned long long "(:struct (l1 :unsigned-long)
(l2 :unsigned-long))";
%typemap(ffitype) unsigned long long "(:struct (l1 :unsigned-long) (l2 :unsigned-long))";
%typemap(lout) long long
" (make-instance #.(swig-insert-id \"longlong\" () :type :class)
:foreign-address $body)";
" (cl::setq ACL_ffresult (make-instance '#.(swig-insert-id \"longlong\" () :type :class)
:foreign-address $body))";
%typemap(lout) unsigned long long
" (make-instance #.(swig-insert-id \"ulonglong\" () :type :class)
:foreign-address $body)";
" (cl:setq ACL_ffresult (make-instance '#.(swig-insert-id \"ulonglong\" () :type :class)
:foreign-address $body))";
#endif
%typemap(in) long long, unsigned long long "$1 = $input;";
%insert("lisphead") %{
#-64bit
(swig-def-foreign-class "longlong"
(ff:foreign-pointer)
(:struct (:struct (l1 :long) (l2 :long))))
(:struct (l1 :long) (l2 :long)))
#-64bit
(swig-def-foreign-class "ulonglong"
(ff:foreign-pointer)
(:struct (:struct (l1 :unsigned-long) (l2 :unsigned-long))))
(:struct (l1 :unsigned-long) (l2 :unsigned-long)))
%}

View file

@ -17,12 +17,6 @@
%{
#include <string>
// #include <vector>
// using std::vector;
using std::string;
%}
// %include <std_vector.i>
@ -127,7 +121,7 @@ namespace std {
// SWIG_exception(SWIG_TypeError, "string expected");
// }
// %typemap(in) const string & (std::string temp) {
// %typemap(in) const string & ($*1_ltype temp) {
// if (caml_ptr_check($input)) {
// temp.assign((char *)caml_ptr_val($input,0),
// caml_string_len($input));
@ -137,7 +131,7 @@ namespace std {
// }
// }
// %typemap(in) string & (std::string temp) {
// %typemap(in) string & ($*1_ltype temp) {
// if (caml_ptr_check($input)) {
// temp.assign((char *)caml_ptr_val($input,0),
// caml_string_len($input));
@ -147,9 +141,9 @@ namespace std {
// }
// }
// %typemap(in) string * (std::string *temp) {
// %typemap(in) string * ($*1_ltype *temp) {
// if (caml_ptr_check($input)) {
// temp = new std::string((char *)caml_ptr_val($input,0),
// temp = new $*1_ltype((char *)caml_ptr_val($input,0),
// caml_string_len($input));
// $1 = temp;
// } else {
@ -157,7 +151,7 @@ namespace std {
// }
// }
// %typemap(free) string * (std::string *temp) {
// %typemap(free) string * ($*1_ltype *temp) {
// delete temp;
// }

View file

@ -18,6 +18,7 @@
%include <chicken/chickenkw.swg>
%include <csharp/csharpkw.swg>
%include <d/dkw.swg>
%include <java/javakw.swg>
%include <php/phpkw.swg>
%include <pike/pikekw.swg>

View file

@ -73,9 +73,8 @@ void NAME##_setitem(TYPE *ary, int index, TYPE value);
%{
typedef TYPE NAME;
%}
typedef struct NAME {
typedef struct {
/* Put language specific enhancements here */
} NAME;
%extend NAME {

View file

@ -548,7 +548,7 @@ $result = C_SCHEME_UNDEFINED;
* String & length
* ------------------------------------------------------------ */
%typemap(in) (char *STRING, int LENGTH) {
%typemap(in) (char *STRING, int LENGTH), (char *STRING, size_t LENGTH) {
if ($input == C_SCHEME_FALSE) {
swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Cannot use a null/#f string for a char*, int arguments");
}

View file

@ -36,7 +36,7 @@ extern "C" {
SWIG_Chicken_Barf(SWIG_BARF1_CONTRACT_ASSERT, C_text(message)); } else
/* Runtime API */
#define SWIG_GetModule(clientdata) SWIG_Chicken_GetModule()
#define SWIG_GetModule(clientdata) SWIG_Chicken_GetModule(clientdata)
#define SWIG_SetModule(clientdata, pointer) SWIG_Chicken_SetModule(pointer)
#define C_swig_is_bool(x) C_truep (C_booleanp (x))
@ -309,7 +309,7 @@ SWIG_Chicken_MustGetPtr (C_word s, swig_type_info *type, int argnum, int flags)
static char *chicken_runtimevar_name = "type_pointer" SWIG_TYPE_TABLE_NAME;
static swig_module_info *
SWIG_Chicken_GetModule() {
SWIG_Chicken_GetModule(void *SWIGUNUSEDPARM(clientdata)) {
swig_module_info *ret = 0;
C_word sym;

View file

@ -44,7 +44,7 @@ namespace std {
}
}
%typemap(in) const string& (std::string temp, char *tempptr) {
%typemap(in) const string& ($*1_ltype temp, char *tempptr) {
if ($input == C_SCHEME_FALSE) {
temp.resize(0);

View file

@ -93,7 +93,6 @@ or you can use the %apply directive :
*/
// These typemaps contributed by Robin Dunn
//----------------------------------------------------------------------
//
// T_OUTPUT typemap (and helper function) to return multiple argouts as

View file

@ -55,14 +55,14 @@ NAME() {
return new TYPE();
}
~NAME() {
if (self) delete self;
if ($self) delete $self;
}
#else
NAME() {
return (TYPE *) calloc(1,sizeof(TYPE));
}
~NAME() {
if (self) free(self);
if ($self) free($self);
}
#endif
}
@ -70,13 +70,13 @@ NAME() {
%extend NAME {
void assign(TYPE value) {
*self = value;
*$self = value;
}
TYPE value() {
return *self;
return *$self;
}
TYPE * cast() {
return self;
return $self;
}
static NAME * frompointer(TYPE *t) {
return (NAME *) t;
@ -126,34 +126,34 @@ static TYPE *copy_##NAME(TYPE value) { %}
#ifdef __cplusplus
%{ return new TYPE(value); %}
#else
%{ TYPE *self = (TYPE *) calloc(1,sizeof(TYPE));
*self = value;
return self; %}
%{ TYPE *obj = (TYPE *) calloc(1,sizeof(TYPE));
*obj = value;
return obj; %}
#endif
%{}
static void delete_##NAME(TYPE *self) { %}
static void delete_##NAME(TYPE *obj) { %}
#ifdef __cplusplus
%{ if (self) delete self; %}
%{ if (obj) delete obj; %}
#else
%{ if (self) free(self); %}
%{ if (obj) free(obj); %}
#endif
%{}
static void NAME ##_assign(TYPE *self, TYPE value) {
*self = value;
static void NAME ##_assign(TYPE *obj, TYPE value) {
*obj = value;
}
static TYPE NAME ##_value(TYPE *self) {
return *self;
static TYPE NAME ##_value(TYPE *obj) {
return *obj;
}
%}
TYPE *new_##NAME();
TYPE *copy_##NAME(TYPE value);
void delete_##NAME(TYPE *self);
void NAME##_assign(TYPE *self, TYPE value);
TYPE NAME##_value(TYPE *self);
void delete_##NAME(TYPE *obj);
void NAME##_assign(TYPE *obj, TYPE value);
TYPE NAME##_value(TYPE *obj);
%enddef

View file

@ -0,0 +1,511 @@
// Users can provide their own SWIG_INTRUSIVE_PTR_TYPEMAPS or SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP macros before including this file to change the
// visibility of the constructor and getCPtr method if desired to public if using multiple modules.
#ifndef SWIG_INTRUSIVE_PTR_TYPEMAPS
#define SWIG_INTRUSIVE_PTR_TYPEMAPS(CONST, TYPE...) SWIG_INTRUSIVE_PTR_TYPEMAPS_IMPLEMENTATION(internal, internal, CONST, TYPE)
#endif
#ifndef SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP
#define SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(CONST, TYPE...) SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP_IMPLEMENTATION(internal, internal, CONST, TYPE)
#endif
%include <intrusive_ptr.i>
// Language specific macro implementing all the customisations for handling the smart pointer
%define SWIG_INTRUSIVE_PTR_TYPEMAPS_IMPLEMENTATION(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, CONST, TYPE...)
// %naturalvar is as documented for member variables
%naturalvar TYPE;
%naturalvar SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >;
// destructor wrapper customisation
%feature("unref") TYPE "(void)arg1; delete smartarg1;"
// Typemap customisations...
%typemap(in, canthrow=1) CONST TYPE ($&1_type argp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
// plain value
argp = (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0;
if (!argp) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null $1_type", 0);
return $null;
}
$1 = *argp;
%}
%typemap(out, fragment="SWIG_intrusive_deleter") CONST TYPE %{
//plain value(out)
$1_ltype* resultp = new $1_ltype(($1_ltype &)$1);
intrusive_ptr_add_ref(resultp);
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(resultp, SWIG_intrusive_deleter< CONST TYPE >());
%}
%typemap(in, canthrow=1) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
// plain pointer
smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input;
$1 = (TYPE *)(smartarg ? smartarg->get() : 0);
%}
%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") CONST TYPE * %{
//plain pointer(out)
#if ($owner)
if ($1) {
intrusive_ptr_add_ref($1);
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1, SWIG_intrusive_deleter< CONST TYPE >());
} else {
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
}
#else
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0;
#endif
%}
%typemap(in, canthrow=1) CONST TYPE & (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
// plain reference
$1 = ($1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0);
if(!$1) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type reference is null", 0);
return $null;
}
%}
%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") CONST TYPE & %{
//plain reference(out)
#if ($owner)
if ($1) {
intrusive_ptr_add_ref($1);
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1, SWIG_intrusive_deleter< CONST TYPE >());
} else {
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
}
#else
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0;
#endif
%}
%typemap(in) TYPE *CONST& ($*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
// plain pointer by reference
temp = ($*1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0);
$1 = &temp;
%}
%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") TYPE *CONST& %{
// plain pointer by reference(out)
#if ($owner)
if (*$1) {
intrusive_ptr_add_ref(*$1);
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1, SWIG_intrusive_deleter< CONST TYPE >());
} else {
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
}
#else
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_0);
#endif
%}
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{
// intrusive_ptr by value
smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input;
if (smartarg) {
$1 = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true);
}
%}
%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > %{
if ($1) {
intrusive_ptr_add_ref($1.get());
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1.get(), SWIG_intrusive_deleter< CONST TYPE >());
} else {
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
}
%}
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast ($&1_type smartarg) %{
// shared_ptr by value
smartarg = *($&1_ltype*)&$input;
if (smartarg) $1 = *smartarg;
%}
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ANY_TYPE_SWIGSharedPtrUpcast %{
*($&1_ltype*)&$result = $1 ? new $1_ltype($1) : 0;
%}
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & ($*1_ltype tempnull, $*1_ltype temp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{
// intrusive_ptr by reference
if ( $input ) {
smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input;
temp = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true);
$1 = &temp;
} else {
$1 = &tempnull;
}
%}
%typemap(memberin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & %{
delete &($1);
if ($self) {
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * temp = new SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(*$input);
$1 = *temp;
}
%}
%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & %{
if (*$1) {
intrusive_ptr_add_ref($1->get());
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1->get(), SWIG_intrusive_deleter< CONST TYPE >());
} else {
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
}
%}
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * ($*1_ltype tempnull, $*1_ltype temp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{
// intrusive_ptr by pointer
if ( $input ) {
smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input;
temp = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true);
$1 = &temp;
} else {
$1 = &tempnull;
}
%}
%typemap(memberin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * %{
delete $1;
if ($self) $1 = new SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(*$input);
%}
%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * %{
if ($1 && *$1) {
intrusive_ptr_add_ref($1->get());
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1->get(), SWIG_intrusive_deleter< CONST TYPE >());
} else {
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
}
if ($owner) delete $1;
%}
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& (SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > temp, $*1_ltype tempp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{
// intrusive_ptr by pointer reference
smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input;
if ($input) {
temp = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true);
}
tempp = &temp;
$1 = &tempp;
%}
%typemap(memberin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& %{
if ($self) $1 = *$input;
%}
%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& %{
if (*$1 && **$1) {
intrusive_ptr_add_ref((*$1)->get());
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >((*$1)->get(), SWIG_intrusive_deleter< CONST TYPE >());
} else {
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
}
%}
// 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"
%}
%typemap (ctype) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "void *"
%typemap (imtype, out="IntPtr") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "HandleRef"
%typemap (cstype) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "$typemap(cstype, TYPE)"
%typemap(csin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "$typemap(cstype, TYPE).getCPtr($csinput)"
%typemap(csout, excode=SWIGEXCODE) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > {
IntPtr cPtr = $imcall;
$typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(csout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
IntPtr cPtr = $imcall;
$typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(csout, excode=SWIGEXCODE) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & {
IntPtr cPtr = $imcall;
$typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(csout, excode=SWIGEXCODE) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * {
IntPtr cPtr = $imcall;
$typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(csout, excode=SWIGEXCODE) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& {
IntPtr cPtr = $imcall;
$typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(csvarout, excode=SWIGEXCODE2) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > %{
get {
$typemap(cstype, TYPE) ret = new $typemap(cstype, TYPE)($imcall, true);$excode
return ret;
} %}
%typemap(csvarout, excode=SWIGEXCODE2) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >& %{
get {
$typemap(cstype, TYPE) ret = new $typemap(cstype, TYPE)($imcall, true);$excode
return ret;
} %}
%typemap(csvarout, excode=SWIGEXCODE2) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >* %{
get {
$typemap(cstype, TYPE) ret = new $typemap(cstype, TYPE)($imcall, true);$excode
return ret;
} %}
%typemap(csout, excode=SWIGEXCODE) CONST TYPE {
$typemap(cstype, TYPE) ret = new $typemap(cstype, TYPE)($imcall, true);$excode
return ret;
}
%typemap(csout, excode=SWIGEXCODE) CONST TYPE & {
$typemap(cstype, TYPE) ret = new $typemap(cstype, TYPE)($imcall, true);$excode
return ret;
}
%typemap(csout, excode=SWIGEXCODE) CONST TYPE * {
IntPtr cPtr = $imcall;
$typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(csout, excode=SWIGEXCODE) TYPE *CONST& {
IntPtr cPtr = $imcall;
$typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
return ret;
}
// Base proxy classes
%typemap(csbody) TYPE %{
private HandleRef swigCPtr;
private bool swigCMemOwnBase;
PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) {
swigCMemOwnBase = cMemoryOwn;
swigCPtr = new HandleRef(this, cPtr);
}
CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
%}
// Derived proxy classes
%typemap(csbody_derived) TYPE %{
private HandleRef swigCPtr;
private bool swigCMemOwnDerived;
PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclazznameSWIGSmartPtrUpcast(cPtr), true) {
swigCMemOwnDerived = cMemoryOwn;
swigCPtr = new HandleRef(this, cPtr);
}
CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
%}
%typemap(csdestruct, methodname="Dispose", methodmodifiers="public") TYPE {
lock(this) {
if (swigCPtr.Handle != IntPtr.Zero) {
if (swigCMemOwnBase) {
swigCMemOwnBase = false;
$imcall;
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
}
GC.SuppressFinalize(this);
}
}
%typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") TYPE {
lock(this) {
if (swigCPtr.Handle != IntPtr.Zero) {
if (swigCMemOwnDerived) {
swigCMemOwnDerived = false;
$imcall;
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
}
GC.SuppressFinalize(this);
base.Dispose();
}
}
// CONST version needed ???? also for C#
%typemap(imtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast "HandleRef"
%typemap(imtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast "HandleRef"
%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
%template() SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >;
%enddef
/////////////////////////////////////////////////////////////////////
%include <shared_ptr.i>
%define SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP_IMPLEMENTATION(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, CONST, TYPE...)
%naturalvar TYPE;
%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
// destructor mods
%feature("unref") TYPE "(void)arg1; delete smartarg1;"
// plain value
%typemap(in, canthrow=1) CONST TYPE ($&1_type argp = 0) %{
argp = (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0;
if (!argp) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null $1_type", 0);
return $null;
}
$1 = *argp; %}
%typemap(out) CONST TYPE
%{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); %}
// plain pointer
%typemap(in) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input;
$1 = (TYPE *)(smartarg ? smartarg->get() : 0); %}
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE * %{
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0;
%}
// plain reference
%typemap(in, canthrow=1) CONST TYPE & %{
$1 = ($1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0);
if (!$1) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type reference is null", 0);
return $null;
} %}
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE &
%{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); %}
// plain pointer by reference
%typemap(in) TYPE *CONST& ($*1_ltype temp = 0)
%{ temp = ($*1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0);
$1 = &temp; %}
%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST&
%{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %}
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast ($&1_type smartarg) %{
// shared_ptr by value
smartarg = *($&1_ltype*)&$input;
if (smartarg) $1 = *smartarg;
%}
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ANY_TYPE_SWIGSharedPtrUpcast %{
*($&1_ltype*)&$result = $1 ? new $1_ltype($1) : 0;
%}
// 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"
%}
%typemap (ctype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "void *"
%typemap (imtype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "void *"
%typemap (cstype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "$typemap(cstype, TYPE)"
%typemap (csin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "$typemap(cstype, TYPE).getCPtr($csinput)"
%typemap(csout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
IntPtr cPtr = $imcall;
return (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);
}
%typemap(csout, excode=SWIGEXCODE) CONST TYPE {
return new $typemap(cstype, TYPE)($imcall, true);
}
%typemap(csout, excode=SWIGEXCODE) CONST TYPE & {
return new $typemap(cstype, TYPE)($imcall, true);
}
%typemap(csout, excode=SWIGEXCODE) CONST TYPE * {
IntPtr cPtr = $imcall;
return (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);
}
%typemap(csout, excode=SWIGEXCODE) TYPE *CONST& {
IntPtr cPtr = $imcall;
return (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);
}
// Base proxy classes
%typemap(csbody) TYPE %{
private HandleRef swigCPtr;
private bool swigCMemOwnBase;
PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) {
swigCMemOwnBase = cMemoryOwn;
swigCPtr = new HandleRef(this, cPtr);
}
CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
%}
// Derived proxy classes
%typemap(csbody_derived) TYPE %{
private HandleRef swigCPtr;
private bool swigCMemOwnDerived;
PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclazznameSWIGSmartPtrUpcast(cPtr), true) {
swigCMemOwnDerived = cMemoryOwn;
swigCPtr = new HandleRef(this, cPtr);
}
CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
%}
%typemap(csdestruct, methodname="Dispose", methodmodifiers="public") TYPE {
lock(this) {
if (swigCPtr.Handle != IntPtr.Zero) {
if (swigCMemOwnBase) {
swigCMemOwnBase = false;
$imcall;
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
}
GC.SuppressFinalize(this);
}
}
%typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") TYPE {
lock(this) {
if (swigCPtr.Handle != IntPtr.Zero) {
if (swigCMemOwnDerived) {
swigCMemOwnDerived = false;
$imcall;
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
}
GC.SuppressFinalize(this);
base.Dispose();
}
}
// CONST version needed ???? also for C#
%typemap(imtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast "HandleRef"
%typemap(imtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast "HandleRef"
%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
%enddef

View file

@ -1,7 +1,13 @@
// Users can provide their own SWIG_SHARED_PTR_TYPEMAPS macro before including this file to change the
// visibility of the constructor and getCPtr method if desired to public if using multiple modules.
#ifndef SWIG_SHARED_PTR_TYPEMAPS
#define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...) SWIG_SHARED_PTR_TYPEMAPS_IMPLEMENTATION(internal, internal, CONST, TYPE)
#endif
%include <shared_ptr.i>
// Language specific macro implementing all the customisations for handling the smart pointer
%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...)
%define SWIG_SHARED_PTR_TYPEMAPS_IMPLEMENTATION(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, CONST, TYPE...)
// %naturalvar is as documented for member variables
%naturalvar TYPE;
@ -175,12 +181,12 @@
private HandleRef swigCPtr;
private bool swigCMemOwnBase;
internal $csclassname(IntPtr cPtr, bool cMemoryOwn) {
PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) {
swigCMemOwnBase = cMemoryOwn;
swigCPtr = new HandleRef(this, cPtr);
}
internal static HandleRef getCPtr($csclassname obj) {
CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
%}
@ -190,12 +196,12 @@
private HandleRef swigCPtr;
private bool swigCMemOwnDerived;
internal $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclazznameSWIGSmartPtrUpcast(cPtr), true) {
PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclazznameSWIGSmartPtrUpcast(cPtr), true) {
swigCMemOwnDerived = cMemoryOwn;
swigCPtr = new HandleRef(this, cPtr);
}
internal static HandleRef getCPtr($csclassname obj) {
CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
%}

View file

@ -295,25 +295,27 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
const long &,
const unsigned long &,
const long long &,
const unsigned long long &,
const float &,
const double &
%{ static $*1_ltype temp;
temp = ($*1_ltype)$input;
$result = &temp; %}
%typemap(directorin) const bool & "$input = $1_name;"
%typemap(directorin) const char & "$input = $1_name;"
%typemap(directorin) const signed char & "$input = $1_name;"
%typemap(directorin) const unsigned char & "$input = $1_name;"
%typemap(directorin) const short & "$input = $1_name;"
%typemap(directorin) const unsigned short & "$input = $1_name;"
%typemap(directorin) const int & "$input = $1_name;"
%typemap(directorin) const unsigned int & "$input = $1_name;"
%typemap(directorin) const long & "$input = $1_name;"
%typemap(directorin) const unsigned long & "$input = $1_name;"
%typemap(directorin) const long long & "$input = $1_name;"
%typemap(directorin) const float & "$input = $1_name;"
%typemap(directorin) const double & "$input = $1_name;"
%typemap(directorin) const bool & "$input = $1;"
%typemap(directorin) const char & "$input = $1;"
%typemap(directorin) const signed char & "$input = $1;"
%typemap(directorin) const unsigned char & "$input = $1;"
%typemap(directorin) const short & "$input = $1;"
%typemap(directorin) const unsigned short & "$input = $1;"
%typemap(directorin) const int & "$input = $1;"
%typemap(directorin) const unsigned int & "$input = $1;"
%typemap(directorin) const long & "$input = $1;"
%typemap(directorin) const unsigned long & "$input = $1;"
%typemap(directorin) const long long & "$input = $1;"
%typemap(directorin) const unsigned long long & "$input = $1;"
%typemap(directorin) const float & "$input = $1;"
%typemap(directorin) const double & "$input = $1;"
%typemap(csdirectorin) const char & ($*1_ltype temp),
const signed char & ($*1_ltype temp),
@ -325,6 +327,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
const long & ($*1_ltype temp),
const unsigned long & ($*1_ltype temp),
const long long & ($*1_ltype temp),
const unsigned long long & ($*1_ltype temp),
const float & ($*1_ltype temp),
const double & ($*1_ltype temp)
"$iminput"
@ -339,6 +342,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
const long & ($*1_ltype temp),
const unsigned long & ($*1_ltype temp),
const long long & ($*1_ltype temp),
const unsigned long long & ($*1_ltype temp),
const float & ($*1_ltype temp),
const double & ($*1_ltype temp)
"$cscall"
@ -849,66 +853,78 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%typemap(csinterfaces) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
%typemap(csinterfaces_derived) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
// csbody typemaps... these are in macros so that the visibility of the methods can be easily changed by users.
%define SWIG_CSBODY_PROXY(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE...)
// Proxy classes (base classes, ie, not derived classes)
%typemap(csbody) SWIGTYPE %{
%typemap(csbody) TYPE %{
private HandleRef swigCPtr;
protected bool swigCMemOwn;
internal $csclassname(IntPtr cPtr, bool cMemoryOwn) {
PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = new HandleRef(this, cPtr);
}
internal static HandleRef getCPtr($csclassname obj) {
CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
%}
// Derived proxy classes
%typemap(csbody_derived) SWIGTYPE %{
%typemap(csbody_derived) TYPE %{
private HandleRef swigCPtr;
internal $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclazznameSWIGUpcast(cPtr), cMemoryOwn) {
PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclazznameSWIGUpcast(cPtr), cMemoryOwn) {
swigCPtr = new HandleRef(this, cPtr);
}
internal static HandleRef getCPtr($csclassname obj) {
CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
%}
%enddef
%define SWIG_CSBODY_TYPEWRAPPER(PTRCTOR_VISIBILITY, DEFAULTCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE...)
// Typewrapper classes
%typemap(csbody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] %{
%typemap(csbody) TYPE *, TYPE &, TYPE &&, TYPE [] %{
private HandleRef swigCPtr;
internal $csclassname(IntPtr cPtr, bool futureUse) {
PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool futureUse) {
swigCPtr = new HandleRef(this, cPtr);
}
protected $csclassname() {
DEFAULTCTOR_VISIBILITY $csclassname() {
swigCPtr = new HandleRef(null, IntPtr.Zero);
}
internal static HandleRef getCPtr($csclassname obj) {
CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
%}
%typemap(csbody) SWIGTYPE (CLASS::*) %{
%typemap(csbody) TYPE (CLASS::*) %{
private string swigCMemberPtr;
internal $csclassname(string cMemberPtr, bool futureUse) {
PTRCTOR_VISIBILITY $csclassname(string cMemberPtr, bool futureUse) {
swigCMemberPtr = cMemberPtr;
}
protected $csclassname() {
DEFAULTCTOR_VISIBILITY $csclassname() {
swigCMemberPtr = null;
}
internal static string getCMemberPtr($csclassname obj) {
CPTR_VISIBILITY static string getCMemberPtr($csclassname obj) {
return obj.swigCMemberPtr;
}
%}
%enddef
/* Set the default csbody typemaps to use internal visibility.
Use the macros to change to public if using multiple modules. */
SWIG_CSBODY_PROXY(internal, internal, SWIGTYPE)
SWIG_CSBODY_TYPEWRAPPER(internal, protected, internal, SWIGTYPE)
%typemap(csfinalize) SWIGTYPE %{
~$csclassname() {

View file

@ -18,7 +18,7 @@
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE &
%{ static $*1_ltype temp = ($*1_ltype)$input;
$result = &temp; %}
%typemap(directorin) const enum SWIGTYPE & "$input = $1_name;"
%typemap(directorin) const enum SWIGTYPE & "$input = $1;"
%typemap(csdirectorin) const enum SWIGTYPE & "($*csclassname)$iminput"
%typemap(csdirectorout) const enum SWIGTYPE & "(int)$cscall"

View file

@ -20,7 +20,7 @@
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE &
%{ static $*1_ltype temp = ($*1_ltype)$input;
$result = &temp; %}
%typemap(directorin) const enum SWIGTYPE & "$input = $1_name;"
%typemap(directorin) const enum SWIGTYPE & "$input = $1;"
%typemap(csdirectorin) const enum SWIGTYPE & "$iminput"
%typemap(csdirectorout) const enum SWIGTYPE & "$cscall"

View file

@ -19,7 +19,7 @@
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE &
%{ static $*1_ltype temp = ($*1_ltype)$input;
$result = &temp; %}
%typemap(directorin) const enum SWIGTYPE & "$input = $1_name;"
%typemap(directorin) const enum SWIGTYPE & "$input = $1;"
%typemap(csdirectorin) const enum SWIGTYPE & "$*csclassname.swigToEnum($iminput)"
%typemap(csdirectorout) const enum SWIGTYPE & "$cscall.swigValue"

View file

@ -67,12 +67,13 @@
public System.Collections.Generic.ICollection<$typemap(cstype, K)> Keys {
get {
System.Collections.Generic.ICollection<$typemap(cstype, K)> keys = new System.Collections.Generic.List<$typemap(cstype, K)>();
IntPtr iter = create_iterator_begin();
try {
while (true) {
int size = this.Count;
if (size > 0) {
IntPtr iter = create_iterator_begin();
for (int i = 0; i < size; i++) {
keys.Add(get_next_key(iter));
}
} catch (ArgumentOutOfRangeException) {
destroy_iterator(iter);
}
return keys;
}
@ -214,12 +215,13 @@
%}
public:
map();
map(const map< K, T > &other);
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef K key_type;
typedef T mapped_type;
typedef size_t size_type;
map();
map(const map< K, T > &other);
size_type size() const;
bool empty() const;
%rename(Clear) clear;
@ -258,7 +260,7 @@
return false;
}
// create_iterator_begin() and get_next_key() work together to provide a collection of keys to C#
// create_iterator_begin(), get_next_key() and destroy_iterator work together to provide a collection of keys to C#
%apply void *VOID_INT_PTR { std::map< K, T >::iterator *create_iterator_begin }
%apply void *VOID_INT_PTR { std::map< K, T >::iterator *swigiterator }
@ -266,15 +268,15 @@
return new std::map< K, T >::iterator($self->begin());
}
const key_type& get_next_key(std::map< K, T >::iterator *swigiterator) throw (std::out_of_range) {
const key_type& get_next_key(std::map< K, T >::iterator *swigiterator) {
std::map< K, T >::iterator iter = *swigiterator;
if (iter == $self->end()) {
delete swigiterator;
throw std::out_of_range("no more map elements");
}
(*swigiterator)++;
return (*iter).first;
}
void destroy_iterator(std::map< K, T >::iterator *swigiterator) {
delete swigiterator;
}
}
@ -285,6 +287,7 @@
%csmethodmodifiers std::map::setitem "private"
%csmethodmodifiers std::map::create_iterator_begin "private"
%csmethodmodifiers std::map::get_next_key "private"
%csmethodmodifiers std::map::destroy_iterator "private"
// Default implementation
namespace std {

View file

@ -69,7 +69,7 @@ class string;
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
return $null;
}
std::string $1_str($input);
$*1_ltype $1_str($input);
$1 = &$1_str; %}
%typemap(out) const string & %{ $result = SWIG_csharp_string_callback($1->c_str()); %}
@ -85,7 +85,7 @@ class string;
return $null;
}
/* possible thread/reentrant code problem */
static std::string $1_str;
static $*1_ltype $1_str;
$1_str = $input;
$result = &$1_str; %}

View file

@ -51,29 +51,17 @@ or you can use the %apply directive :
In C# you could then use it like this:
double answer = modulename.fadd(10.0, 20.0);
*/
%define INPUT_TYPEMAP(TYPE, CTYPE, CSTYPE)
%typemap(ctype) TYPE *INPUT, TYPE &INPUT "CTYPE"
%typemap(imtype) TYPE *INPUT, TYPE &INPUT "CSTYPE"
%typemap(cstype) TYPE *INPUT, TYPE &INPUT "CSTYPE"
%typemap(ctype, out="void *") TYPE *INPUT, TYPE &INPUT "CTYPE"
%typemap(imtype, out="IntPtr") TYPE *INPUT, TYPE &INPUT "CSTYPE"
%typemap(cstype, out="$csclassname") TYPE *INPUT, TYPE &INPUT "CSTYPE"
%typemap(csin) TYPE *INPUT, TYPE &INPUT "$csinput"
%typemap(csdirectorin) TYPE *INPUT, TYPE &INPUT "$iminput"
%typemap(csdirectorout) TYPE *INPUT, TYPE &INPUT "$cscall"
%typemap(in) TYPE *INPUT, TYPE &INPUT
%{ $1 = ($1_ltype)&$input; %}
%typemap(directorout) TYPE *INPUT, TYPE &INPUT
%{ $result = ($1_ltype)&$input; %}
%typemap(directorin) TYPE &INPUT
%{ $input = (CTYPE *)$1; %}
%typemap(directorin) TYPE *INPUT
%{ $input = (CTYPE *)$1; %}
%typemap(typecheck) TYPE *INPUT = TYPE;
%typemap(typecheck) TYPE &INPUT = TYPE;
%enddef
@ -143,32 +131,17 @@ value returned in the second output parameter. In C# you would use it like this:
double dptr;
double fraction = modulename.modf(5, out dptr);
*/
%define OUTPUT_TYPEMAP(TYPE, CTYPE, CSTYPE, TYPECHECKPRECEDENCE)
%typemap(ctype) TYPE *OUTPUT, TYPE &OUTPUT "CTYPE *"
%typemap(imtype) TYPE *OUTPUT, TYPE &OUTPUT "out CSTYPE"
%typemap(cstype) TYPE *OUTPUT, TYPE &OUTPUT "out CSTYPE"
%typemap(ctype, out="void *") TYPE *OUTPUT, TYPE &OUTPUT "CTYPE *"
%typemap(imtype, out="IntPtr") TYPE *OUTPUT, TYPE &OUTPUT "out CSTYPE"
%typemap(cstype, out="$csclassname") TYPE *OUTPUT, TYPE &OUTPUT "out CSTYPE"
%typemap(csin) TYPE *OUTPUT, TYPE &OUTPUT "out $csinput"
%typemap(csdirectorin) TYPE *OUTPUT, TYPE &OUTPUT "$iminput"
%typemap(csdirectorout) TYPE *OUTPUT, TYPE &OUTPUT "$cscall"
%typemap(in) TYPE *OUTPUT, TYPE &OUTPUT
%{ $1 = ($1_ltype)$input; %}
%typemap(directorout,warning="Need to provide TYPE *OUTPUT directorout typemap") TYPE *OUTPUT, TYPE &OUTPUT {
}
%typemap(directorin) TYPE &OUTPUT
%{ $input = &$1; %}
%typemap(directorin,warning="Need to provide TYPE *OUTPUT directorin typemap, TYPE array length is unknown") TYPE *OUTPUT
{
}
%typecheck(SWIG_TYPECHECK_##TYPECHECKPRECEDENCE) TYPE *OUTPUT, TYPE &OUTPUT ""
%enddef
@ -250,26 +223,14 @@ of the function return value.
*/
%define INOUT_TYPEMAP(TYPE, CTYPE, CSTYPE, TYPECHECKPRECEDENCE)
%typemap(ctype) TYPE *INOUT, TYPE &INOUT "CTYPE *"
%typemap(imtype) TYPE *INOUT, TYPE &INOUT "ref CSTYPE"
%typemap(cstype) TYPE *INOUT, TYPE &INOUT "ref CSTYPE"
%typemap(ctype, out="void *") TYPE *INOUT, TYPE &INOUT "CTYPE *"
%typemap(imtype, out="IntPtr") TYPE *INOUT, TYPE &INOUT "ref CSTYPE"
%typemap(cstype, out="$csclassname") TYPE *INOUT, TYPE &INOUT "ref CSTYPE"
%typemap(csin) TYPE *INOUT, TYPE &INOUT "ref $csinput"
%typemap(csdirectorin) TYPE *INOUT, TYPE &INOUT "$iminput"
%typemap(csdirectorout) TYPE *INOUT, TYPE &INOUT "$cscall"
%typemap(in) TYPE *INOUT, TYPE &INOUT
%{ $1 = ($1_ltype)$input; %}
%typemap(directorout,warning="Need to provide TYPE *INOUT directorout typemap") TYPE *INOUT, TYPE &INOUT {
}
%typemap(directorin) TYPE &INOUT
%{ $input = &$1; %}
%typemap(directorin,warning="Need to provide TYPE *INOUT directorin typemap, TYPE array length is unknown") TYPE *INOUT, TYPE &INOUT
{
}
%typecheck(SWIG_TYPECHECK_##TYPECHECKPRECEDENCE) TYPE *INOUT, TYPE &INOUT ""
%enddef

View file

@ -1,102 +1,102 @@
/* -----------------------------------------------------------------------------
* wchar.i
*
* Typemaps for the wchar_t type
* These are mapped to a C# String and are passed around by value.
*
* Support code for wide strings can be turned off by defining SWIG_CSHARP_NO_WSTRING_HELPER
*
* ----------------------------------------------------------------------------- */
#if !defined(SWIG_CSHARP_NO_WSTRING_HELPER)
#if !defined(SWIG_CSHARP_WSTRING_HELPER_)
#define SWIG_CSHARP_WSTRING_HELPER_
%insert(runtime) %{
/* Callback for returning strings to C# without leaking memory */
typedef void * (SWIGSTDCALL* SWIG_CSharpWStringHelperCallback)(const wchar_t *);
static SWIG_CSharpWStringHelperCallback SWIG_csharp_wstring_callback = NULL;
%}
%pragma(csharp) imclasscode=%{
protected class SWIGWStringHelper {
public delegate string SWIGWStringDelegate(IntPtr message);
static SWIGWStringDelegate wstringDelegate = new SWIGWStringDelegate(CreateWString);
[DllImport("$dllimport", EntryPoint="SWIGRegisterWStringCallback_$module")]
public static extern void SWIGRegisterWStringCallback_$module(SWIGWStringDelegate wstringDelegate);
static string CreateWString([MarshalAs(UnmanagedType.LPWStr)]IntPtr cString) {
return System.Runtime.InteropServices.Marshal.PtrToStringUni(cString);
}
static SWIGWStringHelper() {
SWIGRegisterWStringCallback_$module(wstringDelegate);
}
}
static protected SWIGWStringHelper swigWStringHelper = new SWIGWStringHelper();
%}
%insert(runtime) %{
#ifdef __cplusplus
extern "C"
#endif
SWIGEXPORT void SWIGSTDCALL SWIGRegisterWStringCallback_$module(SWIG_CSharpWStringHelperCallback callback) {
SWIG_csharp_wstring_callback = callback;
}
%}
#endif // SWIG_CSHARP_WSTRING_HELPER_
#endif // SWIG_CSHARP_NO_WSTRING_HELPER
// wchar_t
%typemap(ctype) wchar_t "wchar_t"
%typemap(imtype) wchar_t "char"
%typemap(cstype) wchar_t "char"
%typemap(csin) wchar_t "$csinput"
%typemap(csout, excode=SWIGEXCODE) wchar_t {
char ret = $imcall;$excode
return ret;
}
%typemap(csvarin, excode=SWIGEXCODE2) wchar_t %{
set {
$imcall;$excode
} %}
%typemap(csvarout, excode=SWIGEXCODE2) wchar_t %{
get {
char ret = $imcall;$excode
return ret;
} %}
%typemap(in) wchar_t %{ $1 = ($1_ltype)$input; %}
%typemap(out) wchar_t %{ $result = (wchar_t)$1; %}
%typemap(typecheck) wchar_t = char;
// wchar_t *
%typemap(ctype) wchar_t * "wchar_t *"
%typemap(imtype, inattributes="[MarshalAs(UnmanagedType.LPWStr)]", out="IntPtr" ) wchar_t * "string"
%typemap(cstype) wchar_t * "string"
%typemap(csin) wchar_t * "$csinput"
%typemap(csout, excode=SWIGEXCODE) wchar_t * {
string ret = System.Runtime.InteropServices.Marshal.PtrToStringUni($imcall);$excode
return ret;
}
%typemap(csvarin, excode=SWIGEXCODE2) wchar_t * %{
set {
$imcall;$excode
} %}
%typemap(csvarout, excode=SWIGEXCODE2) wchar_t * %{
get {
string ret = $imcall;$excode
return ret;
} %}
%typemap(in) wchar_t * %{ $1 = ($1_ltype)$input; %}
%typemap(out) wchar_t * %{ $result = (wchar_t *)$1; %}
%typemap(typecheck) wchar_t * = char *;
/* -----------------------------------------------------------------------------
* wchar.i
*
* Typemaps for the wchar_t type
* These are mapped to a C# String and are passed around by value.
*
* Support code for wide strings can be turned off by defining SWIG_CSHARP_NO_WSTRING_HELPER
*
* ----------------------------------------------------------------------------- */
#if !defined(SWIG_CSHARP_NO_WSTRING_HELPER)
#if !defined(SWIG_CSHARP_WSTRING_HELPER_)
#define SWIG_CSHARP_WSTRING_HELPER_
%insert(runtime) %{
/* Callback for returning strings to C# without leaking memory */
typedef void * (SWIGSTDCALL* SWIG_CSharpWStringHelperCallback)(const wchar_t *);
static SWIG_CSharpWStringHelperCallback SWIG_csharp_wstring_callback = NULL;
%}
%pragma(csharp) imclasscode=%{
protected class SWIGWStringHelper {
public delegate string SWIGWStringDelegate(IntPtr message);
static SWIGWStringDelegate wstringDelegate = new SWIGWStringDelegate(CreateWString);
[DllImport("$dllimport", EntryPoint="SWIGRegisterWStringCallback_$module")]
public static extern void SWIGRegisterWStringCallback_$module(SWIGWStringDelegate wstringDelegate);
static string CreateWString([MarshalAs(UnmanagedType.LPWStr)]IntPtr cString) {
return System.Runtime.InteropServices.Marshal.PtrToStringUni(cString);
}
static SWIGWStringHelper() {
SWIGRegisterWStringCallback_$module(wstringDelegate);
}
}
static protected SWIGWStringHelper swigWStringHelper = new SWIGWStringHelper();
%}
%insert(runtime) %{
#ifdef __cplusplus
extern "C"
#endif
SWIGEXPORT void SWIGSTDCALL SWIGRegisterWStringCallback_$module(SWIG_CSharpWStringHelperCallback callback) {
SWIG_csharp_wstring_callback = callback;
}
%}
#endif // SWIG_CSHARP_WSTRING_HELPER_
#endif // SWIG_CSHARP_NO_WSTRING_HELPER
// wchar_t
%typemap(ctype) wchar_t "wchar_t"
%typemap(imtype) wchar_t "char"
%typemap(cstype) wchar_t "char"
%typemap(csin) wchar_t "$csinput"
%typemap(csout, excode=SWIGEXCODE) wchar_t {
char ret = $imcall;$excode
return ret;
}
%typemap(csvarin, excode=SWIGEXCODE2) wchar_t %{
set {
$imcall;$excode
} %}
%typemap(csvarout, excode=SWIGEXCODE2) wchar_t %{
get {
char ret = $imcall;$excode
return ret;
} %}
%typemap(in) wchar_t %{ $1 = ($1_ltype)$input; %}
%typemap(out) wchar_t %{ $result = (wchar_t)$1; %}
%typemap(typecheck) wchar_t = char;
// wchar_t *
%typemap(ctype) wchar_t * "wchar_t *"
%typemap(imtype, inattributes="[MarshalAs(UnmanagedType.LPWStr)]", out="IntPtr" ) wchar_t * "string"
%typemap(cstype) wchar_t * "string"
%typemap(csin) wchar_t * "$csinput"
%typemap(csout, excode=SWIGEXCODE) wchar_t * {
string ret = System.Runtime.InteropServices.Marshal.PtrToStringUni($imcall);$excode
return ret;
}
%typemap(csvarin, excode=SWIGEXCODE2) wchar_t * %{
set {
$imcall;$excode
} %}
%typemap(csvarout, excode=SWIGEXCODE2) wchar_t * %{
get {
string ret = $imcall;$excode
return ret;
} %}
%typemap(in) wchar_t * %{ $1 = ($1_ltype)$input; %}
%typemap(out) wchar_t * %{ $result = (wchar_t *)$1; %}
%typemap(typecheck) wchar_t * = char *;

201
Lib/d/boost_shared_ptr.i Normal file
View file

@ -0,0 +1,201 @@
%include <shared_ptr.i>
%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...)
%naturalvar TYPE;
%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
// destructor mods
%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;"
// plain value
%typemap(in, canthrow=1) CONST TYPE ($&1_type argp = 0) %{
argp = ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input) ? ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input)->get() : 0;
if (!argp) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Attempt to dereference null $1_type");
return $null;
}
$1 = *argp; %}
%typemap(out) CONST TYPE
%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); %}
// plain pointer
%typemap(in, canthrow=1) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
smartarg = (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input;
$1 = (TYPE *)(smartarg ? smartarg->get() : 0); %}
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE * %{
$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0;
%}
// plain reference
%typemap(in, canthrow=1) CONST TYPE & %{
$1 = ($1_ltype)(((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input) ? ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input)->get() : 0);
if (!$1) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type reference is null");
return $null;
} %}
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE &
%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); %}
// plain pointer by reference
%typemap(in) TYPE *CONST& ($*1_ltype temp = 0)
%{ temp = (TYPE *)(((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input) ? ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input)->get() : 0);
$1 = &temp; %}
%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST&
%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %}
// shared_ptr by value
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >
%{ if ($input) $1 = *($&1_ltype)$input; %}
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >
%{ $result = $1 ? new $1_ltype($1) : 0; %}
// shared_ptr by reference
%typemap(in, canthrow=1) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & ($*1_ltype tempnull)
%{ $1 = $input ? ($1_ltype)$input : &tempnull; %}
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &
%{ $result = *$1 ? new $*1_ltype(*$1) : 0; %}
// shared_ptr by pointer
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * ($*1_ltype tempnull)
%{ $1 = $input ? ($1_ltype)$input : &tempnull; %}
%typemap(out, fragment="SWIG_null_deleter") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *
%{ $result = ($1 && *$1) ? new $*1_ltype(*($1_ltype)$1) : 0;
if ($owner) delete $1; %}
// shared_ptr by pointer reference
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempnull, $*1_ltype temp = 0)
%{ temp = $input ? *($1_ltype)&$input : &tempnull;
$1 = &temp; %}
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *&
%{ *($1_ltype)&$result = (*$1 && **$1) ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(**$1) : 0; %}
// 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"
%}
%typemap (ctype) 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 > *& "void *"
%typemap (imtype) 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 > *& "void*"
%typemap (dtype) 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 > *& "$typemap(dtype, TYPE)"
%typemap(din) 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 > *& "$typemap(dtype, TYPE).swigGetCPtr($dinput)"
%typemap(dout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
void* cPtr = $imcall;
auto ret = (cPtr is null) ? null : new $typemap(dtype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(dout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & {
void* cPtr = $imcall;
auto ret = (cPtr is null) ? null : new $typemap(dtype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(dout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * {
void* cPtr = $imcall;
auto ret = (cPtr is null) ? null : new $typemap(dtype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(dout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& {
void* cPtr = $imcall;
auto ret = (cPtr is null) ? null : new $typemap(dtype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(dout, excode=SWIGEXCODE) CONST TYPE {
auto ret = new $typemap(dtype, TYPE)($imcall, true);$excode
return ret;
}
%typemap(dout, excode=SWIGEXCODE) CONST TYPE & {
auto ret = new $typemap(dtype, TYPE)($imcall, true);$excode
return ret;
}
%typemap(dout, excode=SWIGEXCODE) CONST TYPE * {
void* cPtr = $imcall;
auto ret = (cPtr is null) ? null : new $typemap(dtype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(dout, excode=SWIGEXCODE) TYPE *CONST& {
void* cPtr = $imcall;
auto ret = (cPtr is null) ? null : new $typemap(dtype, TYPE)(cPtr, true);$excode
return ret;
}
// For shared pointers, both the derived and the base class have to »own« their
// pointer; otherwise the reference count is not decreased properly on destruction.
%typemap(dbody) SWIGTYPE %{
private void* swigCPtr;
private bool swigCMemOwn;
public this(void* cObject, bool ownCObject) {
swigCPtr = cObject;
swigCMemOwn = ownCObject;
}
public static void* swigGetCPtr($dclassname obj) {
return (obj is null) ? null : obj.swigCPtr;
}
%}
%typemap(dbody_derived) SWIGTYPE %{
private void* swigCPtr;
private bool swigCMemOwn;
public this(void* cObject, bool ownCObject) {
super($imdmodule.$dclazznameSmartPtrUpcast(cObject), ownCObject);
swigCPtr = cObject;
swigCMemOwn = ownCObject;
}
public static void* swigGetCPtr($dclassname obj) {
return (obj is null) ? null : obj.swigCPtr;
}
%}
%typemap(ddispose, methodname="dispose", methodmodifiers="public") TYPE {
synchronized(this) {
if (swigCPtr !is null) {
if (swigCMemOwn) {
swigCMemOwn = false;
$imcall;
}
swigCPtr = null;
}
}
}
%typemap(ddispose_derived, methodname="dispose", methodmodifiers="public") TYPE {
synchronized(this) {
if (swigCPtr !is null) {
if (swigCMemOwn) {
swigCMemOwn = false;
$imcall;
}
swigCPtr = null;
super.dispose();
}
}
}
%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
%enddef

111
Lib/d/carrays.i Normal file
View file

@ -0,0 +1,111 @@
/* -----------------------------------------------------------------------------
* carrays.i
*
* D-specific version of ../carrays.i.
* ----------------------------------------------------------------------------- */
/* -----------------------------------------------------------------------------
* %array_functions(TYPE,NAME)
*
* Generates functions for creating and accessing elements of a C array
* (as pointers). Creates the following functions:
*
* TYPE *new_NAME(int nelements)
* void delete_NAME(TYPE *);
* TYPE NAME_getitem(TYPE *, int index);
* void NAME_setitem(TYPE *, int index, TYPE value);
*
* ----------------------------------------------------------------------------- */
%define %array_functions(TYPE,NAME)
%{
static TYPE *new_##NAME(int nelements) { %}
#ifdef __cplusplus
%{ return new TYPE[nelements]; %}
#else
%{ return (TYPE *) calloc(nelements,sizeof(TYPE)); %}
#endif
%{}
static void delete_##NAME(TYPE *ary) { %}
#ifdef __cplusplus
%{ delete [] ary; %}
#else
%{ free(ary); %}
#endif
%{}
static TYPE NAME##_getitem(TYPE *ary, int index) {
return ary[index];
}
static void NAME##_setitem(TYPE *ary, int index, TYPE value) {
ary[index] = value;
}
%}
TYPE *new_##NAME(int nelements);
void delete_##NAME(TYPE *ary);
TYPE NAME##_getitem(TYPE *ary, int index);
void NAME##_setitem(TYPE *ary, int index, TYPE value);
%enddef
/* -----------------------------------------------------------------------------
* %array_class(TYPE,NAME)
*
* Generates a class wrapper around a C array. The class has the following
* interface:
*
* struct NAME {
* NAME(int nelements);
* ~NAME();
* TYPE getitem(int index);
* void setitem(int index, TYPE value);
* TYPE * ptr();
* static NAME *frompointer(TYPE *t);
* }
*
* ----------------------------------------------------------------------------- */
%define %array_class(TYPE,NAME)
%{
typedef TYPE NAME;
%}
typedef struct {} NAME;
%extend NAME {
#ifdef __cplusplus
NAME(int nelements) {
return new TYPE[nelements];
}
~NAME() {
delete [] self;
}
#else
NAME(int nelements) {
return (TYPE *) calloc(nelements,sizeof(TYPE));
}
~NAME() {
free(self);
}
#endif
TYPE getitem(int index) {
return self[index];
}
void setitem(int index, TYPE value) {
self[index] = value;
}
TYPE * ptr() {
return self;
}
static NAME *frompointer(TYPE *t) {
return (NAME *) t;
}
};
%types(NAME = TYPE);
%enddef

171
Lib/d/cpointer.i Normal file
View file

@ -0,0 +1,171 @@
/* -----------------------------------------------------------------------------
* cpointer.i
*
* D-specific version of ../cpointer.i.
* ----------------------------------------------------------------------------- */
/* -----------------------------------------------------------------------------
* %pointer_class(type,name)
*
* Places a simple proxy around a simple type like 'int', 'float', or whatever.
* The proxy provides this interface:
*
* class type {
* public:
* type();
* ~type();
* type value();
* void assign(type value);
* };
*
* Example:
*
* %pointer_class(int, intp);
*
* int add(int *x, int *y) { return *x + *y; }
*
* In python (with proxies)
*
* >>> a = intp()
* >>> a.assign(10)
* >>> a.value()
* 10
* >>> b = intp()
* >>> b.assign(20)
* >>> print add(a,b)
* 30
*
* As a general rule, this macro should not be used on class/structures that
* are already defined in the interface.
* ----------------------------------------------------------------------------- */
%define %pointer_class(TYPE, NAME)
%{
typedef TYPE NAME;
%}
typedef struct {
} NAME;
%extend NAME {
#ifdef __cplusplus
NAME() {
return new TYPE();
}
~NAME() {
if (self) delete self;
}
#else
NAME() {
return (TYPE *) calloc(1,sizeof(TYPE));
}
~NAME() {
if (self) free(self);
}
#endif
}
%extend NAME {
void assign(TYPE value) {
*self = value;
}
TYPE value() {
return *self;
}
TYPE * ptr() {
return self;
}
static NAME * frompointer(TYPE *t) {
return (NAME *) t;
}
}
%types(NAME = TYPE);
%enddef
/* -----------------------------------------------------------------------------
* %pointer_functions(type,name)
*
* Create functions for allocating/deallocating pointers. This can be used
* if you don't want to create a proxy class or if the pointer is complex.
*
* %pointer_functions(int, intp)
*
* int add(int *x, int *y) { return *x + *y; }
*
* In python (with proxies)
*
* >>> a = copy_intp(10)
* >>> intp_value(a)
* 10
* >>> b = new_intp()
* >>> intp_assign(b,20)
* >>> print add(a,b)
* 30
* >>> delete_intp(a)
* >>> delete_intp(b)
*
* ----------------------------------------------------------------------------- */
%define %pointer_functions(TYPE,NAME)
%{
static TYPE *new_##NAME() { %}
#ifdef __cplusplus
%{ return new TYPE(); %}
#else
%{ return (TYPE *) calloc(1,sizeof(TYPE)); %}
#endif
%{}
static TYPE *copy_##NAME(TYPE value) { %}
#ifdef __cplusplus
%{ return new TYPE(value); %}
#else
%{ TYPE *self = (TYPE *) calloc(1,sizeof(TYPE));
*self = value;
return self; %}
#endif
%{}
static void delete_##NAME(TYPE *self) { %}
#ifdef __cplusplus
%{ if (self) delete self; %}
#else
%{ if (self) free(self); %}
#endif
%{}
static void NAME ##_assign(TYPE *self, TYPE value) {
*self = value;
}
static TYPE NAME ##_value(TYPE *self) {
return *self;
}
%}
TYPE *new_##NAME();
TYPE *copy_##NAME(TYPE value);
void delete_##NAME(TYPE *self);
void NAME##_assign(TYPE *self, TYPE value);
TYPE NAME##_value(TYPE *self);
%enddef
/* -----------------------------------------------------------------------------
* %pointer_cast(type1,type2,name)
*
* Generates a pointer casting function.
* ----------------------------------------------------------------------------- */
%define %pointer_cast(TYPE1,TYPE2,NAME)
%inline %{
TYPE2 NAME(TYPE1 x) {
return (TYPE2) x;
}
%}
%enddef

46
Lib/d/d.swg Normal file
View file

@ -0,0 +1,46 @@
/* -----------------------------------------------------------------------------
* d.swg
*
* Main library file for the D language module. See the D chapter in the SWIG
* manual for explanation on the typemaps, pragmas, etc. used.
* ----------------------------------------------------------------------------- */
// Typemaps for exception handling.
%include <dexception.swg>
// Typemaps for primitive types.
%include <dprimitives.swg>
// Typemaps for non-primitive types (C/C++ classes and structs).
%include <dswigtype.swg>
// Typemaps for enumeration types.
%include <denums.swg>
// Typemaps for member function pointers.
%include <dmemberfunctionpointers.swg>
// Typemaps for wrapping pointers to/arrays of C chars as D strings.
%include <dstrings.swg>
// Typemaps for handling void function return types and empty parameter lists.
%include <dvoid.swg>
// Typemaps containing D code used when generating D proxy classes.
%include <dclassgen.swg>
// Mapping of C++ operator overloading methods to D.
%include <doperators.swg>
// Helper code string and exception handling.
%include <dhead.swg>
// Wrapper loader code for dynamically linking the C wrapper library from the D
// wrapper module.
%include <wrapperloader.swg>
// List of all reserved D keywords.
%include <dkw.swg>
// D-specific directives.
%include <ddirectives.swg>

142
Lib/d/dclassgen.swg Normal file
View file

@ -0,0 +1,142 @@
/* -----------------------------------------------------------------------------
* dclassgen.swg
*
* Typemaps containing D code used when generating D proxy classes.
* ----------------------------------------------------------------------------- */
%typemap(dbase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
%typemap(dclassmodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "class"
%typemap(dcode) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
%typemap(dimports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
%typemap(dinterfaces) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
%typemap(dinterfaces_derived) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
// See <denums.swg>.
%typemap(dclassmodifiers) enum SWIGTYPE "enum"
%typemap(dcode) enum SWIGTYPE ""
/*
* Proxy classes.
*/
%typemap(dconstructor, excode=SWIGEXCODE,directorconnect="\n swigDirectorConnect();") SWIGTYPE {
this($imcall, true);$excode$directorconnect
}
%typemap(ddestructor) SWIGTYPE %{
~this() {
dispose();
}
%}
// We do not use »override« attribute for generated dispose() methods to stay
// somewhat compatible to Phobos and older Tango versions where Object.dispose()
// does not exist.
%typemap(ddispose, methodname="dispose", methodmodifiers="public") SWIGTYPE {
synchronized(this) {
if (swigCPtr !is null) {
if (swigCMemOwn) {
swigCMemOwn = false;
$imcall;
}
swigCPtr = null;
}
}
}
%typemap(ddispose_derived, methodname="dispose", methodmodifiers="public") SWIGTYPE {
synchronized(this) {
if (swigCPtr !is null) {
if (swigCMemOwn) {
swigCMemOwn = false;
$imcall;
}
swigCPtr = null;
super.dispose();
}
}
}
// Unfortunately, the »package« visibility attribute does not work in D when the
// module in question is in the root package (happens if no -package is specified
// at the SWIG command line), so we are stuck with public visibility for
// swigGetCPtr().
%typemap(dbody) SWIGTYPE %{
private void* swigCPtr;
protected bool swigCMemOwn;
public this(void* cObject, bool ownCObject) {
swigCPtr = cObject;
swigCMemOwn = ownCObject;
}
public static void* swigGetCPtr($dclassname obj) {
return (obj is null) ? null : obj.swigCPtr;
}
mixin $imdmodule.SwigOperatorDefinitions;
%}
%typemap(dbody_derived) SWIGTYPE %{
private void* swigCPtr;
public this(void* cObject, bool ownCObject) {
super($imdmodule.$dclazznameUpcast(cObject), ownCObject);
swigCPtr = cObject;
}
public static void* swigGetCPtr($dclassname obj) {
return (obj is null) ? null : obj.swigCPtr;
}
mixin $imdmodule.SwigOperatorDefinitions;
%}
/*
* Type wrapper classes.
*/
%typemap(dbody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] %{
private void* swigCPtr;
public this(void* cObject, bool futureUse) {
swigCPtr = cObject;
}
protected this() {
swigCPtr = null;
}
public static void* swigGetCPtr($dclassname obj) {
return (obj is null) ? null : obj.swigCPtr;
}
mixin $imdmodule.SwigOperatorDefinitions;
%}
/*
* Member function pointer wrapper classes (see <dmemberfunctionpointers.swg>).
*/
%typemap(dbody) SWIGTYPE (CLASS::*) %{
private char* swigCPtr;
public this(char* cMemberPtr, bool futureUse) {
swigCPtr = cMemberPtr;
}
protected this() {
swigCPtr = null;
}
package static char* swigGetCMemberPtr($dclassname obj) {
return (obj is null) ? null : obj.swigCPtr;
}
mixin $imdmodule.SwigOperatorDefinitions;
%}

10
Lib/d/ddirectives.swg Normal file
View file

@ -0,0 +1,10 @@
/* -----------------------------------------------------------------------------
* ddirectives.swg
*
* D-specifiv directives.
* ----------------------------------------------------------------------------- */
#define %dmanifestconst %feature("d:manifestconst")
#define %dconstvalue(value) %feature("d:constvalue",value)
#define %dmethodmodifiers %feature("d:methodmodifiers")
#define %dnothrowexception %feature("except")

60
Lib/d/denums.swg Normal file
View file

@ -0,0 +1,60 @@
/* -----------------------------------------------------------------------------
* denums.swg
*
* Typemaps for enumerations.
* ----------------------------------------------------------------------------- */
/*
* Typemaps for enumeration types.
*/
%typemap(ctype) enum SWIGTYPE "int"
%typemap(imtype) enum SWIGTYPE "int"
%typemap(dtype, cprimitive="1") enum SWIGTYPE "$dclassname"
%typecheck(SWIG_TYPECHECK_POINTER) enum SWIGTYPE ""
%typemap(in) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}
%typemap(out) enum SWIGTYPE %{ $result = $1; %}
%typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %}
%typemap(directorin) enum SWIGTYPE "$input = $1;"
%typemap(ddirectorin) enum SWIGTYPE "cast($dclassname)$winput"
%typemap(ddirectorout) enum SWIGTYPE "cast(int)$dcall"
%typemap(din) enum SWIGTYPE "cast(int)$dinput"
%typemap(dout, excode=SWIGEXCODE) enum SWIGTYPE {
$dclassname ret = cast($dclassname)$imcall;$excode
return ret;
}
/*
* Typemaps for (const) references to enumeration types.
*/
%typemap(ctype) const enum SWIGTYPE & "int"
%typemap(imtype) const enum SWIGTYPE & "int"
%typemap(dtype) const enum SWIGTYPE & "$*dclassname"
%typecheck(SWIG_TYPECHECK_POINTER) const enum SWIGTYPE & ""
%typemap(in) const enum SWIGTYPE & ($*1_ltype temp)
%{ temp = ($*1_ltype)$input;
$1 = &temp; %}
%typemap(out) const enum SWIGTYPE & %{ $result = *$1; %}
%typemap(directorin) const enum SWIGTYPE & "$input = $1;"
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE &
%{ static $*1_ltype temp = ($*1_ltype)$input;
$result = &temp; %}
%typemap(ddirectorin) const enum SWIGTYPE & "cast($*dclassname)$winput"
%typemap(ddirectorout) const enum SWIGTYPE & "cast(int)$dcall"
%typemap(din) const enum SWIGTYPE & "cast(int)$dinput"
%typemap(dout, excode=SWIGEXCODE) const enum SWIGTYPE & {
$*dclassname ret = cast($*dclassname)$imcall;$excode
return ret;
}

30
Lib/d/dexception.swg Normal file
View file

@ -0,0 +1,30 @@
/* -----------------------------------------------------------------------------
* dexception.swg
*
* Typemaps used for propagating C++ exceptions to D.
* ----------------------------------------------------------------------------- */
// Code which is inserted into the dout typemaps and class constructors via
// excode if exceptions can be thrown.
%define SWIGEXCODE "\n if ($imdmodule.SwigPendingException.isPending) throw $imdmodule.SwigPendingException.retrieve();" %enddef
%typemap(throws, canthrow=1) int,
long,
short,
unsigned int,
unsigned long,
unsigned short
%{ char error_msg[256];
sprintf(error_msg, "C++ $1_type exception thrown, value: %d", $1);
SWIG_DSetPendingException(SWIG_DException, error_msg);
return $null; %}
%typemap(throws, canthrow=1) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [ANY],
enum SWIGTYPE, const enum SWIGTYPE &
%{ (void)$1;
SWIG_DSetPendingException(SWIG_DException, "C++ $1_type exception thrown");
return $null; %}
%typemap(throws, canthrow=1) char *
%{ SWIG_DSetPendingException(SWIG_DException, $1);
return $null; %}

344
Lib/d/dhead.swg Normal file
View file

@ -0,0 +1,344 @@
/* -----------------------------------------------------------------------------
* dhead.swg
*
* Support code for exceptions if the SWIG_D_NO_EXCEPTION_HELPER is not defined
* Support code for strings if the SWIG_D_NO_STRING_HELPER is not defined
*
* Support code for function pointers. ----------------------------------------------------------------------------- */
%insert(runtime) %{
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
/* Contract support. */
#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_DSetPendingException(SWIG_DException, msg); return nullreturn; } else
%}
/*
* Exception support code.
*/
#if !defined(SWIG_D_NO_EXCEPTION_HELPER)
%insert(runtime) %{
// Support for throwing D exceptions from C/C++.
typedef enum {
SWIG_DException = 0,
SWIG_DIllegalArgumentException,
SWIG_DIllegalElementException,
SWIG_DIOException,
SWIG_DNoSuchElementException,
} SWIG_DExceptionCodes;
typedef void (* SWIG_DExceptionCallback_t)(const char *);
typedef struct {
SWIG_DExceptionCodes code;
SWIG_DExceptionCallback_t callback;
} SWIG_DException_t;
static SWIG_DException_t SWIG_d_exceptions[] = {
{ SWIG_DException, NULL },
{ SWIG_DIllegalArgumentException, NULL },
{ SWIG_DIllegalElementException, NULL },
{ SWIG_DIOException, NULL },
{ SWIG_DNoSuchElementException, NULL }
};
static void SWIGUNUSED SWIG_DSetPendingException(SWIG_DExceptionCodes code, const char *msg) {
if ((size_t)code < sizeof(SWIG_d_exceptions)/sizeof(SWIG_DException_t)) {
SWIG_d_exceptions[code].callback(msg);
} else {
SWIG_d_exceptions[SWIG_DException].callback(msg);
}
}
#ifdef __cplusplus
extern "C"
#endif
SWIGEXPORT void SWIGRegisterExceptionCallbacks_$module(
SWIG_DExceptionCallback_t exceptionCallback,
SWIG_DExceptionCallback_t illegalArgumentCallback,
SWIG_DExceptionCallback_t illegalElementCallback,
SWIG_DExceptionCallback_t ioCallback,
SWIG_DExceptionCallback_t noSuchElementCallback) {
SWIG_d_exceptions[SWIG_DException].callback = exceptionCallback;
SWIG_d_exceptions[SWIG_DIllegalArgumentException].callback = illegalArgumentCallback;
SWIG_d_exceptions[SWIG_DIllegalElementException].callback = illegalElementCallback;
SWIG_d_exceptions[SWIG_DIOException].callback = ioCallback;
SWIG_d_exceptions[SWIG_DNoSuchElementException].callback = noSuchElementCallback;
}
%}
#if (SWIG_D_VERSION == 1)
%pragma(d) imdmoduleimports=%{
// Exception throwing support currently requires Tango, but there is no reason
// why it could not support Phobos.
static import tango.core.Exception;
static import tango.core.Thread;
static import tango.stdc.stringz;
%}
%pragma(d) imdmodulecode=%{
private class SwigExceptionHelper {
static this() {
swigRegisterExceptionCallbacks$module(
&setException,
&setIllegalArgumentException,
&setIllegalElementException,
&setIOException,
&setNoSuchElementException);
}
static void setException(char* message) {
auto exception = new object.Exception(tango.stdc.stringz.fromStringz(message).dup);
exception.next = SwigPendingException.retrieve();
SwigPendingException.set(exception);
}
static void setIllegalArgumentException(char* message) {
auto exception = new tango.core.Exception.IllegalArgumentException(tango.stdc.stringz.fromStringz(message).dup);
exception.next = SwigPendingException.retrieve();
SwigPendingException.set(exception);
}
static void setIllegalElementException(char* message) {
auto exception = new tango.core.Exception.IllegalElementException(tango.stdc.stringz.fromStringz(message).dup);
exception.next = SwigPendingException.retrieve();
SwigPendingException.set(exception);
}
static void setIOException(char* message) {
auto exception = new tango.core.Exception.IOException(tango.stdc.stringz.fromStringz(message).dup);
exception.next = SwigPendingException.retrieve();
SwigPendingException.set(exception);
}
static void setNoSuchElementException(char* message) {
auto exception = new tango.core.Exception.NoSuchElementException(tango.stdc.stringz.fromStringz(message).dup);
exception.next = SwigPendingException.retrieve();
SwigPendingException.set(exception);
}
}
package class SwigPendingException {
public:
static this() {
m_sPendingCount = 0;
m_sPendingException = new ThreadLocalData(null);
}
static bool isPending() {
bool pending = false;
if (m_sPendingCount > 0) {
if (m_sPendingException.val !is null) {
pending = true;
}
}
return pending;
}
static void set(object.Exception e) {
if (m_sPendingException.val !is null) {
throw new object.Exception("FATAL: An earlier pending exception from C/C++ code " ~
"was missed and thus not thrown (" ~ m_sPendingException.val.classinfo.name ~
": " ~ m_sPendingException.val.msg ~ ")!", e);
}
m_sPendingException.val = e;
synchronized {
++m_sPendingCount;
}
}
static object.Exception retrieve() {
object.Exception e = null;
if (m_sPendingCount > 0) {
if (m_sPendingException.val !is null) {
e = m_sPendingException.val;
m_sPendingException.val = null;
synchronized {
--m_sPendingCount;
}
}
}
return e;
}
private:
// The pending exception counter is stored thread-global.
static int m_sPendingCount;
// The reference to the pending exception (if any) is stored thread-local.
alias tango.core.Thread.ThreadLocal!(object.Exception) ThreadLocalData;
static ThreadLocalData m_sPendingException;
}
alias void function(char* message) SwigExceptionCallback;
%}
#else
%pragma(d) imdmoduleimports=%{
static import std.conv;
%}
%pragma(d) imdmodulecode=%{
private class SwigExceptionHelper {
static this() {
// The D1/Tango version maps C++ exceptions to multiple exception types.
swigRegisterExceptionCallbacks$module(
&setException,
&setException,
&setException,
&setException,
&setException
);
}
static void setException(const char* message) {
auto exception = new object.Exception(std.conv.to!string(message).idup);
exception.next = SwigPendingException.retrieve();
SwigPendingException.set(exception);
}
}
package struct SwigPendingException {
public:
static this() {
m_sPendingCount = 0;
m_sPendingException = null;
}
static bool isPending() {
bool pending = false;
if (m_sPendingCount > 0) {
if (m_sPendingException !is null) {
pending = true;
}
}
return pending;
}
static void set(object.Exception e) {
if (m_sPendingException !is null) {
throw new object.Exception("FATAL: An earlier pending exception from C/C++ code " ~
"was missed and thus not thrown (" ~ m_sPendingException.classinfo.name ~
": " ~ m_sPendingException.msg ~ ")!", e);
}
m_sPendingException = e;
synchronized {
++m_sPendingCount;
}
}
static object.Exception retrieve() {
object.Exception e = null;
if (m_sPendingCount > 0) {
if (m_sPendingException !is null) {
e = m_sPendingException;
m_sPendingException = null;
synchronized {
--m_sPendingCount;
}
}
}
return e;
}
private:
// The pending exception counter is stored thread-global.
static shared int m_sPendingCount;
// The reference to the pending exception (if any) is stored thread-local.
static object.Exception m_sPendingException;
}
alias void function(const char* message) SwigExceptionCallback;
%}
#endif
// Callback registering function in wrapperloader.swg.
#endif // SWIG_D_NO_EXCEPTION_HELPER
/*
* String support code.
*/
#if !defined(SWIG_D_NO_STRING_HELPER)
%insert(runtime) %{
// Callback for returning strings to D without leaking memory.
typedef char * (* SWIG_DStringHelperCallback)(const char *);
static SWIG_DStringHelperCallback SWIG_d_string_callback = NULL;
#ifdef __cplusplus
extern "C"
#endif
SWIGEXPORT void SWIGRegisterStringCallback_$module(SWIG_DStringHelperCallback callback) {
SWIG_d_string_callback = callback;
}
%}
#if (SWIG_D_VERSION == 1)
%pragma(d) imdmoduleimports = "static import tango.stdc.stringz;";
%pragma(d) imdmodulecode = %{
private class SwigStringHelper {
static this() {
swigRegisterStringCallback$module(&createString);
}
static char* createString(char* cString) {
// We are effectively dup'ing the string here.
return tango.stdc.stringz.toStringz(tango.stdc.stringz.fromStringz(cString));
}
}
alias char* function(char* cString) SwigStringCallback;
%}
#else
%pragma(d) imdmoduleimports = %{
static import std.conv;
static import std.string;
%}
%pragma(d) imdmodulecode = %{
private class SwigStringHelper {
static this() {
swigRegisterStringCallback$module(&createString);
}
static const(char)* createString(const(char*) cString) {
// We are effectively dup'ing the string here.
// TODO: Is this also correct for D2/Phobos?
return std.string.toStringz(std.conv.to!string(cString));
}
}
alias const(char)* function(const(char*) cString) SwigStringCallback;
%}
#endif
// Callback registering function in wrapperloader.swg.
#endif // SWIG_D_NO_STRING_HELPER
/*
* Function pointer support code.
*/
#if (SWIG_D_VERSION == 1)
%pragma(d) imdmodulecode = %{
template SwigExternC(T) {
static if (is(typeof(*(T.init)) R == return)) {
static if (is(typeof(*(T.init)) P == function)) {
alias extern(C) R function(P) SwigExternC;
}
}
}
%}
#else
%pragma(d) imdmodulecode = %{
template SwigExternC(T) if (is(typeof(*(T.init)) P == function)) {
static if (is(typeof(*(T.init)) R == return)) {
static if (is(typeof(*(T.init)) P == function)) {
alias extern(C) R function(P) SwigExternC;
}
}
}
%}
#endif

46
Lib/d/director.swg Normal file
View file

@ -0,0 +1,46 @@
/* -----------------------------------------------------------------------------
* director.swg
*
* This file contains support for director classes so that D proxy
* methods can be called from C++.
* ----------------------------------------------------------------------------- */
#ifdef __cplusplus
#if defined(DEBUG_DIRECTOR_OWNED)
#include <iostream>
#endif
#include <string>
namespace Swig {
// Director base class – not used in D directors.
class Director {
};
// Base class for director exceptions.
class DirectorException {
protected:
std::string swig_msg;
public:
DirectorException(const char* msg) : swig_msg(msg) {
}
DirectorException(const std::string &msg) : swig_msg(msg) {
}
const std::string& what() const {
return swig_msg;
}
virtual ~DirectorException() {
}
};
// Exception which is thrown when attempting to call a pure virtual method
// from D code thorugh the director layer.
class DirectorPureVirtualException : public Swig::DirectorException {
public:
DirectorPureVirtualException(const char* msg) : DirectorException(std::string("Attempted to invoke pure virtual method ") + msg) {
}
};
}
#endif /* __cplusplus */

128
Lib/d/dkw.swg Normal file
View file

@ -0,0 +1,128 @@
#ifndef D_DKW_SWG_
#define D_DKW_SWG_
/* Warnings for D keywords */
#define DKEYWORD(x) %keywordwarn("'" `x` "' is a D keyword, renaming to '_" `x` "'",rename="_%s") `x`
// Source: http://www.digitalmars.com/d/{1.0,2.0}/lex.html and
DKEYWORD(Error);
DKEYWORD(Exception);
DKEYWORD(Object);
DKEYWORD(__FILE__);
DKEYWORD(__LINE__);
DKEYWORD(__gshared);
DKEYWORD(__thread);
DKEYWORD(__traits);
DKEYWORD(abstract);
DKEYWORD(alias);
DKEYWORD(align);
DKEYWORD(asm);
DKEYWORD(assert);
DKEYWORD(auto);
DKEYWORD(body);
DKEYWORD(bool);
DKEYWORD(break);
DKEYWORD(byte);
DKEYWORD(case);
DKEYWORD(cast);
DKEYWORD(catch);
DKEYWORD(cdouble);
DKEYWORD(cent);
DKEYWORD(cfloat);
DKEYWORD(char);
DKEYWORD(class);
DKEYWORD(const);
DKEYWORD(continue);
DKEYWORD(creal);
DKEYWORD(dchar);
DKEYWORD(debug);
DKEYWORD(default);
DKEYWORD(delegate);
DKEYWORD(delete);
DKEYWORD(deprecated);
DKEYWORD(do);
DKEYWORD(double);
DKEYWORD(dstring);
DKEYWORD(else);
DKEYWORD(enum);
DKEYWORD(export);
DKEYWORD(extern);
DKEYWORD(false);
DKEYWORD(final);
DKEYWORD(finally);
DKEYWORD(float);
DKEYWORD(for);
DKEYWORD(foreach);
DKEYWORD(foreach_reverse);
DKEYWORD(function);
DKEYWORD(goto);
DKEYWORD(idouble);
DKEYWORD(if);
DKEYWORD(ifloat);
DKEYWORD(immutable);
DKEYWORD(import);
DKEYWORD(in);
DKEYWORD(inout);
DKEYWORD(int);
DKEYWORD(interface);
DKEYWORD(invariant);
DKEYWORD(ireal);
DKEYWORD(is);
DKEYWORD(lazy);
DKEYWORD(long);
DKEYWORD(macro);
DKEYWORD(mixin);
DKEYWORD(module);
DKEYWORD(new);
DKEYWORD(nothrow);
DKEYWORD(null);
DKEYWORD(out);
DKEYWORD(override);
DKEYWORD(package);
DKEYWORD(pragma);
DKEYWORD(private);
DKEYWORD(protected);
DKEYWORD(public);
DKEYWORD(pure);
DKEYWORD(real);
DKEYWORD(ref);
DKEYWORD(return);
DKEYWORD(scope);
DKEYWORD(shared);
DKEYWORD(short);
DKEYWORD(static);
DKEYWORD(string);
DKEYWORD(struct);
DKEYWORD(super);
DKEYWORD(switch);
DKEYWORD(synchronized);
DKEYWORD(template);
DKEYWORD(this);
DKEYWORD(throw);
DKEYWORD(true);
DKEYWORD(try);
DKEYWORD(typedef);
DKEYWORD(typeid);
DKEYWORD(typeof);
DKEYWORD(ubyte);
DKEYWORD(ucent);
DKEYWORD(uint);
DKEYWORD(ulong);
DKEYWORD(union);
DKEYWORD(unittest);
DKEYWORD(ushort);
DKEYWORD(version);
DKEYWORD(void);
DKEYWORD(volatile);
DKEYWORD(wchar);
DKEYWORD(while);
DKEYWORD(with);
DKEYWORD(wstring);
// Not really a keyword, but dispose() methods are generated in proxy classes
// and it's a special method name for D1/Tango.
DKEYWORD(dispose);
#undef DKEYWORD
#endif //D_DKW_SWG_

View file

@ -0,0 +1,92 @@
/* -----------------------------------------------------------------------------
* dmemberfunctionpointers.swg
*
* Typemaps for member function pointers.
* ----------------------------------------------------------------------------- */
%typemap(ctype) SWIGTYPE (CLASS::*) "char *"
%typemap(imtype) SWIGTYPE (CLASS::*) "char*"
%typemap(dtype) SWIGTYPE (CLASS::*) "$dclassname"
%typecheck(SWIG_TYPECHECK_POINTER)
SWIGTYPE (CLASS::*)
""
/*
* Conversion generation typemaps.
*/
%typemap(in, fragment="SWIG_UnPackData") SWIGTYPE (CLASS::*) %{
SWIG_UnpackData($input, (void *)&$1, sizeof($1));
%}
%typemap(out, fragment="SWIG_PackData") SWIGTYPE (CLASS::*) %{
char buf[128];
char *data = SWIG_PackData(buf, (void *)&$1, sizeof($1));
*data = '\0';
$result = SWIG_d_string_callback(buf);
%}
%typemap(directorin) SWIGTYPE (CLASS::*) "$input = (void *) $1;"
%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE (CLASS::*)
"$result = ($1_ltype)$input;"
%typemap(ddirectorin) SWIGTYPE (CLASS::*)
"($winput is null) ? null : new $dclassname($winput, false)"
%typemap(ddirectorout) SWIGTYPE (CLASS::*) "$dclassname.swigGetCPtr($dcall)"
%typemap(din) SWIGTYPE (CLASS::*) "$dclassname.swigGetCMemberPtr($dinput)"
%typemap(dout, excode=SWIGEXCODE) SWIGTYPE (CLASS::*) {
char* cMemberPtr = $imcall;
$dclassname ret = (cMemberPtr is null) ? null : new $dclassname(cMemberPtr, $owner);$excode
return ret;
}
/*
* Helper functions to pack/unpack arbitrary binary data (member function
* pointers in this case) into a string.
*/
%fragment("SWIG_PackData", "header") {
/* Pack binary data into a string */
SWIGINTERN char * SWIG_PackData(char *c, void *ptr, size_t sz) {
static const char hex[17] = "0123456789abcdef";
register const unsigned char *u = (unsigned char *) ptr;
register const unsigned char *eu = u + sz;
for (; u != eu; ++u) {
register unsigned char uu = *u;
*(c++) = hex[(uu & 0xf0) >> 4];
*(c++) = hex[uu & 0xf];
}
return c;
}
}
%fragment("SWIG_UnPackData", "header") {
/* Unpack binary data from a string */
SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
register unsigned char *u = (unsigned char *) ptr;
register const unsigned char *eu = u + sz;
for (; u != eu; ++u) {
register char d = *(c++);
register unsigned char uu;
if ((d >= '0') && (d <= '9'))
uu = ((d - '0') << 4);
else if ((d >= 'a') && (d <= 'f'))
uu = ((d - ('a'-10)) << 4);
else
return (char *) 0;
d = *(c++);
if ((d >= '0') && (d <= '9'))
uu |= (d - '0');
else if ((d >= 'a') && (d <= 'f'))
uu |= (d - ('a'-10));
else
return (char *) 0;
*u = uu;
}
return c;
}
}

259
Lib/d/doperators.swg Normal file
View file

@ -0,0 +1,259 @@
/* -----------------------------------------------------------------------------
* doperators.swg
*
* Mapping of C++ operator overloading methods to D.
* ----------------------------------------------------------------------------- */
#if (SWIG_D_VERSION == 1)
%pragma(d) imdmodulecode=%{
template SwigOperatorDefinitions() {
public override int opEquals(Object o) {
if (auto rhs = cast(typeof(this))o) {
if (swigCPtr == rhs.swigCPtr) return 1;
static if (is(typeof(swigOpEquals(rhs)))) {
return swigOpEquals(rhs) ? 1 : 0;
} else {
return 0;
}
}
return super.opEquals(o);
}
%}
// opEquals is emitted in pure C mode as well to define two proxy classes
// pointing to the same struct as equal.
#ifdef __cplusplus
%rename(opPos) *::operator+();
%rename(opPos) *::operator+() const;
%rename(opNeg) *::operator-();
%rename(opNeg) *::operator-() const;
%rename(opCom) *::operator~();
%rename(opCom) *::operator~() const;
%rename(opAdd) *::operator+;
%rename(opAddAssign) *::operator+=;
%rename(opSub) *::operator-;
%rename(opSubAssign) *::operator-=;
%rename(opMul) *::operator*;
%rename(opMulAssign) *::operator*=;
%rename(opDiv) *::operator/;
%rename(opDivAssign) *::operator/=;
%rename(opMod) *::operator%;
%rename(opModAssign) *::operator%=;
%rename(opAnd) *::operator&;
%rename(opAndAssign) *::operator&=;
%rename(opOr) *::operator|;
%rename(opOrAssign) *::operator|=;
%rename(opXor) *::operator^;
%rename(opXorAssign) *::operator^=;
%rename(opShl) *::operator<<;
%rename(opShlAssign) *::operator<<=;
%rename(opShr) *::operator>>;
%rename(opShrAssign) *::operator>>=;
%rename(opIndex) *::operator[](unsigned) const;
// opIndexAssign is not currently generated, it needs more extensive support
// mechanisms.
%rename(opCall) *::operator();
// !a is not overrideable in D1.
%ignoreoperator(LNOT) operator!;
// opCmp is used in D.
%rename(swigOpEquals) *::operator==;
%rename(swigOpLt) *::operator<;
%rename(swigOpLtEquals) *::operator<=;
%rename(swigOpGt) *::operator>;
%rename(swigOpGtEquals) *::operator>=;
// a != b is rewritten as !a.opEquals(b) in D.
%ignoreoperator(NOTEQUAL) operator!=;
// The logic operators are not overrideable in D.
%ignoreoperator(LAND) operator&&;
%ignoreoperator(LOR) operator||;
// ++/--a is rewritten as a +/-= 1 in D1,so ignore the prefix operators.
%ignoreoperator(PLUSPLUS) *::operator++();
%ignoreoperator(MINUSMINUS) *::operator--();
%rename(swigOpInc) *::operator++(int);
%rename(swigOpDec) *::operator--(int);
// The C++ assignment operator does not translate well to D where the proxy
// classes have reference semantics.
%ignoreoperator(EQ) operator=;
%pragma(d) imdmodulecode=%{
public override int opCmp(Object o) {
static if (is(typeof(swigOpLt(typeof(this).init) &&
swigOpEquals(typeof(this).init)))) {
if (auto rhs = cast(typeof(this))o) {
if (swigOpLt(rhs)) {
return -1;
} else if (swigOpEquals(rhs)) {
return 0;
} else {
return 1;
}
}
}
return super.opCmp(o);
}
public typeof(this) opPostInc(T = int)(T unused = 0) {
static assert(
is(typeof(swigOpInc(int.init))),
"opPostInc called on " ~ typeof(this).stringof ~ ", but no postfix " ~
"increment operator exists in the corresponding C++ class."
);
return swigOpInc(int.init);
}
public typeof(this) opPostDec(T = int)(T unused = 0) {
static assert(
is(typeof(swigOpDec(int.init))),
"opPostInc called on " ~ typeof(this).stringof ~ ", but no postfix " ~
"decrement operator exists in the corresponding C++ class."
);
return swigOpDec(int.init);
}
%}
#endif
%pragma(d) imdmodulecode=%{
}
%}
#else
%pragma(d) imdmodulecode=%{
mixin template SwigOperatorDefinitions() {
public override bool opEquals(Object o) {
if (auto rhs = cast(typeof(this))o) {
if (swigCPtr == rhs.swigCPtr) return true;
static if (is(typeof(swigOpEquals(rhs)))) {
return swigOpEquals(rhs);
} else {
return false;
}
}
return super.opEquals(o);
}
%}
// opEquals is emitted in pure C mode as well to define two proxy classes
// pointing to the same struct as equal.
#ifdef __cplusplus
%rename(swigOpPos) *::operator+();
%rename(swigOpPos) *::operator+() const;
%rename(swigOpNeg) *::operator-();
%rename(swigOpNeg) *::operator-() const;
%rename(swigOpCom) *::operator~();
%rename(swigOpCom) *::operator~() const;
%rename(swigOpInc) *::operator++();
%rename(swigOpDec) *::operator--();
%ignoreoperator(PLUSPLUS) *::operator++(int);
%ignoreoperator(MINUSMINUS) *::operator--(int);
// The postfix increment/decrement operators are ignored because they are
// rewritten to (auto t = e, ++e, t) in D2. The unary * operator (used for
// pointer dereferencing in C/C++) isn't mapped to opUnary("*") by default,
// despite this would be possible in D2 – the difference in member access
// semantics would only lead to confusion in most cases.
%rename(swigOpAdd) *::operator+;
%rename(swigOpSub) *::operator-;
%rename(swigOpMul) *::operator*;
%rename(swigOpDiv) *::operator/;
%rename(swigOpMod) *::operator%;
%rename(swigOpAnd) *::operator&;
%rename(swigOpOr) *::operator|;
%rename(swigOpXor) *::operator^;
%rename(swigOpShl) *::operator<<;
%rename(swigOpShr) *::operator>>;
%rename(swigOpAddAssign) *::operator+=;
%rename(swigOpSubAssign) *::operator-=;
%rename(swigOpMulAssign) *::operator*=;
%rename(swigOpDivAssign) *::operator/=;
%rename(swigOpModAssign) *::operator%=;
%rename(swigOpAndAssign) *::operator&=;
%rename(swigOpOrAssign) *::operator|=;
%rename(swigOpXorAssign) *::operator^=;
%rename(swigOpShlAssign) *::operator<<=;
%rename(swigOpShrAssign) *::operator>>=;
%rename(opIndex) *::operator[];
// opIndexAssign is not currently generated, it needs more extensive support
// mechanisms.
%rename(opCall) *::operator();
%rename(swigOpEquals) *::operator==;
%rename(swigOpLt) *::operator<;
%rename(swigOpLtEquals) *::operator<=;
%rename(swigOpGt) *::operator>;
%rename(swigOpGtEquals) *::operator>=;
// a != b is rewritten as !a.opEquals(b) in D.
%ignoreoperator(NOTEQUAL) operator!=;
// The logic operators are not overrideable in D.
%ignoreoperator(LAND) operator&&;
%ignoreoperator(LOR) operator||;
// The C++ assignment operator does not translate well to D where the proxy
// classes have reference semantics.
%ignoreoperator(EQ) operator=;
%pragma(d) imdmodulecode=%{
public override int opCmp(Object o) {
static if (__traits(compiles, swigOpLt(typeof(this).init) &&
swigOpEquals(typeof(this).init))) {
if (auto rhs = cast(typeof(this))o) {
if (swigOpLt(rhs)) {
return -1;
} else if (swigOpEquals(rhs)) {
return 0;
} else {
return 1;
}
}
}
return super.opCmp(o);
}
private template swigOpBinary(string operator, string name) {
enum swigOpBinary = `public void opOpAssign(string op, T)(T rhs) if (op == "` ~ operator ~
`" && __traits(compiles, swigOp` ~ name ~ `Assign(rhs))) { swigOp` ~ name ~ `Assign(rhs);}` ~
`public auto opBinary(string op, T)(T rhs) if (op == "` ~ operator ~
`" && __traits(compiles, swigOp` ~ name ~ `(rhs))) { return swigOp` ~ name ~ `(rhs);}`;
}
mixin(swigOpBinary!("+", "Add"));
mixin(swigOpBinary!("-", "Sub"));
mixin(swigOpBinary!("*", "Mul"));
mixin(swigOpBinary!("/", "Div"));
mixin(swigOpBinary!("%", "Mod"));
mixin(swigOpBinary!("&", "And"));
mixin(swigOpBinary!("|", "Or"));
mixin(swigOpBinary!("^", "Xor"));
mixin(swigOpBinary!("<<", "Shl"));
mixin(swigOpBinary!(">>", "Shr"));
private template swigOpUnary(string operator, string name) {
enum swigOpUnary = `public auto opUnary(string op)() if (op == "` ~ operator ~
`" && __traits(compiles, swigOp` ~ name ~ `())) { return swigOp` ~ name ~ `();}`;
}
mixin(swigOpUnary!("+", "Pos"));
mixin(swigOpUnary!("-", "Neg"));
mixin(swigOpUnary!("~", "Com"));
mixin(swigOpUnary!("++", "Inc"));
mixin(swigOpUnary!("--", "Dec"));
%}
#endif
%pragma(d) imdmodulecode=%{
}
%}
#endif

171
Lib/d/dprimitives.swg Normal file
View file

@ -0,0 +1,171 @@
/* -----------------------------------------------------------------------------
* dprimitves.swg
*
* Typemaps for primitive types.
* ----------------------------------------------------------------------------- */
// C long/ulong width depends on the target arch, use stdlib aliases for them.
#if (SWIG_D_VERSION == 1)
%pragma(d) imdmoduleimports = "static import tango.stdc.config;"
%pragma(d) globalproxyimports = "static import tango.stdc.config;"
#define SWIG_LONG_DTYPE tango.stdc.config.c_long
#define SWIG_ULONG_DTYPE tango.stdc.config.c_ulong
#else
%pragma(d) imdmoduleimports = "static import core.stdc.config;"
%pragma(d) globalproxyimports = "static import core.stdc.config;"
#define SWIG_LONG_DTYPE core.stdc.config.c_long
#define SWIG_ULONG_DTYPE core.stdc.config.c_ulong
#endif
/*
* The SWIG_D_PRIMITIVE macro is used to define the typemaps for the primitive
* types, because are more or less the same for all of them. The few special
* cases are handeled below.
*/
%define SWIG_D_PRIMITIVE(TYPE, DTYPE)
%typemap(ctype) TYPE, const TYPE & "TYPE"
%typemap(imtype) TYPE, const TYPE & "DTYPE"
%typemap(dtype, cprimitive="1") TYPE, const TYPE & "DTYPE"
%typemap(in) TYPE "$1 = ($1_ltype)$input;"
%typemap(out) TYPE "$result = $1;"
%typemap(directorin) TYPE "$input = $1;"
%typemap(directorout) TYPE "$result = ($1_ltype)$input;"
%typemap(ddirectorin) TYPE "$winput"
%typemap(ddirectorout) TYPE "$dcall"
%typemap(in) const TYPE & ($*1_ltype temp)
%{ temp = ($*1_ltype)$input;
$1 = &temp; %}
%typemap(out) const TYPE & "$result = *$1;"
%typemap(directorin) const TYPE & "$input = $1;"
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const TYPE &
%{ static $*1_ltype temp;
temp = ($*1_ltype)$input;
$result = &temp; %}
%typemap(ddirectorin) const TYPE & "$winput"
%typemap(ddirectorout) const TYPE & "$dcall"
%typemap(din) TYPE, const TYPE & "$dinput"
%typemap(dout, excode=SWIGEXCODE) TYPE, const TYPE & {
auto ret = $imcall;$excode
return ret;
}
%enddef
SWIG_D_PRIMITIVE(bool, bool)
SWIG_D_PRIMITIVE(char, char)
SWIG_D_PRIMITIVE(signed char, byte)
SWIG_D_PRIMITIVE(unsigned char, ubyte)
SWIG_D_PRIMITIVE(short, short)
SWIG_D_PRIMITIVE(unsigned short, ushort)
SWIG_D_PRIMITIVE(int, int)
SWIG_D_PRIMITIVE(unsigned int, uint)
SWIG_D_PRIMITIVE(long, SWIG_LONG_DTYPE)
SWIG_D_PRIMITIVE(unsigned long, SWIG_ULONG_DTYPE)
SWIG_D_PRIMITIVE(size_t, size_t)
SWIG_D_PRIMITIVE(long long, long)
SWIG_D_PRIMITIVE(unsigned long long, ulong)
SWIG_D_PRIMITIVE(float, float)
SWIG_D_PRIMITIVE(double, double)
// The C++ boolean type needs some special casing since it is not part of the
// C standard and is thus represented as unsigned int in the C wrapper layer.
%typemap(ctype) bool, const bool & "unsigned int"
%typemap(imtype) bool, const bool & "uint"
%typemap(in) bool "$1 = $input ? true : false;"
%typemap(in) const bool & ($*1_ltype temp)
%{ temp = $input ? true : false;
$1 = &temp; %}
%typemap(directorout) bool
"$result = $input ? true : false;"
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const bool &
%{ static $*1_ltype temp;
temp = $input ? true : false;
$result = &temp; %}
%typemap(ddirectorin) bool "($winput ? true : false)"
%typemap(dout, excode=SWIGEXCODE) bool, const bool & {
bool ret = $imcall ? true : false;$excode
return ret;
}
// Judging from the history of the C# module, the explicit casts are needed for
// certain versions of VC++.
%typemap(out) unsigned long "$result = (unsigned long)$1;"
%typemap(out) const unsigned long & "$result = (unsigned long)*$1;"
/*
* Typecheck typemaps.
*/
%typecheck(SWIG_TYPECHECK_BOOL)
bool,
const bool &
""
%typecheck(SWIG_TYPECHECK_CHAR)
char,
const char &
""
%typecheck(SWIG_TYPECHECK_INT8)
signed char,
const signed char &
""
%typecheck(SWIG_TYPECHECK_UINT8)
unsigned char,
const unsigned char &
""
%typecheck(SWIG_TYPECHECK_INT16)
short,
const short &
""
%typecheck(SWIG_TYPECHECK_UINT16)
unsigned short,
const unsigned short &
""
%typecheck(SWIG_TYPECHECK_INT32)
int,
long,
const int &,
const long &
""
%typecheck(SWIG_TYPECHECK_UINT32)
unsigned int,
unsigned long,
const unsigned int &,
const unsigned long &
""
%typecheck(SWIG_TYPECHECK_INT64)
long long,
const long long &
""
%typecheck(SWIG_TYPECHECK_UINT64)
unsigned long long,
const unsigned long long &
""
%typecheck(SWIG_TYPECHECK_FLOAT)
float,
const float &
""
%typecheck(SWIG_TYPECHECK_DOUBLE)
double,
const double &
""

80
Lib/d/dstrings.swg Normal file
View file

@ -0,0 +1,80 @@
/* -----------------------------------------------------------------------------
* dstrings.swg
*
* Typemaps for wrapping pointers to/arrays of C chars as D strings.
* ----------------------------------------------------------------------------- */
%define SWIGD_STRING_TYPEMAPS(DW_STRING_TYPE, DP_STRING_TYPE, FROM_STRINGZ, TO_STRINGZ)
%typemap(ctype) char *, char *&, char[ANY], char[] "char *"
%typemap(imtype) char *, char *&, char[ANY], char[] #DW_STRING_TYPE
%typemap(dtype) char *, char *&, char[ANY], char[] #DP_STRING_TYPE
/*
* char* typemaps.
*/
%typemap(in) char * %{ $1 = ($1_ltype)$input; %}
%typemap(out) char * %{ $result = SWIG_d_string_callback((const char *)$1); %}
%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) char * %{ $result = ($1_ltype)$input; %}
%typemap(directorin) char * %{ $input = SWIG_d_string_callback((const char *)$1); %}
%typemap(ddirectorin) char * "FROM_STRINGZ($winput)"
%typemap(ddirectorout) char * "TO_STRINGZ($dcall)"
/*
* char*& typemaps.
*/
%typemap(in) char *& ($*1_ltype temp = 0) %{
temp = ($*1_ltype)$input;
$1 = &temp;
%}
%typemap(out) char *& %{ if ($1) $result = SWIG_d_string_callback((const char *)*$1); %}
/*
* char array typemaps.
*/
%typemap(in) char[ANY], char[] %{ $1 = ($1_ltype)$input; %}
%typemap(out) char[ANY], char[] %{ $result = SWIG_d_string_callback((const char *)$1); %}
%typemap(directorout) char[ANY], char[] %{ $result = ($1_ltype)$input; %}
%typemap(directorin) char[ANY], char[] %{ $input = SWIG_d_string_callback((const char *)$1); %}
%typemap(ddirectorin) char[ANY], char[] "$winput"
%typemap(ddirectorout) char[ANY], char[] "$dcall"
%typemap(din) char *, char *&, char[ANY], char[] "($dinput ? TO_STRINGZ($dinput) : null)"
%typemap(dout, excode=SWIGEXCODE) char *, char *&, char[ANY], char[] {
DP_STRING_TYPE ret = FROM_STRINGZ ## ($imcall);$excode
return ret;
}
%typecheck(SWIG_TYPECHECK_STRING)
char *,
char *&,
char[ANY],
char[]
""
%enddef
// We need to have the \0-terminated string conversion functions available in
// the D proxy modules.
#if (SWIG_D_VERSION == 1)
// Could be easily extended to support Phobos as well.
SWIGD_STRING_TYPEMAPS(char*, char[], tango.stdc.stringz.fromStringz, tango.stdc.stringz.toStringz)
%pragma(d) globalproxyimports = "static import tango.stdc.stringz;";
#else
SWIGD_STRING_TYPEMAPS(const(char)*, string, std.conv.to!string, std.string.toStringz)
%pragma(d) globalproxyimports = %{
static import std.conv;
static import std.string;
%}
#endif
#undef SWIGD_STRING_TYPEMAPS

184
Lib/d/dswigtype.swg Normal file
View file

@ -0,0 +1,184 @@
/* -----------------------------------------------------------------------------
* dswigtype.swg
*
* Typemaps for non-primitive types (C/C++ classes and structs).
* ----------------------------------------------------------------------------- */
%typemap(ctype) SWIGTYPE "void *"
%typemap(imtype) SWIGTYPE "void*"
%typemap(dtype) SWIGTYPE "$&dclassname"
%typemap(ctype) SWIGTYPE [] "void *"
%typemap(imtype) SWIGTYPE [] "void*"
%typemap(dtype) SWIGTYPE [] "$dclassname"
%typemap(ctype) SWIGTYPE * "void *"
%typemap(imtype) SWIGTYPE * "void*"
%typemap(dtype, nativepointer="$dtype") SWIGTYPE * "$dclassname"
%typemap(ctype) SWIGTYPE & "void *"
%typemap(imtype) SWIGTYPE & "void*"
%typemap(dtype, nativepointer="$dtype") SWIGTYPE & "$dclassname"
%typemap(ctype) SWIGTYPE *const& "void *"
%typemap(imtype) SWIGTYPE *const& "void*"
%typemap(dtype) SWIGTYPE *const& "$*dclassname"
%typecheck(SWIG_TYPECHECK_POINTER)
SWIGTYPE,
SWIGTYPE *,
SWIGTYPE &,
SWIGTYPE [],
SWIGTYPE *const&
""
/*
* By-value conversion typemaps (parameter is converted to a pointer).
*/
%typemap(in, canthrow=1) SWIGTYPE ($&1_type argp)
%{ argp = ($&1_ltype)$input;
if (!argp) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Attempt to dereference null $1_type");
return $null;
}
$1 = *argp; %}
%typemap(out) SWIGTYPE
#ifdef __cplusplus
%{ $result = new $1_ltype((const $1_ltype &)$1); %}
#else
{
$&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype));
memmove($1ptr, &$1, sizeof($1_type));
$result = $1ptr;
}
#endif
%typemap(directorin) SWIGTYPE
"$input = (void *)&$1;"
%typemap(directorout) SWIGTYPE
%{ if (!$input) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Unexpected null return for type $1_type");
return $null;
}
$result = *($&1_ltype)$input; %}
%typemap(ddirectorin) SWIGTYPE "new $&dclassname($winput, false)"
%typemap(ddirectorout) SWIGTYPE "$&dclassname.swigGetCPtr($dcall)"
%typemap(din) SWIGTYPE "$&dclassname.swigGetCPtr($dinput)"
%typemap(dout, excode=SWIGEXCODE) SWIGTYPE {
$&dclassname ret = new $&dclassname($imcall, true);$excode
return ret;
}
/*
* Pointer conversion typemaps.
*/
%typemap(in) SWIGTYPE * "$1 = ($1_ltype)$input;"
%typemap(out) SWIGTYPE * "$result = (void *)$1;"
%typemap(directorin) SWIGTYPE *
"$input = (void *) $1;"
%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE *
"$result = ($1_ltype)$input;"
%typemap(ddirectorin,
nativepointer="cast($dtype)$winput"
) SWIGTYPE * "($winput is null) ? null : new $dclassname($winput, false)"
%typemap(ddirectorout,
nativepointer="cast(void*)$dcall"
) SWIGTYPE * "$dclassname.swigGetCPtr($dcall)"
%typemap(din,
nativepointer="cast(void*)$dinput"
) SWIGTYPE * "$dclassname.swigGetCPtr($dinput)"
%typemap(dout, excode=SWIGEXCODE,
nativepointer="{\n auto ret = cast($dtype)$imcall;$excode\n return ret;\n}"
) SWIGTYPE * {
void* cPtr = $imcall;
$dclassname ret = (cPtr is null) ? null : new $dclassname(cPtr, $owner);$excode
return ret;
}
// Use the same typemaps for const pointers.
%apply SWIGTYPE * { SWIGTYPE *const }
/*
* Reference conversion typemaps.
*/
%typemap(in, canthrow=1) SWIGTYPE & %{ $1 = ($1_ltype)$input;
if (!$1) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type type is null");
return $null;
} %}
%typemap(out) SWIGTYPE & "$result = (void *)$1;"
%typemap(directorin) SWIGTYPE &
"$input = ($1_ltype) &$1;"
%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE &
%{ if (!$input) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Unexpected null return for type $1_type");
return $null;
}
$result = ($1_ltype)$input; %}
%typemap(ddirectorin,
nativepointer="cast($dtype)$winput"
) SWIGTYPE & "new $dclassname($winput, false)"
%typemap(ddirectorout,
nativepointer="cast(void*)$dcall"
) SWIGTYPE & "$dclassname.swigGetCPtr($dcall)"
%typemap(din,
nativepointer="cast(void*)$dinput"
) SWIGTYPE & "$dclassname.swigGetCPtr($dinput)"
%typemap(dout, excode=SWIGEXCODE,
nativepointer="{\n auto ret = cast($dtype)$imcall;$excode\n return ret;\n}") SWIGTYPE & {
$dclassname ret = new $dclassname($imcall, $owner);$excode
return ret;
}
/*
* Array conversion typemaps.
*/
%typemap(in) SWIGTYPE [] %{ $1 = ($1_ltype)$input; %}
%typemap(out) SWIGTYPE [] %{ $result = $1; %}
%typemap(din) SWIGTYPE [] "$dclassname.swigGetCPtr($dinput)"
%typemap(dout, excode=SWIGEXCODE) SWIGTYPE [] {
void* cPtr = $imcall;
$dclassname ret = (cPtr is null) ? null : new $dclassname(cPtr, $owner);$excode
return ret;
}
// Treat references to arrays like like references to a single element.
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
/*
* Pointer reference conversion typemaps.
*/
%typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0)
%{ temp = ($*1_ltype)$input;
$1 = ($1_ltype)&temp; %}
%typemap(out) SWIGTYPE *const&
%{ $result = (void *)*$1; %}
%typemap(din) SWIGTYPE *const& "$*dclassname.swigGetCPtr($dinput)"
%typemap(dout, excode=SWIGEXCODE) SWIGTYPE *const& {
void* cPtr = $imcall;
$*dclassname ret = (cPtr is null) ? null : new $*dclassname(cPtr, $owner);$excode
return ret;
}

18
Lib/d/dvoid.swg Normal file
View file

@ -0,0 +1,18 @@
/* -----------------------------------------------------------------------------
* dvoid.swg
*
* Typemaps for handling void function return types and empty parameter lists.
* ----------------------------------------------------------------------------- */
%typemap(ctype) void "void"
%typemap(imtype) void "void"
%typemap(dtype, cprimitive="1") void "void"
%typemap(out, null="") void ""
%typemap(ddirectorin) void "$winput"
%typemap(ddirectorout) void "$dcall"
%typemap(directorin) void ""
%typemap(dout, excode=SWIGEXCODE) void {
$imcall;$excode
}

5
Lib/d/std_common.i Normal file
View file

@ -0,0 +1,5 @@
%include <std_except.i>
%apply size_t { std::size_t };
%apply const size_t& { const std::size_t& };

1
Lib/d/std_deque.i Normal file
View file

@ -0,0 +1 @@
%include <std/_std_deque.i>

30
Lib/d/std_except.i Normal file
View file

@ -0,0 +1,30 @@
/* -----------------------------------------------------------------------------
* std_except.i
*
* Typemaps used by the STL wrappers that throw exceptions. These typemaps are
* used when methods are declared with an STL exception specification, such as
* size_t at() const throw (std::out_of_range);
* ----------------------------------------------------------------------------- */
%{
#include <stdexcept>
%}
namespace std
{
%ignore exception;
struct exception {};
}
%typemap(throws, canthrow=1) std::bad_exception "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::domain_error "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::exception "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::invalid_argument "SWIG_DSetPendingException(SWIG_DIllegalArgumentException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::length_error "SWIG_DSetPendingException(SWIG_DNoSuchElementException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::logic_error "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::out_of_range "SWIG_DSetPendingException(SWIG_DNoSuchElementException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::overflow_error "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::range_error "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::runtime_error "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::underflow_error "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"

59
Lib/d/std_map.i Normal file
View file

@ -0,0 +1,59 @@
/* -----------------------------------------------------------------------------
* std_map.i
*
* SWIG typemaps for std::map
* ----------------------------------------------------------------------------- */
%include <std_common.i>
// ------------------------------------------------------------------------
// std::map
// ------------------------------------------------------------------------
%{
#include <map>
#include <algorithm>
#include <stdexcept>
%}
// exported class
namespace std {
template<class K, class T> class map {
// add typemaps here
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef K key_type;
typedef T mapped_type;
map();
map(const map<K,T> &);
unsigned int size() const;
bool empty() const;
void clear();
%extend {
const T& get(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void set(const K& key, const T& x) {
(*self)[key] = x;
}
void del(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
else
throw std::out_of_range("key not found");
}
bool has_key(const K& key) {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
}
}
};
}

34
Lib/d/std_pair.i Normal file
View file

@ -0,0 +1,34 @@
/* -----------------------------------------------------------------------------
* std_pair.i
*
* SWIG typemaps for std::pair
* ----------------------------------------------------------------------------- */
%include <std_common.i>
%include <exception.i>
// ------------------------------------------------------------------------
// std::pair
// ------------------------------------------------------------------------
%{
#include <utility>
%}
namespace std {
template<class T, class U> struct pair {
pair();
pair(T t, U u);
pair(const pair& p);
template <class U1, class U2> pair(const pair<U1, U2> &p);
T first;
U second;
};
// add specializations here
}

2
Lib/d/std_shared_ptr.i Normal file
View file

@ -0,0 +1,2 @@
#define SWIG_SHARED_PTR_NAMESPACE std
%include <boost_shared_ptr.i>

98
Lib/d/std_string.i Normal file
View file

@ -0,0 +1,98 @@
/* -----------------------------------------------------------------------------
* std_string.i
*
* Typemaps for std::string and const std::string&
* These are mapped to a D char[] and are passed around by value.
*
* To use non-const std::string references, use the following %apply. Note
* that they are passed by value.
* %apply const std::string & {std::string &};
* ----------------------------------------------------------------------------- */
%{
#include <string>
%}
namespace std {
%naturalvar string;
class string;
%define SWIGD_STD_STRING_TYPEMAPS(DW_STRING_TYPE, DP_STRING_TYPE, FROM_STRINGZ, TO_STRINGZ)
// string
%typemap(ctype) string, const string & "char *"
%typemap(imtype) string, const string & #DW_STRING_TYPE
%typemap(dtype) string, const string & #DP_STRING_TYPE
%typemap(in, canthrow=1) string, const string &
%{ if (!$input) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string");
return $null;
}
$1.assign($input); %}
%typemap(in, canthrow=1) const string &
%{ if (!$input) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string");
return $null;
}
$*1_ltype $1_str($input);
$1 = &$1_str; %}
%typemap(out) string %{ $result = SWIG_d_string_callback($1.c_str()); %}
%typemap(out) const string & %{ $result = SWIG_d_string_callback($1->c_str()); %}
%typemap(din) string, const string & "($dinput ? TO_STRINGZ($dinput) : null)"
%typemap(dout, excode=SWIGEXCODE) string, const string & {
DP_STRING_TYPE ret = FROM_STRINGZ($imcall);$excode
return ret;
}
%typemap(directorin) string, const string & %{ $input = SWIG_d_string_callback($1.c_str()); %}
%typemap(directorout, canthrow=1) string
%{ if (!$input) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string");
return $null;
}
$result.assign($input); %}
%typemap(directorout, canthrow=1, warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const string &
%{ if (!$input) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string");
return $null;
}
/* possible thread/reentrant code problem */
static $*1_ltype $1_str;
$1_str = $input;
$result = &$1_str; %}
%typemap(ddirectorin) string, const string & "FROM_STRINGZ($winput)"
%typemap(ddirectorout) string, const string & "TO_STRINGZ($dcall)"
%typemap(throws, canthrow=1) string, const string &
%{ SWIG_DSetPendingException(SWIG_DException, $1.c_str());
return $null; %}
%typemap(typecheck) string, const string & = char *;
%enddef
// We need to have the \0-terminated string conversion functions available in
// the D proxy modules.
#if (SWIG_D_VERSION == 1)
// Could be easily extended to support Phobos as well.
SWIGD_STD_STRING_TYPEMAPS(char*, char[], tango.stdc.stringz.fromStringz, tango.stdc.stringz.toStringz)
%pragma(d) globalproxyimports = "static import tango.stdc.stringz;";
#else
SWIGD_STD_STRING_TYPEMAPS(const(char)*, string, std.conv.to!string, std.string.toStringz)
%pragma(d) globalproxyimports = %{
static import std.conv;
static import std.string;
%}
#endif
#undef SWIGD_STD_STRING_TYPEMAPS
} // namespace std

591
Lib/d/std_vector.i Normal file
View file

@ -0,0 +1,591 @@
/* -----------------------------------------------------------------------------
* std_vector.i
*
* SWIG typemaps for std::vector<T>, D implementation.
*
* The D wrapper is made to loosely resemble a tango.util.container.more.Vector
* and to provide built-in array-like access.
*
* If T does define an operator==, then use the SWIG_STD_VECTOR_ENHANCED
* macro to obtain enhanced functionality (none yet), for example:
*
* SWIG_STD_VECTOR_ENHANCED(SomeNamespace::Klass)
* %template(VectKlass) std::vector<SomeNamespace::Klass>;
*
* Warning: heavy macro usage in this file. Use swig -E to get a sane view on
* the real file contents!
* ----------------------------------------------------------------------------- */
// Warning: Use the typemaps here in the expectation that the macros they are in will change name.
%include <std_common.i>
// MACRO for use within the std::vector class body
%define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CONST_REFERENCE, CTYPE...)
#if (SWIG_D_VERSION == 1)
%typemap(dimports) std::vector< CTYPE > "static import tango.core.Exception;"
%typemap(dcode) std::vector< CTYPE > %{
public this($typemap(dtype, CTYPE)[] values) {
this();
append(values);
}
alias push_back add;
alias push_back push;
alias push_back opCatAssign;
alias size length;
alias opSlice slice;
public $typemap(dtype, CTYPE) opIndexAssign($typemap(dtype, CTYPE) value, size_t index) {
if (index >= size()) {
throw new tango.core.Exception.NoSuchElementException("Tried to assign to element out of vector bounds.");
}
setElement(index, value);
return value;
}
public $typemap(dtype, CTYPE) opIndex(size_t index) {
if (index >= size()) {
throw new tango.core.Exception.NoSuchElementException("Tried to read from element out of vector bounds.");
}
return getElement(index);
}
public void append($typemap(dtype, CTYPE)[] value...) {
foreach (v; value) {
add(v);
}
}
public $typemap(dtype, CTYPE)[] opSlice() {
$typemap(dtype, CTYPE)[] array = new $typemap(dtype, CTYPE)[size()];
foreach (i, ref value; array) {
value = getElement(i);
}
return array;
}
public int opApply(int delegate(ref $typemap(dtype, CTYPE) value) dg) {
int result;
size_t currentSize = size();
for (size_t i = 0; i < currentSize; ++i) {
auto value = getElement(i);
result = dg(value);
setElement(i, value);
}
return result;
}
public int opApply(int delegate(ref size_t index, ref $typemap(dtype, CTYPE) value) dg) {
int result;
size_t currentSize = size();
for (size_t i = 0; i < currentSize; ++i) {
auto value = getElement(i);
// Workaround for http://d.puremagic.com/issues/show_bug.cgi?id=2443.
auto index = i;
result = dg(index, value);
setElement(i, value);
}
return result;
}
public void capacity(size_t value) {
if (value < size()) {
throw new tango.core.Exception.IllegalArgumentException("Tried to make the capacity of a vector smaller than its size.");
}
reserve(value);
}
%}
public:
typedef size_t size_type;
typedef CTYPE value_type;
typedef CONST_REFERENCE const_reference;
void clear();
void push_back(CTYPE const& x);
size_type size() const;
size_type capacity() const;
void reserve(size_type n) throw (std::length_error);
vector();
vector(const vector &other);
%extend {
vector(size_type capacity) throw (std::length_error) {
std::vector< CTYPE >* pv = 0;
pv = new std::vector< CTYPE >();
// Might throw std::length_error.
pv->reserve(capacity);
return pv;
}
size_type unused() const {
return $self->capacity() - $self->size();
}
const_reference remove() throw (std::out_of_range) {
if ($self->empty()) {
throw std::out_of_range("Tried to remove last element from empty vector.");
}
std::vector< CTYPE >::const_reference value = $self->back();
$self->pop_back();
return value;
}
const_reference remove(size_type index) throw (std::out_of_range) {
if (index >= $self->size()) {
throw std::out_of_range("Tried to remove element with invalid index.");
}
std::vector< CTYPE >::iterator it = $self->begin() + index;
std::vector< CTYPE >::const_reference value = *it;
$self->erase(it);
return value;
}
}
// Wrappers for setting/getting items with the possibly thrown exception
// specified (important for SWIG wrapper generation).
%extend {
const_reference getElement(size_type index) throw (std::out_of_range) {
if ((index < 0) || ($self->size() <= index)) {
throw std::out_of_range("Tried to get value of element with invalid index.");
}
return (*$self)[index];
}
}
// Use CTYPE const& instead of const_reference to work around SWIG code
// generation issue when using const pointers as vector elements (like
// std::vector< const int* >).
%extend {
void setElement(size_type index, CTYPE const& val) throw (std::out_of_range) {
if ((index < 0) || ($self->size() <= index)) {
throw std::out_of_range("Tried to set value of element with invalid index.");
}
(*$self)[index] = val;
}
}
%dmethodmodifiers std::vector::getElement "private"
%dmethodmodifiers std::vector::setElement "private"
%dmethodmodifiers std::vector::reserve "private"
#else
%typemap(dimports) std::vector< CTYPE > %{
static import std.algorithm;
static import std.exception;
static import std.range;
static import std.traits;
%}
%typemap(dcode) std::vector< CTYPE > %{
alias size_t KeyType;
alias $typemap(dtype, CTYPE) ValueType;
this(ValueType[] values...) {
this();
reserve(values.length);
foreach (e; values) {
this ~= e;
}
}
struct Range {
private $typemap(dtype, std::vector< CTYPE >) _outer;
private size_t _a, _b;
this($typemap(dtype, std::vector< CTYPE >) data, size_t a, size_t b) {
_outer = data;
_a = a;
_b = b;
}
@property bool empty() const {
assert((cast($typemap(dtype, std::vector< CTYPE >))_outer).length >= _b);
return _a >= _b;
}
@property Range save() {
return this;
}
@property ValueType front() {
std.exception.enforce(!empty);
return _outer[_a];
}
@property void front(ValueType value) {
std.exception.enforce(!empty);
_outer[_a] = std.algorithm.move(value);
}
void popFront() {
std.exception.enforce(!empty);
++_a;
}
void opIndexAssign(ValueType value, size_t i) {
i += _a;
std.exception.enforce(i < _b && _b <= _outer.length);
_outer[i] = value;
}
void opIndexOpAssign(string op)(ValueType value, size_t i) {
std.exception.enforce(_outer && _a + i < _b && _b <= _outer.length);
auto element = _outer[i];
mixin("element "~op~"= value;");
_outer[i] = element;
}
}
// TODO: dup?
Range opSlice() {
return Range(this, 0, length);
}
Range opSlice(size_t a, size_t b) {
std.exception.enforce(a <= b && b <= length);
return Range(this, a, b);
}
size_t opDollar() const {
return length;
}
@property ValueType front() {
std.exception.enforce(!empty);
return getElement(0);
}
@property void front(ValueType value) {
std.exception.enforce(!empty);
setElement(0, value);
}
@property ValueType back() {
std.exception.enforce(!empty);
return getElement(length - 1);
}
@property void back(ValueType value) {
std.exception.enforce(!empty);
setElement(length - 1, value);
}
ValueType opIndex(size_t i) {
return getElement(i);
}
void opIndexAssign(ValueType value, size_t i) {
setElement(i, value);
}
void opIndexOpAssign(string op)(ValueType value, size_t i) {
auto element = this[i];
mixin("element "~op~"= value;");
this[i] = element;
}
ValueType[] opBinary(string op, Stuff)(Stuff stuff) if (op == "~") {
ValueType[] result;
result ~= this[];
assert(result.length == length);
result ~= stuff[];
return result;
}
void opOpAssign(string op, Stuff)(Stuff stuff) if (op == "~") {
static if (is(typeof(insertBack(stuff)))) {
insertBack(stuff);
} else if (is(typeof(insertBack(stuff[])))) {
insertBack(stuff[]);
} else {
static assert(false, "Cannot append " ~ Stuff.stringof ~ " to " ~ typeof(this).stringof);
}
}
alias size length;
alias remove removeAny;
alias removeAny stableRemoveAny;
size_t insertBack(Stuff)(Stuff stuff)
if (std.traits.isImplicitlyConvertible!(Stuff, ValueType)){
push_back(stuff);
return 1;
}
size_t insertBack(Stuff)(Stuff stuff)
if (std.range.isInputRange!Stuff &&
std.traits.isImplicitlyConvertible!(std.range.ElementType!Stuff, ValueType)) {
size_t itemCount;
foreach(item; stuff) {
insertBack(item);
++itemCount;
}
return itemCount;
}
alias insertBack insert;
alias pop_back removeBack;
alias pop_back stableRemoveBack;
size_t insertBefore(Stuff)(Range r, Stuff stuff)
if (std.traits.isImplicitlyConvertible!(Stuff, ValueType)) {
std.exception.enforce(r._outer.swigCPtr == swigCPtr && r._a < length);
insertAt(r._a, stuff);
return 1;
}
size_t insertBefore(Stuff)(Range r, Stuff stuff)
if (std.range.isInputRange!Stuff && std.traits.isImplicitlyConvertible!(ElementType!Stuff, ValueType)) {
std.exception.enforce(r._outer.swigCPtr == swigCPtr && r._a <= length);
size_t insertCount;
foreach(i, item; stuff) {
insertAt(r._a + i, item);
++insertCount;
}
return insertCount;
}
size_t insertAfter(Stuff)(Range r, Stuff stuff) {
// TODO: optimize
immutable offset = r._a + r.length;
std.exception.enforce(offset <= length);
auto result = insertBack(stuff);
std.algorithm.bringToFront(this[offset .. length - result],
this[length - result .. length]);
return result;
}
size_t replace(Stuff)(Range r, Stuff stuff)
if (std.range.isInputRange!Stuff &&
std.traits.isImplicitlyConvertible!(ElementType!Stuff, ValueType)) {
immutable offset = r._a;
std.exception.enforce(offset <= length);
size_t result;
for (; !stuff.empty; stuff.popFront()) {
if (r.empty) {
// append the rest
return result + insertBack(stuff);
}
r.front = stuff.front;
r.popFront();
++result;
}
// Remove remaining stuff in r
remove(r);
return result;
}
size_t replace(Stuff)(Range r, Stuff stuff)
if (std.traits.isImplicitlyConvertible!(Stuff, ValueType))
{
if (r.empty)
{
insertBefore(r, stuff);
}
else
{
r.front = stuff;
r.popFront();
remove(r);
}
return 1;
}
Range linearRemove(Range r) {
std.exception.enforce(r._a <= r._b && r._b <= length);
immutable tailLength = length - r._b;
linearRemove(r._a, r._b);
return this[length - tailLength .. length];
}
alias remove stableLinearRemove;
int opApply(int delegate(ref $typemap(dtype, CTYPE) value) dg) {
int result;
size_t currentSize = size();
for (size_t i = 0; i < currentSize; ++i) {
auto value = getElement(i);
result = dg(value);
setElement(i, value);
}
return result;
}
int opApply(int delegate(ref size_t index, ref $typemap(dtype, CTYPE) value) dg) {
int result;
size_t currentSize = size();
for (size_t i = 0; i < currentSize; ++i) {
auto value = getElement(i);
// Workaround for http://d.puremagic.com/issues/show_bug.cgi?id=2443.
auto index = i;
result = dg(index, value);
setElement(i, value);
}
return result;
}
%}
public:
typedef size_t size_type;
typedef CTYPE value_type;
typedef CONST_REFERENCE const_reference;
bool empty() const;
void clear();
void push_back(CTYPE const& x);
void pop_back();
size_type size() const;
size_type capacity() const;
void reserve(size_type n) throw (std::length_error);
vector();
vector(const vector &other);
%extend {
vector(size_type capacity) throw (std::length_error) {
std::vector< CTYPE >* pv = 0;
pv = new std::vector< CTYPE >();
// Might throw std::length_error.
pv->reserve(capacity);
return pv;
}
const_reference remove() throw (std::out_of_range) {
if ($self->empty()) {
throw std::out_of_range("Tried to remove last element from empty vector.");
}
std::vector< CTYPE >::const_reference value = $self->back();
$self->pop_back();
return value;
}
const_reference remove(size_type index) throw (std::out_of_range) {
if (index >= $self->size()) {
throw std::out_of_range("Tried to remove element with invalid index.");
}
std::vector< CTYPE >::iterator it = $self->begin() + index;
std::vector< CTYPE >::const_reference value = *it;
$self->erase(it);
return value;
}
void removeBack(size_type how_many) throw (std::out_of_range) {
std::vector< CTYPE >::iterator end = $self->end();
std::vector< CTYPE >::iterator start = end - how_many;
$self->erase(start, end);
}
void linearRemove(size_type start_index, size_type end_index) throw (std::out_of_range) {
std::vector< CTYPE >::iterator start = $self->begin() + start_index;
std::vector< CTYPE >::iterator end = $self->begin() + end_index;
$self->erase(start, end);
}
void insertAt(size_type index, CTYPE const& x) throw (std::out_of_range) {
std::vector< CTYPE >::iterator it = $self->begin() + index;
$self->insert(it, x);
}
}
// Wrappers for setting/getting items with the possibly thrown exception
// specified (important for SWIG wrapper generation).
%extend {
const_reference getElement(size_type index) throw (std::out_of_range) {
if ((index < 0) || ($self->size() <= index)) {
throw std::out_of_range("Tried to get value of element with invalid index.");
}
return (*$self)[index];
}
}
// Use CTYPE const& instead of const_reference to work around SWIG code
// generation issue when using const pointers as vector elements (like
// std::vector< const int* >).
%extend {
void setElement(size_type index, CTYPE const& val) throw (std::out_of_range) {
if ((index < 0) || ($self->size() <= index)) {
throw std::out_of_range("Tried to set value of element with invalid index.");
}
(*$self)[index] = val;
}
}
%dmethodmodifiers std::vector::getElement "private"
%dmethodmodifiers std::vector::setElement "private"
#endif
%enddef
// Extra methods added to the collection class if operator== is defined for the class being wrapped
// The class will then implement IList<>, which adds extra functionality
%define SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CTYPE...)
%extend {
}
%enddef
// For vararg handling in macros, from swigmacros.swg
#define %arg(X...) X
// Macros for std::vector class specializations/enhancements
%define SWIG_STD_VECTOR_ENHANCED(CTYPE...)
namespace std {
template<> class vector<CTYPE > {
SWIG_STD_VECTOR_MINIMUM_INTERNAL(%arg(CTYPE const&), %arg(CTYPE))
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CTYPE)
};
}
%enddef
%{
#include <vector>
#include <stdexcept>
%}
namespace std {
// primary (unspecialized) class template for std::vector
// does not require operator== to be defined
template<class T> class vector {
SWIG_STD_VECTOR_MINIMUM_INTERNAL(T const&, T)
};
// specializations for pointers
template<class T> class vector<T *> {
SWIG_STD_VECTOR_MINIMUM_INTERNAL(T *const&, T *)
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(T *)
};
// bool is a bit different in the C++ standard - const_reference in particular
template<> class vector<bool> {
SWIG_STD_VECTOR_MINIMUM_INTERNAL(bool, bool)
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(bool)
};
}
// template specializations for std::vector
// these provide extra collections methods as operator== is defined
SWIG_STD_VECTOR_ENHANCED(char)
SWIG_STD_VECTOR_ENHANCED(signed char)
SWIG_STD_VECTOR_ENHANCED(unsigned char)
SWIG_STD_VECTOR_ENHANCED(short)
SWIG_STD_VECTOR_ENHANCED(unsigned short)
SWIG_STD_VECTOR_ENHANCED(int)
SWIG_STD_VECTOR_ENHANCED(unsigned int)
SWIG_STD_VECTOR_ENHANCED(long)
SWIG_STD_VECTOR_ENHANCED(unsigned long)
SWIG_STD_VECTOR_ENHANCED(long long)
SWIG_STD_VECTOR_ENHANCED(unsigned long long)
SWIG_STD_VECTOR_ENHANCED(float)
SWIG_STD_VECTOR_ENHANCED(double)
SWIG_STD_VECTOR_ENHANCED(std::string) // also requires a %include <std_string.i>

12
Lib/d/stl.i Normal file
View file

@ -0,0 +1,12 @@
/* -----------------------------------------------------------------------------
* stl.i
*
* Initial STL definition. extended as needed in each language
* ----------------------------------------------------------------------------- */
%include <std_common.i>
%include <std_string.i>
%include <std_vector.i>
%include <std_map.i>
%include <std_pair.i>

261
Lib/d/typemaps.i Normal file
View file

@ -0,0 +1,261 @@
/* -----------------------------------------------------------------------------
* typemaps.i
*
* Pointer and reference handling typemap library
*
* These mappings provide support for input/output arguments and common
* uses for C/C++ pointers and C++ references.
* ----------------------------------------------------------------------------- */
/*
INPUT typemaps
--------------
These typemaps are used for pointer/reference parameters that are input only
and are mapped to a D input parameter.
The following typemaps can be applied to turn a pointer or reference into a simple
input value. That is, instead of passing a pointer or reference to an object,
you would use a real value instead.
bool *INPUT, bool &INPUT
signed char *INPUT, signed char &INPUT
unsigned char *INPUT, unsigned char &INPUT
short *INPUT, short &INPUT
unsigned short *INPUT, unsigned short &INPUT
int *INPUT, int &INPUT
unsigned int *INPUT, unsigned int &INPUT
long *INPUT, long &INPUT
unsigned long *INPUT, unsigned long &INPUT
long long *INPUT, long long &INPUT
unsigned long long *INPUT, unsigned long long &INPUT
float *INPUT, float &INPUT
double *INPUT, double &INPUT
To use these, suppose you had a C function like this :
double fadd(double *a, double *b) {
return *a+*b;
}
You could wrap it with SWIG as follows :
%include <typemaps.i>
double fadd(double *INPUT, double *INPUT);
or you can use the %apply directive :
%include <typemaps.i>
%apply double *INPUT { double *a, double *b };
double fadd(double *a, double *b);
In D you could then use it like this:
double answer = fadd(10.0, 20.0);
*/
%define INPUT_TYPEMAP(TYPE, CTYPE, DTYPE)
%typemap(ctype, out="void *") TYPE *INPUT, TYPE &INPUT "CTYPE"
%typemap(imtype, out="void*") TYPE *INPUT, TYPE &INPUT "DTYPE"
%typemap(dtype, out="DTYPE*") TYPE *INPUT, TYPE &INPUT "DTYPE"
%typemap(din) TYPE *INPUT, TYPE &INPUT "$dinput"
%typemap(in) TYPE *INPUT, TYPE &INPUT
%{ $1 = ($1_ltype)&$input; %}
%typemap(typecheck) TYPE *INPUT = TYPE;
%typemap(typecheck) TYPE &INPUT = TYPE;
%enddef
INPUT_TYPEMAP(bool, unsigned int, bool)
//INPUT_TYPEMAP(char, char, char) // Why was this commented out?
INPUT_TYPEMAP(signed char, signed char, byte)
INPUT_TYPEMAP(unsigned char, unsigned char, ubyte)
INPUT_TYPEMAP(short, short, short)
INPUT_TYPEMAP(unsigned short, unsigned short, ushort)
INPUT_TYPEMAP(int, int, int)
INPUT_TYPEMAP(unsigned int, unsigned int, uint)
INPUT_TYPEMAP(long, long, SWIG_LONG_DTYPE)
INPUT_TYPEMAP(unsigned long, unsigned long, SWIG_ULONG_DTYPE)
INPUT_TYPEMAP(long long, long long, long)
INPUT_TYPEMAP(unsigned long long, unsigned long long, ulong)
INPUT_TYPEMAP(float, float, float)
INPUT_TYPEMAP(double, double, double)
INPUT_TYPEMAP(enum SWIGTYPE, unsigned int, int)
%typemap(dtype) enum SWIGTYPE *INPUT, enum SWIGTYPE &INPUT "$*dclassname"
#undef INPUT_TYPEMAP
/*
OUTPUT typemaps
---------------
These typemaps are used for pointer/reference parameters that are output only and
are mapped to a D output parameter.
The following typemaps can be applied to turn a pointer or reference into an
"output" value. When calling a function, no input value would be given for
a parameter, but an output value would be returned. In D, the 'out' keyword is
used when passing the parameter to a function that takes an output parameter.
bool *OUTPUT, bool &OUTPUT
signed char *OUTPUT, signed char &OUTPUT
unsigned char *OUTPUT, unsigned char &OUTPUT
short *OUTPUT, short &OUTPUT
unsigned short *OUTPUT, unsigned short &OUTPUT
int *OUTPUT, int &OUTPUT
unsigned int *OUTPUT, unsigned int &OUTPUT
long *OUTPUT, long &OUTPUT
unsigned long *OUTPUT, unsigned long &OUTPUT
long long *OUTPUT, long long &OUTPUT
unsigned long long *OUTPUT, unsigned long long &OUTPUT
float *OUTPUT, float &OUTPUT
double *OUTPUT, double &OUTPUT
For example, suppose you were trying to wrap the modf() function in the
C math library which splits x into integral and fractional parts (and
returns the integer part in one of its parameters):
double modf(double x, double *ip);
You could wrap it with SWIG as follows :
%include <typemaps.i>
double modf(double x, double *OUTPUT);
or you can use the %apply directive :
%include <typemaps.i>
%apply double *OUTPUT { double *ip };
double modf(double x, double *ip);
The D output of the function would be the function return value and the
value returned in the second output parameter. In D you would use it like this:
double dptr;
double fraction = modf(5, dptr);
*/
%define OUTPUT_TYPEMAP(TYPE, CTYPE, DTYPE, TYPECHECKPRECEDENCE)
%typemap(ctype, out="void *") TYPE *OUTPUT, TYPE &OUTPUT "CTYPE *"
%typemap(imtype, out="void*") TYPE *OUTPUT, TYPE &OUTPUT "out DTYPE"
%typemap(dtype, out="DTYPE*") TYPE *OUTPUT, TYPE &OUTPUT "out DTYPE"
%typemap(din) TYPE *OUTPUT, TYPE &OUTPUT "$dinput"
%typemap(in) TYPE *OUTPUT, TYPE &OUTPUT
%{ $1 = ($1_ltype)$input; %}
%typecheck(SWIG_TYPECHECK_##TYPECHECKPRECEDENCE) TYPE *OUTPUT, TYPE &OUTPUT ""
%enddef
OUTPUT_TYPEMAP(bool, unsigned int, bool, BOOL_PTR)
//OUTPUT_TYPEMAP(char, char, char, CHAR_PTR) // Why was this commented out?
OUTPUT_TYPEMAP(signed char, signed char, byte, INT8_PTR)
OUTPUT_TYPEMAP(unsigned char, unsigned char, ubyte, UINT8_PTR)
OUTPUT_TYPEMAP(short, short, short, INT16_PTR)
OUTPUT_TYPEMAP(unsigned short, unsigned short, ushort, UINT16_PTR)
OUTPUT_TYPEMAP(int, int, int, INT32_PTR)
OUTPUT_TYPEMAP(unsigned int, unsigned int, uint, UINT32_PTR)
OUTPUT_TYPEMAP(long, long, SWIG_LONG_DTYPE,INT32_PTR)
OUTPUT_TYPEMAP(unsigned long, unsigned long, SWIG_ULONG_DTYPE,UINT32_PTR)
OUTPUT_TYPEMAP(long long, long long, long, INT64_PTR)
OUTPUT_TYPEMAP(unsigned long long, unsigned long long, ulong, UINT64_PTR)
OUTPUT_TYPEMAP(float, float, float, FLOAT_PTR)
OUTPUT_TYPEMAP(double, double, double, DOUBLE_PTR)
OUTPUT_TYPEMAP(enum SWIGTYPE, unsigned int, int, INT32_PTR)
%typemap(dtype) enum SWIGTYPE *OUTPUT, enum SWIGTYPE &OUTPUT "out $*dclassname"
#undef OUTPUT_TYPEMAP
%typemap(in) bool *OUTPUT, bool &OUTPUT
%{ *$input = 0;
$1 = ($1_ltype)$input; %}
/*
INOUT typemaps
--------------
These typemaps are for pointer/reference parameters that are both input and
output and are mapped to a D reference parameter.
The following typemaps can be applied to turn a pointer or reference into a
reference parameters, that is the parameter is both an input and an output.
In D, the 'ref' keyword is used for reference parameters.
bool *INOUT, bool &INOUT
signed char *INOUT, signed char &INOUT
unsigned char *INOUT, unsigned char &INOUT
short *INOUT, short &INOUT
unsigned short *INOUT, unsigned short &INOUT
int *INOUT, int &INOUT
unsigned int *INOUT, unsigned int &INOUT
long *INOUT, long &INOUT
unsigned long *INOUT, unsigned long &INOUT
long long *INOUT, long long &INOUT
unsigned long long *INOUT, unsigned long long &INOUT
float *INOUT, float &INOUT
double *INOUT, double &INOUT
For example, suppose you were trying to wrap the following function :
void neg(double *x) {
*x = -(*x);
}
You could wrap it with SWIG as follows :
%include <typemaps.i>
void neg(double *INOUT);
or you can use the %apply directive :
%include <typemaps.i>
%apply double *INOUT { double *x };
void neg(double *x);
The D output of the function would be the new value returned by the
reference parameter. In D you would use it like this:
double x = 5.0;
neg(x);
The implementation of the OUTPUT and INOUT typemaps is different to the scripting
languages in that the scripting languages will return the output value as part
of the function return value.
*/
%define INOUT_TYPEMAP(TYPE, CTYPE, DTYPE, TYPECHECKPRECEDENCE)
%typemap(ctype, out="void *") TYPE *INOUT, TYPE &INOUT "CTYPE *"
%typemap(imtype, out="void*") TYPE *INOUT, TYPE &INOUT "ref DTYPE"
%typemap(dtype, out="DTYPE*") TYPE *INOUT, TYPE &INOUT "ref DTYPE"
%typemap(din) TYPE *INOUT, TYPE &INOUT "$dinput"
%typemap(in) TYPE *INOUT, TYPE &INOUT
%{ $1 = ($1_ltype)$input; %}
%typecheck(SWIG_TYPECHECK_##TYPECHECKPRECEDENCE) TYPE *INOUT, TYPE &INOUT ""
%enddef
INOUT_TYPEMAP(bool, unsigned int, bool, BOOL_PTR)
//INOUT_TYPEMAP(char, char, char, CHAR_PTR)
INOUT_TYPEMAP(signed char, signed char, byte, INT8_PTR)
INOUT_TYPEMAP(unsigned char, unsigned char, ubyte, UINT8_PTR)
INOUT_TYPEMAP(short, short, short, INT16_PTR)
INOUT_TYPEMAP(unsigned short, unsigned short, ushort, UINT16_PTR)
INOUT_TYPEMAP(int, int, int, INT32_PTR)
INOUT_TYPEMAP(unsigned int, unsigned int, uint, UINT32_PTR)
INOUT_TYPEMAP(long, long, SWIG_LONG_DTYPE,INT32_PTR)
INOUT_TYPEMAP(unsigned long, unsigned long, SWIG_ULONG_DTYPE,UINT32_PTR)
INOUT_TYPEMAP(long long, long long, long, INT64_PTR)
INOUT_TYPEMAP(unsigned long long, unsigned long long, ulong, UINT64_PTR)
INOUT_TYPEMAP(float, float, float, FLOAT_PTR)
INOUT_TYPEMAP(double, double, double, DOUBLE_PTR)
INOUT_TYPEMAP(enum SWIGTYPE, unsigned int, int, INT32_PTR)
%typemap(dtype) enum SWIGTYPE *INOUT, enum SWIGTYPE &INOUT "ref $*dclassname"
#undef INOUT_TYPEMAP

308
Lib/d/wrapperloader.swg Normal file
View file

@ -0,0 +1,308 @@
/* -----------------------------------------------------------------------------
* wrapperloader.swg
*
* Support code for dynamically linking the C wrapper library from the D
* wrapper module.
*
* The loading code was adapted from the Derelict project and is used with
* permission from Michael Parker, the original author.
* ----------------------------------------------------------------------------- */
%pragma(d) wrapperloadercode = %{
private {
version(linux) {
version = Nix;
} else version(darwin) {
version = Nix;
} else version(OSX) {
version = Nix;
} else version(FreeBSD) {
version = Nix;
version = freebsd;
} else version(freebsd) {
version = Nix;
} else version(Unix) {
version = Nix;
} else version(Posix) {
version = Nix;
}
version(Tango) {
static import tango.stdc.string;
static import tango.stdc.stringz;
version (PhobosCompatibility) {
} else {
alias char[] string;
alias wchar[] wstring;
alias dchar[] dstring;
}
} else {
version(D_Version2) {
static import std.conv;
}
static import std.string;
static import std.c.string;
}
version(D_Version2) {
mixin("alias const(char)* CCPTR;");
} else {
alias char* CCPTR;
}
CCPTR swigToCString(string str) {
version(Tango) {
return tango.stdc.stringz.toStringz(str);
} else {
return std.string.toStringz(str);
}
}
string swigToDString(CCPTR cstr) {
version(Tango) {
return tango.stdc.stringz.fromStringz(cstr);
} else {
version(D_Version2) {
mixin("return std.conv.to!string(cstr);");
} else {
return std.c.string.toString(cstr);
}
}
}
}
class SwigSwigSharedLibLoadException : Exception {
this(in string[] libNames, in string[] reasons) {
string msg = "Failed to load one or more shared libraries:";
foreach(i, n; libNames) {
msg ~= "\n\t" ~ n ~ " - ";
if(i < reasons.length)
msg ~= reasons[i];
else
msg ~= "Unknown";
}
super(msg);
}
}
class SwigSymbolLoadException : Exception {
this(string SwigSharedLibName, string symbolName) {
super("Failed to load symbol " ~ symbolName ~ " from shared library " ~ SwigSharedLibName);
_symbolName = symbolName;
}
string symbolName() {
return _symbolName;
}
private:
string _symbolName;
}
private {
version(Nix) {
version(freebsd) {
// the dl* functions are in libc on FreeBSD
}
else {
pragma(lib, "dl");
}
version(Tango) {
import tango.sys.Common;
} else version(linux) {
import std.c.linux.linux;
} else {
extern(C) {
const RTLD_NOW = 2;
void *dlopen(CCPTR file, int mode);
int dlclose(void* handle);
void *dlsym(void* handle, CCPTR name);
CCPTR dlerror();
}
}
alias void* SwigSharedLibHandle;
SwigSharedLibHandle swigLoadSharedLib(string libName) {
return dlopen(swigToCString(libName), RTLD_NOW);
}
void swigUnloadSharedLib(SwigSharedLibHandle hlib) {
dlclose(hlib);
}
void* swigGetSymbol(SwigSharedLibHandle hlib, string symbolName) {
return dlsym(hlib, swigToCString(symbolName));
}
string swigGetErrorStr() {
CCPTR err = dlerror();
if (err is null) {
return "Unknown Error";
}
return swigToDString(err);
}
} else version(Windows) {
alias ushort WORD;
alias uint DWORD;
alias CCPTR LPCSTR;
alias void* HMODULE;
alias void* HLOCAL;
alias int function() FARPROC;
struct VA_LIST {}
extern (Windows) {
HMODULE LoadLibraryA(LPCSTR);
FARPROC GetProcAddress(HMODULE, LPCSTR);
void FreeLibrary(HMODULE);
DWORD GetLastError();
DWORD FormatMessageA(DWORD, in void*, DWORD, DWORD, LPCSTR, DWORD, VA_LIST*);
HLOCAL LocalFree(HLOCAL);
}
DWORD MAKELANGID(WORD p, WORD s) {
return (((cast(WORD)s) << 10) | cast(WORD)p);
}
enum {
LANG_NEUTRAL = 0,
SUBLANG_DEFAULT = 1,
FORMAT_MESSAGE_ALLOCATE_BUFFER = 256,
FORMAT_MESSAGE_IGNORE_INSERTS = 512,
FORMAT_MESSAGE_FROM_SYSTEM = 4096
}
alias HMODULE SwigSharedLibHandle;
SwigSharedLibHandle swigLoadSharedLib(string libName) {
return LoadLibraryA(swigToCString(libName));
}
void swigUnloadSharedLib(SwigSharedLibHandle hlib) {
FreeLibrary(hlib);
}
void* swigGetSymbol(SwigSharedLibHandle hlib, string symbolName) {
return GetProcAddress(hlib, swigToCString(symbolName));
}
string swigGetErrorStr() {
DWORD errcode = GetLastError();
LPCSTR msgBuf;
DWORD i = FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
null,
errcode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
cast(LPCSTR)&msgBuf,
0,
null);
string text = swigToDString(msgBuf);
LocalFree(cast(HLOCAL)msgBuf);
if (i >= 2) {
i -= 2;
}
return text[0 .. i];
}
} else {
static assert(0, "Operating system not supported by the wrapper loading code.");
}
final class SwigSharedLib {
void load(string[] names) {
if (_hlib !is null) return;
string[] failedLibs;
string[] reasons;
foreach(n; names) {
_hlib = swigLoadSharedLib(n);
if (_hlib is null) {
failedLibs ~= n;
reasons ~= swigGetErrorStr();
continue;
}
_name = n;
break;
}
if (_hlib is null) {
throw new SwigSwigSharedLibLoadException(failedLibs, reasons);
}
}
void* loadSymbol(string symbolName, bool doThrow = true) {
void* sym = swigGetSymbol(_hlib, symbolName);
if(doThrow && (sym is null)) {
throw new SwigSymbolLoadException(_name, symbolName);
}
return sym;
}
void unload() {
if(_hlib !is null) {
swigUnloadSharedLib(_hlib);
_hlib = null;
}
}
private:
string _name;
SwigSharedLibHandle _hlib;
}
}
static this() {
string[] possibleFileNames;
version (Posix) {
version (OSX) {
possibleFileNames ~= ["lib$wraplibrary.dylib", "lib$wraplibrary.bundle"];
}
possibleFileNames ~= ["lib$wraplibrary.so"];
} else version (Windows) {
possibleFileNames ~= ["$wraplibrary.dll", "lib$wraplibrary.so"];
} else {
static assert(false, "Operating system not supported by the wrapper loading code.");
}
auto library = new SwigSharedLib;
library.load(possibleFileNames);
string bindCode(string functionPointer, string symbol) {
return functionPointer ~ " = cast(typeof(" ~ functionPointer ~
"))library.loadSymbol(`" ~ symbol ~ "`);";
}
//#if !defined(SWIG_D_NO_EXCEPTION_HELPER)
mixin(bindCode("swigRegisterExceptionCallbacks$module", "SWIGRegisterExceptionCallbacks_$module"));
//#endif // SWIG_D_NO_EXCEPTION_HELPER
//#if !defined(SWIG_D_NO_STRING_HELPER)
mixin(bindCode("swigRegisterStringCallback$module", "SWIGRegisterStringCallback_$module"));
//#endif // SWIG_D_NO_STRING_HELPER
$wrapperloaderbindcode
}
//#if !defined(SWIG_D_NO_EXCEPTION_HELPER)
extern(C) void function(
SwigExceptionCallback exceptionCallback,
SwigExceptionCallback illegalArgumentCallback,
SwigExceptionCallback illegalElementCallback,
SwigExceptionCallback ioCallback,
SwigExceptionCallback noSuchElementCallback) swigRegisterExceptionCallbacks$module;
//#endif // SWIG_D_NO_EXCEPTION_HELPER
//#if !defined(SWIG_D_NO_STRING_HELPER)
extern(C) void function(SwigStringCallback callback) swigRegisterStringCallback$module;
//#endif // SWIG_D_NO_STRING_HELPER
%}
%pragma(d) wrapperloaderbindcommand = %{
mixin(bindCode("$function", "$symbol"));%}

View file

@ -209,6 +209,40 @@ SWIGINTERN void SWIG_CSharpException(int code, const char *msg) {
#endif // SWIGLUA
#ifdef SWIGD
%{
SWIGINTERN void SWIG_DThrowException(int code, const char *msg) {
SWIG_DExceptionCodes exception_code;
switch(code) {
case SWIG_IndexError:
exception_code = SWIG_DNoSuchElementException;
break;
case SWIG_IOError:
exception_code = SWIG_DIOException;
break;
case SWIG_ValueError:
exception_code = SWIG_DIllegalArgumentException;
break;
case SWIG_DivisionByZero:
case SWIG_MemoryError:
case SWIG_OverflowError:
case SWIG_RuntimeError:
case SWIG_TypeError:
case SWIG_SyntaxError:
case SWIG_SystemError:
case SWIG_UnknownError:
default:
exception_code = SWIG_DException;
break;
}
SWIG_DSetPendingException(exception_code, msg);
}
%}
#define SWIG_exception(code, msg)\
{ SWIG_DThrowException(code, msg); return $null; }
#endif // SWIGD
#ifdef __cplusplus
/*
You can use the SWIG_CATCH_STDEXCEPT macro with the %exception
@ -259,7 +293,7 @@ SWIGINTERN void SWIG_CSharpException(int code, const char *msg) {
/* rethrow the unknown exception */
#ifdef SWIGCSHARP
#if defined(SWIGCSHARP) || defined(SWIGD)
%typemap(throws,noblock=1, canthrow=1) (...) {
SWIG_exception(SWIG_RuntimeError,"unknown exception");
}

View file

@ -12,83 +12,12 @@ typedef struct SWIGCDATA {
%}
%typemap(gotype) SWIGCDATA %{ []byte %}
%typemap(out) SWIGCDATA (swigcdata argp) {
argp = _swig_makegobyteslice($1.data, $1.len);
$result.data = (char*)argp.data;
$result.len = (int)argp.len;
}
/* The makegobyteslice function. */
%insert(runtime) %{
typedef struct {
char *data;
int len;
} swigcdata;
%typemap(out) SWIGCDATA %{
$result.data = (char*)_swig_goallocate($1.len);
memcpy($result.data, $1.data, $1.len);
$result.len = (int)$1.len;
%}
#ifndef SWIGGO_GCCGO
%insert(runtime) %{
extern
#ifdef __cplusplus
"C"
#endif
void _swig_gc_makegobyteslice(void *, int);
static swigcdata _swig_makegobyteslice(const char *data, int len) {
struct {
const char *data;
int len;
swigcdata ret;
} a;
a.data = data;
a.len = len;
crosscall2(_swig_gc_makegobyteslice, &a, (int) sizeof a);
return a.ret;
}
%}
%insert(gc_header) %{
typedef struct {
byte *data;
int32 len;
} swigcdata;
extern void ·_swig_internal_makegobyteslice(void);
#pragma dynexport _swig_gc_makegobyteslice _swig_gc_makegobyteslice
void _swig_gc_makegobyteslice(void *a, int32 n) {
cgocallback(·_swig_internal_makegobyteslice, a, n);
}
void ·_swig_allocategobyteslice(byte *data, int32 len, swigcdata ret) {
ret.data = mal(len);
mcpy(ret.data, data, len);
ret.len = len;
FLUSH(&ret);
}
%}
%insert(go_header) %{
type swigcdata struct { data *byte; len int }
func _swig_allocategobyteslice(*byte, int) swigcdata
func _swig_internal_makegobyteslice(data *byte, len int) swigcdata {
return _swig_allocategobyteslice(data, len)
}
%}
#else
%insert(runtime) %{
static swigcdata _swig_makegobyteslice(const char *data, int len) {
swigcdata ret;
ret.data = (char*)__go_alloc(len);
memcpy(ret.data, data, len);
ret.len = (int)len;
return ret;
}
%}
#endif
/* -----------------------------------------------------------------------------
* %cdata(TYPE [, NAME])
*

View file

@ -108,7 +108,7 @@
unsigned long long,
float,
double
%{ $input = ($1_ltype)$1_name; %}
%{ $input = ($1_ltype)$1; %}
%typemap(directorin) const bool &,
const char &,
@ -124,7 +124,7 @@
const unsigned long long &,
const float &,
const double &
%{ $input = ($*1_ltype)$1_name; %}
%{ $input = ($*1_ltype)$1; %}
%typemap(directorout) bool,
char,
@ -157,8 +157,8 @@
const float &,
const double &
%{
$result = ($1_ltype)_swig_allocate(sizeof($*1_ltype));
*$result = *($1_ltype)$input;
$result = ($1_ltype)_swig_goallocate(sizeof($*1_ltype));
*$result = *($1_ltype)&$input;
%}
/* The size_t type. */
@ -182,17 +182,17 @@
%{ $result = ($*1_ltype)*$1; %}
%typemap(directorin) size_t
%{ $input = (size_t)$1_name; %}
%{ $input = (size_t)$1; %}
%typemap(directorin) const size_t &
%{ $input = ($*1_ltype)$1_name; %}
%{ $input = ($*1_ltype)$1; %}
%typemap(directorout) size_t
%{ $result = ($1_ltype)$input; %}
%typemap(directorout) const size_t &
%{
$result = ($1_ltype)_swig_allocate(sizeof($*1_ltype));
$result = ($1_ltype)_swig_goallocate(sizeof($*1_ltype));
*$result = *($1_ltype)$input;
%}
@ -206,16 +206,16 @@
%typemap(out) SWIGTYPE (CLASS::*)
%{
$result = _swig_allocate(sizeof($1_ltype));
$result = _swig_goallocate(sizeof($1_ltype));
*($&1_ltype)$result = $1;
%}
%typemap(directorin) SWIGTYPE (CLASS::*)
%{ $input = *($&1_ltype)$1_name; %}
%{ $input = *($&1_ltype)$1; %}
%typemap(directorout) SWIGTYPE (CLASS::*)
%{
$result = _swig_allocate(sizeof($1_ltype));
$result = _swig_goallocate(sizeof($1_ltype));
*($&1_ltype)$result = $input;
%}
@ -233,7 +233,7 @@
%{ *($&1_ltype)&$result = $1; %}
%typemap(directorin) SWIGTYPE *
%{ $input = ($1_ltype)$1_name; %}
%{ $input = ($1_ltype)$1; %}
%typemap(directorout) SWIGTYPE *
%{ $result = ($1_ltype)$input; %}
@ -254,14 +254,6 @@
%typemap(out) SWIGTYPE *const&
%{ *($1_ltype)&$result = *$1; %}
/* Function pointers are translated by the code in go.cxx into
_swig_fnptr. Member pointers are translated to _swig_memberptr. */
%insert(go_header) %{
type _swig_fnptr *byte
type _swig_memberptr *byte
%}
/* References. */
/* Converting a C++ reference to Go has to be handled in the C++
@ -276,7 +268,7 @@ type _swig_memberptr *byte
%{ *($&1_ltype)&$result = $1; %}
%typemap(directorin) SWIGTYPE &
%{ $input = ($1_ltype)&$1_name; %}
%{ $input = ($1_ltype)&$1; %}
%typemap(directorout) SWIGTYPE &
%{ *($&1_ltype)&$result = $input; %}
@ -309,7 +301,7 @@ type _swig_memberptr *byte
%{ *($&1_ltype)&$result = $1; %}
%typemap(directorin) SWIGTYPE []
%{ $input = *($1_ltype)&$1_name; %}
%{ $input = *($1_ltype)&$1; %}
%typemap(directorout) SWIGTYPE []
%{ *($&1_ltype)&$result = $input; %}
@ -347,7 +339,7 @@ type _swig_memberptr *byte
signed char *, signed char *&, signed char[ANY], signed char[],
unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[]
%{
$input = _swig_makegostring((char*)$1_name, $1_name ? strlen((char*)$1_name) : 0);
$input = _swig_makegostring((char*)$1, $1 ? strlen((char*)$1) : 0);
%}
%typemap(directorout)
@ -356,6 +348,28 @@ type _swig_memberptr *byte
unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[]
%{ $result = ($1_ltype)$input.p; %}
/* String & length */
%typemap(gotype) (char *STRING, size_t LENGTH) "string"
%typemap(in) (char *STRING, size_t LENGTH)
%{
$1 = ($1_ltype)$input.p;
$2 = ($2_ltype)$input.n;
%}
%typemap(out) (char *STRING, size_t LENGTH)
%{ $result = _swig_makegostring((char*)$1, (size_t)$2); %}
%typemap(directorin) (char *STRING, size_t LENGTH)
%{ $input = _swig_makegostring((char*)$1, $2); %}
%typemap(directorout) (char *STRING, size_t LENGTH)
%{
$1 = ($1_ltype)$input.p;
$2 = ($2_ltype)$input.n;
%}
/* Enums. We can't do the right thing for enums in typemap(gotype) so
we deliberately don't define them. The right thing would be to
capitalize the name. This is instead done in go.cxx. */
@ -367,14 +381,26 @@ type _swig_memberptr *byte
%{ $1 = ($1_ltype)$input; %}
%typemap(out) enum SWIGTYPE
%{ $result = $1; %}
%{ $result = (intgo)$1; %}
%typemap(directorin) enum SWIGTYPE
%{ $input = ($1_ltype)$1_name; %}
%{ $input = ($1_ltype)$1; %}
%typemap(directorout) enum SWIGTYPE
%{ $result = ($1_ltype)$input; %}
%typemap(directorin) enum SWIGTYPE & (intgo e)
%{
e = (intgo)$1;
$input = &e;
%}
%typemap(directorout) enum SWIGTYPE &
%{
$*1_ltype f = ($*1_ltype)*$input;
$result = ($1_ltype)&f;
%}
/* Arbitrary type. This is a type passed by value in the C/C++ code.
We convert it to a pointer for the Go code. Note that all basic
types are explicitly handled above. */
@ -403,7 +429,7 @@ type _swig_memberptr *byte
#endif
%typemap(directorin) SWIGTYPE
%{ $input = ($&1_ltype)&$1_name; %}
%{ $input = ($&1_ltype)&$1; %}
%typemap(directorout) SWIGTYPE
%{ $result = *($&1_ltype)$input; %}
@ -524,6 +550,7 @@ type _swig_memberptr *byte
SWIGTYPE [],
SWIGTYPE (CLASS::*)
""
/* Go keywords. */
%include <gokw.swg>

View file

@ -5,12 +5,35 @@
* ------------------------------------------------------------ */
%insert(runtime) %{
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
typedef struct { char *p; int n; } _gostring_;
typedef struct { void* array; unsigned int len; unsigned int cap; } _goslice_;
%}
#if SWIGGO_INTGO_SIZE == 32
%insert(runtime) %{
typedef int intgo;
typedef unsigned int uintgo;
%}
#elif SWIGGO_INTGO_SIZE == 64
%insert(runtime) %{
typedef long long intgo;
typedef unsigned long long uintgo;
%}
#else
%insert(runtime) %{
typedef ptrdiff_t intgo;
typedef size_t uintgo;
%}
#endif
%insert(runtime) %{
typedef struct { char *p; intgo n; } _gostring_;
typedef struct { void* array; intgo len; intgo cap; } _goslice_;
%}
@ -30,57 +53,32 @@ swiggo_size_assert(swiggo_long_long, 8)
swiggo_size_assert(float, 4)
swiggo_size_assert(double, 8)
extern
#ifdef __cplusplus
"C"
extern "C" {
#endif
extern void crosscall2(void (*fn)(void *, int), void *, int);
extern void _cgo_allocate(void *, int);
extern void _cgo_panic(void *, int);
#ifdef __cplusplus
}
#endif
void crosscall2(void (*fn)(void *, int), void *, int);
extern
#ifdef __cplusplus
"C"
#endif
void _swig_gc_allocate(void *, int);
static void *_swig_allocate(int len) {
static void *_swig_goallocate(size_t len) {
struct {
int len;
size_t len;
void *ret;
} a;
a.len = len;
crosscall2(_swig_gc_allocate, &a, (int) sizeof a);
crosscall2(_cgo_allocate, &a, (int) sizeof a);
return a.ret;
}
extern
#ifdef __cplusplus
"C"
#endif
void _swig_gc_makegostring(void *, int);
static _gostring_ _swig_makegostring(const char *p, size_t l) {
struct {
const char *p;
int l;
_gostring_ ret;
} a;
a.p = p;
a.l = l;
crosscall2(_swig_gc_makegostring, &a, (int) sizeof a);
return a.ret;
}
extern
#ifdef __cplusplus
"C"
#endif
void _swig_gc_gopanic(void *, int);
static void _swig_gopanic(const char *p) {
struct {
const char *p;
int l;
} a;
a.p = p;
a.l = strlen(p);
crosscall2(_swig_gc_gopanic, &a, (int) sizeof a);
crosscall2(_cgo_panic, &a, (int) sizeof a);
}
%}
@ -91,10 +89,6 @@ static void _swig_gopanic(const char *p) {
#include "runtime.h"
#include "cgocall.h"
#pragma dynimport initcgo initcgo "libcgo.so"
#pragma dynimport libcgo_thread_start libcgo_thread_start "libcgo.so"
#pragma dynimport libcgo_set_scheduler libcgo_set_scheduler "libcgo.so"
#ifdef _64BIT
#define SWIG_PARM_SIZE 8
#else
@ -102,97 +96,123 @@ static void _swig_gopanic(const char *p) {
#endif
%}
/* 6g/8g C boilerplate that is only needed once in a program. This
only gets added to the file if nothing is imported. */
%insert(gc_once) %{
extern void ·_swig_internal_allocate(void);
#pragma dynexport _swig_gc_allocate _swig_gc_allocate
void _swig_gc_allocate(void *a, int32 n) {
cgocallback(·_swig_internal_allocate, a, n);
}
void ·_swig_allocatememory(int32 len, byte *ret) {
ret = mal(len);
FLUSH(&ret);
}
extern void ·_swig_internal_makegostring(void);
#pragma dynexport _swig_gc_makegostring _swig_gc_makegostring
void _swig_gc_makegostring(void *a, int32 n) {
cgocallback(·_swig_internal_makegostring, a, n);
}
void ·_swig_allocatestring(byte *p, int32 l, String ret) {
ret.str = mal(l+1);
mcpy(ret.str, p, l);
ret.len = l;
FLUSH(&ret);
}
extern void ·_swig_internal_gopanic(void);
#pragma dynexport _swig_gc_gopanic _swig_gc_gopanic
void _swig_gc_gopanic(void *a, int32 n) {
cgocallback(·_swig_internal_gopanic, a, n);
}
%}
/* Go code that is only needed once in a program. This is only added
to the file if nothing is imported. */
%insert(go_once) %{
func _swig_allocatememory(int) *byte
func _swig_internal_allocate(len int) *byte {
return _swig_allocatememory(len)
}
func _swig_allocatestring(*byte, int) string
func _swig_internal_makegostring(p *byte, l int) string {
return _swig_allocatestring(p, l)
}
func _swig_internal_gopanic(p *byte, l int) {
panic(_swig_allocatestring(p, l))
}
%}
#else
/* Boilerplate for C/C++ code when using gccgo. */
%insert(runtime) %{
#define SWIGGO_GCCGO
extern
#ifdef __cplusplus
"C"
extern "C" {
#endif
void *__go_alloc (size_t);
extern void *_cgo_allocate(size_t);
extern void _cgo_panic(const char *);
static void *_swig_allocate(int len) {
return __go_alloc(len);
/* Implementations of SwigCgocall and friends for different versions
of gccgo. The Go code will call these functions using C names with
a prefix of the module name. The implementations here call the
routine in libgo. The routines to call vary depending on the gccgo
version. We assume that the version of gcc used to compile this
file is the same as the version of gccgo. */
#define SWIGCONCAT2(s1, s2) s1 ## s2
#define SWIGCONCAT1(s1, s2) SWIGCONCAT2(s1, s2)
#define SwigCgocall SWIGCONCAT1(SWIGMODULE, SwigCgocall)
#define SwigCgocallDone SWIGCONCAT1(SWIGMODULE, SwigCgocallDone)
#define SwigCgocallBack SWIGCONCAT1(SWIGMODULE, SwigCgocallBack)
#define SwigCgocallBackDone SWIGCONCAT1(SWIGMODULE, SwigCgocallBackDone)
#define SWIG_GCC_VERSION \
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC__PATH_LEVEL__)
#if SWIG_GCC_VERSION < 40700
#define SwigDoCgocall()
#define SwigDoCgocallDone()
#define SwigDoCgocallBack()
#define SwigDoCgocallBackDone()
#elif SWIG_GCC_VERSION == 40700
void SwigDoCgocall(void) __asm__("libgo_syscall.syscall.Entersyscall");
void SwigDoCgocallDone(void) __asm__("libgo_syscall.syscall.Exitsyscall");
void SwigDoCgocallBack(void) __asm__("libgo_syscall.syscall.Exitsyscall");
void SwigDoCgocallBackDone(void) __asm__("libgo_syscall.syscall.Entersyscall");
#else
void SwigDoCgocall(void) __asm__("syscall.Cgocall");
void SwigDoCgocallDone(void) __asm__("syscall.CgocallDone");
void SwigDoCgocallBack(void) __asm__("syscall.CgocallBack");
void SwigDoCgocallBackDone(void) __asm__("syscall.CgocallBackDone");
#endif
void SwigCgocall() {
SwigDoCgocall();
}
static _gostring_ _swig_makegostring(const char *p, size_t l) {
_gostring_ ret;
ret.p = (char*)__go_alloc(l);
memcpy(ret.p, p, l);
ret.n = l;
return ret;
void SwigCgocallDone() {
SwigDoCgocallDone();
}
void SwigCgocallBack() {
SwigDoCgocallBack();
}
void SwigCgocallBackDone() {
SwigDoCgocallBackDone();
}
extern
#ifdef __cplusplus
"C"
}
#endif
void __go_panic_msg(const char *);
#define _swig_gopanic __go_panic_msg
#define _swig_goallocate _cgo_allocate
#define _swig_gopanic _cgo_panic
%}
#endif
%insert(runtime) %{
static _gostring_ _swig_makegostring(const char *p, size_t l) {
_gostring_ ret;
ret.p = (char*)_swig_goallocate(l + 1);
memcpy(ret.p, p, l);
ret.n = l;
return ret;
}
#define SWIG_contract_assert(expr, msg) \
if (!(expr)) { _swig_gopanic(msg); } else
%}
#ifndef SWIGGO_GCCGO
%insert(go_header) %{
import _ "runtime/cgo"
import "unsafe"
type _ unsafe.Pointer
%}
#else
%insert(go_header) %{
import "syscall"
import "unsafe"
type _ syscall.Sockaddr
type _ unsafe.Pointer
%}
#endif
/* Function pointers are translated by the code in go.cxx into
_swig_fnptr. Member pointers are translated to _swig_memberptr. */
%insert(go_header) %{
type _swig_fnptr *byte
type _swig_memberptr *byte
%}

40
Lib/go/std_list.i Normal file
View file

@ -0,0 +1,40 @@
/* -----------------------------------------------------------------------------
* std_vector.i
* ----------------------------------------------------------------------------- */
%{
#include <list>
#include <stdexcept>
%}
namespace std {
template<class T, class Alloc = allocator<T> >
class list {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef Alloc allocator_type;
list();
size_type size() const;
bool empty() const;
%rename(isEmpty) empty;
void clear();
void push_front(const value_type& x);
void pop_front();
void push_back(const value_type& x);
void pop_back();
void remove(value_type x);
void reverse();
void unique();
void sort();
void merge(list& x);
};
}

View file

@ -31,17 +31,17 @@ class string;
%{ $result = _swig_makegostring($1.data(), $1.length()); %}
%typemap(directorin) string
%{ $input = _swig_makegostring($1_name.data(), $1_name.length()); %}
%{ $input = _swig_makegostring($1.data(), $1.length()); %}
%typemap(in) const string &
%{
std::string $1_str($input.p, $input.n);
$*1_ltype $1_str($input.p, $input.n);
$1 = &$1_str;
%}
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const string &
%{
static std::string $1_str;
static $*1_ltype $1_str;
$1_str.assign($input.p, $input.n);
$result = &$1_str;
%}
@ -50,6 +50,6 @@ class string;
%{ $result = _swig_makegostring((*$1).data(), (*$1).length()); %}
%typemap(directorin) const string &
%{ $input = _swig_makegostring($1_name.data(), $1_name.length()); %}
%{ $input = _swig_makegostring($1.data(), $1.length()); %}
}

View file

@ -62,22 +62,14 @@ char * typemaps instead:
%define INPUT_TYPEMAP(TYPE, GOTYPE)
%typemap(gotype) TYPE *INPUT, TYPE &INPUT "GOTYPE"
%typemap(in) TYPE *INPUT
%typemap(in) TYPE *INPUT, TYPE &INPUT
%{ $1 = ($1_ltype)&$input; %}
%typemap(in) TYPE &INPUT
%{ $1 = ($1_ltype)$input; %}
%typemap(out) TYPE *INPUT, TYPE &INPUT ""
%typemap(freearg) TYPE *INPUT, TYPE &INPUT ""
%typemap(directorout) TYPE *INPUT
%{ $result = ($1_ltype)&$input; %}
%typemap(directorout) TYPE &INPUT
%{ $result = ($1_ltype)$input; %}
%typemap(directorin) TYPE &INPUT
%{ $1 = ($input_ltype)&$input; %}
%typemap(argout) TYPE *INPUT, TYPE &INPUT ""
// %typemap(typecheck) TYPE *INPUT = TYPE;
// %typemap(typecheck) TYPE &INPUT = TYPE;
@ -95,7 +87,7 @@ INPUT_TYPEMAP(long, int64);
INPUT_TYPEMAP(unsigned long, uint64);
INPUT_TYPEMAP(long long, int64);
INPUT_TYPEMAP(unsigned long long, uint64);
INPUT_TYPEMAP(float, float);
INPUT_TYPEMAP(float, float32);
INPUT_TYPEMAP(double, float64);
#undef INPUT_TYPEMAP
@ -165,7 +157,7 @@ char * typemaps instead:
%define OUTPUT_TYPEMAP(TYPE, GOTYPE)
%typemap(gotype) TYPE *OUTPUT, TYPE &OUTPUT %{[]GOTYPE%}
%typemap(in) TYPE *OUTPUT($*1_ltype temp)
%typemap(in) TYPE *OUTPUT($*1_ltype temp), TYPE &OUTPUT($*1_ltype temp)
{
if ($input.len == 0) {
_swig_gopanic("array must contain at least 1 element");
@ -173,38 +165,16 @@ char * typemaps instead:
$1 = &temp;
}
%typemap(in) TYPE &OUTPUT($*1_ltype temp)
{
if ($input->len == 0) {
_swig_gopanic("array must contain at least 1 element");
}
$1 = &temp;
}
%typemap(out) TYPE *OUTPUT, TYPE &OUTPUT ""
%typemap(freearg) TYPE *OUTPUT, TYPE &OUTPUT ""
%typemap(argout) TYPE *OUTPUT
%typemap(argout) TYPE *OUTPUT, TYPE &OUTPUT
{
TYPE* a = (TYPE *) $input.array;
a[0] = temp$argnum;
}
%typemap(argout) TYPE &OUTPUT
{
TYPE* a = (TYPE *) $input->array;
a[0] = temp$argnum;
}
%typemap(directorout,warning="Need to provide TYPE *OUTPUT directorout typemap") TYPE *OUTPUT, TYPE &OUTPUT {
}
%typemap(directorin) TYPE &OUTPUT
%{ *(($&1_ltype) $input = &$1; %}
%typemap(directorin,warning="Need to provide TYPE *OUTPUT directorin typemap, TYPE array length is unknown") TYPE *OUTPUT
{
}
%enddef
OUTPUT_TYPEMAP(bool, bool);
@ -219,7 +189,7 @@ OUTPUT_TYPEMAP(long, int64);
OUTPUT_TYPEMAP(unsigned long, uint64);
OUTPUT_TYPEMAP(long long, int64);
OUTPUT_TYPEMAP(unsigned long long, uint64);
OUTPUT_TYPEMAP(float, float);
OUTPUT_TYPEMAP(float, float32);
OUTPUT_TYPEMAP(double, float64);
#undef OUTPUT_TYPEMAP
@ -289,31 +259,18 @@ char * typemaps instead:
%define INOUT_TYPEMAP(TYPE, GOTYPE)
%typemap(gotype) TYPE *INOUT, TYPE &INOUT %{[]GOTYPE%}
%typemap(in) TYPE *INOUT {
%typemap(in) TYPE *INOUT, TYPE &INOUT {
if ($input.len == 0) {
_swig_gopanic("array must contain at least 1 element");
}
$1 = ($1_ltype) $input.array;
}
%typemap(in) TYPE &INOUT {
if ($input->len == 0) {
_swig_gopanic("array must contain at least 1 element");
}
$1 = ($1_ltype) $input->array;
}
%typemap(out) TYPE *INOUT, TYPE &INOUT ""
%typemap(freearg) TYPE *INOUT, TYPE &INOUT ""
%typemap(directorout,warning="Need to provide TYPE *INOUT directorout typemap") TYPE *INOUT, TYPE &INOUT {
}
%typemap(directorin) TYPE &INOUT
%{ *(($&1_ltype)&$input) = &$1; %}
%typemap(directorin,warning="Need to provide TYPE *INOUT directorin typemap, TYPE array length is unknown") TYPE *INOUT, TYPE &INOUT
{
}
%typemap(argout) TYPE *INOUT, TYPE &INOUT ""
%enddef
@ -329,7 +286,7 @@ INOUT_TYPEMAP(long, int64);
INOUT_TYPEMAP(unsigned long, uint64);
INOUT_TYPEMAP(long long, int64);
INOUT_TYPEMAP(unsigned long long, uint64);
INOUT_TYPEMAP(float, float);
INOUT_TYPEMAP(float, float32);
INOUT_TYPEMAP(double, float64);
#undef INOUT_TYPEMAP

View file

@ -27,7 +27,7 @@ typedef SCM (*swig_guile_proc)();
SWIG_Guile_MustGetPtr(&swig_module, s, type, argnum, flags, FUNC_NAME)
#define SWIG_NewPointerObj(ptr, type, owner) \
SWIG_Guile_NewPointerObj(&swig_module, (void*)ptr, type, owner)
#define SWIG_GetModule(clientdata) SWIG_Guile_GetModule()
#define SWIG_GetModule(clientdata) SWIG_Guile_GetModule(clientdata)
#define SWIG_SetModule(clientdata, pointer) SWIG_Guile_SetModule(pointer)
/* Ignore object-ownership changes in gh mode */
@ -114,14 +114,14 @@ SWIG_Guile_LookupType(swig_module_info *module, SCM s, int normal)
#ifdef SWIG_GUILE_MODULE_STATIC
static swig_module_info *swig_guile_module = 0;
SWIG_GUILE_MODULE_STATIC swig_module_info *SWIG_Guile_GetModule(void) {
SWIG_GUILE_MODULE_STATIC swig_module_info *SWIG_Guile_GetModule(void *SWIGUNUSEDPARM(clientdata)) {
return swig_guile_module;
}
SWIG_GUILE_MODULE_STATIC void SWIG_Guile_SetModule(swig_module_info *pointer) {
swig_guile_module = pointer;
}
#else
SWIGEXPORT swig_module_info * SWIG_Guile_GetModule(void);
SWIGEXPORT swig_module_info * SWIG_Guile_GetModule(void *SWIGUNUSEDPARM(clientdata));
SWIGEXPORT void SWIG_Guile_SetModule(swig_module_info *pointer);
#endif

View file

@ -53,8 +53,8 @@ typedef struct swig_guile_clientdata {
SWIG_Guile_NewMemberObj(ptr, sz, type, FUNC_NAME)
/* Runtime API */
static swig_module_info *SWIG_Guile_GetModule(void);
#define SWIG_GetModule(clientdata) SWIG_Guile_GetModule()
static swig_module_info *SWIG_Guile_GetModule(void *SWIGUNUSEDPARM(clientdata));
#define SWIG_GetModule(clientdata) SWIG_Guile_GetModule(clientdata)
#define SWIG_SetModule(clientdata, pointer) SWIG_Guile_SetModule(pointer)
SWIGINTERN char *
@ -204,7 +204,7 @@ SWIGINTERNINLINE int
SWIG_Guile_IsPointer (SCM s)
{
/* module might not be initialized yet, so initialize it */
SWIG_Guile_GetModule();
SWIG_GetModule(0);
return SWIG_Guile_IsPointerOfType (s, NULL);
}
@ -419,7 +419,7 @@ SWIG_Guile_Init ()
}
SWIGINTERN swig_module_info *
SWIG_Guile_GetModule(void)
SWIG_Guile_GetModule(void *SWIGUNUSEDPARM(clientdata))
{
SCM module;
SCM variable;

View file

@ -217,6 +217,10 @@ namespace std {
%rename("delete!") __delitem__;
%rename("has-key?") has_key;
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef K key_type;
typedef T mapped_type;
map();
map(const map<K,T> &);

View file

@ -36,7 +36,7 @@ namespace std {
}
}
%typemap(in) const string & (std::string temp, char *tempptr) {
%typemap(in) const string & ($*1_ltype temp, char *tempptr) {
if (gh_string_p($input)) {
tempptr = SWIG_scm2str($input);
temp.assign(tempptr);
@ -50,7 +50,7 @@ namespace std {
%typemap(in) string * (char *tempptr) {
if (gh_string_p($input)) {
tempptr = SWIG_scm2str($input);
$1 = new std::string(tempptr);
$1 = new $*1_ltype(tempptr);
if (tempptr) SWIG_free(tempptr);
} else {
SWIG_exception(SWIG_TypeError, "string expected");

View file

@ -306,18 +306,18 @@ SIMPLE_MAP(unsigned long long, gh_scm2ulong_long, gh_ulong_long2scm, integer);
%typemap (varin, doc="NEW-VALUE is a string") char * {$1 = ($1_ltype)SWIG_scm2str($input);}
%typemap (out, doc="<string>") char * {$result = gh_str02scm((const char *)$1);}
%typemap (varout, doc="<string>") char * {$result = gh_str02scm($1);}
%typemap (in, doc="$NAME is a string") char * *INPUT(char * temp, int must_free = 0) {
%typemap (in, doc="$NAME is a string") char **INPUT(char * temp, int must_free = 0) {
temp = (char *) SWIG_scm2str($input); $1 = &temp;
must_free = 1;
}
%typemap (in,numinputs=0) char * *OUTPUT (char * temp)
%typemap (in,numinputs=0) char **OUTPUT (char * temp)
{$1 = &temp;}
%typemap (argout,doc="$NAME (a string)") char * *OUTPUT
%typemap (argout,doc="$NAME (a string)") char **OUTPUT
{SWIG_APPEND_VALUE(gh_str02scm(*$1));}
%typemap (in) char * *BOTH = char * *INPUT;
%typemap (argout) char * *BOTH = char * *OUTPUT;
%typemap (in) char * *INOUT = char * *INPUT;
%typemap (argout) char * *INOUT = char * *OUTPUT;
%typemap (in) char **BOTH = char **INPUT;
%typemap (argout) char **BOTH = char **OUTPUT;
%typemap (in) char **INOUT = char **INPUT;
%typemap (argout) char **INOUT = char **OUTPUT;
/* SWIG_scm2str makes a malloc'ed copy of the string, so get rid of it after
the function call. */
@ -362,7 +362,7 @@ typedef unsigned long SCM;
* String & length
* ------------------------------------------------------------ */
%typemap(in) (char *STRING, int LENGTH) {
%typemap(in) (char *STRING, int LENGTH), (char *STRING, size_t LENGTH) {
size_t temp;
$1 = ($1_ltype) gh_scm2newstr($input, &temp);
$2 = ($2_ltype) temp;
@ -420,7 +420,7 @@ typedef unsigned long SCM;
const std::size_t &, const std::ptrdiff_t &,
enum SWIGTYPE
{
$1 = SCM_NFALSEP(scm_integer_p($input)) ? 1 : 0;
$1 = SCM_NFALSEP(scm_integer_p($input)) && SCM_NFALSEP(scm_exact_p($input))? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_BOOL)

View file

@ -1,82 +1,82 @@
// Allow for different namespaces for shared_ptr / intrusive_ptr - they could be boost or std or std::tr1
// For example for std::tr1, use:
// #define SWIG_SHARED_PTR_NAMESPACE std
// #define SWIG_SHARED_PTR_SUBNAMESPACE tr1
// #define SWIG_INTRUSIVE_PTR_NAMESPACE boost
// #define SWIG_INTRUSIVE_PTR_SUBNAMESPACE
#if !defined(SWIG_INTRUSIVE_PTR_NAMESPACE)
# define SWIG_INTRUSIVE_PTR_NAMESPACE boost
#endif
#if defined(SWIG_INTRUSIVE_PTR_SUBNAMESPACE)
# define SWIG_INTRUSIVE_PTR_QNAMESPACE SWIG_INTRUSIVE_PTR_NAMESPACE::SWIG_INTRUSIVE_PTR_SUBNAMESPACE
#else
# define SWIG_INTRUSIVE_PTR_QNAMESPACE SWIG_INTRUSIVE_PTR_NAMESPACE
#endif
namespace SWIG_INTRUSIVE_PTR_NAMESPACE {
#if defined(SWIG_INTRUSIVE_PTR_SUBNAMESPACE)
namespace SWIG_INTRUSIVE_PTR_SUBNAMESPACE {
#endif
template <class T> class intrusive_ptr {
};
#if defined(SWIG_INTRUSIVE_PTR_SUBNAMESPACE)
}
#endif
}
%fragment("SWIG_intrusive_deleter", "header") {
template<class T> struct SWIG_intrusive_deleter {
void operator()(T *p) {
if (p)
intrusive_ptr_release(p);
}
};
}
%fragment("SWIG_null_deleter", "header") {
struct SWIG_null_deleter {
void operator() (void const *) const {
}
};
%#define SWIG_NO_NULL_DELETER_0 , SWIG_null_deleter()
%#define SWIG_NO_NULL_DELETER_1
}
// Workaround empty first macro argument bug
#define SWIGEMPTYHACK
// Main user macro for defining intrusive_ptr typemaps for both const and non-const pointer types
%define %intrusive_ptr(TYPE...)
%feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }
SWIG_INTRUSIVE_PTR_TYPEMAPS(SWIGEMPTYHACK, TYPE)
SWIG_INTRUSIVE_PTR_TYPEMAPS(const, TYPE)
%enddef
%define %intrusive_ptr_no_wrap(TYPE...)
%feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }
SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(SWIGEMPTYHACK, TYPE)
SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(const, TYPE)
%enddef
// Legacy macros
%define SWIG_INTRUSIVE_PTR(PROXYCLASS, TYPE...)
#warning "SWIG_INTRUSIVE_PTR(PROXYCLASS, TYPE) is deprecated. Please use %intrusive_ptr(TYPE) instead."
%intrusive_ptr(TYPE)
%enddef
%define SWIG_INTRUSIVE_PTR_DERIVED(PROXYCLASS, BASECLASSTYPE, TYPE...)
#warning "SWIG_INTRUSIVE_PTR_DERIVED(PROXYCLASS, BASECLASSTYPE, TYPE) is deprecated. Please use %intrusive_ptr(TYPE) instead."
%intrusive_ptr(TYPE)
%enddef
%define SWIG_INTRUSIVE_PTR_NO_WRAP(PROXYCLASS, TYPE...)
#warning "SWIG_INTRUSIVE_PTR_NO_WRAP(PROXYCLASS, TYPE) is deprecated. Please use %intrusive_ptr_no_wrap(TYPE) instead."
%intrusive_ptr_no_wrap(TYPE)
%enddef
%define SWIG_INTRUSIVE_PTR_DERIVED_NO_WRAP(PROXYCLASS, BASECLASSTYPE, TYPE...)
#warning "SWIG_INTRUSIVE_PTR_DERIVED_NO_WRAP(PROXYCLASS, BASECLASSTYPE, TYPE) is deprecated. Please use %intrusive_ptr_no_wrap(TYPE) instead."
%intrusive_ptr_no_wrap(TYPE)
%enddef
// Allow for different namespaces for shared_ptr / intrusive_ptr - they could be boost or std or std::tr1
// For example for std::tr1, use:
// #define SWIG_SHARED_PTR_NAMESPACE std
// #define SWIG_SHARED_PTR_SUBNAMESPACE tr1
// #define SWIG_INTRUSIVE_PTR_NAMESPACE boost
// #define SWIG_INTRUSIVE_PTR_SUBNAMESPACE
#if !defined(SWIG_INTRUSIVE_PTR_NAMESPACE)
# define SWIG_INTRUSIVE_PTR_NAMESPACE boost
#endif
#if defined(SWIG_INTRUSIVE_PTR_SUBNAMESPACE)
# define SWIG_INTRUSIVE_PTR_QNAMESPACE SWIG_INTRUSIVE_PTR_NAMESPACE::SWIG_INTRUSIVE_PTR_SUBNAMESPACE
#else
# define SWIG_INTRUSIVE_PTR_QNAMESPACE SWIG_INTRUSIVE_PTR_NAMESPACE
#endif
namespace SWIG_INTRUSIVE_PTR_NAMESPACE {
#if defined(SWIG_INTRUSIVE_PTR_SUBNAMESPACE)
namespace SWIG_INTRUSIVE_PTR_SUBNAMESPACE {
#endif
template <class T> class intrusive_ptr {
};
#if defined(SWIG_INTRUSIVE_PTR_SUBNAMESPACE)
}
#endif
}
%fragment("SWIG_intrusive_deleter", "header") {
template<class T> struct SWIG_intrusive_deleter {
void operator()(T *p) {
if (p)
intrusive_ptr_release(p);
}
};
}
%fragment("SWIG_null_deleter", "header") {
struct SWIG_null_deleter {
void operator() (void const *) const {
}
};
%#define SWIG_NO_NULL_DELETER_0 , SWIG_null_deleter()
%#define SWIG_NO_NULL_DELETER_1
}
// Workaround empty first macro argument bug
#define SWIGEMPTYHACK
// Main user macro for defining intrusive_ptr typemaps for both const and non-const pointer types
%define %intrusive_ptr(TYPE...)
%feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }
SWIG_INTRUSIVE_PTR_TYPEMAPS(SWIGEMPTYHACK, TYPE)
SWIG_INTRUSIVE_PTR_TYPEMAPS(const, TYPE)
%enddef
%define %intrusive_ptr_no_wrap(TYPE...)
%feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }
SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(SWIGEMPTYHACK, TYPE)
SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(const, TYPE)
%enddef
// Legacy macros
%define SWIG_INTRUSIVE_PTR(PROXYCLASS, TYPE...)
#warning "SWIG_INTRUSIVE_PTR(PROXYCLASS, TYPE) is deprecated. Please use %intrusive_ptr(TYPE) instead."
%intrusive_ptr(TYPE)
%enddef
%define SWIG_INTRUSIVE_PTR_DERIVED(PROXYCLASS, BASECLASSTYPE, TYPE...)
#warning "SWIG_INTRUSIVE_PTR_DERIVED(PROXYCLASS, BASECLASSTYPE, TYPE) is deprecated. Please use %intrusive_ptr(TYPE) instead."
%intrusive_ptr(TYPE)
%enddef
%define SWIG_INTRUSIVE_PTR_NO_WRAP(PROXYCLASS, TYPE...)
#warning "SWIG_INTRUSIVE_PTR_NO_WRAP(PROXYCLASS, TYPE) is deprecated. Please use %intrusive_ptr_no_wrap(TYPE) instead."
%intrusive_ptr_no_wrap(TYPE)
%enddef
%define SWIG_INTRUSIVE_PTR_DERIVED_NO_WRAP(PROXYCLASS, BASECLASSTYPE, TYPE...)
#warning "SWIG_INTRUSIVE_PTR_DERIVED_NO_WRAP(PROXYCLASS, BASECLASSTYPE, TYPE) is deprecated. Please use %intrusive_ptr_no_wrap(TYPE) instead."
%intrusive_ptr_no_wrap(TYPE)
%enddef

View file

@ -28,9 +28,9 @@
/* Array support functions declarations macro */
%define JAVA_ARRAYS_DECL(CTYPE, JNITYPE, JAVATYPE, JFUNCNAME)
%{
int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNITYPE##Array input);
void SWIG_JavaArrayArgout##JFUNCNAME (JNIEnv *jenv, JNITYPE *jarr, CTYPE *carr, JNITYPE##Array input);
JNITYPE##Array SWIG_JavaArrayOut##JFUNCNAME (JNIEnv *jenv, CTYPE *result, jsize sz);
static int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNITYPE##Array input);
static void SWIG_JavaArrayArgout##JFUNCNAME (JNIEnv *jenv, JNITYPE *jarr, CTYPE *carr, JNITYPE##Array input);
static JNITYPE##Array SWIG_JavaArrayOut##JFUNCNAME (JNIEnv *jenv, CTYPE *result, jsize sz);
%}
%enddef
@ -38,7 +38,7 @@ JNITYPE##Array SWIG_JavaArrayOut##JFUNCNAME (JNIEnv *jenv, CTYPE *result, jsize
%define JAVA_ARRAYS_IMPL(CTYPE, JNITYPE, JAVATYPE, JFUNCNAME)
%{
/* CTYPE[] support */
int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNITYPE##Array input) {
static int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNITYPE##Array input) {
int i;
jsize sz;
if (!input) {
@ -63,7 +63,7 @@ int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNI
return 1;
}
void SWIG_JavaArrayArgout##JFUNCNAME (JNIEnv *jenv, JNITYPE *jarr, CTYPE *carr, JNITYPE##Array input) {
static void SWIG_JavaArrayArgout##JFUNCNAME (JNIEnv *jenv, JNITYPE *jarr, CTYPE *carr, JNITYPE##Array input) {
int i;
jsize sz = JCALL1(GetArrayLength, jenv, input);
for (i=0; i<sz; i++)
@ -71,7 +71,7 @@ void SWIG_JavaArrayArgout##JFUNCNAME (JNIEnv *jenv, JNITYPE *jarr, CTYPE *carr,
JCALL3(Release##JAVATYPE##ArrayElements, jenv, input, jarr, 0);
}
JNITYPE##Array SWIG_JavaArrayOut##JFUNCNAME (JNIEnv *jenv, CTYPE *result, jsize sz) {
static JNITYPE##Array SWIG_JavaArrayOut##JFUNCNAME (JNIEnv *jenv, CTYPE *result, jsize sz) {
JNITYPE *arr;
int i;
JNITYPE##Array jresult = JCALL1(New##JAVATYPE##Array, jenv, sz);
@ -147,19 +147,19 @@ JAVA_ARRAYS_IMPL(double, jdouble, Double, Double) /* double[] */
%typemap(jstype) CTYPE[ANY], CTYPE[] %{JTYPE[]%}
%typemap(in) CTYPE[] (JNITYPE *jarr)
%{ if (!SWIG_JavaArrayIn##JFUNCNAME(jenv, &jarr, &$1, $input)) return $null; %}
%{ if (!SWIG_JavaArrayIn##JFUNCNAME(jenv, &jarr, (CTYPE **)&$1, $input)) return $null; %}
%typemap(in) CTYPE[ANY] (JNITYPE *jarr)
%{ if ($input && JCALL1(GetArrayLength, jenv, $input) != $1_size) {
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "incorrect array size");
return $null;
}
if (!SWIG_JavaArrayIn##JFUNCNAME(jenv, &jarr, &$1, $input)) return $null; %}
if (!SWIG_JavaArrayIn##JFUNCNAME(jenv, &jarr, (CTYPE **)&$1, $input)) return $null; %}
%typemap(argout) CTYPE[ANY], CTYPE[]
%{ SWIG_JavaArrayArgout##JFUNCNAME(jenv, jarr$argnum, $1, $input); %}
%{ SWIG_JavaArrayArgout##JFUNCNAME(jenv, jarr$argnum, (CTYPE *)$1, $input); %}
%typemap(out) CTYPE[ANY]
%{$result = SWIG_JavaArrayOut##JFUNCNAME(jenv, $1, $1_dim0); %}
%{$result = SWIG_JavaArrayOut##JFUNCNAME(jenv, (CTYPE *)$1, $1_dim0); %}
%typemap(out) CTYPE[]
%{$result = SWIG_JavaArrayOut##JFUNCNAME(jenv, $1, FillMeInAsSizeCannotBeDeterminedAutomatically); %}
%{$result = SWIG_JavaArrayOut##JFUNCNAME(jenv, (CTYPE *)$1, FillMeInAsSizeCannotBeDeterminedAutomatically); %}
%typemap(freearg) CTYPE[ANY], CTYPE[]
#ifdef __cplusplus
%{ delete [] $1; %}
@ -172,6 +172,8 @@ JAVA_ARRAYS_IMPL(double, jdouble, Double, Double) /* double[] */
return $jnicall;
}
%typemap(memberin) CTYPE[ANY], CTYPE[];
%typemap(globalin) CTYPE[ANY], CTYPE[];
%enddef
JAVA_ARRAYS_TYPEMAPS(bool, boolean, jboolean, Bool, "[Z") /* bool[ANY] */

View file

@ -1,463 +1,473 @@
%include <intrusive_ptr.i>
// Language specific macro implementing all the customisations for handling the smart pointer
%define SWIG_INTRUSIVE_PTR_TYPEMAPS(CONST, TYPE...)
// %naturalvar is as documented for member variables
%naturalvar TYPE;
%naturalvar SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >;
// destructor wrapper customisation
%feature("unref") TYPE "(void)arg1; delete smartarg1;"
// Typemap customisations...
%typemap(in) CONST TYPE ($&1_type argp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
// plain value
argp = (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0;
if (!argp) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null $1_type");
return $null;
}
$1 = *argp;
%}
%typemap(out, fragment="SWIG_intrusive_deleter") CONST TYPE %{
//plain value(out)
$1_ltype* resultp = new $1_ltype(($1_ltype &)$1);
intrusive_ptr_add_ref(resultp);
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(resultp, SWIG_intrusive_deleter< CONST TYPE >());
%}
%typemap(in) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
// plain pointer
smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input;
$1 = (TYPE *)(smartarg ? smartarg->get() : 0);
%}
%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") CONST TYPE * %{
//plain pointer(out)
#if ($owner)
if ($1) {
intrusive_ptr_add_ref($1);
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1, SWIG_intrusive_deleter< CONST TYPE >());
} else {
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
}
#else
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0;
#endif
%}
%typemap(in) CONST TYPE & (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
// plain reference
$1 = ($1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0);
if(!$1) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null");
return $null;
}
%}
%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") CONST TYPE & %{
//plain reference(out)
#if ($owner)
if ($1) {
intrusive_ptr_add_ref($1);
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1, SWIG_intrusive_deleter< CONST TYPE >());
} else {
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
}
#else
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0;
#endif
%}
%typemap(in) TYPE *CONST& ($*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
// plain pointer by reference
temp = ($*1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0);
$1 = &temp;
%}
%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") TYPE *CONST& %{
// plain pointer by reference(out)
#if ($owner)
if (*$1) {
intrusive_ptr_add_ref(*$1);
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1, SWIG_intrusive_deleter< CONST TYPE >());
} else {
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
}
#else
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_0);
#endif
%}
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > ($&1_type argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{
// intrusive_ptr by value
smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input;
if (smartarg) {
$1 = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true);
}
%}
%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > %{
if ($1) {
intrusive_ptr_add_ref(result.get());
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(result.get(), SWIG_intrusive_deleter< CONST TYPE >());
} else {
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
}
%}
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast ($&1_type smartarg) %{
// shared_ptr by value
smartarg = *($&1_ltype*)&$input;
if (smartarg) $1 = *smartarg;
%}
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ANY_TYPE_SWIGSharedPtrUpcast %{
*($&1_ltype*)&$result = $1 ? new $1_ltype($1) : 0;
%}
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & ($*1_ltype tempnull, $*1_ltype temp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{
// intrusive_ptr by reference
if ( $input ) {
smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input;
temp = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true);
$1 = &temp;
} else {
$1 = &tempnull;
}
%}
%typemap(memberin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & %{
delete &($1);
if ($self) {
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * temp = new SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(*$input);
$1 = *temp;
}
%}
%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & %{
if (*$1) {
intrusive_ptr_add_ref($1->get());
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1->get(), SWIG_intrusive_deleter< CONST TYPE >());
} else {
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
}
%}
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * ($*1_ltype tempnull, $*1_ltype temp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{
// intrusive_ptr by pointer
if ( $input ) {
smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input;
temp = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true);
$1 = &temp;
} else {
$1 = &tempnull;
}
%}
%typemap(memberin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * %{
delete $1;
if ($self) $1 = new SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(*$input);
%}
%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * %{
if ($1 && *$1) {
intrusive_ptr_add_ref($1->get());
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1->get(), SWIG_intrusive_deleter< CONST TYPE >());
} else {
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
}
if ($owner) delete $1;
%}
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& (SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > temp, $*1_ltype tempp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{
// intrusive_ptr by pointer reference
smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input;
if ($input) {
temp = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true);
}
tempp = &temp;
$1 = &tempp;
%}
%typemap(memberin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& %{
if ($self) $1 = *$input;
%}
%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& %{
if (*$1 && **$1) {
intrusive_ptr_add_ref((*$1)->get());
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >((*$1)->get(), SWIG_intrusive_deleter< CONST TYPE >());
} else {
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
}
%}
// 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"
%}
%typemap (jni) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "jlong"
%typemap (jtype) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "long"
%typemap (jstype) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "$typemap(jstype, TYPE)"
%typemap(javain) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "$typemap(jstype, TYPE).getCPtr($javainput)"
%typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
%typemap(javaout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
%typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
%typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
%typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
%typemap(javaout) CONST TYPE {
return new $typemap(jstype, TYPE)($jnicall, true);
}
%typemap(javaout) CONST TYPE & {
return new $typemap(jstype, TYPE)($jnicall, true);
}
%typemap(javaout) CONST TYPE * {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
%typemap(javaout) TYPE *CONST& {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
// Base proxy classes
%typemap(javabody) TYPE %{
private long swigCPtr;
private boolean swigCMemOwnBase;
public $javaclassname(long cPtr, boolean cMemoryOwn) {
swigCMemOwnBase = cMemoryOwn;
swigCPtr = cPtr;
}
protected static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
%}
// Derived proxy classes
%typemap(javabody_derived) TYPE %{
private long swigCPtr;
private boolean swigCMemOwnDerived;
public $javaclassname(long cPtr, boolean cMemoryOwn) {
super($imclassname.$javaclazznameSWIGSmartPtrUpcast(cPtr), true);
swigCMemOwnDerived = cMemoryOwn;
swigCPtr = cPtr;
}
protected static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
%}
%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") TYPE {
if(swigCPtr != 0 && swigCMemOwnBase) {
swigCMemOwnBase = false;
$jnicall;
}
swigCPtr = 0;
}
%typemap(javadestruct_derived, methodname="delete", methodmodifiers="public synchronized") TYPE {
if(swigCPtr != 0 && swigCMemOwnDerived) {
swigCMemOwnDerived = false;
$jnicall;
}
swigCPtr = 0;
super.delete();
}
// CONST version needed ???? also for C#
%typemap(jtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast "long"
%typemap(jtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast "long"
%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
%template() SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >;
%enddef
/////////////////////////////////////////////////////////////////////
%include <shared_ptr.i>
%define SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(CONST, TYPE...)
%naturalvar TYPE;
%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
// destructor mods
%feature("unref") TYPE "(void)arg1; delete smartarg1;"
// plain value
%typemap(in) CONST TYPE ($&1_type argp = 0) %{
argp = (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0;
if (!argp) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null $1_type");
return $null;
}
$1 = *argp; %}
%typemap(out) CONST TYPE
%{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); %}
// plain pointer
%typemap(in) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input;
$1 = (TYPE *)(smartarg ? smartarg->get() : 0); %}
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE * %{
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0;
%}
// plain reference
%typemap(in) CONST TYPE & %{
$1 = ($1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0);
if (!$1) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null");
return $null;
} %}
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE &
%{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); %}
// plain pointer by reference
%typemap(in) TYPE *CONST& ($*1_ltype temp = 0)
%{ temp = ($*1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0);
$1 = &temp; %}
%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST&
%{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %}
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast ($&1_type smartarg) %{
// shared_ptr by value
smartarg = *($&1_ltype*)&$input;
if (smartarg) $1 = *smartarg;
%}
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ANY_TYPE_SWIGSharedPtrUpcast %{
*($&1_ltype*)&$result = $1 ? new $1_ltype($1) : 0;
%}
// 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"
%}
%typemap (jni) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "jlong"
%typemap (jtype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "long"
%typemap (jstype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "$typemap(jstype, TYPE)"
%typemap (javain) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "$typemap(jstype, TYPE).getCPtr($javainput)"
%typemap(javaout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
%typemap(javaout) CONST TYPE {
return new $typemap(jstype, TYPE)($jnicall, true);
}
%typemap(javaout) CONST TYPE & {
return new $typemap(jstype, TYPE)($jnicall, true);
}
%typemap(javaout) CONST TYPE * {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
%typemap(javaout) TYPE *CONST& {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
// Base proxy classes
%typemap(javabody) TYPE %{
private long swigCPtr;
private boolean swigCMemOwnBase;
public $javaclassname(long cPtr, boolean cMemoryOwn) {
swigCMemOwnBase = cMemoryOwn;
swigCPtr = cPtr;
}
protected static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
%}
// Derived proxy classes
%typemap(javabody_derived) TYPE %{
private long swigCPtr;
private boolean swigCMemOwnDerived;
public $javaclassname(long cPtr, boolean cMemoryOwn) {
super($imclassname.$javaclazznameSWIGSmartPtrUpcast(cPtr), true);
swigCMemOwnDerived = cMemoryOwn;
swigCPtr = cPtr;
}
protected static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
%}
%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") TYPE {
if (swigCPtr != 0) {
if (swigCMemOwnBase) {
swigCMemOwnBase = false;
$jnicall;
}
swigCPtr = 0;
}
}
%typemap(javadestruct_derived, methodname="delete", methodmodifiers="public synchronized") TYPE {
if (swigCPtr != 0) {
if (swigCMemOwnDerived) {
swigCMemOwnDerived = false;
$jnicall;
}
swigCPtr = 0;
}
super.delete();
}
// CONST version needed ???? also for C#
%typemap(jtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast "long"
%typemap(jtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast "long"
%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
%enddef
// Users can provide their own SWIG_INTRUSIVE_PTR_TYPEMAPS or SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP macros before including this file to change the
// visibility of the constructor and getCPtr method if desired to public if using multiple modules.
#ifndef SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP
#define SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(CONST, TYPE...) SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP_IMPLEMENTATION(protected, protected, CONST, TYPE)
#endif
#ifndef SWIG_INTRUSIVE_PTR_TYPEMAPS
#define SWIG_INTRUSIVE_PTR_TYPEMAPS(CONST, TYPE...) SWIG_INTRUSIVE_PTR_TYPEMAPS_IMPLEMENTATION(protected, protected, CONST, TYPE)
#endif
%include <intrusive_ptr.i>
// Language specific macro implementing all the customisations for handling the smart pointer
%define SWIG_INTRUSIVE_PTR_TYPEMAPS_IMPLEMENTATION(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, CONST, TYPE...)
// %naturalvar is as documented for member variables
%naturalvar TYPE;
%naturalvar SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >;
// destructor wrapper customisation
%feature("unref") TYPE "(void)arg1; delete smartarg1;"
// Typemap customisations...
%typemap(in) CONST TYPE ($&1_type argp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
// plain value
argp = (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0;
if (!argp) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null $1_type");
return $null;
}
$1 = *argp;
%}
%typemap(out, fragment="SWIG_intrusive_deleter") CONST TYPE %{
//plain value(out)
$1_ltype* resultp = new $1_ltype(($1_ltype &)$1);
intrusive_ptr_add_ref(resultp);
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(resultp, SWIG_intrusive_deleter< CONST TYPE >());
%}
%typemap(in) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
// plain pointer
smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input;
$1 = (TYPE *)(smartarg ? smartarg->get() : 0);
%}
%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") CONST TYPE * %{
//plain pointer(out)
#if ($owner)
if ($1) {
intrusive_ptr_add_ref($1);
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1, SWIG_intrusive_deleter< CONST TYPE >());
} else {
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
}
#else
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0;
#endif
%}
%typemap(in) CONST TYPE & (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
// plain reference
$1 = ($1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0);
if(!$1) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null");
return $null;
}
%}
%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") CONST TYPE & %{
//plain reference(out)
#if ($owner)
if ($1) {
intrusive_ptr_add_ref($1);
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1, SWIG_intrusive_deleter< CONST TYPE >());
} else {
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
}
#else
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0;
#endif
%}
%typemap(in) TYPE *CONST& ($*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
// plain pointer by reference
temp = ($*1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0);
$1 = &temp;
%}
%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") TYPE *CONST& %{
// plain pointer by reference(out)
#if ($owner)
if (*$1) {
intrusive_ptr_add_ref(*$1);
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1, SWIG_intrusive_deleter< CONST TYPE >());
} else {
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
}
#else
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_0);
#endif
%}
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > ($&1_type argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{
// intrusive_ptr by value
smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input;
if (smartarg) {
$1 = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true);
}
%}
%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > %{
if ($1) {
intrusive_ptr_add_ref(result.get());
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(result.get(), SWIG_intrusive_deleter< CONST TYPE >());
} else {
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
}
%}
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast ($&1_type smartarg) %{
// shared_ptr by value
smartarg = *($&1_ltype*)&$input;
if (smartarg) $1 = *smartarg;
%}
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ANY_TYPE_SWIGSharedPtrUpcast %{
*($&1_ltype*)&$result = $1 ? new $1_ltype($1) : 0;
%}
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & ($*1_ltype tempnull, $*1_ltype temp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{
// intrusive_ptr by reference
if ( $input ) {
smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input;
temp = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true);
$1 = &temp;
} else {
$1 = &tempnull;
}
%}
%typemap(memberin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & %{
delete &($1);
if ($self) {
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * temp = new SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(*$input);
$1 = *temp;
}
%}
%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & %{
if (*$1) {
intrusive_ptr_add_ref($1->get());
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1->get(), SWIG_intrusive_deleter< CONST TYPE >());
} else {
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
}
%}
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * ($*1_ltype tempnull, $*1_ltype temp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{
// intrusive_ptr by pointer
if ( $input ) {
smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input;
temp = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true);
$1 = &temp;
} else {
$1 = &tempnull;
}
%}
%typemap(memberin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * %{
delete $1;
if ($self) $1 = new SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(*$input);
%}
%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * %{
if ($1 && *$1) {
intrusive_ptr_add_ref($1->get());
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1->get(), SWIG_intrusive_deleter< CONST TYPE >());
} else {
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
}
if ($owner) delete $1;
%}
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& (SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > temp, $*1_ltype tempp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{
// intrusive_ptr by pointer reference
smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input;
if ($input) {
temp = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true);
}
tempp = &temp;
$1 = &tempp;
%}
%typemap(memberin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& %{
if ($self) $1 = *$input;
%}
%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& %{
if (*$1 && **$1) {
intrusive_ptr_add_ref((*$1)->get());
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >((*$1)->get(), SWIG_intrusive_deleter< CONST TYPE >());
} else {
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
}
%}
// 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"
%}
%typemap (jni) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "jlong"
%typemap (jtype) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "long"
%typemap (jstype) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "$typemap(jstype, TYPE)"
%typemap(javain) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *,
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "$typemap(jstype, TYPE).getCPtr($javainput)"
%typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
%typemap(javaout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
%typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
%typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
%typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
%typemap(javaout) CONST TYPE {
return new $typemap(jstype, TYPE)($jnicall, true);
}
%typemap(javaout) CONST TYPE & {
return new $typemap(jstype, TYPE)($jnicall, true);
}
%typemap(javaout) CONST TYPE * {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
%typemap(javaout) TYPE *CONST& {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
// Base proxy classes
%typemap(javabody) TYPE %{
private long swigCPtr;
private boolean swigCMemOwnBase;
PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
swigCMemOwnBase = cMemoryOwn;
swigCPtr = cPtr;
}
CPTR_VISIBILITY static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
%}
// Derived proxy classes
%typemap(javabody_derived) TYPE %{
private long swigCPtr;
private boolean swigCMemOwnDerived;
PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
super($imclassname.$javaclazznameSWIGSmartPtrUpcast(cPtr), true);
swigCMemOwnDerived = cMemoryOwn;
swigCPtr = cPtr;
}
CPTR_VISIBILITY static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
%}
%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") TYPE {
if(swigCPtr != 0 && swigCMemOwnBase) {
swigCMemOwnBase = false;
$jnicall;
}
swigCPtr = 0;
}
%typemap(javadestruct_derived, methodname="delete", methodmodifiers="public synchronized") TYPE {
if(swigCPtr != 0 && swigCMemOwnDerived) {
swigCMemOwnDerived = false;
$jnicall;
}
swigCPtr = 0;
super.delete();
}
// CONST version needed ???? also for C#
%typemap(jtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast "long"
%typemap(jtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast "long"
%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
%template() SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >;
%enddef
/////////////////////////////////////////////////////////////////////
%include <shared_ptr.i>
%define SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP_IMPLEMENTATION(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, CONST, TYPE...)
%naturalvar TYPE;
%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
// destructor mods
%feature("unref") TYPE "(void)arg1; delete smartarg1;"
// plain value
%typemap(in) CONST TYPE ($&1_type argp = 0) %{
argp = (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0;
if (!argp) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null $1_type");
return $null;
}
$1 = *argp; %}
%typemap(out) CONST TYPE
%{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); %}
// plain pointer
%typemap(in) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input;
$1 = (TYPE *)(smartarg ? smartarg->get() : 0); %}
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE * %{
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0;
%}
// plain reference
%typemap(in) CONST TYPE & %{
$1 = ($1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0);
if (!$1) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null");
return $null;
} %}
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE &
%{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); %}
// plain pointer by reference
%typemap(in) TYPE *CONST& ($*1_ltype temp = 0)
%{ temp = ($*1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0);
$1 = &temp; %}
%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST&
%{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %}
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast ($&1_type smartarg) %{
// shared_ptr by value
smartarg = *($&1_ltype*)&$input;
if (smartarg) $1 = *smartarg;
%}
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ANY_TYPE_SWIGSharedPtrUpcast %{
*($&1_ltype*)&$result = $1 ? new $1_ltype($1) : 0;
%}
// 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"
%}
%typemap (jni) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "jlong"
%typemap (jtype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "long"
%typemap (jstype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "$typemap(jstype, TYPE)"
%typemap (javain) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "$typemap(jstype, TYPE).getCPtr($javainput)"
%typemap(javaout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
%typemap(javaout) CONST TYPE {
return new $typemap(jstype, TYPE)($jnicall, true);
}
%typemap(javaout) CONST TYPE & {
return new $typemap(jstype, TYPE)($jnicall, true);
}
%typemap(javaout) CONST TYPE * {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
%typemap(javaout) TYPE *CONST& {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
// Base proxy classes
%typemap(javabody) TYPE %{
private long swigCPtr;
private boolean swigCMemOwnBase;
PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
swigCMemOwnBase = cMemoryOwn;
swigCPtr = cPtr;
}
CPTR_VISIBILITY static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
%}
// Derived proxy classes
%typemap(javabody_derived) TYPE %{
private long swigCPtr;
private boolean swigCMemOwnDerived;
PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
super($imclassname.$javaclazznameSWIGSmartPtrUpcast(cPtr), true);
swigCMemOwnDerived = cMemoryOwn;
swigCPtr = cPtr;
}
CPTR_VISIBILITY static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
%}
%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") TYPE {
if (swigCPtr != 0) {
if (swigCMemOwnBase) {
swigCMemOwnBase = false;
$jnicall;
}
swigCPtr = 0;
}
}
%typemap(javadestruct_derived, methodname="delete", methodmodifiers="public synchronized") TYPE {
if (swigCPtr != 0) {
if (swigCMemOwnDerived) {
swigCMemOwnDerived = false;
$jnicall;
}
swigCPtr = 0;
}
super.delete();
}
// CONST version needed ???? also for C#
%typemap(jtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast "long"
%typemap(jtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast "long"
%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
%enddef

View file

@ -1,7 +1,13 @@
// Users can provide their own SWIG_SHARED_PTR_TYPEMAPS macro before including this file to change the
// visibility of the constructor and getCPtr method if desired to public if using multiple modules.
#ifndef SWIG_SHARED_PTR_TYPEMAPS
#define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...) SWIG_SHARED_PTR_TYPEMAPS_IMPLEMENTATION(protected, protected, CONST, TYPE)
#endif
%include <shared_ptr.i>
// Language specific macro implementing all the customisations for handling the smart pointer
%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...)
%define SWIG_SHARED_PTR_TYPEMAPS_IMPLEMENTATION(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, CONST, TYPE...)
// %naturalvar is as documented for member variables
%naturalvar TYPE;
@ -140,14 +146,14 @@
// Base proxy classes
%typemap(javabody) TYPE %{
private long swigCPtr;
private boolean swigCMemOwnBase;
private boolean swigCMemOwn;
public $javaclassname(long cPtr, boolean cMemoryOwn) {
swigCMemOwnBase = cMemoryOwn;
PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
protected static long getCPtr($javaclassname obj) {
CPTR_VISIBILITY static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
%}
@ -157,21 +163,21 @@
private long swigCPtr;
private boolean swigCMemOwnDerived;
public $javaclassname(long cPtr, boolean cMemoryOwn) {
PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
super($imclassname.$javaclazznameSWIGSmartPtrUpcast(cPtr), true);
swigCMemOwnDerived = cMemoryOwn;
swigCPtr = cPtr;
}
protected static long getCPtr($javaclassname obj) {
CPTR_VISIBILITY static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
%}
%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") TYPE {
if (swigCPtr != 0) {
if (swigCMemOwnBase) {
swigCMemOwnBase = false;
if (swigCMemOwn) {
swigCMemOwn = false;
$jnicall;
}
swigCPtr = 0;

View file

@ -25,9 +25,9 @@ namespace Swig {
bool set(JNIEnv *jenv, jobject jobj, bool mem_own, bool weak_global) {
if (!jthis_) {
weak_global_ = weak_global;
weak_global_ = weak_global || !mem_own; // hold as weak global if explicitly requested or not owned
if (jobj)
jthis_ = ((weak_global_ || !mem_own) ? jenv->NewWeakGlobalRef(jobj) : jenv->NewGlobalRef(jobj));
jthis_ = weak_global_ ? jenv->NewWeakGlobalRef(jobj) : jenv->NewGlobalRef(jobj);
#if defined(DEBUG_DIRECTOR_OWNED)
std::cout << "JObjectWrapper::set(" << jobj << ", " << (weak_global ? "weak_global" : "global_ref") << ") -> " << jthis_ << std::endl;
#endif
@ -68,6 +68,7 @@ namespace Swig {
weak_global_ = true;
}
/* Only call peek if you know what you are doing wrt to weak/global references */
jobject peek() {
return jthis_;
}
@ -112,21 +113,29 @@ namespace Swig {
class JNIEnvWrapper {
const Director *director_;
JNIEnv *jenv_;
int env_status;
public:
JNIEnvWrapper(const Director *director) : director_(director), jenv_(0) {
JNIEnvWrapper(const Director *director) : director_(director), jenv_(0), env_status(0) {
#if defined(__ANDROID__)
JNIEnv **jenv = &jenv_;
#else
void **jenv = (void **)&jenv_;
#endif
env_status = director_->swig_jvm_->GetEnv((void **)&jenv_, JNI_VERSION_1_2);
#if defined(SWIG_JAVA_ATTACH_CURRENT_THREAD_AS_DAEMON)
// Attach a daemon thread to the JVM. Useful when the JVM should not wait for
// the thread to exit upon shutdown. Only for jdk-1.4 and later.
director_->swig_jvm_->AttachCurrentThreadAsDaemon((void **) &jenv_, NULL);
director_->swig_jvm_->AttachCurrentThreadAsDaemon(jenv, NULL);
#else
director_->swig_jvm_->AttachCurrentThread((void **) &jenv_, NULL);
director_->swig_jvm_->AttachCurrentThread(jenv, NULL);
#endif
}
~JNIEnvWrapper() {
#if !defined(SWIG_JAVA_NO_DETACH_CURRENT_THREAD)
// Some JVMs, eg jdk-1.4.2 and lower on Solaris have a bug and crash with the DetachCurrentThread call.
// However, without this call, the JVM hangs on exit when the thread was not created by the JVM and creates a memory leak.
director_->swig_jvm_->DetachCurrentThread();
if (env_status == JNI_EDETACHED)
director_->swig_jvm_->DetachCurrentThread();
#endif
}
JNIEnv *getJNIEnv() const {
@ -141,7 +150,7 @@ namespace Swig {
void swig_disconnect_director_self(const char *disconn_method) {
JNIEnvWrapper jnienv(this) ;
JNIEnv *jenv = jnienv.getJNIEnv() ;
jobject jobj = swig_self_.peek();
jobject jobj = swig_self_.get(jenv);
#if defined(DEBUG_DIRECTOR_OWNED)
std::cout << "Swig::Director::disconnect_director_self(" << jobj << ")" << std::endl;
#endif
@ -154,6 +163,7 @@ namespace Swig {
jenv->CallVoidMethod(jobj, disconn_meth);
}
}
jenv->DeleteLocalRef(jobj);
}
public:

View file

@ -20,7 +20,7 @@
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE &
%{ static $*1_ltype temp = ($*1_ltype)$input;
$result = &temp; %}
%typemap(directorin, descriptor="L$packagepath/$*javaclassname;") const enum SWIGTYPE & "$input = (jint)$1_name;"
%typemap(directorin, descriptor="L$packagepath/$*javaclassname;") const enum SWIGTYPE & "$input = (jint)$1;"
%typemap(javadirectorin) const enum SWIGTYPE & "$*javaclassname.swigToEnum($jniinput)"
%typemap(javadirectorout) const enum SWIGTYPE & "($javacall).swigValue()"
@ -45,7 +45,7 @@
%typemap(out) enum SWIGTYPE %{ $result = (jint)$1; %}
%typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %}
%typemap(directorin, descriptor="L$packagepath/$javaclassname;") enum SWIGTYPE "$input = (jint) $1;"
%typemap(directorin, descriptor="L$packagepath/$javaclassname;") enum SWIGTYPE "$input = (jint) $1;"
%typemap(javadirectorin) enum SWIGTYPE "$javaclassname.swigToEnum($jniinput)"
%typemap(javadirectorout) enum SWIGTYPE "($javacall).swigValue()"

View file

@ -20,7 +20,7 @@
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE &
%{ static $*1_ltype temp = ($*1_ltype)$input;
$result = &temp; %}
%typemap(directorin, descriptor="I") const enum SWIGTYPE & "$input = (jint)$1_name;"
%typemap(directorin, descriptor="I") const enum SWIGTYPE & "$input = (jint)$1;"
%typemap(javadirectorin) const enum SWIGTYPE & "$jniinput"
%typemap(javadirectorout) const enum SWIGTYPE & "$javacall"
@ -45,7 +45,7 @@
%typemap(out) enum SWIGTYPE %{ $result = (jint)$1; %}
%typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %}
%typemap(directorin, descriptor="I") enum SWIGTYPE "$input = (jint) $1;"
%typemap(directorin, descriptor="I") enum SWIGTYPE "$input = (jint) $1;"
%typemap(javadirectorin) enum SWIGTYPE "$jniinput"
%typemap(javadirectorout) enum SWIGTYPE "$javacall"

View file

@ -19,7 +19,7 @@
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE &
%{ static $*1_ltype temp = ($*1_ltype)$input;
$result = &temp; %}
%typemap(directorin, descriptor="L$packagepath/$*javaclassname;") const enum SWIGTYPE & "$input = (jint)$1_name;"
%typemap(directorin, descriptor="L$packagepath/$*javaclassname;") const enum SWIGTYPE & "$input = (jint)$1;"
%typemap(javadirectorin) const enum SWIGTYPE & "$*javaclassname.swigToEnum($jniinput)"
%typemap(javadirectorout) const enum SWIGTYPE & "($javacall).swigValue()"
@ -43,7 +43,7 @@
%typemap(out) enum SWIGTYPE %{ $result = (jint)$1; %}
%typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %}
%typemap(directorin, descriptor="L$packagepath/$javaclassname;") enum SWIGTYPE "$input = (jint) $1;"
%typemap(directorin, descriptor="L$packagepath/$javaclassname;") enum SWIGTYPE "$input = (jint) $1;"
%typemap(javadirectorin) enum SWIGTYPE "$javaclassname.swigToEnum($jniinput)"
%typemap(javadirectorout) enum SWIGTYPE "($javacall).swigValue()"

View file

@ -20,7 +20,7 @@
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE &
%{ static $*1_ltype temp = ($*1_ltype)$input;
$result = &temp; %}
%typemap(directorin, descriptor="I") const enum SWIGTYPE & "$input = (jint)$1_name;"
%typemap(directorin, descriptor="I") const enum SWIGTYPE & "$input = (jint)$1;"
%typemap(javadirectorin) const enum SWIGTYPE & "$jniinput"
%typemap(javadirectorout) const enum SWIGTYPE & "$javacall"
@ -45,7 +45,7 @@
%typemap(out) enum SWIGTYPE %{ $result = (jint)$1; %}
%typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %}
%typemap(directorin, descriptor="I") enum SWIGTYPE "$input = (jint) $1;"
%typemap(directorin, descriptor="I") enum SWIGTYPE "$input = (jint) $1;"
%typemap(javadirectorin) enum SWIGTYPE "$jniinput"
%typemap(javadirectorout) enum SWIGTYPE "$javacall"

View file

@ -473,19 +473,19 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
temp = ($*1_ltype)$input;
$result = &temp; %}
%typemap(directorin, descriptor="Z") const bool & "$input = (jboolean)$1_name;"
%typemap(directorin, descriptor="C") const char & "$input = (jchar)$1_name;"
%typemap(directorin, descriptor="B") const signed char & "$input = (jbyte)$1_name;"
%typemap(directorin, descriptor="S") const unsigned char & "$input = (jshort)$1_name;"
%typemap(directorin, descriptor="S") const short & "$input = (jshort)$1_name;"
%typemap(directorin, descriptor="I") const unsigned short & "$input = (jint)$1_name;"
%typemap(directorin, descriptor="I") const int & "$input = (jint)$1_name;"
%typemap(directorin, descriptor="J") const unsigned int & "$input = (jlong)$1_name;"
%typemap(directorin, descriptor="I") const long & "$input = (jint)$1_name;"
%typemap(directorin, descriptor="J") const unsigned long & "$input = (jlong)$1_name;"
%typemap(directorin, descriptor="J") const long long & "$input = (jlong)$1_name;"
%typemap(directorin, descriptor="F") const float & "$input = (jfloat)$1_name;"
%typemap(directorin, descriptor="D") const double & "$input = (jdouble)$1_name;"
%typemap(directorin, descriptor="Z") const bool & "$input = (jboolean)$1;"
%typemap(directorin, descriptor="C") const char & "$input = (jchar)$1;"
%typemap(directorin, descriptor="B") const signed char & "$input = (jbyte)$1;"
%typemap(directorin, descriptor="S") const unsigned char & "$input = (jshort)$1;"
%typemap(directorin, descriptor="S") const short & "$input = (jshort)$1;"
%typemap(directorin, descriptor="I") const unsigned short & "$input = (jint)$1;"
%typemap(directorin, descriptor="I") const int & "$input = (jint)$1;"
%typemap(directorin, descriptor="J") const unsigned int & "$input = (jlong)$1;"
%typemap(directorin, descriptor="I") const long & "$input = (jint)$1;"
%typemap(directorin, descriptor="J") const unsigned long & "$input = (jlong)$1;"
%typemap(directorin, descriptor="J") const long long & "$input = (jlong)$1;"
%typemap(directorin, descriptor="F") const float & "$input = (jfloat)$1;"
%typemap(directorin, descriptor="D") const double & "$input = (jdouble)$1;"
%typemap(javadirectorin) const char & ($*1_ltype temp),
const signed char & ($*1_ltype temp),
@ -1140,9 +1140,11 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
/* javabody typemaps */
%define SWIG_JAVABODY_METHODS(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, TYPENAME...)
%define SWIG_JAVABODY_METHODS(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE...) SWIG_JAVABODY_PROXY(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE) %enddef // legacy name
%define SWIG_JAVABODY_PROXY(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE...)
// Base proxy classes
%typemap(javabody) TYPENAME %{
%typemap(javabody) TYPE %{
private long swigCPtr;
protected boolean swigCMemOwn;
@ -1157,7 +1159,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%}
// Derived proxy classes
%typemap(javabody_derived) TYPENAME %{
%typemap(javabody_derived) TYPE %{
private long swigCPtr;
PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
@ -1171,43 +1173,45 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%}
%enddef
/* Set the default for SWIGTYPE: pointer constructor is protected,
getCPtr is protected. Season to your own taste! */
SWIG_JAVABODY_METHODS(public, public, SWIGTYPE)
%define SWIG_JAVABODY_TYPEWRAPPER(PTRCTOR_VISIBILITY, DEFAULTCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE...)
// Typewrapper classes
%typemap(javabody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] %{
%typemap(javabody) TYPE *, TYPE &, TYPE &&, TYPE [] %{
private long swigCPtr;
protected $javaclassname(long cPtr, boolean futureUse) {
PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean futureUse) {
swigCPtr = cPtr;
}
protected $javaclassname() {
DEFAULTCTOR_VISIBILITY $javaclassname() {
swigCPtr = 0;
}
protected static long getCPtr($javaclassname obj) {
CPTR_VISIBILITY static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
%}
%typemap(javabody) SWIGTYPE (CLASS::*) %{
%typemap(javabody) TYPE (CLASS::*) %{
private String swigCMemberPtr;
protected $javaclassname(String cMemberPtr, boolean futureUse) {
PTRCTOR_VISIBILITY $javaclassname(String cMemberPtr, boolean futureUse) {
swigCMemberPtr = cMemberPtr;
}
protected $javaclassname() {
DEFAULTCTOR_VISIBILITY $javaclassname() {
swigCMemberPtr = null;
}
protected static String getCMemberPtr($javaclassname obj) {
CPTR_VISIBILITY static String getCMemberPtr($javaclassname obj) {
return obj.swigCMemberPtr;
}
%}
%enddef
/* Set the default javabody typemaps to use protected visibility.
Use the macros to change to public if using multiple modules. */
SWIG_JAVABODY_PROXY(protected, protected, SWIGTYPE)
SWIG_JAVABODY_TYPEWRAPPER(protected, protected, protected, SWIGTYPE)
%typemap(javafinalize) SWIGTYPE %{
protected void finalize() {
@ -1315,6 +1319,33 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE)
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
/* String & length */
%typemap(jni) (char *STRING, size_t LENGTH) "jbyteArray"
%typemap(jtype) (char *STRING, size_t LENGTH) "byte[]"
%typemap(jstype) (char *STRING, size_t LENGTH) "byte[]"
%typemap(javain) (char *STRING, size_t LENGTH) "$javainput"
%typemap(freearg) (char *STRING, size_t LENGTH) ""
%typemap(in) (char *STRING, size_t LENGTH) {
if ($input) {
$1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
$2 = (size_t) JCALL1(GetArrayLength, jenv, $input);
} else {
$1 = 0;
$2 = 0;
}
}
%typemap(argout) (char *STRING, size_t LENGTH) {
if ($input) JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0);
}
%typemap(directorin, descriptor="[B") (char *STRING, size_t LENGTH) {
jbyteArray jb = (jenv)->NewByteArray($2);
(jenv)->SetByteArrayRegion(jb, 0, $2, (jbyte *)$1);
$input = jb;
}
%typemap(directorargout) (char *STRING, size_t LENGTH)
%{(jenv)->GetByteArrayRegion($input, 0, $2, (jbyte *)$1); %}
%apply (char *STRING, size_t LENGTH) { (char *STRING, int LENGTH) }
/* java keywords */
%include <javakw.swg>

View file

@ -28,7 +28,7 @@ class string;
%typemap(in) string
%{ if(!$input) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string");
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string");
return $null;
}
const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0);
@ -38,7 +38,7 @@ class string;
%typemap(directorout) string
%{ if(!$input) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string");
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string");
return $null;
}
const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0);
@ -73,24 +73,24 @@ class string;
%typemap(in) const string &
%{ if(!$input) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string");
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string");
return $null;
}
const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0);
if (!$1_pstr) return $null;
std::string $1_str($1_pstr);
$*1_ltype $1_str($1_pstr);
$1 = &$1_str;
jenv->ReleaseStringUTFChars($input, $1_pstr); %}
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const string &
%{ if(!$input) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string");
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string");
return $null;
}
const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0);
if (!$1_pstr) return $null;
/* possible thread/reentrant code problem */
static std::string $1_str;
static $*1_ltype $1_str;
$1_str = $1_pstr;
$result = &$1_str;
jenv->ReleaseStringUTFChars($input, $1_pstr); %}

View file

@ -63,23 +63,12 @@ There are no char *INPUT typemaps, however you can apply the signed char * typem
%typemap(jtype) TYPE *INPUT, TYPE &INPUT "JTYPE"
%typemap(jstype) TYPE *INPUT, TYPE &INPUT "JTYPE"
%typemap(javain) TYPE *INPUT, TYPE &INPUT "$javainput"
%typemap(javadirectorin) TYPE *INPUT, TYPE &INPUT "$jniinput"
%typemap(javadirectorout) TYPE *INPUT, TYPE &INPUT "$javacall"
%typemap(in) TYPE *INPUT, TYPE &INPUT
%{ $1 = ($1_ltype)&$input; %}
%typemap(freearg) TYPE *INPUT, TYPE &INPUT ""
%typemap(directorout) TYPE *INPUT, TYPE &INPUT
%{ $result = ($1_ltype)&$input; %}
%typemap(directorin,descriptor=JNIDESC) TYPE &INPUT
%{ *(($&1_ltype) $input) = (JNITYPE *) &$1; %}
%typemap(directorin,descriptor=JNIDESC) TYPE *INPUT
%{ *(($&1_ltype) $input) = (JNITYPE *) $1; %}
%typemap(typecheck) TYPE *INPUT = TYPE;
%typemap(typecheck) TYPE &INPUT = TYPE;
%enddef
@ -195,8 +184,6 @@ There are no char *OUTPUT typemaps, however you can apply the signed char * type
%typemap(jtype) TYPE *OUTPUT, TYPE &OUTPUT "JTYPE[]"
%typemap(jstype) TYPE *OUTPUT, TYPE &OUTPUT "JTYPE[]"
%typemap(javain) TYPE *OUTPUT, TYPE &OUTPUT "$javainput"
%typemap(javadirectorin) TYPE *OUTPUT, TYPE &OUTPUT "$jniinput"
%typemap(javadirectorout) TYPE *OUTPUT, TYPE &OUTPUT "$javacall"
%typemap(in) TYPE *OUTPUT($*1_ltype temp), TYPE &OUTPUT($*1_ltype temp)
{
@ -208,6 +195,7 @@ There are no char *OUTPUT typemaps, however you can apply the signed char * type
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "Array must contain at least 1 element");
return $null;
}
temp = ($*1_ltype)0;
$1 = &temp;
}
@ -219,16 +207,6 @@ There are no char *OUTPUT typemaps, however you can apply the signed char * type
JCALL4(Set##JAVATYPE##ArrayRegion, jenv, $input, 0, 1, &jvalue);
}
%typemap(directorout,warning="Need to provide TYPE *OUTPUT directorout typemap") TYPE *OUTPUT, TYPE &OUTPUT {
}
%typemap(directorin,descriptor=JNIDESC) TYPE &OUTPUT
%{ *(($&1_ltype) $input = &$1; %}
%typemap(directorin,descriptor=JNIDESC,warning="Need to provide TYPE *OUTPUT directorin typemap, TYPE array length is unknown") TYPE *OUTPUT
{
}
%typemap(typecheck) TYPE *INOUT = TYPECHECKTYPE;
%typemap(typecheck) TYPE &INOUT = TYPECHECKTYPE;
%enddef
@ -249,6 +227,20 @@ OUTPUT_TYPEMAP(double, jdouble, double, Double, "[Ljava/lang/Double;", jdoubleAr
#undef OUTPUT_TYPEMAP
%typemap(in) bool *OUTPUT($*1_ltype temp), bool &OUTPUT($*1_ltype temp)
{
if (!$input) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "array null");
return $null;
}
if (JCALL1(GetArrayLength, jenv, $input) == 0) {
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "Array must contain at least 1 element");
return $null;
}
temp = false;
$1 = &temp;
}
/* Convert to BigInteger - byte array holds number in 2's complement big endian format */
/* Use first element in BigInteger array for output */
/* Overrides the typemap in the OUTPUT_TYPEMAP macro */
@ -335,8 +327,6 @@ There are no char *INOUT typemaps, however you can apply the signed char * typem
%typemap(jtype) TYPE *INOUT, TYPE &INOUT "JTYPE[]"
%typemap(jstype) TYPE *INOUT, TYPE &INOUT "JTYPE[]"
%typemap(javain) TYPE *INOUT, TYPE &INOUT "$javainput"
%typemap(javadirectorin) TYPE *INOUT, TYPE &INOUT "$jniinput"
%typemap(javadirectorout) TYPE *INOUT, TYPE &INOUT "$javacall"
%typemap(in) TYPE *INOUT, TYPE &INOUT {
if (!$input) {
@ -355,15 +345,6 @@ There are no char *INOUT typemaps, however you can apply the signed char * typem
%typemap(argout) TYPE *INOUT, TYPE &INOUT
{ JCALL3(Release##JAVATYPE##ArrayElements, jenv, $input, (JNITYPE *)$1, 0); }
%typemap(directorout,warning="Need to provide TYPE *INOUT directorout typemap") TYPE *INOUT, TYPE &INOUT {
}
%typemap(directorin,descriptor=JNIDESC) TYPE &INOUT
%{ *(($&1_ltype)&$input) = &$1; %}
%typemap(directorin,descriptor=JNIDESC,warning="Need to provide TYPE *INOUT directorin typemap, TYPE array length is unknown") TYPE *INOUT, TYPE &INOUT
{
}
%typemap(typecheck) TYPE *INOUT = TYPECHECKTYPE;
%typemap(typecheck) TYPE &INOUT = TYPECHECKTYPE;

View file

@ -23,7 +23,8 @@
%typemap(jtype) char **STRING_ARRAY "String[]"
%typemap(jstype) char **STRING_ARRAY "String[]"
%typemap(in) char **STRING_ARRAY (jint size) {
int i = 0;
int i = 0;
if ($input) {
size = JCALL1(GetArrayLength, jenv, $input);
#ifdef __cplusplus
$1 = new char*[size+1];
@ -31,51 +32,57 @@
$1 = (char **)calloc(size+1, sizeof(char *));
#endif
for (i = 0; i<size; i++) {
jstring j_string = (jstring)JCALL2(GetObjectArrayElement, jenv, $input, i);
const char *c_string = JCALL2(GetStringUTFChars, jenv, j_string, 0);
jstring j_string = (jstring)JCALL2(GetObjectArrayElement, jenv, $input, i);
const char *c_string = JCALL2(GetStringUTFChars, jenv, j_string, 0);
#ifdef __cplusplus
$1[i] = new char [strlen(c_string)+1];
$1[i] = new char [strlen(c_string)+1];
#else
$1[i] = (char *)calloc(strlen(c_string)+1, sizeof(const char *));
$1[i] = (char *)calloc(strlen(c_string)+1, sizeof(const char *));
#endif
strcpy($1[i], c_string);
JCALL2(ReleaseStringUTFChars, jenv, j_string, c_string);
JCALL1(DeleteLocalRef, jenv, j_string);
strcpy($1[i], c_string);
JCALL2(ReleaseStringUTFChars, jenv, j_string, c_string);
JCALL1(DeleteLocalRef, jenv, j_string);
}
$1[i] = 0;
} else {
$1 = 0;
size = 0;
}
}
%typemap(freearg) char **STRING_ARRAY {
int i;
for (i=0; i<size$argnum-1; i++)
int i;
for (i=0; i<size$argnum-1; i++)
#ifdef __cplusplus
delete[] $1[i];
delete[] $1;
delete[] $1[i];
delete[] $1;
#else
free($1[i]);
free($1);
free($1[i]);
free($1);
#endif
}
%typemap(out) char **STRING_ARRAY {
if ($1) {
int i;
int len=0;
jstring temp_string;
const jclass clazz = JCALL1(FindClass, jenv, "java/lang/String");
while ($1[len]) len++;
jresult = JCALL3(NewObjectArray, jenv, len, clazz, NULL);
while ($1[len]) len++;
$result = JCALL3(NewObjectArray, jenv, len, clazz, NULL);
/* exception checking omitted */
for (i=0; i<len; i++) {
temp_string = JCALL1(NewStringUTF, jenv, *result++);
JCALL3(SetObjectArrayElement, jenv, jresult, i, temp_string);
temp_string = JCALL1(NewStringUTF, jenv, *$1++);
JCALL3(SetObjectArrayElement, jenv, $result, i, temp_string);
JCALL1(DeleteLocalRef, jenv, temp_string);
}
}
}
%typemap(javain) char **STRING_ARRAY "$javainput"
%typemap(javaout) char **STRING_ARRAY {
%typemap(javaout) char **STRING_ARRAY {
return $jnicall;
}
@ -107,11 +114,12 @@
return $null;
}
$1 = &temp;
*$1 = 0;
}
%typemap(argout) char **STRING_OUT {
jstring jnewstring = NULL;
if($1) {
if ($1) {
jnewstring = JCALL1(NewStringUTF, jenv, *$1);
}
JCALL3(SetObjectArrayElement, jenv, $input, 0, jnewstring);
@ -134,11 +142,11 @@
%typemap(jtype) char *BYTE "byte[]"
%typemap(jstype) char *BYTE "byte[]"
%typemap(in) char *BYTE {
$1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
$1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(argout) char *BYTE {
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
}
%typemap(javain) char *BYTE "$javainput"

View file

@ -4,7 +4,7 @@
* std::helpers for LUA
* ----------------------------------------------------------------------------- */
%include <std_except.i> // the general exepctions
%include <std_except.i> // the general exceptions
/*
The basic idea here, is instead of trying to feed SWIG all the
@ -16,9 +16,9 @@ so the class declarations become just a set of %defines
*/
/* #define for basic container features
note: I allow front(), back() & pop_back() to throw execptions
note: I allow front(), back() & pop_back() to throw exceptions
upon empty containers, rather than coredump
(as we have'nt defined the methods, we can use %extend to add with
(as we haven't defined the methods, we can use %extend to add with
new features)
*/

View file

@ -1,5 +1,5 @@
/* Small change to the standard carrays.i
renaming the field to __getitem__ & __setitem__
renaming the field to __getitem & __setitem
for operator[] access
*/
%rename(__getitem) *::getitem; // the v=X[i] (get operator)

23
Lib/lua/factory.i Normal file
View file

@ -0,0 +1,23 @@
/*
A modification of factory.swg from the generic UTL library.
*/
%include <typemaps/swigmacros.swg>
%define %_factory_dispatch(Type)
if (!dcast) {
Type *dobj = dynamic_cast<Type *>($1);
if (dobj) {
dcast = 1;
SWIG_NewPointerObj(L, dobj, $descriptor(Type *), $owner); SWIG_arg++;
}
}%enddef
%define %factory(Method,Types...)
%typemap(out) Method {
int dcast = 0;
%formacro(%_factory_dispatch, Types)
if (!dcast) {
SWIG_NewPointerObj(L, $1, $descriptor, $owner); SWIG_arg++;
}
}%enddef

View file

@ -18,27 +18,27 @@
* ----------------------------------------------------------------------------- */
// this basically adds to a table of constants
%typemap(consttab) int, unsigned int, short, unsigned short, long, unsigned long, unsigned char, signed char, bool, enum SWIGTYPE
{ SWIG_LUA_INT, (char *)"$symname", (long) $value, 0, 0, 0}
{SWIG_LUA_CONSTTAB_INT("$symname", $value)}
%typemap(consttab) float, double
{ SWIG_LUA_FLOAT, (char *)"$symname", 0, (double) $value, 0, 0}
{SWIG_LUA_CONSTTAB_FLOAT("$symname", $value)}
%typemap(consttab) long long, unsigned long long, signed long long
{ SWIG_LUA_FLOAT, (char *)"$symname", 0, (double) $value, 0, 0}
{SWIG_LUA_CONSTTAB_FLOAT("$symname", $value)}
%typemap(consttab) const long long&, const unsigned long long&, const signed long long&
{ SWIG_LUA_FLOAT, (char *)"$symname", 0, (double) *$value, 0, 0}
{SWIG_LUA_CONSTTAB_FLOAT("$symname", *$value)}
%typemap(consttab) char *, const char *, char [], const char []
{ SWIG_LUA_STRING, (char *)"$symname", 0, 0, (void *)$value, 0}
{SWIG_LUA_CONSTTAB_STRING("$symname", $value)}
// note: char is treated as a seperate special type
// signed char & unsigned char are numbers
%typemap(consttab) char
{ SWIG_LUA_CHAR, (char *)"$symname", (long)$value, 0, 0, 0}
{SWIG_LUA_CONSTTAB_CHAR("$symname", $value)}
%typemap(consttab) long long, unsigned long long
{ SWIG_LUA_STRING, (char *) "$symname", 0, 0, (void *)"$value", 0}
{SWIG_LUA_CONSTTAB_STRING("$symname", "$value")}
%typemap(consttab) SWIGTYPE *, SWIGTYPE *const, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE []
{ SWIG_LUA_POINTER, (char *)"$symname", 0, 0, (void *)$value, &$1_descriptor}
@ -142,8 +142,8 @@
/* ------------------------------------------------------------
* Exceptions
* ------------------------------------------------------------ */
/* Confession: I dont really like C++ exceptions
The python/lua ones are great, but C++ ones I dont like
/* Confession: I don't really like C++ exceptions
The python/lua ones are great, but C++ ones I don't like
(mainly because I cannot get the stack trace out of it)
Therefore I have not bothered to try doing much in this
@ -191,7 +191,7 @@ There are a few options:
- return a copy of it: but not all objects are copyable
(see exception_partial_info in the test suite for a case where you cannot do this)
- convert to a string & throw that
its not so useful, but it works (this is more lua like).
it's not so useful, but it works (this is more lua like).
The third option (though not nice) is used
For a more useful solution: see std_except for more details
*/

View file

@ -8,7 +8,7 @@
* Basic function pointer support
* ----------------------------------------------------------------------------- */
/*
The structure: SWIGLUA_FN provides a simple (local only) wrappering for a function.
The structure: SWIGLUA_FN provides a simple (local only) wrapping for a function.
For example if you wanted to have a C/C++ function take a lua function as a parameter.
You could declare it as:
@ -29,7 +29,7 @@ just push the parameters, call the function and return the result.
return luaL_checknumber(fn.L,-1);
}
SWIG will automatically performs the wrappering of the arguments in and out.
SWIG will automatically performs the wrapping of the arguments in and out.
However: if you wish to store the function between calls, look to the SWIGLUA_REF below.
@ -64,8 +64,8 @@ Then call it later, You could declare it as:
note: it should be passed by value, not byref or as a pointer.
The SWIGLUA_REF holds a pointer to the lua_State, and an integer reference to the object.
Because it holds a permenet ref to an object, the SWIGLUA_REF must be handled with a bit more care.
It should be initalised to {0,0}. The function swiglua_ref_set() should be used to set it.
Because it holds a permanent ref to an object, the SWIGLUA_REF must be handled with a bit more care.
It should be initialised to {0,0}. The function swiglua_ref_set() should be used to set it.
swiglua_ref_clear() should be used to clear it when not in use, and swiglua_ref_get() to get the
data back.
@ -82,7 +82,7 @@ if you need that you must add it yourself.
return luaL_checknumber(fn.L,-1);
}
SWIG will automatically performs the wrappering of the arguments in and out.
SWIG will automatically performs the wrapping of the arguments in and out.
However: if you wish to store the function between calls, look to the SWIGLUA_REF below.

View file

@ -15,6 +15,62 @@ extern "C" {
#include <stdlib.h> /* for malloc */
#include <assert.h> /* for a few sanity tests */
/* -----------------------------------------------------------------------------
* Lua flavors
* ----------------------------------------------------------------------------- */
#define SWIG_LUA_FLAVOR_LUA 1
#define SWIG_LUA_FLAVOR_ELUA 2
#define SWIG_LUA_FLAVOR_ELUAC 3
#if !defined(SWIG_LUA_TARGET)
# error SWIG_LUA_TARGET not defined
#endif
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
# define SWIG_LUA_CONSTTAB_INT(B, C) LSTRKEY(B), LNUMVAL(C)
# define SWIG_LUA_CONSTTAB_FLOAT(B, C) LSTRKEY(B), LNUMVAL(C)
# define SWIG_LUA_CONSTTAB_STRING(B, C) LSTRKEY(B), LSTRVAL(C)
# define SWIG_LUA_CONSTTAB_CHAR(B, C) LSTRKEY(B), LNUMVAL(C)
#else /* SWIG_LUA_FLAVOR_LUA */
# define SWIG_LUA_CONSTTAB_INT(B, C) SWIG_LUA_INT, (char *)B, (long)C, 0, 0, 0
# define SWIG_LUA_CONSTTAB_FLOAT(B, C) SWIG_LUA_FLOAT, (char *)B, 0, (double)C, 0, 0
# define SWIG_LUA_CONSTTAB_STRING(B, C) SWIG_LUA_STRING, (char *)B, 0, 0, (void *)C, 0
# define SWIG_LUA_CONSTTAB_CHAR(B, C) SWIG_LUA_CHAR, (char *)B, (long)C, 0, 0, 0
#endif
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
# define LRO_STRVAL(v) {{.p = (char *) v}, LUA_TSTRING}
# define LSTRVAL LRO_STRVAL
#endif
/* -----------------------------------------------------------------------------
* compatibility defines
* ----------------------------------------------------------------------------- */
/* History of Lua C API length functions: In Lua 5.0 (and before?)
there was "lua_strlen". In Lua 5.1, this was renamed "lua_objlen",
but a compatibility define of "lua_strlen" was added. In Lua 5.2,
this function was again renamed, to "lua_rawlen" (to emphasize that
it doesn't call the "__len" metamethod), and the compatibility
define of lua_strlen was removed. All SWIG uses have been updated
to "lua_rawlen", and we add our own defines of that here for older
versions of Lua. */
#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 501
# define lua_rawlen lua_strlen
#elif LUA_VERSION_NUM == 501
# define lua_rawlen lua_objlen
#endif
/* lua_pushglobaltable is the recommended "future-proof" way to get
the global table for Lua 5.2 and later. Here we define
lua_pushglobaltable ourselves for Lua versions before 5.2. */
#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502
# define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX)
#endif
/* -----------------------------------------------------------------------------
* global swig types
* ----------------------------------------------------------------------------- */
@ -65,7 +121,7 @@ typedef struct swig_lua_class {
const char **base_names;
} swig_lua_class;
/* this is the struct for wrappering all pointers in SwigLua
/* this is the struct for wrapping all pointers in SwigLua
*/
typedef struct {
swig_type_info *type;
@ -73,7 +129,7 @@ typedef struct {
void *ptr;
} swig_lua_userdata;
/* this is the struct for wrapping arbitary packed binary data
/* this is the struct for wrapping arbitrary packed binary data
(currently it is only used for member function pointers)
the data ordering is similar to swig_lua_userdata, but it is currently not possible
to tell the two structures apart within SWIG, other than by looking at the type
@ -157,7 +213,7 @@ SWIG_Lua_SetModule(lua_State* L, swig_module_info *module) {
* ----------------------------------------------------------------------------- */
/* this function is called when trying to set an immutable.
default value is to print an error.
default action is to print an error.
This can removed with a compile flag SWIGLUA_IGNORE_SET_IMMUTABLE */
SWIGINTERN int SWIG_Lua_set_immutable(lua_State* L)
{
@ -181,12 +237,24 @@ SWIGINTERN int SWIG_Lua_module_get(lua_State* L)
lua_tostring(L,2));
*/
/* get the metatable */
assert(lua_istable(L,1)); /* just in case */
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
assert(lua_isrotable(L,1)); /* just in case */
#else
assert(lua_istable(L,1)); /* default Lua action */
#endif
lua_getmetatable(L,1); /* get the metatable */
assert(lua_istable(L,-1)); /* just in case */
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
assert(lua_isrotable(L,-1)); /* just in case */
#else
assert(lua_istable(L,-1));
#endif
SWIG_Lua_get_table(L,".get"); /* get the .get table */
lua_remove(L,3); /* remove metatable */
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
if (lua_isrotable(L,-1))
#else
if (lua_istable(L,-1))
#endif
{
/* look for the key in the .get table */
lua_pushvalue(L,2); /* key */
@ -201,7 +269,7 @@ SWIGINTERN int SWIG_Lua_module_get(lua_State* L)
}
lua_pop(L,1); /* remove the .get */
lua_pushnil(L); /* return a nil */
return 1;
return 1;
}
/* the module.set method used for setting linked data */
@ -213,12 +281,24 @@ SWIGINTERN int SWIG_Lua_module_set(lua_State* L)
(3) any for the new value
*/
/* get the metatable */
assert(lua_istable(L,1)); /* just in case */
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
assert(lua_isrotable(L,1)); /* just in case */
#else
assert(lua_istable(L,1)); /* default Lua action */
#endif
lua_getmetatable(L,1); /* get the metatable */
assert(lua_istable(L,-1)); /* just in case */
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
assert(lua_isrotable(L,-1)); /* just in case */
#else
assert(lua_istable(L,-1));
#endif
SWIG_Lua_get_table(L,".set"); /* get the .set table */
lua_remove(L,4); /* remove metatable */
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
if (lua_isrotable(L,-1))
#else
if (lua_istable(L,-1))
#endif
{
/* look for the key in the .set table */
lua_pushvalue(L,2); /* key */
@ -230,6 +310,11 @@ SWIGINTERN int SWIG_Lua_module_set(lua_State* L)
lua_call(L,1,0);
return 0;
}
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA)
else {
return 0; // Exits stoically if an invalid key is initialized.
}
#endif
}
lua_settop(L,3); /* reset back to start */
/* we now have the table, key & new value, so just set directly */
@ -237,7 +322,8 @@ SWIGINTERN int SWIG_Lua_module_set(lua_State* L)
return 0;
}
/* registering a module in lua */
#if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
/* registering a module in lua. Pushes the module table on the stack. */
SWIGINTERN void SWIG_Lua_module_begin(lua_State* L,const char* name)
{
assert(lua_istable(L,-1)); /* just in case */
@ -254,8 +340,16 @@ SWIGINTERN void SWIG_Lua_module_begin(lua_State* L,const char* name)
lua_newtable(L); /* the .set table */
lua_rawset(L,-3); /* add .set into metatable */
lua_setmetatable(L,-2); /* sets meta table in module */
#ifdef SWIG_LUA_MODULE_GLOBAL
/* If requested, install the module directly into the global namespace. */
lua_rawset(L,-3); /* add module into parent */
SWIG_Lua_get_table(L,name); /* get the table back out */
#else
/* Do not install the module table as global name. The stack top has
the module table with the name below. We pop the top and replace
the name with it. */
lua_replace(L,-2);
#endif
}
/* ending the register */
@ -283,6 +377,7 @@ SWIGINTERN void SWIG_Lua_module_add_variable(lua_State* L,const char* name,lua_C
}
lua_pop(L,1); /* tidy stack (remove meta) */
}
#endif
/* adding a function module */
SWIGINTERN void SWIG_Lua_module_add_function(lua_State* L,const char* name,lua_CFunction fn)
@ -412,6 +507,39 @@ SWIGINTERN int SWIG_Lua_class_destruct(lua_State* L)
return 0;
}
/* the class.__tostring method called by the interpreter and print */
SWIGINTERN int SWIG_Lua_class_tostring(lua_State* L)
{
/* there should be 1 param passed in
(1) userdata (not the metatable) */
assert(lua_isuserdata(L,1)); /* just in case */
unsigned long userData = (unsigned long)lua_touserdata(L,1); /* get the userdata address for later */
lua_getmetatable(L,1); /* get the meta table */
assert(lua_istable(L,-1)); /* just in case */
lua_getfield(L, -1, ".type");
const char* className = lua_tostring(L, -1);
char output[256];
sprintf(output, "<%s userdata: %lX>", className, userData);
lua_pushstring(L, (const char*)output);
return 1;
}
/* to manually disown some userdata */
SWIGINTERN int SWIG_Lua_class_disown(lua_State* L)
{
/* there should be 1 params passed in
(1) userdata (not the meta table) */
swig_lua_userdata* usr;
assert(lua_isuserdata(L,-1)); /* just in case */
usr=(swig_lua_userdata*)lua_touserdata(L,-1); /* get it */
usr->own = 0; /* clear our ownership */
return 0;
}
/* gets the swig class registry (or creates it) */
SWIGINTERN void SWIG_Lua_get_class_registry(lua_State* L)
{
@ -506,7 +634,7 @@ SWIGINTERN void SWIG_Lua_init_base_class(lua_State* L,swig_lua_class* clss)
swig_type_info *info = SWIG_TypeQueryModule(module,module,clss->base_names[i]);
if (info) clss->bases[i] = (swig_lua_class *) info->clientdata;
}
}
}
}
/* performs the entire class registration process */
@ -537,11 +665,15 @@ SWIGINTERN void SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss)
/* add a table called ".fn" */
lua_pushstring(L,".fn");
lua_newtable(L);
/* add manual disown method */
SWIG_Lua_add_function(L,"__disown",SWIG_Lua_class_disown);
lua_rawset(L,-3);
/* add accessor fns for using the .get,.set&.fn */
SWIG_Lua_add_function(L,"__index",SWIG_Lua_class_get);
SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_class_set);
SWIG_Lua_add_function(L,"__gc",SWIG_Lua_class_destruct);
/* add tostring method for better output */
SWIG_Lua_add_function(L,"__tostring",SWIG_Lua_class_tostring);
/* add it */
lua_rawset(L,-3); /* metatable into registry */
lua_pop(L,1); /* tidy stack (remove registry) */
@ -584,7 +716,9 @@ SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State* L,void* ptr,swig_type_info *t
usr->ptr=ptr; /* set the ptr */
usr->type=type;
usr->own=own;
#if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
_SWIG_Lua_AddMetatable(L,type); /* add metatable */
#endif
}
/* takes a object from the lua stack & converts it into an object of the correct type
@ -697,6 +831,7 @@ SWIGRUNTIME int SWIG_Lua_equal(lua_State* L)
* global variable support code: class/struct typemap functions
* ----------------------------------------------------------------------------- */
#if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
/* Install Constants */
SWIGINTERN void
SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]) {
@ -738,6 +873,7 @@ SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]) {
}
}
}
#endif
/* -----------------------------------------------------------------------------
* executing lua code from within the wrapper
@ -746,8 +882,8 @@ SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]) {
#ifndef SWIG_DOSTRING_FAIL /* Allows redefining of error function */
#define SWIG_DOSTRING_FAIL(S) fprintf(stderr,"%s\n",S)
#endif
/* Executes a C string in Lua a really simple way of calling lua from C
Unfortunately lua keeps changing its API's, so we need a conditional compile
/* Executes a C string in Lua which is a really simple way of calling lua from C
Unfortunately lua keeps changing its APIs, so we need a conditional compile
In lua 5.0.X its lua_dostring()
In lua 5.1.X its luaL_dostring()
*/

View file

@ -19,16 +19,24 @@ extern "C" {
#endif
/* this is the initialization function
added at the very end of the code
the function is always called SWIG_init, but an eariler #define will rename it
the function is always called SWIG_init, but an earlier #define will rename it
*/
SWIGEXPORT int SWIG_init(lua_State* L)
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
LUALIB_API int SWIG_init(lua_State* L)
#else
SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */
#endif
{
#if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) /* valid for both Lua and eLua */
int i;
/* start with global table */
lua_pushvalue(L,LUA_GLOBALSINDEX);
lua_pushglobaltable (L);
/* SWIG's internal initalisation */
SWIG_InitializeModule((void*)L);
SWIG_PropagateClientData();
#endif
#if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
/* add a global fn */
SWIG_Lua_add_function(L,"swig_type",SWIG_Lua_type);
SWIG_Lua_add_function(L,"swig_equals",SWIG_Lua_equal);
@ -42,7 +50,10 @@ SWIGEXPORT int SWIG_init(lua_State* L)
for (i = 0; swig_variables[i].name; i++){
SWIG_Lua_module_add_variable(L,swig_variables[i].name,swig_variables[i].get,swig_variables[i].set);
}
/* set up base class pointers (the hierachy) */
#endif
#if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
/* set up base class pointers (the hierarchy) */
for (i = 0; swig_types[i]; i++){
if (swig_types[i]->clientdata){
SWIG_Lua_init_base_class(L,(swig_lua_class*)(swig_types[i]->clientdata));
@ -54,14 +65,24 @@ SWIGEXPORT int SWIG_init(lua_State* L)
SWIG_Lua_class_register(L,(swig_lua_class*)(swig_types[i]->clientdata));
}
}
#endif
#if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
/* constants */
SWIG_Lua_InstallConstants(L,swig_constants);
#endif
#if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
/* invoke user-specific initialization */
SWIG_init_user(L);
/* end module */
lua_pop(L,1); /* tidy stack (remove module table)*/
lua_pop(L,1); /* tidy stack (remove global table)*/
/* Note: We do not clean up the stack here (Lua will do this for us). At this
point, we have the globals table and out module table on the stack. Returning
one value makes the module table the result of the require command. */
return 1;
#else
return 0;
#endif
}
#ifdef __cplusplus

View file

@ -13,7 +13,7 @@
the fn call must be of the form
int checkfn(lua_State *L, int index);
and return 1/0 depending upon if this is the correct type
For the typemap(out), an additional SWIG_arg parmeter must be incremented
For the typemap(out), an additional SWIG_arg parameter must be incremented
to reflect the number of values returned (normally SWIG_arg++; will do)
*/
// numbers
@ -33,7 +33,7 @@ $1 = ($type)lua_tonumber(L, $input);%}
float,double
%{ lua_pushnumber(L, (lua_Number) $1); SWIG_arg++;%}
// we must also provide typemaps for privitives by const reference:
// we must also provide typemaps for primitives by const reference:
// given a function:
// int intbyref(const int& i);
// SWIG assumes that this code will need a pointer to int to be passed in
@ -136,7 +136,7 @@ SWIGINTERN int SWIG_lua_isnilstring(lua_State *L, int idx) {
// it should be converted to a SWIG NULL.
// This will only be allowed for pointers & arrays, not refs or by value
// the checkfn lua_isuserdata will only work for userdata
// the checkfn SWIG_isptrtype will work for both userdata and nil's
// the checkfn SWIG_isptrtype will work for both userdata and nil
%typemap(in,checkfn="SWIG_isptrtype") SWIGTYPE*,SWIGTYPE[]
%{
if (!SWIG_IsOK(SWIG_ConvertPtr(L,$input,(void**)&$1,$descriptor,$disown))){
@ -232,9 +232,9 @@ $1=($1_ltype)&temp;%}
// member function pointer
// a member fn ptr is not 4 bytes like a normal pointer, but 8 bytes (at least on mingw)
// so the standard wrappering cannot be done
// so the standard wrapping cannot be done
// nor can you cast a member function pointer to a void* (obviously)
// therefore a special wrappering functions SWIG_ConvertMember() & SWIG_NewMemberObj() were written
// therefore a special wrapping functions SWIG_ConvertMember() & SWIG_NewMemberObj() were written
#ifdef __cplusplus
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE (CLASS::*)
%{
@ -254,7 +254,7 @@ $1=($1_ltype)&temp;%}
/* void* is a special case
A function void fn(void*) should take any kind of pointer as a parameter (just like C/C++ does)
but if its an output, then it should be wrappered like any other SWIG object (using default typemap)
but if its an output, then it should be wrapped like any other SWIG object (using default typemap)
*/
%typemap(in,checkfn="SWIG_isptrtype") void*
%{$1=($1_ltype)SWIG_MustGetPtr(L,$input,0,0,$argnum,"$symname");%}
@ -282,7 +282,7 @@ void fn(int a, float b, lua_State* s) is wrappable as
* ----------------------------------------------------------------------------- */
/* These are needed for the overloaded functions
These define the detection routines which will spot what
parmeters match which function
parameters match which function
*/
// unfortunately lua only considers one type of number
@ -311,7 +311,7 @@ parmeters match which function
// special check for a char (string of length 1)
%typecheck(SWIG_TYPECHECK_CHAR,fragment="SWIG_lua_isnilstring") char, const char& {
$1 = SWIG_lua_isnilstring(L,$input) && (lua_strlen(L,$input)==1);
$1 = SWIG_lua_isnilstring(L,$input) && (lua_rawlen(L,$input)==1);
}
%typecheck(SWIG_TYPECHECK_STRING,fragment="SWIG_lua_isnilstring") char *, char[] {
@ -363,7 +363,7 @@ parmeters match which function
}
}
// Also needed for object ptrs by const ref
// Also needed for object pointers by const ref
// eg const A* ref_pointer(A* const& a);
// found in mixed_types.i
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *const&

View file

@ -24,8 +24,8 @@ namespace std
};
}
// normally object which are thrown are returned to interpreter as errors
// (which potentally may have problems if they are not copied)
// normally objects which are thrown are returned to the interpreter as errors
// (which potentially may have problems if they are not copied)
// therefore all classes based upon std::exception are converted to their strings & returned as errors
%typemap(throws) std::bad_exception "SWIG_exception(SWIG_RuntimeError, $1.what());"
%typemap(throws) std::domain_error "SWIG_exception(SWIG_ValueError, $1.what());"

View file

@ -10,7 +10,7 @@
/*
A really cut down version of the pair class.
this is not useful on its owns is it needs a %template definition with it
this is not useful on its own - it needs a %template definition with it
eg.
namespace std {

View file

@ -5,10 +5,11 @@
* ----------------------------------------------------------------------------- */
%{
#include <string>
#include <string>
%}
/*
Only std::string and const std::string& are typemaped
Only std::string and const std::string& are typemapped
they are converted to the Lua strings automatically
std::string& and std::string* are not
@ -25,14 +26,15 @@ can be used as
s="hello world"
s2=test_value(s)
assert(s==s2)
*/
%naturalvar std::string;
namespace std {
%naturalvar string;
/*
Bug report #1526022 by neomantra
Lua strings and std::string can contain embeded zero's
Bug report #1526022:
Lua strings and std::string can contain embedded zero bytes
Therefore a standard out typemap should not be:
lua_pushstring(L,$1.c_str());
but
@ -41,82 +43,56 @@ but
Similarly for getting the string
$1 = (char*)lua_tostring(L, $input);
becomes
$1.assign(lua_tostring(L,$input),lua_strlen(L,$input));
$1.assign(lua_tostring(L,$input),lua_rawlen(L,$input));
Not using: lua_tolstring() as this is only found in Lua 5.1 & not 5.0.2
*/
%typemap(in,checkfn="lua_isstring") std::string
%{$1.assign(lua_tostring(L,$input),lua_strlen(L,$input));%}
%typemap(out) std::string
%typemap(in,checkfn="lua_isstring") string
%{$1.assign(lua_tostring(L,$input),lua_rawlen(L,$input));%}
%typemap(out) string
%{ lua_pushlstring(L,$1.data(),$1.size()); SWIG_arg++;%}
%typemap(in,checkfn="lua_isstring") const std::string& (std::string temp)
%{temp.assign(lua_tostring(L,$input),lua_strlen(L,$input)); $1=&temp;%}
%typemap(in,checkfn="lua_isstring") const string& ($*1_ltype temp)
%{temp.assign(lua_tostring(L,$input),lua_rawlen(L,$input)); $1=&temp;%}
%typemap(out) const std::string&
%typemap(out) const string&
%{ lua_pushlstring(L,$1->data(),$1->size()); SWIG_arg++;%}
// for throwing of any kind of string, string ref's and string pointers
// we convert all to lua strings
%typemap(throws) std::string,std::string&,const std::string&
%typemap(throws) string, string&, const string&
%{ lua_pushlstring(L,$1.data(),$1.size()); SWIG_fail;%}
%typemap(throws) std::string*,const std::string*
%typemap(throws) string*, const string*
%{ lua_pushlstring(L,$1->data(),$1->size()); SWIG_fail;%}
// and the typechecks
%typecheck(SWIG_TYPECHECK_STRING) std::string,const std::string& {
%typecheck(SWIG_TYPECHECK_STRING) string, const string& {
$1 = lua_isstring(L,$input);
}
/*
std::string& can be wrappered, but you must inform SWIG if it is in or out
std::string& can be wrapped, but you must inform SWIG if it is in or out
eg:
void fn(std::string& str);
Is this an in/out/inout value?
Therefore you need the usual
%apply (std::string& INOUT) {(std::string& str)};
%apply (std::string& INOUT) {std::string& str};
or
%apply std::string& INOUT {std::string& str};
typemaps to tell SWIG what to do.
*/
%typemap(in) std::string &INPUT=const std::string &;
%typemap(in, numinputs=0) std::string &OUTPUT (std::string temp)
%typemap(in) string &INPUT=const string &;
%typemap(in, numinputs=0) string &OUTPUT ($*1_ltype temp)
%{ $1 = &temp; %}
%typemap(argout) std::string &OUTPUT
%typemap(argout) string &OUTPUT
%{ lua_pushlstring(L,$1->data(),$1->size()); SWIG_arg++;%}
%typemap(in) std::string &INOUT =const std::string &;
%typemap(argout) std::string &INOUT = std::string &OUTPUT;
/*
For const std::string* and std::string* is not clear
is this a pointer or an array?
Therefore just leaving it as is
(there is some rough code below which could be used if needed
// SWIG wraps const ref's as pointer
// typemaps to deal with this and const ptrs
%typemap(in,checkfn="lua_isstring")
const std::string& INPUT(std::string temp),
const std::string* INPUT(std::string temp)
%{temp=(char*)lua_tostring(L, $input); $1=&temp;%}
%typemap(out) const std::string&, const std::string*
%{ lua_pushstring(L,$1->c_str()); SWIG_arg++;%}
// the non-const pointer version
%typemap(in) std::string *INPUT=const std::string *INPUT;
%typemap(in, numinputs=0) std::string *OUTPUT (std::string temp)
%{ $1 = &temp; %}
%typemap(argout) std::string *OUTPUT
%{ lua_pushstring(L,$1->c_str()); SWIG_arg++;%}
%typemap(in) std::string *INOUT = std::string *INPUT;
%typemap(argout) std::string *INOUT = std::string *OUTPUT;
*/
%typemap(in) string &INOUT =const string &;
%typemap(argout) string &INOUT = string &OUTPUT;
/*
A really cut down version of the string class
@ -128,25 +104,24 @@ and little else
note: no fn's taking the const string&
as this is overloaded by the const char* version
*/
namespace std {
class string {
public:
string();
string(const char*);
//string(const string&);
unsigned int size() const;
unsigned int length() const;
bool empty() const;
// no support for operator[]
const char* c_str()const;
const char* data()const;
// assign does not return a copy of this object
// (no point in a scripting language)
void assign(const char*);
//void assign(const string&);
// no support for all the other features
// its probably better to do it in lua
};
class string {
public:
string();
string(const char*);
//string(const string&);
unsigned int size() const;
unsigned int length() const;
bool empty() const;
// no support for operator[]
const char* c_str()const;
const char* data()const;
// assign does not return a copy of this object
// (no point in a scripting language)
void assign(const char*);
//void assign(const string&);
// no support for all the other features
// it's probably better to do it in lua
};
}

View file

@ -7,7 +7,7 @@
%{
#include <vector>
%}
%include <std_except.i> // the general exepctions
%include <std_except.i> // the general exceptions
/*
A really cut down version of the vector class.

View file

@ -66,8 +66,10 @@ or provide a %apply statement
%enddef
// now the code
SWIG_NUMBER_TYPEMAP(int); SWIG_NUMBER_TYPEMAP(unsigned int); SWIG_NUMBER_TYPEMAP(signed int);
SWIG_NUMBER_TYPEMAP(unsigned char); SWIG_NUMBER_TYPEMAP(signed char);
SWIG_NUMBER_TYPEMAP(short); SWIG_NUMBER_TYPEMAP(unsigned short); SWIG_NUMBER_TYPEMAP(signed short);
SWIG_NUMBER_TYPEMAP(int); SWIG_NUMBER_TYPEMAP(unsigned int); SWIG_NUMBER_TYPEMAP(signed int);
SWIG_NUMBER_TYPEMAP(long); SWIG_NUMBER_TYPEMAP(unsigned long); SWIG_NUMBER_TYPEMAP(signed long);
SWIG_NUMBER_TYPEMAP(float);
SWIG_NUMBER_TYPEMAP(double);
@ -138,21 +140,21 @@ a few things of note:
so for the above mentioned return_array_5() would look like
arr=return_array_5() -- no parameters passed in
* for INOUT arrays, a table must be passed in, and a new table will be returned
(this is consistant with the way that numbers are processed)
(this is consistent with the way that numbers are processed)
if you want just use
arr={...}
arr=process_var_array_inout(arr) -- arr is replaced by the new version
The following are not yet supported:
* variable length output only array (inout's work ok)
* multidimentional arrays
* variable length output only array (inout works ok)
* multidimensional arrays
* arrays of objects/structs
* arrays of pointers
*/
/*
The internals of the array managment stuff
The internals of the array management stuff
helper fns/macros
SWIG_ALLOC_ARRAY(TYPE,LEN) // returns a typed array TYPE[LEN]
SWIG_FREE_ARRAY(PTR) // delete the ptr (if not zero)
@ -345,6 +347,8 @@ for array handling
// as well as defining typemaps for
// fixed len arrays in & out, & variable length arrays in
SWIG_TYPEMAP_NUM_ARR(schar,signed char);
SWIG_TYPEMAP_NUM_ARR(uchar,unsigned char);
SWIG_TYPEMAP_NUM_ARR(int,int);
SWIG_TYPEMAP_NUM_ARR(uint,unsigned int);
SWIG_TYPEMAP_NUM_ARR(short,short);
@ -363,7 +367,7 @@ SWIG_TYPEMAP_NUM_ARR(double,double);
%typemap(freearg) enum SWIGTYPE INPUT[ANY]
%{ SWIG_FREE_ARRAY($1);%}
// variable size array's
// variable size arrays
%typemap(in) (enum SWIGTYPE *INPUT,int)
%{ $1 = ($ltype)SWIG_get_int_num_array_var(L,$input,&$2);
if (!$1) SWIG_fail;%}
@ -410,7 +414,7 @@ void** SWIG_get_ptr_array_var(lua_State* L, int index, int* size,swig_type_info
// all pointers have the ownership value 'own' (normally 0)
void SWIG_write_ptr_array(lua_State* L,void **array,int size,int own);
// read the specified table, and fills the array with ptrs
// returns 1 of ok (only fails if it doesnt find correct type of ptrs)
// returns 1 of ok (only fails if it doesn't find correct type of ptrs)
// helper fn (called by SWIG_get_ptr_array_*() fns)
int SWIG_read_ptr_array(lua_State* L,int index,void **array,int size,swig_type_info *type);
@ -420,7 +424,7 @@ modification of pointers ownership in the arrays
eg A fn:
void pointers_in(TYPE* arr[],int len);
will make copies of the pointer into a temp array and then pass it into the fn
Lua does not remeber that this fn held the pointers, so it is not safe to keep
Lua does not remember that this fn held the pointers, so it is not safe to keep
these pointers until later
eg A fn:
@ -547,13 +551,14 @@ free(ptr);
With the following SWIG code
%apply SWIGTYPE** OUTPUT{iMath **pptr };
You can get natural wrappering in Lua as follows:
You can get natural wrapping in Lua as follows:
ok,ptr=Create_Math() -- ptr is a iMath* which is returned with the int
ptr=nil -- the iMath* will be GC'ed as normal
*/
%typemap(in,numinputs=0) SWIGTYPE** OUTPUT ($*ltype temp)
%{ $1 = &temp; %}
%{ temp = ($*ltype)0;
$1 = &temp; %}
%typemap(argout) SWIGTYPE** OUTPUT
%{SWIG_NewPointerObj(L,*$1,$*descriptor,1); SWIG_arg++; %}

View file

@ -30,7 +30,7 @@ wchar_t* str2wstr(const char *str, int len)
%typemap(in, checkfn="SWIG_lua_isnilstring", fragment="SWIG_lua_isnilstring") wchar_t *
%{
$1 = str2wstr(lua_tostring( L, $input ),lua_strlen( L, $input ));
$1 = str2wstr(lua_tostring( L, $input ),lua_rawlen( L, $input ));
if ($1==0) {lua_pushfstring(L,"Error in converting to wchar (arg %d)",$input);goto fail;}
%}

View file

@ -91,7 +91,6 @@ SWIG_is_unsigned_integer(Scheme_Object *o)
/* -----------------------------------------------------------------------
* mzscheme 30X support code
* Contributed by Hans Oesterholt
* ----------------------------------------------------------------------- */
#ifndef SCHEME_STR_VAL
@ -252,10 +251,6 @@ SWIG_MzScheme_new_scheme_struct (Scheme_Env* env, const char* basename,
return new_type;
}
/*** DLOPEN PATCH ******************************************************
* Contributed by Hans Oesterholt-Dijkema (jan. 2006)
***********************************************************************/
#if defined(_WIN32) || defined(__WIN32__)
#define __OS_WIN32
#endif
@ -442,10 +437,6 @@ SWIG_MzScheme_new_scheme_struct (Scheme_Env* env, const char* basename,
}
}
/*** DLOPEN PATCH ******************************************************
* Contributed by Hans Oesterholt-Dijkema (jan. 2006)
***********************************************************************/
/* The interpreter will store a pointer to this structure in a global
variable called swig-runtime-data-type-pointer. The instance of this
struct is only used if no other module has yet been loaded */

View file

@ -217,6 +217,10 @@ namespace std {
%rename("delete!") __delitem__;
%rename("has-key?") has_key;
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef K key_type;
typedef T mapped_type;
map();
map(const map<K,T> &);

View file

@ -35,7 +35,7 @@ namespace std {
SWIG_exception(SWIG_TypeError, "string expected");
}
%typemap(in) const string & (std::string temp) {
%typemap(in) const string & ($*1_ltype temp) {
if (SCHEME_STRINGP($input)) {
temp.assign(SCHEME_STR_VAL($input));
$1 = &temp;

View file

@ -578,7 +578,7 @@ extern "C" {
}
}
static swig_module_info *SWIG_Ocaml_GetModule() {
static swig_module_info *SWIG_Ocaml_GetModule(void *SWIGUNUSEDPARM(clientdata)) {
CAML_VALUE pointer;
pointer = callback(*caml_named_value("swig_find_type_info"), caml_val_int(0));

View file

@ -108,7 +108,7 @@ CAMLextern int64 Int64_val(caml_value_t v);
#endif
#define SWIG_NewPointerObj(p,type,flags) caml_val_ptr(p,type)
#define SWIG_GetModule(clientdata) SWIG_Ocaml_GetModule()
#define SWIG_GetModule(clientdata) SWIG_Ocaml_GetModule(clientdata)
#define SWIG_SetModule(clientdata, pointer) SWIG_Ocaml_SetModule(pointer)
#define SWIG_contract_assert(expr, msg) if(!(expr)) {failwith(msg);} else

View file

@ -22,6 +22,10 @@ namespace std {
template<class K, class T> class map {
// add typemaps here
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef K key_type;
typedef T mapped_type;
map();
map(const map<K,T> &);

View file

@ -11,141 +11,91 @@
// However, I think I'll wait until someone asks for it...
// ------------------------------------------------------------------------
%include <exception.i>
%{
#include <string>
#include <vector>
using std::string;
using std::vector;
%}
%include <exception.i>
%include <std_vector.i>
%naturalvar std::string;
%naturalvar std::wstring;
namespace std {
template <class charT> class basic_string {
public:
typedef charT *pointer;
typedef charT &reference;
typedef const charT &const_reference;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
basic_string();
basic_string( charT *str );
size_t size();
charT operator []( int pos ) const;
charT *c_str() const;
basic_string<charT> &operator = ( const basic_string &ws );
basic_string<charT> &operator = ( const charT *str );
basic_string<charT> &append( const basic_string<charT> &other );
basic_string<charT> &append( const charT *str );
void push_back( charT c );
void clear();
void reserve( size_type t );
void resize( size_type n, charT c = charT() );
int compare( const basic_string<charT> &other ) const;
int compare( const charT *str ) const;
basic_string<charT> &insert( size_type pos,
const basic_string<charT> &str );
size_type find( const basic_string<charT> &other, int pos = 0 ) const;
size_type find( charT c, int pos = 0 ) const;
%extend {
bool operator == ( const basic_string<charT> &other ) const {
return self->compare( other ) == 0;
}
bool operator != ( const basic_string<charT> &other ) const {
return self->compare( other ) != 0;
}
bool operator < ( const basic_string<charT> &other ) const {
return self->compare( other ) == -1;
}
bool operator > ( const basic_string<charT> &other ) const {
return self->compare( other ) == 1;
}
bool operator <= ( const basic_string<charT> &other ) const {
return self->compare( other ) != 1;
}
bool operator >= ( const basic_string<charT> &other ) const {
return self->compare( other ) != -1;
}
}
};
%template(string) basic_string<char>;
%template(wstring) basic_string<wchar_t>;
typedef basic_string<char> string;
typedef basic_string<wchar_t> wstring;
%naturalvar string;
%naturalvar wstring;
class string;
class wstring;
/* Overloading check */
%typemap(in) string {
/* %typemap(in) string */
if (caml_ptr_check($input))
$1.assign((char *)caml_ptr_val($input,0), caml_string_len($input));
else
SWIG_exception(SWIG_TypeError, "string expected");
}
/* Overloading check */
%typemap(in) string {
if (caml_ptr_check($input))
$1.assign((char *)caml_ptr_val($input,0),
caml_string_len($input));
else
SWIG_exception(SWIG_TypeError, "string expected");
}
%typemap(in) const string & ($*1_ltype temp) {
/* %typemap(in) const string & */
if (caml_ptr_check($input)) {
temp.assign((char *)caml_ptr_val($input,0), caml_string_len($input));
$1 = &temp;
} else {
SWIG_exception(SWIG_TypeError, "string expected");
}
}
%typemap(in) const string & (std::string temp) {
if (caml_ptr_check($input)) {
temp.assign((char *)caml_ptr_val($input,0),
caml_string_len($input));
$1 = &temp;
} else {
SWIG_exception(SWIG_TypeError, "string expected");
}
}
%typemap(in) string & ($*1_ltype temp) {
/* %typemap(in) string & */
if (caml_ptr_check($input)) {
temp.assign((char *)caml_ptr_val($input,0), caml_string_len($input));
$1 = &temp;
} else {
SWIG_exception(SWIG_TypeError, "string expected");
}
}
%typemap(in) string & (std::string temp) {
if (caml_ptr_check($input)) {
temp.assign((char *)caml_ptr_val($input,0),
caml_string_len($input));
$1 = &temp;
} else {
SWIG_exception(SWIG_TypeError, "string expected");
}
}
%typemap(in) string * ($*1_ltype *temp) {
/* %typemap(in) string * */
if (caml_ptr_check($input)) {
temp = new $*1_ltype((char *)caml_ptr_val($input,0), caml_string_len($input));
$1 = temp;
} else {
SWIG_exception(SWIG_TypeError, "string expected");
}
}
%typemap(in) string * (std::string *temp) {
if (caml_ptr_check($input)) {
temp = new std::string((char *)caml_ptr_val($input,0),
caml_string_len($input));
$1 = temp;
} else {
SWIG_exception(SWIG_TypeError, "string expected");
}
}
%typemap(free) string * ($*1_ltype *temp) {
delete temp;
}
%typemap(free) string * (std::string *temp) {
delete temp;
}
%typemap(argout) string & {
/* %typemap(argout) string & */
swig_result = caml_list_append(swig_result,caml_val_string_len((*$1).c_str(), (*$1).size()));
}
%typemap(argout) string & {
caml_list_append(swig_result,caml_val_string_len((*$1).c_str(),
(*$1).size()));
}
%typemap(directorout) string {
/* %typemap(directorout) string */
$result.assign((char *)caml_ptr_val($input,0), caml_string_len($input));
}
%typemap(directorout) string {
$result.assign((char *)caml_ptr_val($input,0),
caml_string_len($input));
}
%typemap(out) string {
/* %typemap(out) string */
$result = caml_val_string_len($1.c_str(),$1.size());
}
%typemap(out) string {
$result = caml_val_string_len($1.c_str(),$1.size());
}
%typemap(out) string * {
%typemap(out) string * {
/* %typemap(out) string * */
$result = caml_val_string_len((*$1).c_str(),(*$1).size());
}
}
}
#ifdef ENABLE_CHARPTR_ARRAY
char **c_charptr_array( const std::vector <string > &str_v );
char **c_charptr_array( const std::vector <std::string > &str_v );
%{
SWIGEXT char **c_charptr_array( const std::vector <string > &str_v ) {
SWIGEXT char **c_charptr_array( const std::vector <std::string > &str_v ) {
char **out = new char *[str_v.size() + 1];
out[str_v.size()] = 0;
for( int i = 0; i < str_v.size(); i++ ) {
@ -157,7 +107,7 @@ char **c_charptr_array( const std::vector <string > &str_v );
#endif
#ifdef ENABLE_STRING_VECTOR
%template (StringVector) std::vector<string >;
%template (StringVector) std::vector<std::string >;
%insert(ml) %{
(* Some STL convenience items *)

View file

@ -1,118 +1,135 @@
open Pcaml ;;
open Camlp4
module Id : Sig.Id =
struct
let name = "swigp4"
let version = "0.1"
end
module Make (Syntax : Sig.Camlp4Syntax) =
struct
open Sig
include Syntax
let lap x y = x :: y
let c_ify e @OCAMLLOC@ =
match e with
<:expr< $int:_$ >> -> <:expr< (C_int $e$) >>
| <:expr< $str:_$ >> -> <:expr< (C_string $e$) >>
| <:expr< $chr:_$ >> -> <:expr< (C_char $e$) >>
| <:expr< $flo:_$ >> -> <:expr< (C_double $e$) >>
| <:expr< True >> -> <:expr< (C_bool $e$) >>
| <:expr< False >> -> <:expr< (C_bool $e$) >>
| _ -> <:expr< $e$ >>
let mk_list args @OCAMLLOC@ f =
let rec mk_list_inner args @OCAMLLOC@ f =
match args with
[] -> <:expr< [] >>
| x :: xs ->
(let @OCAMLLOC@ = MLast.loc_of_expr x in
<:expr< [ ($f x @OCAMLLOC@$) ] @ ($mk_list_inner xs @OCAMLLOC@ f$) >>) in
match args with
[] -> <:expr< (Obj.magic C_void) >>
| [ a ] -> <:expr< (Obj.magic $f a @OCAMLLOC@$) >>
| _ -> <:expr< (Obj.magic (C_list ($mk_list_inner args @OCAMLLOC@ f$))) >>
let _loc = Loc.ghost
let lap x y = x :: y
let c_ify e loc =
match e with
<:expr< $int:_$ >> -> <:expr< (C_int $e$) >>
| <:expr< $str:_$ >> -> <:expr< (C_string $e$) >>
| <:expr< $chr:_$ >> -> <:expr< (C_char $e$) >>
| <:expr< $flo:_$ >> -> <:expr< (C_double $e$) >>
| <:expr< True >> -> <:expr< (C_bool $e$) >>
| <:expr< False >> -> <:expr< (C_bool $e$) >>
| _ -> <:expr< $e$ >>
let mk_list args loc f =
let rec mk_list_inner args loc f =
match args with
[] -> <:expr< [] >>
| x :: xs ->
(let loc = Ast.loc_of_expr x in
<:expr< [ ($f x _loc$) ] @ ($mk_list_inner xs loc f$) >>) in
match args with
[] -> <:expr< (Obj.magic C_void) >>
| [ a ] -> <:expr< (Obj.magic $f a _loc$) >>
| _ -> <:expr< (Obj.magic (C_list ($mk_list_inner args loc f$))) >> ;;
EXTEND Gram
GLOBAL: expr;
EXTEND
expr:
[ [ e1 = expr ; "'" ; "[" ; e2 = expr ; "]" ->
<:expr< (invoke $e1$) "[]" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "->" ; l = LIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke $e1$) $str:l$ ($mk_list args @OCAMLLOC@ c_ify$) >>
| e1 = expr ; "->" ; u = UIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke $e1$) $str:u$ ($mk_list args @OCAMLLOC@ c_ify$) >>
| e1 = expr ; "->" ; s = expr LEVEL "simple" ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke $e1$) $s$ ($mk_list args @OCAMLLOC@ c_ify$) >>
| e1 = expr ; "'" ; "." ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke $e1$) "()" ($mk_list args @OCAMLLOC@ c_ify$) >>
| e1 = expr ; "'" ; "->" ; l = LIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke ((invoke $e1$) "->" C_void)) $str:l$ ($mk_list args @OCAMLLOC@ c_ify$) >>
| e1 = expr ; "'" ; "->" ; u = UIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke ((invoke $e1$) "->" C_void)) $str:u$ ($mk_list args @OCAMLLOC@ c_ify$) >>
| e1 = expr ; "'" ; "->" ; s = expr LEVEL "simple" ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke ((invoke $e1$) "->" C_void)) $s$ ($mk_list args @OCAMLLOC@ c_ify$) >>
| e1 = expr ; "'" ; "++" ->
<:expr< (invoke $e1$) "++" C_void >>
| e1 = expr ; "'" ; "--" ->
<:expr< (invoke $e1$) "--" C_void >>
| e1 = expr ; "'" ; "-" ; e2 = expr ->
<:expr< (invoke $e1$) "-" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "+" ; e2 = expr -> <:expr< (invoke $e1$) "+" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "*" ; e2 = expr -> <:expr< (invoke $e1$) "*" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| "'" ; "&" ; e1 = expr ->
<:expr< (invoke $e1$) "&" C_void >>
| "'" ; "!" ; e1 = expr ->
<:expr< (invoke $e1$) "!" C_void >>
| "'" ; "~" ; e1 = expr ->
<:expr< (invoke $e1$) "~" C_void >>
| e1 = expr ; "'" ; "/" ; e2 = expr ->
<:expr< (invoke $e1$) "/" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "%" ; e2 = expr ->
<:expr< (invoke $e1$) "%" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "lsl" ; e2 = expr ->
<:expr< (invoke $e1$) ("<" ^ "<") (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "lsr" ; e2 = expr ->
<:expr< (invoke $e1$) (">" ^ ">") (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "<" ; e2 = expr ->
<:expr< (invoke $e1$) "<" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "<=" ; e2 = expr ->
<:expr< (invoke $e1$) "<=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; ">" ; e2 = expr ->
<:expr< (invoke $e1$) ">" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; ">=" ; e2 = expr ->
<:expr< (invoke $e1$) ">=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "==" ; e2 = expr ->
<:expr< (invoke $e1$) "==" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "!=" ; e2 = expr ->
<:expr< (invoke $e1$) "!=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "&" ; e2 = expr ->
<:expr< (invoke $e1$) "&" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "^" ; e2 = expr ->
<:expr< (invoke $e1$) "^" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "|" ; e2 = expr ->
<:expr< (invoke $e1$) "|" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "&&" ; e2 = expr ->
<:expr< (invoke $e1$) "&&" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "||" ; e2 = expr ->
<:expr< (invoke $e1$) "||" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "=" ; e2 = expr ->
<:expr< (invoke $e1$) "=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "+=" ; e2 = expr ->
<:expr< (invoke $e1$) "+=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "-=" ; e2 = expr ->
<:expr< (invoke $e1$) "-=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "*=" ; e2 = expr ->
<:expr< (invoke $e1$) "*=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "/=" ; e2 = expr ->
<:expr< (invoke $e1$) "/=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "%=" ; e2 = expr ->
<:expr< (invoke $e1$) "%=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "lsl" ; "=" ; e2 = expr ->
<:expr< (invoke $e1$) ("<" ^ "<=") (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "lsr" ; "=" ; e2 = expr ->
<:expr< (invoke $e1$) (">" ^ ">=") (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "&=" ; e2 = expr ->
<:expr< (invoke $e1$) "&=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "^=" ; e2 = expr ->
<:expr< (invoke $e1$) "^=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| e1 = expr ; "'" ; "|=" ; e2 = expr ->
<:expr< (invoke $e1$) "|=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
| "'" ; e = expr -> c_ify e @OCAMLLOC@
| c = expr ; "as" ; id = LIDENT -> <:expr< $lid:"get_" ^ id$ $c$ >>
| c = expr ; "to" ; id = LIDENT -> <:expr< $uid:"C_" ^ id$ $c$ >>
| "`" ; "`" ; l = LIDENT -> <:expr< C_enum `$lid:l$ >>
| "`" ; "`" ; u = UIDENT -> <:expr< C_enum `$uid:u$ >>
| f = expr ; "'" ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< $f$ ($mk_list args @OCAMLLOC@ c_ify$) >>
] ] ;
END ;;
expr: LEVEL "top"
[ [ e1 = expr ; "'" ; "[" ; e2 = expr ; "]" ->
<:expr< (invoke $e1$) "[]" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "->" ; l = LIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke $e1$) $str:l$ ($mk_list args _loc c_ify$) >>
| e1 = expr ; "->" ; u = UIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke $e1$) $str:u$ ($mk_list args _loc c_ify$) >>
| e1 = expr ; "->" ; s = expr LEVEL "simple" ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke $e1$) $s$ ($mk_list args _loc c_ify$) >>
| e1 = expr ; "'" ; "." ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke $e1$) "()" ($mk_list args _loc c_ify$) >>
| e1 = expr ; "'" ; "->" ; l = LIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke ((invoke $e1$) "->" C_void)) $str:l$ ($mk_list args _loc c_ify$) >>
| e1 = expr ; "'" ; "->" ; u = UIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke ((invoke $e1$) "->" C_void)) $str:u$ ($mk_list args _loc c_ify$) >>
| e1 = expr ; "'" ; "->" ; s = expr LEVEL "simple" ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke ((invoke $e1$) "->" C_void)) $s$ ($mk_list args _loc c_ify$) >>
| e1 = expr ; "'" ; "++" ->
<:expr< (invoke $e1$) "++" C_void >>
| e1 = expr ; "'" ; "--" ->
<:expr< (invoke $e1$) "--" C_void >>
| e1 = expr ; "'" ; "-" ; e2 = expr ->
<:expr< (invoke $e1$) "-" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "+" ; e2 = expr -> <:expr< (invoke $e1$) "+" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "*" ; e2 = expr -> <:expr< (invoke $e1$) "*" (C_list [ $c_ify e2 _loc$ ]) >>
| "'" ; "&" ; e1 = expr ->
<:expr< (invoke $e1$) "&" C_void >>
| "'" ; "!" ; e1 = expr ->
<:expr< (invoke $e1$) "!" C_void >>
| "'" ; "~" ; e1 = expr ->
<:expr< (invoke $e1$) "~" C_void >>
| e1 = expr ; "'" ; "/" ; e2 = expr ->
<:expr< (invoke $e1$) "/" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "%" ; e2 = expr ->
<:expr< (invoke $e1$) "%" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "lsl" ; e2 = expr ->
<:expr< (invoke $e1$) ("<" ^ "<") (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "lsr" ; e2 = expr ->
<:expr< (invoke $e1$) (">" ^ ">") (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "<" ; e2 = expr ->
<:expr< (invoke $e1$) "<" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "<=" ; e2 = expr ->
<:expr< (invoke $e1$) "<=" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; ">" ; e2 = expr ->
<:expr< (invoke $e1$) ">" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; ">=" ; e2 = expr ->
<:expr< (invoke $e1$) ">=" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "==" ; e2 = expr ->
<:expr< (invoke $e1$) "==" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "!=" ; e2 = expr ->
<:expr< (invoke $e1$) "!=" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "&" ; e2 = expr ->
<:expr< (invoke $e1$) "&" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "^" ; e2 = expr ->
<:expr< (invoke $e1$) "^" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "|" ; e2 = expr ->
<:expr< (invoke $e1$) "|" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "&&" ; e2 = expr ->
<:expr< (invoke $e1$) "&&" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "||" ; e2 = expr ->
<:expr< (invoke $e1$) "||" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "=" ; e2 = expr ->
<:expr< (invoke $e1$) "=" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "+=" ; e2 = expr ->
<:expr< (invoke $e1$) "+=" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "-=" ; e2 = expr ->
<:expr< (invoke $e1$) "-=" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "*=" ; e2 = expr ->
<:expr< (invoke $e1$) "*=" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "/=" ; e2 = expr ->
<:expr< (invoke $e1$) "/=" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "%=" ; e2 = expr ->
<:expr< (invoke $e1$) "%=" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "lsl" ; "=" ; e2 = expr ->
<:expr< (invoke $e1$) ("<" ^ "<=") (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "lsr" ; "=" ; e2 = expr ->
<:expr< (invoke $e1$) (">" ^ ">=") (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "&=" ; e2 = expr ->
<:expr< (invoke $e1$) "&=" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "^=" ; e2 = expr ->
<:expr< (invoke $e1$) "^=" (C_list [ $c_ify e2 _loc$ ]) >>
| e1 = expr ; "'" ; "|=" ; e2 = expr ->
<:expr< (invoke $e1$) "|=" (C_list [ $c_ify e2 _loc$ ]) >>
| "'" ; e = expr -> c_ify e _loc
| c = expr ; "as" ; id = LIDENT -> <:expr< $lid:"get_" ^ id$ $c$ >>
| c = expr ; "to" ; id = LIDENT -> <:expr< $uid:"C_" ^ id$ $c$ >>
| "`" ; "`" ; l = LIDENT -> <:expr< C_enum `$lid:l$ >>
| "`" ; "`" ; u = UIDENT -> <:expr< C_enum `$uid:u$ >>
| f = expr ; "'" ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< $f$ ($mk_list args _loc c_ify$) >>
] ] ;
END ;;
end
module M = Register.OCamlSyntaxExtension(Id)(Make)

View file

@ -116,6 +116,17 @@
}
}
%typemap(in) char *& (char *temp) {
/* %typemap(in) char *& */
temp = (char*)caml_val_ptr($1,$descriptor);
$1 = &temp;
}
%typemap(argout) char *& {
/* %typemap(argout) char *& */
swig_result = caml_list_append(swig_result,caml_val_string_len(*$1, strlen(*$1)));
}
#else
%typemap(in) SWIGTYPE {
@ -189,7 +200,7 @@
swig_result = caml_list_append(swig_result,C_TO_MZ((long)*$1));
}
%typemap(directorin) C_NAME {
args = caml_list_append(args,C_TO_MZ($1_name));
args = caml_list_append(args,C_TO_MZ($1));
}
%enddef

View file

@ -1,3 +1,124 @@
// ***** move the director stuff from octrun.swg here...
# define SWIG_DIRECTOR_CAST(ARG) dynamic_cast<Swig::Director *>(ARG)
namespace Swig {
class Director {
octave_swig_type *self;
bool swig_disowned;
Director(const Director &x);
Director &operator=(const Director &rhs);
public:
Director(void *vptr):self(0), swig_disowned(false) {
set_rtdir(vptr, this);
}
~Director() {
swig_director_destroyed(self, this);
if (swig_disowned)
self->decref();
}
void swig_set_self(octave_swig_type *new_self) {
assert(!swig_disowned);
self = new_self;
}
octave_swig_type *swig_get_self() const {
return self;
}
void swig_disown() {
if (swig_disowned)
return;
swig_disowned = true;
self->incref();
}
};
struct DirectorTypeMismatchException {
static void raise(const char *msg) {
// ... todo
throw(DirectorTypeMismatchException());
}
static void raise(const octave_value &ov, const char *msg) {
// ... todo
raise(msg);
}
};
struct DirectorPureVirtualException {
static void raise(const char *msg) {
// ... todo
throw(DirectorPureVirtualException());
}
static void raise(const octave_value &ov, const char *msg) {
// ... todo
raise(msg);
}
};
SWIGINTERN rtdir_map* get_rtdir_map() {
static swig_module_info *module = 0;
if (!module)
module = SWIG_GetModule(0);
if (!module)
return 0;
if (!module->clientdata)
module->clientdata = new rtdir_map;
return (rtdir_map *) module->clientdata;
}
SWIGINTERNINLINE void set_rtdir(void *vptr, Director *d) {
rtdir_map* rm = get_rtdir_map();
if (rm)
(*rm)[vptr] = d;
}
SWIGINTERNINLINE void erase_rtdir(void *vptr) {
rtdir_map* rm = get_rtdir_map();
if (rm)
(*rm).erase(vptr);
}
SWIGINTERNINLINE Director *get_rtdir(void *vptr) {
rtdir_map* rm = get_rtdir_map();
if (!rm)
return 0;
rtdir_map::const_iterator pos = rm->find(vptr);
Director *rtdir = (pos != rm->end())? pos->second : 0;
return rtdir;
}
SWIGRUNTIME void swig_director_destroyed(octave_swig_type *self, Director *d) {
self->director_destroyed(d);
}
SWIGRUNTIME octave_swig_type *swig_director_get_self(Director *d) {
return d->swig_get_self();
}
SWIGRUNTIME void swig_director_set_self(Director *d, octave_swig_type *self) {
d->swig_set_self(self);
}
}
SWIGRUNTIME void swig_acquire_ownership(void *vptr) {
// assert(0);
// ... todo
}
SWIGRUNTIME void swig_acquire_ownership_array(void *vptr) {
// assert(0);
// ... todo
}
SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own) {
// assert(0);
// ... todo
}

View file

@ -4,17 +4,17 @@
the complex Constructor method, and the Real and Imag complex
accesor methods.
See the std_complex.i and ccomplex.i for concret examples.
See the std_complex.i and ccomplex.i for concrete examples.
*/
/* the common from conversor */
%define %swig_fromcplx_conv(Type, Real, Imag)
%define %swig_fromcplx_conv(Type, OctConstructor, Real, Imag)
%fragment(SWIG_From_frag(Type),"header")
{
SWIGINTERNINLINE octave_value
SWIG_From(Type)(%ifcplusplus(const Type&, Type) c)
SWIG_From(Type)(const Type& c)
{
return octave_value(Complex(Real(c), Imag(c)));
return octave_value(OctConstructor(Real(c), Imag(c)));
}
}
%enddef
@ -45,7 +45,7 @@
return SWIG_TypeError;
}
}
%swig_fromcplx_conv(Type, Real, Imag);
%swig_fromcplx_conv(Type, Complex, Real, Imag);
%enddef
// the float case
@ -53,7 +53,7 @@
%fragment(SWIG_AsVal_frag(Type),"header",
fragment=SWIG_AsVal_frag(float)) {
SWIGINTERN int
SWIG_AsVal(Type)(PyObject *o, Type *val)
SWIG_AsVal(Type) (const octave_value& ov, Type* val)
{
if (ov.is_complex_scalar()) {
if (val) {
@ -81,7 +81,7 @@
}
}
%swig_fromcplx_conv(Type, Real, Imag);
%swig_fromcplx_conv(Type, FloatComplex, Real, Imag);
%enddef
#define %swig_cplxflt_convn(Type, Constructor, Real, Imag) \
@ -90,6 +90,3 @@
#define %swig_cplxdbl_convn(Type, Constructor, Real, Imag) \
%swig_cplxdbl_conv(Type, Constructor, Real, Imag)

View file

@ -4,8 +4,7 @@
* Octave cell <-> C++ container wrapper
*
* This wrapper, and its iterator, allows a general use (and reuse) of
* the the mapping between C++ and Octave, thanks to the C++
* templates.
* the mapping between C++ and Octave, thanks to the C++ templates.
*
* Of course, it needs the C++ compiler to support templates, but
* since we will use this wrapper with the STL containers, that should
@ -64,7 +63,7 @@ namespace swig {
}
}
%fragment("OctSequence_Base","header")
%fragment("OctSequence_Base","header",fragment="<stddef.h>")
{
%#include <functional>

View file

@ -9,7 +9,7 @@
%include <std_common.i>
%fragment("OctSwigIterator","header") {
%fragment("OctSwigIterator","header",fragment="<stddef.h>") {
namespace swig {
struct stop_iteration {
};
@ -113,7 +113,7 @@ namespace swig {
}
}
%fragment("OctSwigIterator_T","header",fragment="OctSwigIterator",fragment="StdTraits",fragment="StdIteratorTraits") {
%fragment("OctSwigIterator_T","header",fragment="<stddef.h>",fragment="OctSwigIterator",fragment="StdTraits",fragment="StdIteratorTraits") {
namespace swig {
template<typename OutIterator>
class OctSwigIterator_T : public OctSwigIterator

Some files were not shown because too many files have changed in this diff Show more