Merge branch 'master' into C

This commit is contained in:
Vadim Zeitlin 2019-07-24 20:26:50 +02:00
commit 55741f9e31
1702 changed files with 57386 additions and 21599 deletions

View file

@ -232,6 +232,8 @@ $body)"
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
/* name conversion for overloaded operators. */
#ifdef __cplusplus

View file

@ -28,17 +28,20 @@ namespace std{
template<class T> class list
{
public:
typedef T &reference;
typedef const T& const_reference;
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 T &iterator;
typedef const T& const_iterator;
list();
list(unsigned int size, const T& value = T());
list(const list<T> &);
list(const list& other);
~list();
void assign(unsigned int n, const T& value);
void swap(list<T> &x);
@ -46,21 +49,20 @@ namespace std{
const_reference back();
const_iterator begin();
const_iterator end();
void resize(unsigned int n, T c = T());
bool empty() const;
void push_front(const T& INPUT);
void push_back(const T& INPUT);
void pop_front();
void pop_back();
void clear();
unsigned int size() const;
unsigned int max_size() const;
void resize(unsigned int n, const T& INPUT);
void remove(const T& INPUT);
void unique();
void reverse();
@ -153,7 +155,7 @@ namespace std{
if (j<0) j += size;
if (i<0) i = 0;
if (j>size) j = size;
for (int k=0;k<i;k++)
{
first++;
@ -174,7 +176,7 @@ namespace std{
if (j<0) j += size;
if (i<0) i = 0;
if (j>size) j = size;
for (int k=0;k<i;k++)
{
first++;
@ -200,7 +202,6 @@ namespace std{
}
else self->insert(self->end(),v.begin(),v.end());
}
}
unsigned int __len__()
{
@ -218,8 +219,7 @@ namespace std{
{
self->pop_back();
}
};
}
};
}

View file

@ -16,7 +16,6 @@
*/
%include <chicken/chickenkw.swg>
%include <csharp/csharpkw.swg>
%include <d/dkw.swg>
%include <go/gokw.swg>
@ -25,7 +24,6 @@
%include <ocaml/ocamlkw.swg>
%include <perl5/perlkw.swg>
%include <php/phpkw.swg>
%include <pike/pikekw.swg>
%include <python/pythonkw.swg>
%include <r/rkw.swg>
%include <ruby/rubykw.swg>

View file

@ -43,18 +43,10 @@ typedef struct SWIGCDATA {
$2 = $input->len;
}
#elif SWIGCHICKEN
#elif SWIGPHP7
%typemap(out) SWIGCDATA {
C_word *string_space = C_alloc(C_SIZEOF_STRING($1.len));
$result = C_string(&string_space, $1.len, $1.data);
}
%typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
#elif SWIGPHP
%typemap(out) SWIGCDATA {
ZVAL_STRINGL($result, $1.data, $1.len, 1);
ZVAL_STRINGL($result, $1.data, $1.len);
}
%typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
@ -86,8 +78,6 @@ static jbyteArray SWIG_JavaArrayOutCDATA(JNIEnv *jenv, char *result, jsize sz) {
return $jnicall;
}
#else
%echo "cdata.i module not supported."
#endif

View file

@ -136,6 +136,8 @@
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
%{

View file

@ -11,8 +11,9 @@
#include <chicken.h>
%}
%insert(runtime) "swigrun.swg"; // Common C API type-checking code
%insert(runtime) "chickenrun.swg"; // CHICKEN run-time code
%insert(runtime) "swigrun.swg" // Common C API type-checking code
%insert(runtime) "swigerrors.swg" // SWIG errors
%insert(runtime) "chickenrun.swg" // CHICKEN run-time code
/* -----------------------------------------------------------------------------
* standard typemaps
@ -617,7 +618,7 @@ $result = C_SCHEME_UNDEFINED;
$1 = C_swig_is_string ($input);
}
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] {
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE [] {
void *ptr;
$1 = !SWIG_ConvertPtr($input, &ptr, $1_descriptor, 0);
}
@ -630,33 +631,30 @@ $result = C_SCHEME_UNDEFINED;
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE &
{
void *ptr = 0;
if (SWIG_ConvertPtr($input, &ptr, $descriptor, 0)) {
/* error */
if (SWIG_ConvertPtr($input, &ptr, $descriptor, SWIG_POINTER_NO_NULL)) {
$1 = 0;
} else {
$1 = (ptr != 0);
$1 = 1;
}
}
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE &&
{
void *ptr = 0;
if (SWIG_ConvertPtr($input, &ptr, $descriptor, 0)) {
/* error */
if (SWIG_ConvertPtr($input, &ptr, $descriptor, SWIG_POINTER_NO_NULL)) {
$1 = 0;
} else {
$1 = (ptr != 0);
$1 = 1;
}
}
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE
{
void *ptr = 0;
if (SWIG_ConvertPtr($input, &ptr, $&descriptor, 0)) {
/* error */
if (SWIG_ConvertPtr($input, &ptr, $&descriptor, SWIG_POINTER_NO_NULL)) {
$1 = 0;
} else {
$1 = (ptr != 0);
$1 = 1;
}
}
@ -716,6 +714,8 @@ $result = C_SCHEME_UNDEFINED;
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
/* ------------------------------------------------------------
* Overloaded operator support

View file

@ -7,7 +7,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM)
#if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__BORLANDC__) || defined(_WATCOM)
# ifndef snprintf
# define snprintf _snprintf
# endif
@ -265,6 +265,7 @@ SWIG_Chicken_ConvertPtr(C_word s, void **result, swig_type_info *type, int flags
if (s == C_SCHEME_FALSE) {
*result = NULL;
return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
} else if (C_swig_is_swigpointer(s)) {
/* try and convert type */
from = (swig_type_info *) C_block_item(s, 1);

View file

@ -103,7 +103,47 @@ CSHARP_ARRAYS(long long, long)
CSHARP_ARRAYS(unsigned long long, ulong)
CSHARP_ARRAYS(float, float)
CSHARP_ARRAYS(double, double)
CSHARP_ARRAYS(bool, bool)
// By default C# will marshal bools as 4 bytes
// UnmanagedType.I1 will change this to 1 byte
// FIXME - When running on mono ArraySubType appears to be ignored and bools will be marshalled as 4-byte
// https://github.com/mono/mono/issues/15592
// input only arrays
%typemap(ctype) bool INPUT[] "bool*"
%typemap(cstype) bool INPUT[] "bool[]"
%typemap(imtype, inattributes="[global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray,ArraySubType=System.Runtime.InteropServices.UnmanagedType.I1)]") bool INPUT[] "bool[]"
%typemap(csin) bool INPUT[] "$csinput"
%typemap(in) bool INPUT[] %{
$1 = $input;
%}
%typemap(freearg) bool INPUT[] ""
%typemap(argout) bool INPUT[] ""
// output only arrays
%typemap(ctype) bool OUTPUT[] "bool*"
%typemap(cstype) bool OUTPUT[] "bool[]"
%typemap(imtype, inattributes="[global::System.Runtime.InteropServices.Out, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray,ArraySubType=System.Runtime.InteropServices.UnmanagedType.I1)]") bool OUTPUT[] "bool[]"
%typemap(csin) bool OUTPUT[] "$csinput"
%typemap(in) bool OUTPUT[] %{
$1 = $input;
%}
%typemap(freearg) bool OUTPUT[] ""
%typemap(argout) bool OUTPUT[] ""
// inout arrays
%typemap(ctype) bool INOUT[] "bool*"
%typemap(cstype) bool INOUT[] "bool[]"
%typemap(imtype, inattributes="[global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.Out, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray,ArraySubType=System.Runtime.InteropServices.UnmanagedType.I1)]") bool INOUT[] "bool[]"
%typemap(csin) bool INOUT[] "$csinput"
%typemap(in) bool INOUT[] %{
$1 = $input;
%}
%typemap(freearg) bool INOUT[] ""
%typemap(argout) bool INOUT[] ""
%define CSHARP_ARRAYS_FIXED( CTYPE, CSTYPE )

View file

@ -314,7 +314,7 @@
}
%}
%typemap(csdestruct, methodname="Dispose", methodmodifiers="public") TYPE {
%typemap(csdisposing, methodname="Dispose", methodmodifiers="protected", parameters="bool disposing") TYPE {
lock(this) {
if (swigCPtr.Handle != global::System.IntPtr.Zero) {
if (swigCMemOwnBase) {
@ -323,11 +323,10 @@
}
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
}
global::System.GC.SuppressFinalize(this);
}
}
%typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") TYPE {
%typemap(csdisposing_derived, methodname="Dispose", methodmodifiers="protected", parameters="bool disposing") TYPE {
lock(this) {
if (swigCPtr.Handle != global::System.IntPtr.Zero) {
if (swigCMemOwnDerived) {
@ -336,8 +335,7 @@
}
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
}
global::System.GC.SuppressFinalize(this);
base.Dispose();
base.Dispose(disposing);
}
}
@ -473,7 +471,7 @@
}
%}
%typemap(csdestruct, methodname="Dispose", methodmodifiers="public") TYPE {
%typemap(csdisposing, methodname="Dispose", methodmodifiers="protected", parameters="bool disposing") TYPE {
lock(this) {
if (swigCPtr.Handle != global::System.IntPtr.Zero) {
if (swigCMemOwnBase) {
@ -482,11 +480,10 @@
}
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
}
global::System.GC.SuppressFinalize(this);
}
}
%typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") TYPE {
%typemap(csdisposing_derived, methodname="Dispose", methodmodifiers="protected", parameters="bool disposing") TYPE {
lock(this) {
if (swigCPtr.Handle != global::System.IntPtr.Zero) {
if (swigCMemOwnDerived) {
@ -495,8 +492,7 @@
}
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
}
global::System.GC.SuppressFinalize(this);
base.Dispose();
base.Dispose(disposing);
}
}
@ -505,6 +501,17 @@
%typemap(imtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast "global::System.Runtime.InteropServices.HandleRef"
%typemap(imtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast "global::System.Runtime.InteropServices.HandleRef"
// Typecheck typemaps
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *")
TYPE CONST,
TYPE CONST &,
TYPE CONST *,
TYPE *CONST&,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *&
""
%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
%enddef

View file

@ -14,7 +14,7 @@
%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
// destructor mods
%feature("unref") TYPE
%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;"
@ -28,9 +28,21 @@
return $null;
}
$1 = *argp; %}
%typemap(out) CONST TYPE
%typemap(out) CONST TYPE
%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); %}
%typemap(directorin) CONST TYPE
%{ $input = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (new $1_ltype((const $1_ltype &)$1)); %}
%typemap(directorout) CONST TYPE
%{ if (!$input) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null $1_type", 0);
return $null;
}
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input;
$result = *smartarg->get();
%}
// 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;
@ -39,6 +51,13 @@
$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0;
%}
%typemap(directorin) CONST TYPE *
%{ $input = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0; %}
%typemap(directorout) CONST TYPE * %{
#error "typemaps for $1_type not available"
%}
// 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);
@ -49,6 +68,13 @@
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE &
%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); %}
%typemap(directorin) CONST TYPE &
%{ $input = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (&$1 SWIG_NO_NULL_DELETER_0); %}
%typemap(directorout) CONST TYPE & %{
#error "typemaps for $1_type not available"
%}
// 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);
@ -56,17 +82,41 @@
%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST&
%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %}
%typemap(directorin) TYPE *CONST&
%{ $input = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0; %}
%typemap(directorout) TYPE *CONST& %{
#error "typemaps for $1_type not available"
%}
// 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; %}
%typemap(directorin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >
%{ $input = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; %}
%typemap(directorout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >
%{ if ($input) {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input;
$result = *smartarg;
}
%}
// 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; %}
%{ $result = *$1 ? new $*1_ltype(*$1) : 0; %}
%typemap(directorin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &
%{ $input = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; %}
%typemap(directorout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{
#error "typemaps for $1_type not available"
%}
// shared_ptr by pointer
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * ($*1_ltype tempnull)
@ -75,12 +125,26 @@
%{ $result = ($1 && *$1) ? new $*1_ltype(*($1_ltype)$1) : 0;
if ($owner) delete $1; %}
%typemap(directorin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *
%{ $input = ($1 && *$1) ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; %}
%typemap(directorout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{
#error "typemaps for $1_type not available"
%}
// 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; %}
%{ *($1_ltype)&$result = (*$1 && **$1) ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(**$1) : 0; %}
%typemap(directorin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *&
%{ $input = ($1 && *$1) ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; %}
%typemap(directorout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{
#error "typemaps for $1_type not available"
%}
// various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug
%typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{
@ -91,20 +155,20 @@
%}
%typemap (ctype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
%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, out="global::System.IntPtr") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
%typemap (imtype, out="global::System.IntPtr") 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 > *& "global::System.Runtime.InteropServices.HandleRef"
%typemap (cstype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
%typemap (cstype) 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(cstype, TYPE)"
%typemap(csin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
%typemap(csin) 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(cstype, TYPE).getCPtr($csinput)"
@ -175,6 +239,18 @@
return ret;
} %}
%typemap(csdirectorout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "$typemap(cstype, TYPE).getCPtr($cscall).Handle"
%typemap(csdirectorin) CONST TYPE,
CONST TYPE *,
CONST TYPE &,
TYPE *CONST& "($iminput == global::System.IntPtr.Zero) ? null : new $typemap(cstype, TYPE)($iminput, true)"
%typemap(csdirectorin) 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 > *& "($iminput == global::System.IntPtr.Zero) ? null : new $typemap(cstype, TYPE)($iminput, true)"
// Proxy classes (base classes, ie, not derived classes)
%typemap(csbody) TYPE %{
@ -206,7 +282,7 @@
}
%}
%typemap(csdestruct, methodname="Dispose", methodmodifiers="public") TYPE {
%typemap(csdisposing, methodname="Dispose", methodmodifiers="protected", parameters="bool disposing") TYPE {
lock(this) {
if (swigCPtr.Handle != global::System.IntPtr.Zero) {
if (swigCMemOwnBase) {
@ -215,11 +291,10 @@
}
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
}
global::System.GC.SuppressFinalize(this);
}
}
%typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") TYPE {
%typemap(csdisposing_derived, methodname="Dispose", methodmodifiers="protected", parameters="bool disposing") TYPE {
lock(this) {
if (swigCPtr.Handle != global::System.IntPtr.Zero) {
if (swigCMemOwnDerived) {
@ -228,11 +303,21 @@
}
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
}
global::System.GC.SuppressFinalize(this);
base.Dispose();
base.Dispose(disposing);
}
}
// Typecheck typemaps
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *")
TYPE CONST,
TYPE CONST &,
TYPE CONST *,
TYPE *CONST&,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *&
""
%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
%enddef

5
Lib/csharp/complex.i Normal file
View file

@ -0,0 +1,5 @@
#ifdef __cplusplus
%include <std_complex.i>
#else
#error C# module only supports complex in C++ mode.
#endif

View file

@ -843,11 +843,26 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
$*csclassname ret = (cPtr == global::System.IntPtr.Zero) ? null : new $*csclassname(cPtr, $owner);$excode
return ret;
}
%typemap(csvarout, excode=SWIGEXCODE) SWIGTYPE *const& %{
get {
global::System.IntPtr cPtr = $imcall;
$*csclassname ret = (cPtr == global::System.IntPtr.Zero) ? null : new $*csclassname(cPtr, $owner);$excode
return ret;
} %}
%typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0)
%{ temp = ($*1_ltype)$input;
$1 = ($1_ltype)&temp; %}
%typemap(out) SWIGTYPE *const&
%{ $result = (void *)*$1; %}
%typemap(directorin) SWIGTYPE *const&
%{ $input = (void *) $1; %}
%typemap(directorout, warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) SWIGTYPE *const&
%{ static $*1_ltype swig_temp;
swig_temp = ($*1_ltype)$input;
$result = &swig_temp; %}
%typemap(csdirectorin) SWIGTYPE *const& "($iminput == global::System.IntPtr.Zero) ? null : new $*csclassname($iminput, false)"
%typemap(csdirectorout) SWIGTYPE *const& "$*csclassname.getCPtr($cscall).Handle"
/* Marshal C/C++ pointer to global::System.IntPtr */
%typemap(ctype) void *VOID_INT_PTR "void *"
@ -860,7 +875,8 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
global::System.IntPtr ret = $imcall;$excode
return ret;
}
%typemap(csdirectorin) void *VOID_INT_PTR "$iminput"
%typemap(csdirectorout) void *VOID_INT_PTR "$cscall"
/* Typemaps used for the generation of proxy and type wrapper class code */
%typemap(csbase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
@ -943,17 +959,24 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
SWIG_CSBODY_PROXY(internal, internal, SWIGTYPE)
SWIG_CSBODY_TYPEWRAPPER(internal, protected, internal, SWIGTYPE)
%typemap(csfinalize) SWIGTYPE %{
%typemap(csdispose) SWIGTYPE %{
~$csclassname() {
Dispose();
Dispose(false);
}
public void Dispose() {
Dispose(true);
global::System.GC.SuppressFinalize(this);
}
%}
%typemap(csdispose_derived) SWIGTYPE ""
%typemap(csconstruct, excode=SWIGEXCODE,directorconnect="\n SwigDirectorConnect();") SWIGTYPE %{: this($imcall, true) {$excode$directorconnect
}
%}
%typemap(csdestruct, methodname="Dispose", methodmodifiers="public") SWIGTYPE {
%typemap(csdisposing, methodname="Dispose", methodmodifiers="protected", parameters="bool disposing") SWIGTYPE {
lock(this) {
if (swigCPtr.Handle != global::System.IntPtr.Zero) {
if (swigCMemOwn) {
@ -962,11 +985,10 @@ SWIG_CSBODY_TYPEWRAPPER(internal, protected, internal, SWIGTYPE)
}
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
}
global::System.GC.SuppressFinalize(this);
}
}
%typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") SWIGTYPE {
%typemap(csdisposing_derived, methodname="Dispose", methodmodifiers="protected", parameters="bool disposing") SWIGTYPE {
lock(this) {
if (swigCPtr.Handle != global::System.IntPtr.Zero) {
if (swigCMemOwn) {
@ -975,8 +997,7 @@ SWIG_CSBODY_TYPEWRAPPER(internal, protected, internal, SWIGTYPE)
}
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
}
global::System.GC.SuppressFinalize(this);
base.Dispose();
base.Dispose(disposing);
}
}
@ -994,6 +1015,7 @@ SWIG_CSBODY_TYPEWRAPPER(internal, protected, internal, SWIGTYPE)
#define %csmethodmodifiers %feature("cs:methodmodifiers")
#define %csnothrowexception %feature("except")
#define %csattributes %feature("cs:attributes")
#define %proxycode %insert("proxycode")
%pragma(csharp) imclassclassmodifiers="class"
%pragma(csharp) moduleclassmodifiers="public class"
@ -1009,6 +1031,8 @@ SWIG_CSBODY_TYPEWRAPPER(internal, protected, internal, SWIGTYPE)
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
/* csharp keywords */
%include <csharpkw.swg>

View file

@ -244,6 +244,7 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_$module(
[global::System.ThreadStatic]
private static global::System.Exception pendingException = null;
private static int numExceptionsPending = 0;
private static global::System.Object exceptionsLock = null;
public static bool Pending {
get {
@ -259,7 +260,7 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_$module(
if (pendingException != null)
throw new global::System.ApplicationException("FATAL: An earlier pending exception from unmanaged code was missed and thus not thrown (" + pendingException.ToString() + ")", e);
pendingException = e;
lock(typeof($imclassname)) {
lock(exceptionsLock) {
numExceptionsPending++;
}
}
@ -270,13 +271,17 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_$module(
if (pendingException != null) {
e = pendingException;
pendingException = null;
lock(typeof($imclassname)) {
lock(exceptionsLock) {
numExceptionsPending--;
}
}
}
return e;
}
static SWIGPendingException() {
exceptionsLock = new global::System.Object();
}
}
%}
#endif // SWIG_CSHARP_NO_EXCEPTION_HELPER

View file

@ -41,6 +41,10 @@ namespace Swig {
public:
DirectorPureVirtualException(const char *msg) : DirectorException(std::string("Attempt to invoke pure virtual method ") + msg) {
}
static void raise(const char *msg) {
throw DirectorPureVirtualException(msg);
}
};
}

227
Lib/csharp/std_array.i Normal file
View file

@ -0,0 +1,227 @@
/* -----------------------------------------------------------------------------
* std_array.i
*
* SWIG typemaps for std::array<T, N>
* C# implementation
* The C# wrapper is made to look and feel like a C# System.Collections.Generic.IReadOnlyList<> collection.
* ----------------------------------------------------------------------------- */
%{
#include <algorithm>
#include <array>
#include <stdexcept>
%}
%include <std_common.i>
%define SWIG_STD_ARRAY_INTERNAL(T, N)
%typemap(csinterfaces) std::array< T, N > "global::System.IDisposable, global::System.Collections.IEnumerable\n , global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)>\n";
%proxycode %{
public $csclassname(global::System.Collections.ICollection c) : this() {
if (c == null)
throw new global::System.ArgumentNullException("c");
int end = global::System.Math.Min(this.Count, c.Count);
int i = 0;
foreach ($typemap(cstype, T) elem in c) {
if (i >= end)
break;
this[i++] = elem;
}
}
public int Count {
get {
return (int)size();
}
}
public $typemap(cstype, T) this[int index] {
get {
return getitem(index);
}
set {
setitem(index, value);
}
}
public bool IsEmpty {
get {
return empty();
}
}
public void CopyTo($typemap(cstype, T)[] array)
{
CopyTo(0, array, 0, this.Count);
}
public void CopyTo($typemap(cstype, T)[] array, int arrayIndex)
{
CopyTo(0, array, arrayIndex, this.Count);
}
public void CopyTo(int index, $typemap(cstype, T)[] array, int arrayIndex, int count)
{
if (array == null)
throw new global::System.ArgumentNullException("array");
if (index < 0)
throw new global::System.ArgumentOutOfRangeException("index", "Value is less than zero");
if (arrayIndex < 0)
throw new global::System.ArgumentOutOfRangeException("arrayIndex", "Value is less than zero");
if (count < 0)
throw new global::System.ArgumentOutOfRangeException("count", "Value is less than zero");
if (array.Rank > 1)
throw new global::System.ArgumentException("Multi dimensional array.", "array");
if (index+count > this.Count || arrayIndex+count > array.Length)
throw new global::System.ArgumentException("Number of elements to copy is too large.");
for (int i=0; i<count; i++)
array.SetValue(getitemcopy(index+i), arrayIndex+i);
}
global::System.Collections.Generic.IEnumerator<$typemap(cstype, T)> global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)>.GetEnumerator() {
return new $csclassnameEnumerator(this);
}
global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() {
return new $csclassnameEnumerator(this);
}
public $csclassnameEnumerator GetEnumerator() {
return new $csclassnameEnumerator(this);
}
// Type-safe enumerator
/// Note that the IEnumerator documentation requires an InvalidOperationException to be thrown
/// whenever the collection is modified. This has been done for changes in the size of the
/// collection but not when one of the elements of the collection is modified as it is a bit
/// tricky to detect unmanaged code that modifies the collection under our feet.
public sealed class $csclassnameEnumerator : global::System.Collections.IEnumerator
, global::System.Collections.Generic.IEnumerator<$typemap(cstype, T)>
{
private $csclassname collectionRef;
private int currentIndex;
private object currentObject;
private int currentSize;
public $csclassnameEnumerator($csclassname collection) {
collectionRef = collection;
currentIndex = -1;
currentObject = null;
currentSize = collectionRef.Count;
}
// Type-safe iterator Current
public $typemap(cstype, T) Current {
get {
if (currentIndex == -1)
throw new global::System.InvalidOperationException("Enumeration not started.");
if (currentIndex > currentSize - 1)
throw new global::System.InvalidOperationException("Enumeration finished.");
if (currentObject == null)
throw new global::System.InvalidOperationException("Collection modified.");
return ($typemap(cstype, T))currentObject;
}
}
// Type-unsafe IEnumerator.Current
object global::System.Collections.IEnumerator.Current {
get {
return Current;
}
}
public bool MoveNext() {
int size = collectionRef.Count;
bool moveOkay = (currentIndex+1 < size) && (size == currentSize);
if (moveOkay) {
currentIndex++;
currentObject = collectionRef[currentIndex];
} else {
currentObject = null;
}
return moveOkay;
}
public void Reset() {
currentIndex = -1;
currentObject = null;
if (collectionRef.Count != currentSize) {
throw new global::System.InvalidOperationException("Collection modified.");
}
}
public void Dispose() {
currentIndex = -1;
currentObject = null;
}
}
%}
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;
array();
array(const array &other);
size_type size() const;
bool empty() const;
%rename(Fill) fill;
void fill(const value_type& value);
%rename(Swap) swap;
void swap(array& other);
%extend {
T getitemcopy(int index) throw (std::out_of_range) {
if (index>=0 && index<(int)$self->size())
return (*$self)[index];
else
throw std::out_of_range("index");
}
const_reference getitem(int index) throw (std::out_of_range) {
if (index>=0 && index<(int)$self->size())
return (*$self)[index];
else
throw std::out_of_range("index");
}
void setitem(int index, const_reference val) throw (std::out_of_range) {
if (index>=0 && index<(int)$self->size())
(*$self)[index] = val;
else
throw std::out_of_range("index");
}
void Reverse() {
std::reverse($self->begin(), $self->end());
}
void Reverse(int index, int count) throw (std::out_of_range, std::invalid_argument) {
if (index < 0)
throw std::out_of_range("index");
if (count < 0)
throw std::out_of_range("count");
if (index >= (int)$self->size()+1 || index+count > (int)$self->size())
throw std::invalid_argument("invalid range");
std::reverse($self->begin()+index, $self->begin()+index+count);
}
}
%enddef
%csmethodmodifiers std::array::empty "private"
%csmethodmodifiers std::array::getitemcopy "private"
%csmethodmodifiers std::array::getitem "private"
%csmethodmodifiers std::array::setitem "private"
%csmethodmodifiers std::array::size "private"
namespace std {
template<class T, size_t N> class array {
SWIG_STD_ARRAY_INTERNAL(T, N)
};
}

95
Lib/csharp/std_complex.i Normal file
View file

@ -0,0 +1,95 @@
/* -----------------------------------------------------------------------------
* std_complex.i
*
* Typemaps for handling std::complex<float> and std::complex<double> as a .NET
* System.Numerics.Complex type. Requires .NET 4 minimum.
* ----------------------------------------------------------------------------- */
%{
#include <complex>
%}
%fragment("SwigSystemNumericsComplex", "header") {
extern "C" {
// Identical to the layout of System.Numerics.Complex, but does assume that it is
// LayoutKind.Sequential on the managed side
struct SwigSystemNumericsComplex {
double real;
double imag;
};
}
SWIGINTERN SwigSystemNumericsComplex SwigCreateSystemNumericsComplex(double real, double imag) {
SwigSystemNumericsComplex cpx;
cpx.real = real;
cpx.imag = imag;
return cpx;
}
}
namespace std {
%naturalvar complex;
template<typename T>
class complex
{
public:
complex(T re = T(), T im = T());
};
}
%define SWIG_COMPLEX_TYPEMAPS(T)
%typemap(ctype, fragment="SwigSystemNumericsComplex") std::complex<T>, const std::complex<T> & "SwigSystemNumericsComplex"
%typemap(imtype) std::complex<T>, const std::complex<T> & "System.Numerics.Complex"
%typemap(cstype) std::complex<T>, const std::complex<T> & "System.Numerics.Complex"
%typemap(in) std::complex<T>
%{$1 = std::complex< double >($input.real, $input.imag);%}
%typemap(in) const std::complex<T> &($*1_ltype temp)
%{temp = std::complex< T >((T)$input.real, (T)$input.imag);
$1 = &temp;%}
%typemap(out, null="SwigCreateSystemNumericsComplex(0.0, 0.0)") std::complex<T>
%{$result = SwigCreateSystemNumericsComplex($1.real(), $1.imag());%}
%typemap(out, null="SwigCreateSystemNumericsComplex(0.0, 0.0)") const std::complex<T> &
%{$result = SwigCreateSystemNumericsComplex($1->real(), $1->imag());%}
%typemap(cstype) std::complex<T>, const std::complex<T> & "System.Numerics.Complex"
%typemap(csin) std::complex<T>, const std::complex<T> & "$csinput"
%typemap(csout, excode=SWIGEXCODE) std::complex<T>, const std::complex<T> & {
System.Numerics.Complex ret = $imcall;$excode
return ret;
}
%typemap(csvarin, excode=SWIGEXCODE2) const std::complex<T> & %{
set {
$imcall;$excode
}
%}
%typemap(csvarout, excode=SWIGEXCODE2) const std::complex<T> & %{
get {
System.Numerics.Complex ret = $imcall;$excode
return ret;
}
%}
%template() std::complex<T>;
%enddef
// By default, typemaps for both std::complex<double> and std::complex<float>
// are defined, but one of them can be disabled by predefining the
// corresponding symbol before including this file.
#ifndef SWIG_NO_STD_COMPLEX_DOUBLE
SWIG_COMPLEX_TYPEMAPS(double)
#endif
#ifndef SWIG_NO_STD_COMPLEX_FLOAT
SWIG_COMPLEX_TYPEMAPS(float)
#endif

View file

@ -7,6 +7,7 @@
* ----------------------------------------------------------------------------- */
%{
#include <typeinfo>
#include <stdexcept>
%}
@ -16,6 +17,7 @@ namespace std
struct exception {};
}
%typemap(throws, canthrow=1) std::bad_cast "SWIG_CSharpSetPendingException(SWIG_CSharpInvalidCastException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::bad_exception "SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::domain_error "SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::exception "SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, $1.what());\n return $null;"

519
Lib/csharp/std_list.i Normal file
View file

@ -0,0 +1,519 @@
/* -----------------------------------------------------------------------------
* std_list.i
*
* SWIG typemaps for std::list<T>
* C# implementation
* The C# wrapper is made to look and feel like a C# System.Collections.Generic.LinkedList<> collection.
*
* Note that IEnumerable<> is implemented in the proxy class which is useful for using LINQ with
* C++ std::list wrappers. The ICollection<> interface is also implemented to provide enhanced functionality
* whenever we are confident that the required C++ operator== is available. This is the case for when
* T is a primitive type or a pointer. If T does define an operator==, then use the SWIG_STD_LIST_ENHANCED
* macro to obtain this enhanced functionality, for example:
*
* SWIG_STD_LIST_ENHANCED(SomeNamespace::Klass)
* %template(ListKlass) std::list<SomeNamespace::Klass>;
* ----------------------------------------------------------------------------- */
%include <std_common.i>
// MACRO for use within the std::list class body
%define SWIG_STD_LIST_MINIMUM_INTERNAL(CSINTERFACE, CTYPE...)
%typemap(csinterfaces) std::list< CTYPE > "global::System.IDisposable, global::System.Collections.IEnumerable, global::System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n";
%apply void *VOID_INT_PTR { std::list< CTYPE >::iterator * };
%proxycode %{
public $csclassname(global::System.Collections.IEnumerable c) : this() {
if (c == null)
throw new global::System.ArgumentNullException("c");
foreach ($typemap(cstype, CTYPE) element in c) {
this.AddLast(element);
}
}
public bool IsReadOnly {
get {
return false;
}
}
public int Count {
get {
return (int)size();
}
}
public $csclassnameNode First {
get {
if (Count == 0)
return null;
return new $csclassnameNode(getFirstIter(), this);
}
}
public $csclassnameNode Last {
get {
if (Count == 0)
return null;
return new $csclassnameNode(getLastIter(), this);
}
}
public $csclassnameNode AddFirst($typemap(cstype, CTYPE) value) {
push_front(value);
return new $csclassnameNode(getFirstIter(), this);
}
public void AddFirst($csclassnameNode newNode) {
ValidateNewNode(newNode);
if (!newNode.inlist) {
push_front(newNode.csharpvalue);
newNode.iter = getFirstIter();
newNode.inlist = true;
} else {
throw new global::System.InvalidOperationException("The " + newNode.GetType().Name + " node already belongs to a " + this.GetType().Name);
}
}
public $csclassnameNode AddLast($typemap(cstype, CTYPE) value) {
push_back(value);
return new $csclassnameNode(getLastIter(), this);
}
public void AddLast($csclassnameNode newNode) {
ValidateNewNode(newNode);
if (!newNode.inlist) {
push_back(newNode.csharpvalue);
newNode.iter = getLastIter();
newNode.inlist = true;
} else {
throw new global::System.InvalidOperationException("The " + newNode.GetType().Name + " node already belongs to a " + this.GetType().Name);
}
}
public $csclassnameNode AddBefore($csclassnameNode node, $typemap(cstype, CTYPE) value) {
return new $csclassnameNode(insertNode(node.iter, value), this);
}
public void AddBefore($csclassnameNode node, $csclassnameNode newNode) {
ValidateNode(node);
ValidateNewNode(newNode);
if (!newNode.inlist) {
newNode.iter = insertNode(node.iter, newNode.csharpvalue);
newNode.inlist = true;
} else {
throw new global::System.InvalidOperationException("The " + newNode.GetType().Name + " node already belongs to a " + this.GetType().Name);
}
}
public $csclassnameNode AddAfter($csclassnameNode node, $typemap(cstype, CTYPE) value) {
node = node.Next;
return new $csclassnameNode(insertNode(node.iter, value), this);
}
public void AddAfter($csclassnameNode node, $csclassnameNode newNode) {
ValidateNode(node);
ValidateNewNode(newNode);
if (!newNode.inlist) {
if (node == this.Last)
AddLast(newNode);
else
{
node = node.Next;
newNode.iter = insertNode(node.iter, newNode.csharpvalue);
newNode.inlist = true;
}
} else {
throw new global::System.InvalidOperationException("The " + newNode.GetType().Name + " node already belongs to a " + this.GetType().Name);
}
}
public void Add($typemap(cstype, CTYPE) value) {
AddLast(value);
}
public void Remove($csclassnameNode node) {
ValidateNode(node);
eraseIter(node.iter);
}
public void CopyTo($typemap(cstype, CTYPE)[] array, int index) {
if (array == null)
throw new global::System.ArgumentNullException("array");
if (index < 0 || index > array.Length)
throw new global::System.ArgumentOutOfRangeException("index", "Value is less than zero");
if (array.Rank > 1)
throw new global::System.ArgumentException("Multi dimensional array.", "array");
$csclassnameNode node = this.First;
if (node != null) {
do {
array[index++] = node.Value;
node = node.Next;
} while (node != null);
}
}
internal void ValidateNode($csclassnameNode node) {
if (node == null) {
throw new System.ArgumentNullException("node");
}
if (!node.inlist || node.list != this) {
throw new System.InvalidOperationException("node");
}
}
internal void ValidateNewNode($csclassnameNode node) {
if (node == null) {
throw new System.ArgumentNullException("node");
}
}
global::System.Collections.Generic.IEnumerator<$typemap(cstype, CTYPE)> global::System.Collections.Generic.IEnumerable<$typemap(cstype, CTYPE)>.GetEnumerator() {
return new $csclassnameEnumerator(this);
}
global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() {
return new $csclassnameEnumerator(this);
}
public $csclassnameEnumerator GetEnumerator() {
return new $csclassnameEnumerator(this);
}
public sealed class $csclassnameEnumerator : global::System.Collections.IEnumerator,
global::System.Collections.Generic.IEnumerator<$typemap(cstype, CTYPE)>
{
private $csclassname collectionRef;
private $csclassnameNode currentNode;
private int currentIndex;
private object currentObject;
private int currentSize;
public $csclassnameEnumerator($csclassname collection) {
collectionRef = collection;
currentNode = collection.First;
currentIndex = 0;
currentObject = null;
currentSize = collectionRef.Count;
}
// Type-safe iterator Current
public $typemap(cstype, CTYPE) Current {
get {
if (currentIndex == -1)
throw new global::System.InvalidOperationException("Enumeration not started.");
if (currentIndex > currentSize)
throw new global::System.InvalidOperationException("Enumeration finished.");
if (currentObject == null)
throw new global::System.InvalidOperationException("Collection modified.");
return ($typemap(cstype, CTYPE))currentObject;
}
}
// Type-unsafe IEnumerator.Current
object global::System.Collections.IEnumerator.Current {
get {
return Current;
}
}
public bool MoveNext() {
if (currentNode == null) {
currentIndex = collectionRef.Count + 1;
return false;
}
++currentIndex;
currentObject = currentNode.Value;
currentNode = currentNode.Next;
return true;
}
public void Reset() {
currentIndex = -1;
currentObject = null;
if (collectionRef.Count != currentSize) {
throw new global::System.InvalidOperationException("Collection modified.");
}
}
public void Dispose() {
currentIndex = -1;
currentObject = null;
}
}
public sealed class $csclassnameNode {
internal $csclassname list;
internal System.IntPtr iter;
internal $typemap(cstype, CTYPE) csharpvalue;
internal bool inlist;
public $csclassnameNode($typemap(cstype, CTYPE) value) {
csharpvalue = value;
inlist = false;
}
internal $csclassnameNode(System.IntPtr iter, $csclassname list) {
this.list = list;
this.iter = iter;
inlist = true;
}
public $csclassname List {
get {
return this.list;
}
}
public $csclassnameNode Next {
get {
if (list.getNextIter(iter) == System.IntPtr.Zero)
return null;
return new $csclassnameNode(list.getNextIter(iter), list);
}
}
public $csclassnameNode Previous {
get {
if (list.getPrevIter(iter) == System.IntPtr.Zero)
return null;
return new $csclassnameNode(list.getPrevIter(iter), list);
}
}
public $typemap(cstype, CTYPE) Value {
get {
return list.getItem(this.iter);
}
set {
list.setItem(this.iter, value);
}
}
public static bool operator==($csclassnameNode node1, $csclassnameNode node2) {
if (object.ReferenceEquals(node1, null) && object.ReferenceEquals(node2, null))
return true;
if (object.ReferenceEquals(node1, null) || object.ReferenceEquals(node2, null))
return false;
return node1.Equals(node2);
}
public static bool operator!=($csclassnameNode node1, $csclassnameNode node2) {
if (node1 == null && node2 == null)
return false;
if (node1 == null || node2 == null)
return true;
return !node1.Equals(node2);
}
public bool Equals($csclassnameNode node) {
if (node == null)
return false;
if (!node.inlist || !this.inlist)
return object.ReferenceEquals(this, node);
return list.equals(this.iter, node.iter);
}
public override bool Equals(object node) {
return Equals(($csclassnameNode)node);
}
public override int GetHashCode() {
int hash = 13;
if (inlist) {
hash = (hash * 7) + this.list.GetHashCode();
hash = (hash * 7) + this.Value.GetHashCode();
hash = (hash * 7) + this.list.getNextIter(this.iter).GetHashCode();
hash = (hash * 7) + this.list.getPrevIter(this.iter).GetHashCode();
} else {
hash = (hash * 7) + this.csharpvalue.GetHashCode();
}
return hash;
}
public void Dispose() {
list.deleteIter(this.iter);
}
}
%}
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef CTYPE value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
class iterator;
void push_front(CTYPE const& x);
void push_back(CTYPE const& x);
%rename(RemoveFirst) pop_front;
void pop_front();
%rename(RemoveLast) pop_back;
void pop_back();
size_type size() const;
%rename(Clear) clear;
void clear();
%extend {
const_reference getItem(iterator *iter) {
return **iter;
}
void setItem(iterator *iter, CTYPE const& val) {
*(*iter) = val;
}
iterator *getFirstIter() {
if ($self->size() == 0)
return NULL;
return new std::list< CTYPE >::iterator($self->begin());
}
iterator *getLastIter() {
if ($self->size() == 0)
return NULL;
return new std::list< CTYPE >::iterator(--$self->end());
}
iterator *getNextIter(iterator *iter) {
std::list< CTYPE >::iterator it = *iter;
if (std::distance(it, --$self->end()) != 0) {
std::list< CTYPE >::iterator* itnext = new std::list< CTYPE >::iterator(++it);
return itnext;
}
return NULL;
}
iterator *getPrevIter(iterator *iter) {
std::list< CTYPE >::iterator it = *iter;
if (std::distance($self->begin(), it) != 0) {
std::list< CTYPE >::iterator* itprev = new std::list< CTYPE >::iterator(--it);
return itprev;
}
return NULL;
}
iterator *insertNode(iterator *iter, CTYPE const& value) {
std::list< CTYPE >::iterator it = $self->insert(*iter, value);
return new std::list< CTYPE >::iterator(it);
}
void eraseIter(iterator *iter) {
std::list< CTYPE >::iterator it = *iter;
$self->erase(it);
}
void deleteIter(iterator *iter) {
delete iter;
}
bool equals(iterator *iter1, iterator *iter2) {
if (iter1 == NULL && iter2 == NULL)
return true;
std::list< CTYPE >::iterator it1 = *iter1;
std::list< CTYPE >::iterator it2 = *iter2;
return it1 == it2;
}
}
%enddef
// Extra methods added to the collection class if operator== is defined for the class being wrapped
// The class will then implement ICollection<>, which adds extra functionality
%define SWIG_STD_LIST_EXTRA_OP_EQUALS_EQUALS(CTYPE...)
%extend {
bool Contains(CTYPE const& value) {
return std::find($self->begin(), $self->end(), value) != $self->end();
}
bool Remove(CTYPE const& value) {
std::list< CTYPE >::iterator it = std::find($self->begin(), $self->end(), value);
if (it != $self->end()) {
$self->erase(it);
return true;
}
return false;
}
iterator *find(CTYPE const& value) {
if (std::find($self->begin(), $self->end(), value) != $self->end()) {
return new std::list< CTYPE >::iterator(std::find($self->begin(), $self->end(), value));
}
return NULL;
}
}
%proxycode %{
public $csclassnameNode Find($typemap(cstype, CTYPE) value) {
System.IntPtr tmp = find(value);
if (tmp != System.IntPtr.Zero) {
return new $csclassnameNode(tmp, this);
}
return null;
}
%}
%enddef
// Macros for std::list class specializations/enhancements
%define SWIG_STD_LIST_ENHANCED(CTYPE...)
namespace std {
template<> class list< CTYPE > {
SWIG_STD_LIST_MINIMUM_INTERNAL(ICollection, %arg(CTYPE));
SWIG_STD_LIST_EXTRA_OP_EQUALS_EQUALS(CTYPE)
};
}
%enddef
%{
#include <list>
#include <algorithm>
#include <stdexcept>
%}
%csmethodmodifiers std::list::size "private"
%csmethodmodifiers std::list::getItem "private"
%csmethodmodifiers std::list::setItem "private"
%csmethodmodifiers std::list::push_front "private"
%csmethodmodifiers std::list::push_back "private"
%csmethodmodifiers std::list::getFirstIter "private"
%csmethodmodifiers std::list::getNextIter "private"
%csmethodmodifiers std::list::getPrevIter "private"
%csmethodmodifiers std::list::getLastIter "private"
%csmethodmodifiers std::list::find "private"
%csmethodmodifiers std::list::deleteIter "private"
namespace std {
// primary (unspecialized) class template for std::list
// does not require operator== to be defined
template<class T>
class list {
SWIG_STD_LIST_MINIMUM_INTERNAL(IEnumerable, T)
};
// specialization for pointers
template<class T>
class list<T *> {
SWIG_STD_LIST_MINIMUM_INTERNAL(ICollection, T *)
SWIG_STD_LIST_EXTRA_OP_EQUALS_EQUALS(T *)
};
}
// template specializations for std::list
// these provide extra collections methods as operator== is defined
SWIG_STD_LIST_ENHANCED(char)
SWIG_STD_LIST_ENHANCED(signed char)
SWIG_STD_LIST_ENHANCED(unsigned char)
SWIG_STD_LIST_ENHANCED(short)
SWIG_STD_LIST_ENHANCED(unsigned short)
SWIG_STD_LIST_ENHANCED(int)
SWIG_STD_LIST_ENHANCED(unsigned int)
SWIG_STD_LIST_ENHANCED(long)
SWIG_STD_LIST_ENHANCED(unsigned long)
SWIG_STD_LIST_ENHANCED(long long)
SWIG_STD_LIST_ENHANCED(unsigned long long)
SWIG_STD_LIST_ENHANCED(float)
SWIG_STD_LIST_ENHANCED(double)
SWIG_STD_LIST_ENHANCED(std::string) // also requires a %include <std_string.i>
SWIG_STD_LIST_ENHANCED(std::wstring) // also requires a %include <std_wstring.i>

View file

@ -4,14 +4,14 @@
* SWIG typemaps for std::map< K, T, C >
*
* The C# wrapper is made to look and feel like a C# System.Collections.Generic.IDictionary<>.
*
*
* Using this wrapper is fairly simple. For example, to create a map from integers to doubles use:
*
* %include <std_map.i>
* %template(MapIntDouble) std::map<int, double>
*
* Notes:
* 1) IEnumerable<> is implemented in the proxy class which is useful for using LINQ with
* 1) IEnumerable<> is implemented in the proxy class which is useful for using LINQ with
* C++ std::map wrappers.
*
* Warning: heavy macro usage in this file. Use swig -E to get a sane view on the real file contents!
@ -27,7 +27,7 @@
%define SWIG_STD_MAP_INTERNAL(K, T, C)
%typemap(csinterfaces) std::map< K, T, C > "global::System.IDisposable \n , global::System.Collections.Generic.IDictionary<$typemap(cstype, K), $typemap(cstype, T)>\n";
%typemap(cscode) std::map<K, T, C > %{
%proxycode %{
public $typemap(cstype, T) this[$typemap(cstype, K) key] {
get {
@ -55,8 +55,8 @@
}
public bool IsReadOnly {
get {
return false;
get {
return false;
}
}
@ -84,7 +84,7 @@
return vals;
}
}
public void Add(global::System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> item) {
Add(item.Key, item.Value);
}
@ -143,7 +143,7 @@
/// whenever the collection is modified. This has been done for changes in the size of the
/// collection but not when one of the elements of the collection is modified as it is a bit
/// tricky to detect unmanaged code that modifies the collection under our feet.
public sealed class $csclassnameEnumerator : global::System.Collections.IEnumerator,
public sealed class $csclassnameEnumerator : global::System.Collections.IEnumerator,
global::System.Collections.Generic.IEnumerator<global::System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>>
{
private $csclassname collectionRef;
@ -206,7 +206,7 @@
currentObject = null;
}
}
%}
public:
@ -214,9 +214,14 @@
typedef ptrdiff_t difference_type;
typedef K key_type;
typedef T mapped_type;
typedef std::pair< const K, T > value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
map();
map(const map< K, T, C > &other);
map(const map& other);
size_type size() const;
bool empty() const;
%rename(Clear) clear;
@ -239,11 +244,11 @@
return iter != $self->end();
}
void Add(const key_type& key, const mapped_type& val) throw (std::out_of_range) {
void Add(const key_type& key, const mapped_type& value) throw (std::out_of_range) {
std::map< K, T, C >::iterator iter = $self->find(key);
if (iter != $self->end())
throw std::out_of_range("key already exists");
$self->insert(std::pair< K, T >(key, val));
$self->insert(std::pair< K, T >(key, value));
}
bool Remove(const key_type& key) {
@ -251,7 +256,7 @@
if (iter != $self->end()) {
$self->erase(iter);
return true;
}
}
return false;
}
@ -285,12 +290,12 @@
%csmethodmodifiers std::map::destroy_iterator "private"
// Default implementation
namespace std {
namespace std {
template<class K, class T, class C = std::less<K> > class map {
SWIG_STD_MAP_INTERNAL(K, T, C)
};
}
// Legacy macros (deprecated)
%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)

View file

@ -18,12 +18,14 @@
namespace std {
template<class T, class U> struct pair {
typedef T first_type;
typedef U second_type;
pair();
pair(T t, U u);
pair(const pair& p);
pair(T first, U second);
pair(const pair& other);
template <class U1, class U2> pair(const pair<U1, U2> &p);
template <class U1, class U2> pair(const pair<U1, U2> &other);
T first;
U second;

311
Lib/csharp/std_set.i Normal file
View file

@ -0,0 +1,311 @@
/* -----------------------------------------------------------------------------
* std_set.i
*
* SWIG typemaps for std::set<T>.
*
* Note that ISet<> used here requires .NET 4 or later.
*
* The C# wrapper implements ISet<> interface and shares performance
* characteristics of C# System.Collections.Generic.SortedSet<> class, but
* doesn't provide quite all of its methods.
* ----------------------------------------------------------------------------- */
%{
#include <set>
#include <algorithm>
#include <stdexcept>
%}
%csmethodmodifiers std::set::size "private"
%csmethodmodifiers std::set::getitem "private"
%csmethodmodifiers std::set::create_iterator_begin "private"
%csmethodmodifiers std::set::get_next "private"
%csmethodmodifiers std::set::destroy_iterator "private"
namespace std {
// TODO: Add support for comparator and allocator template parameters.
template <class T>
class set {
%typemap(csinterfaces) std::set<T> "global::System.IDisposable, global::System.Collections.Generic.ISet<$typemap(cstype, T)>\n";
%proxycode %{
void global::System.Collections.Generic.ICollection<$typemap(cstype, T)>.Add($typemap(cstype, T) item) {
((global::System.Collections.Generic.ISet<$typemap(cstype, T)>)this).Add(item);
}
public bool TryGetValue($typemap(cstype, T) equalValue, out $typemap(cstype, T) actualValue) {
try {
actualValue = getitem(equalValue);
return true;
} catch {
actualValue = default($typemap(cstype, T));
return false;
}
}
public int Count {
get {
return (int)size();
}
}
public bool IsReadOnly {
get {
return false;
}
}
public void CopyTo($typemap(cstype, T)[] array) {
CopyTo(array, 0);
}
public void CopyTo($typemap(cstype, T)[] array, int arrayIndex) {
if (array == null)
throw new global::System.ArgumentNullException("array");
if (arrayIndex < 0)
throw new global::System.ArgumentOutOfRangeException("arrayIndex", "Value is less than zero");
if (array.Rank > 1)
throw new global::System.ArgumentException("Multi dimensional array.", "array");
if (arrayIndex+this.Count > array.Length)
throw new global::System.ArgumentException("Number of elements to copy is too large.");
foreach ($typemap(cstype, T) item in this) {
array.SetValue(item, arrayIndex++);
}
}
public void ExceptWith(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
foreach ($typemap(cstype, T) item in other) {
Remove(item);
}
}
public void IntersectWith(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
$csclassname old = new $csclassname(this);
Clear();
foreach ($typemap(cstype, T) item in other) {
if (old.Contains(item))
Add(item);
}
}
private static int count_enum(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
int count = 0;
foreach ($typemap(cstype, T) item in other) {
count++;
}
return count;
}
public bool IsProperSubsetOf(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
return IsSubsetOf(other) && Count < count_enum(other);
}
public bool IsProperSupersetOf(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
return IsSupersetOf(other) && Count > count_enum(other);
}
public bool IsSubsetOf(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
int countContained = 0;
foreach ($typemap(cstype, T) item in other) {
if (Contains(item))
countContained++;
}
return countContained == Count;
}
public bool IsSupersetOf(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
foreach ($typemap(cstype, T) item in other) {
if (!Contains(item))
return false;
}
return true;
}
public bool Overlaps(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
foreach ($typemap(cstype, T) item in other) {
if (Contains(item))
return true;
}
return false;
}
public bool SetEquals(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
return IsSupersetOf(other) && Count == count_enum(other);
}
public void SymmetricExceptWith(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
foreach ($typemap(cstype, T) item in other) {
if (!Remove(item))
Add(item);
}
}
public void UnionWith(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
foreach ($typemap(cstype, T) item in other) {
Add(item);
}
}
private global::System.Collections.Generic.ICollection<$typemap(cstype, T)> Items {
get {
global::System.Collections.Generic.ICollection<$typemap(cstype, T)> items = new global::System.Collections.Generic.List<$typemap(cstype, T)>();
int size = this.Count;
if (size > 0) {
global::System.IntPtr iter = create_iterator_begin();
for (int i = 0; i < size; i++) {
items.Add(get_next(iter));
}
destroy_iterator(iter);
}
return items;
}
}
global::System.Collections.Generic.IEnumerator<$typemap(cstype, T)> global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)>.GetEnumerator() {
return new $csclassnameEnumerator(this);
}
global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() {
return new $csclassnameEnumerator(this);
}
public $csclassnameEnumerator GetEnumerator() {
return new $csclassnameEnumerator(this);
}
// Type-safe enumerator
/// Note that the IEnumerator documentation requires an InvalidOperationException to be thrown
/// whenever the collection is modified. This has been done for changes in the size of the
/// collection but not when one of the elements of the collection is modified as it is a bit
/// tricky to detect unmanaged code that modifies the collection under our feet.
public sealed class $csclassnameEnumerator : global::System.Collections.IEnumerator,
global::System.Collections.Generic.IEnumerator<$typemap(cstype, T)>
{
private $csclassname collectionRef;
private global::System.Collections.Generic.IList<$typemap(cstype, T)> ItemsCollection;
private int currentIndex;
private object currentObject;
private int currentSize;
public $csclassnameEnumerator($csclassname collection) {
collectionRef = collection;
ItemsCollection = new global::System.Collections.Generic.List<$typemap(cstype, T)>(collection.Items);
currentIndex = -1;
currentObject = null;
currentSize = collectionRef.Count;
}
// Type-safe iterator Current
public $typemap(cstype, T) Current {
get {
if (currentIndex == -1)
throw new global::System.InvalidOperationException("Enumeration not started.");
if (currentIndex > currentSize - 1)
throw new global::System.InvalidOperationException("Enumeration finished.");
if (currentObject == null)
throw new global::System.InvalidOperationException("Collection modified.");
return ($typemap(cstype, T))currentObject;
}
}
// Type-unsafe IEnumerator.Current
object global::System.Collections.IEnumerator.Current {
get {
return Current;
}
}
public bool MoveNext() {
int size = collectionRef.Count;
bool moveOkay = (currentIndex+1 < size) && (size == currentSize);
if (moveOkay) {
currentIndex++;
currentObject = ItemsCollection[currentIndex];
} else {
currentObject = null;
}
return moveOkay;
}
public void Reset() {
currentIndex = -1;
currentObject = null;
if (collectionRef.Count != currentSize) {
throw new global::System.InvalidOperationException("Collection modified.");
}
}
public void Dispose() {
currentIndex = -1;
currentObject = null;
}
}
%}
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T key_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;
set();
set(const set& other);
size_type size() const;
bool empty() const;
%rename(Clear) clear;
void clear();
%extend {
bool Add(const value_type& item) {
return $self->insert(item).second;
}
bool Contains(const value_type& item) {
return $self->count(item) != 0;
}
bool Remove(const value_type& item) {
return $self->erase(item) != 0;
}
const value_type& getitem(const value_type& item) throw (std::out_of_range) {
std::set<T>::iterator iter = $self->find(item);
if (iter == $self->end())
throw std::out_of_range("item not found");
return *iter;
}
// create_iterator_begin(), get_next() and destroy_iterator work together to provide a collection of items to C#
%apply void *VOID_INT_PTR { std::set<T>::iterator *create_iterator_begin }
%apply void *VOID_INT_PTR { std::set<T>::iterator *swigiterator }
std::set<T>::iterator *create_iterator_begin() {
return new std::set<T>::iterator($self->begin());
}
const key_type& get_next(std::set<T>::iterator *swigiterator) {
std::set<T>::iterator iter = *swigiterator;
(*swigiterator)++;
return *iter;
}
void destroy_iterator(std::set<T>::iterator *swigiterator) {
delete swigiterator;
}
}
};
}

View file

@ -5,28 +5,31 @@
* C# implementation
* The C# wrapper is made to look and feel like a C# System.Collections.Generic.List<> collection.
*
* Note that IEnumerable<> is implemented in the proxy class which is useful for using LINQ with
* Note that IEnumerable<> is implemented in the proxy class which is useful for using LINQ with
* C++ std::vector wrappers. The IList<> interface is also implemented to provide enhanced functionality
* whenever we are confident that the required C++ operator== is available. This is the case for when
* whenever we are confident that the required C++ operator== is available. This is the case for when
* T is a primitive type or a pointer. If T does define an operator==, then use the SWIG_STD_VECTOR_ENHANCED
* macro to obtain this enhanced functionality, 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(CSINTERFACE, CONST_REFERENCE, CTYPE...)
%typemap(csinterfaces) std::vector< CTYPE > "global::System.IDisposable, global::System.Collections.IEnumerable\n , global::System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n";
%typemap(cscode) std::vector< CTYPE > %{
public $csclassname(global::System.Collections.ICollection c) : this() {
%typemap(csinterfaces) std::vector< CTYPE > "global::System.IDisposable, global::System.Collections.IEnumerable, global::System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n";
%proxycode %{
public $csclassname(global::System.Collections.IEnumerable c) : this() {
if (c == null)
throw new global::System.ArgumentNullException("c");
foreach ($typemap(cstype, CTYPE) element in c) {
this.Add(element);
}
}
public $csclassname(global::System.Collections.Generic.IEnumerable<$typemap(cstype, CTYPE)> c) : this() {
if (c == null)
throw new global::System.ArgumentNullException("c");
foreach ($typemap(cstype, CTYPE) element in c) {
@ -62,7 +65,7 @@
set {
if (value < size())
throw new global::System.ArgumentOutOfRangeException("Capacity");
reserve((uint)value);
reserve(($typemap(cstype, size_t))value);
}
}
@ -106,6 +109,12 @@
array.SetValue(getitemcopy(index+i), arrayIndex+i);
}
public $typemap(cstype, CTYPE)[] ToArray() {
$typemap(cstype, CTYPE)[] array = new $typemap(cstype, CTYPE)[this.Count];
this.CopyTo(array);
return array;
}
global::System.Collections.Generic.IEnumerator<$typemap(cstype, CTYPE)> global::System.Collections.Generic.IEnumerable<$typemap(cstype, CTYPE)>.GetEnumerator() {
return new $csclassnameEnumerator(this);
}
@ -187,8 +196,13 @@
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef CTYPE value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef CONST_REFERENCE const_reference;
%rename(Clear) clear;
void clear();
%rename(Add) push_back;
@ -198,8 +212,10 @@
void reserve(size_type n);
%newobject GetRange(int index, int count);
%newobject Repeat(CTYPE const& value, int count);
vector();
vector(const vector &other);
%extend {
vector(int capacity) throw (std::out_of_range) {
std::vector< CTYPE >* pv = 0;
@ -324,7 +340,7 @@
std::vector< CTYPE >::iterator it = std::find($self->begin(), $self->end(), value);
if (it != $self->end()) {
$self->erase(it);
return true;
return true;
}
return false;
}
@ -335,7 +351,7 @@
%define SWIG_STD_VECTOR_ENHANCED(CTYPE...)
namespace std {
template<> class vector< CTYPE > {
SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, %arg(CTYPE const&), %arg(CTYPE))
SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, const value_type&, %arg(CTYPE))
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CTYPE)
};
}
@ -368,11 +384,11 @@ 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(IEnumerable, T const&, T)
SWIG_STD_VECTOR_MINIMUM_INTERNAL(IEnumerable, const value_type&, T)
};
// specialization for pointers
template<class T> class vector<T *> {
SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, T *const&, T *)
SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, const value_type&, T *)
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(T *)
};
// bool is specialized in the C++ standard - const_reference in particular
@ -398,4 +414,5 @@ 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>
SWIG_STD_VECTOR_ENHANCED(std::wstring) // also requires a %include <std_wstring.i>

View file

@ -23,7 +23,10 @@ class wstring;
// wstring
%typemap(ctype, out="void *") wstring "wchar_t *"
%typemap(imtype, inattributes="[global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]") wstring "string"
%typemap(imtype,
inattributes="[global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]",
outattributes="[return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]"
) wstring "string"
%typemap(cstype) wstring "string"
%typemap(csdirectorin) wstring "$iminput"
%typemap(csdirectorout) wstring "$cscall"
@ -60,7 +63,10 @@ class wstring;
// const wstring &
%typemap(ctype, out="void *") const wstring & "wchar_t *"
%typemap(imtype, inattributes="[global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]") const wstring & "string"
%typemap(imtype,
inattributes="[global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]",
outattributes="[return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]"
) const wstring & "string"
%typemap(cstype) const wstring & "string"
%typemap(csdirectorin) const wstring & "$iminput"

View file

@ -1,7 +1,5 @@
/* -----------------------------------------------------------------------------
* stl.i
*
* Initial STL definition. extended as needed in each language
* ----------------------------------------------------------------------------- */
%include <std_common.i>

View file

@ -20,6 +20,7 @@ static SWIG_CSharpWStringHelperCallback SWIG_csharp_wstring_callback = NULL;
%pragma(csharp) imclasscode=%{
protected class SWIGWStringHelper {
[return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]
public delegate string SWIGWStringDelegate(global::System.IntPtr message);
static SWIGWStringDelegate wstringDelegate = new SWIGWStringDelegate(CreateWString);

View file

@ -1,7 +1,9 @@
%include <shared_ptr.i>
// Language specific macro implementing all the customisations for handling the smart pointer
%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...)
// %naturalvar is as documented for member variables
%naturalvar TYPE;
%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
@ -10,6 +12,7 @@
//"if (debug_shared) { cout << \"deleting use_count: \" << (*smartarg1).use_count() << \" [\" << (boost::get_deleter<SWIG_null_deleter>(*smartarg1) ? std::string(\"CANNOT BE DETERMINED SAFELY\") : ((*smartarg1).get() ? (*smartarg1)->getValue() : std::string(\"NULL PTR\"))) << \"]\" << endl << flush; }\n"
"(void)arg1; delete smartarg1;"
// Typemap customisations...
// plain value
%typemap(in, canthrow=1) CONST TYPE ($&1_type argp = 0) %{
@ -22,6 +25,18 @@
%typemap(out) CONST TYPE
%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); %}
%typemap(directorin) CONST TYPE
%{ $input = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (new $1_ltype((const $1_ltype &)$1)); %}
%typemap(directorout) CONST TYPE
%{ if (!$input) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Attempt to dereference null $1_type");
return $null;
}
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input;
$result = *smartarg->get();
%}
// 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;
@ -30,6 +45,13 @@
$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0;
%}
%typemap(directorin) CONST TYPE *
%{ $input = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0; %}
%typemap(directorout) CONST TYPE * %{
#error "typemaps for $1_type not available"
%}
// 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);
@ -40,6 +62,13 @@
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE &
%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); %}
%typemap(directorin) CONST TYPE &
%{ $input = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (&$1 SWIG_NO_NULL_DELETER_0); %}
%typemap(directorout) CONST TYPE & %{
#error "typemaps for $1_type not available"
%}
// 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);
@ -47,18 +76,42 @@
%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST&
%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %}
%typemap(directorin) TYPE *CONST&
%{ $input = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0; %}
%typemap(directorout) TYPE *CONST& %{
#error "typemaps for $1_type not available"
%}
// 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; %}
%typemap(directorin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >
%{ $input = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; %}
%typemap(directorout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >
%{ if ($input) {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input;
$result = *smartarg;
}
%}
// 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; %}
%typemap(directorin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &
%{ $input = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; %}
%typemap(directorout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{
#error "typemaps for $1_type not available"
%}
// shared_ptr by pointer
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * ($*1_ltype tempnull)
%{ $1 = $input ? ($1_ltype)$input : &tempnull; %}
@ -66,6 +119,13 @@
%{ $result = ($1 && *$1) ? new $*1_ltype(*($1_ltype)$1) : 0;
if ($owner) delete $1; %}
%typemap(directorin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *
%{ $input = ($1 && *$1) ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; %}
%typemap(directorout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{
#error "typemaps for $1_type not available"
%}
// 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;
@ -73,6 +133,13 @@
%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; %}
%typemap(directorin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *&
%{ $input = ($1 && *$1) ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; %}
%typemap(directorout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{
#error "typemaps for $1_type not available"
%}
// 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"
@ -96,9 +163,22 @@
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)"
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(ddirectorout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "$typemap(dtype, TYPE).swigGetCPtr($dcall)"
%typemap(ddirectorin) CONST TYPE,
CONST TYPE *,
CONST TYPE &,
TYPE *CONST& "($winput is null) ? null : new $typemap(dtype, TYPE)($winput, true)"
%typemap(ddirectorin) 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 > *& "($winput is null) ? null : new $typemap(dtype, TYPE)($winput, true)"
%typemap(dout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
void* cPtr = $imcall;
@ -141,8 +221,7 @@
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.
// Proxy classes (base classes, ie, not derived classes)
%typemap(dbody) SWIGTYPE %{
private void* swigCPtr;
private bool swigCMemOwn;
@ -157,6 +236,7 @@ public static void* swigGetCPtr(typeof(this) obj) {
}
%}
// Derived proxy classes
%typemap(dbody_derived) SWIGTYPE %{
private void* swigCPtr;
private bool swigCMemOwn;
@ -197,5 +277,17 @@ public static void* swigGetCPtr(typeof(this) obj) {
}
}
// Typecheck typemaps
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *")
TYPE CONST,
TYPE CONST &,
TYPE CONST *,
TYPE *CONST&,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *&
""
%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
%enddef

View file

@ -33,7 +33,7 @@
// 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 {
%typemap(ddispose, methodname="dispose", methodmodifiers="public", parameters="") SWIGTYPE {
synchronized(this) {
if (swigCPtr !is null) {
if (swigCMemOwn) {
@ -45,7 +45,7 @@
}
}
%typemap(ddispose_derived, methodname="dispose", methodmodifiers="public") SWIGTYPE {
%typemap(ddispose_derived, methodname="dispose", methodmodifiers="public", parameters="") SWIGTYPE {
synchronized(this) {
if (swigCPtr !is null) {
if (swigCMemOwn) {

View file

@ -8,3 +8,4 @@
#define %dconstvalue(value) %feature("d:constvalue",value)
#define %dmethodmodifiers %feature("d:methodmodifiers")
#define %dnothrowexception %feature("except")
#define %proxycode %insert("proxycode")

View file

@ -40,6 +40,10 @@ namespace Swig {
public:
DirectorPureVirtualException(const char *msg) : DirectorException(std::string("Attempted to invoke pure virtual method ") + msg) {
}
static void raise(const char *msg) {
throw DirectorPureVirtualException(msg);
}
};
}

View file

@ -43,6 +43,8 @@
return ret;
}
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
/*
* Helper functions to pack/unpack arbitrary binary data (member function

View file

@ -20,7 +20,7 @@
/*
* 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.
* cases are handled below.
*/
%define SWIG_D_PRIMITIVE(TYPE, DTYPE)
%typemap(ctype) TYPE, const TYPE & "TYPE"

View file

@ -162,7 +162,7 @@
return ret;
}
// Treat references to arrays like like references to a single element.
// Treat references to arrays like references to a single element.
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
@ -182,3 +182,16 @@
$*dclassname ret = (cPtr is null) ? null : new $*dclassname(cPtr, $owner);$excode
return ret;
}
%typemap(directorin) SWIGTYPE *const&
"$input = (void *) $1;"
%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE *const&
%{ static $*1_ltype swig_temp;
swig_temp = ($*1_ltype)$input;
$result = &swig_temp; %}
%typemap(ddirectorin,
nativepointer="cast($dtype)$winput"
) SWIGTYPE *const& "($winput is null) ? null : new $*dclassname($winput, false)"
%typemap(ddirectorout,
nativepointer="cast(void*)$dcall"
) SWIGTYPE *const& "$*dclassname.swigGetCPtr($dcall)"

View file

@ -7,6 +7,7 @@
* ----------------------------------------------------------------------------- */
%{
#include <typeinfo>
#include <stdexcept>
%}
@ -16,6 +17,7 @@ namespace std
struct exception {};
}
%typemap(throws, canthrow=1) std::bad_cast "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
%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;"

View file

@ -16,44 +16,47 @@
#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> &);
template<class K, class T, class C = std::less<K> > class map {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef K key_type;
typedef T mapped_type;
typedef std::pair< const K, T > value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
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();
}
map();
map(const map& other);
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, C >::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, C >::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, C >::iterator i = self->find(key);
return i != self->end();
}
}
};
}

View file

@ -18,12 +18,14 @@
namespace std {
template<class T, class U> struct pair {
typedef T first_type;
typedef U second_type;
pair();
pair(T t, U u);
pair(const pair& p);
pair(T first, U second);
pair(const pair& other);
template <class U1, class U2> pair(const pair<U1, U2> &p);
template <class U1, class U2> pair(const pair<U1, U2> &other);
T first;
U second;

View file

@ -24,7 +24,7 @@
%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 > %{
%proxycode %{
public this($typemap(dtype, CTYPE)[] values) {
this();
append(values);
@ -104,15 +104,22 @@ public void capacity(size_t value) {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef CTYPE value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
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;
@ -128,7 +135,7 @@ public void capacity(size_t value) {
return $self->capacity() - $self->size();
}
CONST_REFERENCE remove() throw (std::out_of_range) {
const_reference remove() throw (std::out_of_range) {
if ($self->empty()) {
throw std::out_of_range("Tried to remove last element from empty vector.");
}
@ -138,7 +145,7 @@ public void capacity(size_t value) {
return value;
}
CONST_REFERENCE remove(size_type index) throw (std::out_of_range) {
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.");
}
@ -153,7 +160,7 @@ public void capacity(size_t 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) {
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.");
}
@ -185,7 +192,7 @@ static import std.exception;
static import std.range;
static import std.traits;
%}
%typemap(dcode) std::vector< CTYPE > %{
%proxycode %{
alias size_t KeyType;
alias $typemap(dtype, CTYPE) ValueType;
@ -442,8 +449,13 @@ int opApply(int delegate(ref size_t index, ref $typemap(dtype, CTYPE) value) dg)
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef CTYPE value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef CONST_REFERENCE const_reference;
bool empty() const;
void clear();
void push_back(CTYPE const& x);
@ -451,8 +463,10 @@ int opApply(int delegate(ref size_t index, ref $typemap(dtype, CTYPE) value) dg)
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;
@ -464,7 +478,7 @@ int opApply(int delegate(ref size_t index, ref $typemap(dtype, CTYPE) value) dg)
return pv;
}
CONST_REFERENCE remove() throw (std::out_of_range) {
const_reference remove() throw (std::out_of_range) {
if ($self->empty()) {
throw std::out_of_range("Tried to remove last element from empty vector.");
}
@ -474,7 +488,7 @@ int opApply(int delegate(ref size_t index, ref $typemap(dtype, CTYPE) value) dg)
return value;
}
CONST_REFERENCE remove(size_type index) throw (std::out_of_range) {
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.");
}
@ -506,7 +520,7 @@ int opApply(int delegate(ref size_t index, ref $typemap(dtype, CTYPE) value) dg)
// 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) {
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.");
}
@ -544,7 +558,7 @@ int opApply(int delegate(ref size_t index, ref $typemap(dtype, CTYPE) value) dg)
%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_MINIMUM_INTERNAL(const value_type&, %arg(CTYPE))
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CTYPE)
};
}
@ -559,11 +573,11 @@ 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)
SWIG_STD_VECTOR_MINIMUM_INTERNAL(const value_type&, T)
};
// specializations for pointers
template<class T> class vector<T *> {
SWIG_STD_VECTOR_MINIMUM_INTERNAL(T *const&, T *)
SWIG_STD_VECTOR_MINIMUM_INTERNAL(const value_type&, T *)
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(T *)
};
// bool is a bit different in the C++ standard - const_reference in particular

View file

@ -1,7 +1,5 @@
/* -----------------------------------------------------------------------------
* stl.i
*
* Initial STL definition. extended as needed in each language
* ----------------------------------------------------------------------------- */
%include <std_common.i>

View file

@ -12,10 +12,10 @@
%insert("runtime") "swigerrors.swg"
#ifdef SWIGPHP
#ifdef SWIGPHP7
%{
#include "zend_exceptions.h"
#define SWIG_exception(code, msg) zend_throw_exception(NULL, (char*)msg, code TSRMLS_CC)
#define SWIG_exception(code, msg) do { zend_throw_exception(NULL, (char*)msg, code); goto thrown; } while (0)
%}
#endif
@ -127,33 +127,48 @@ SWIGINTERN void SWIG_JavaException(JNIEnv *jenv, int code, const char *msg) {
#ifdef SWIGOCAML
%{
#define OCAML_MSG_BUF_LEN 1024
SWIGINTERN void SWIG_exception_(int code, const char *msg) {
char msg_buf[OCAML_MSG_BUF_LEN];
sprintf( msg_buf, "Exception(%d): %s\n", code, msg );
failwith( msg_buf );
SWIGINTERN void SWIG_OCamlException(int code, const char *msg) {
CAMLparam0();
SWIG_OCamlExceptionCodes exception_code = SWIG_OCamlUnknownError;
switch (code) {
case SWIG_DivisionByZero:
exception_code = SWIG_OCamlArithmeticException;
break;
case SWIG_IndexError:
exception_code = SWIG_OCamlIndexOutOfBoundsException;
break;
case SWIG_IOError:
case SWIG_SystemError:
exception_code = SWIG_OCamlSystemException;
break;
case SWIG_MemoryError:
exception_code = SWIG_OCamlOutOfMemoryError;
break;
case SWIG_OverflowError:
exception_code = SWIG_OCamlOverflowException;
break;
case SWIG_RuntimeError:
exception_code = SWIG_OCamlRuntimeException;
break;
case SWIG_SyntaxError:
case SWIG_TypeError:
case SWIG_ValueError:
exception_code = SWIG_OCamlIllegalArgumentException;
break;
case SWIG_UnknownError:
default:
exception_code = SWIG_OCamlUnknownError;
break;
}
SWIG_OCamlThrowException(exception_code, msg);
CAMLreturn0;
}
#define SWIG_exception(a,b) SWIG_exception_((a),(b))
#define SWIG_exception(code, msg) SWIG_OCamlException(code, msg)
%}
#endif
#ifdef SWIGCHICKEN
%{
SWIGINTERN void SWIG_exception_(int code, const char *msg) {
C_word *a;
C_word scmmsg;
C_word list;
a = C_alloc (C_SIZEOF_STRING (strlen (msg)) + C_SIZEOF_LIST(2));
scmmsg = C_string2 (&a, (char *) msg);
list = C_list(&a, 2, C_fix(code), scmmsg);
SWIG_ThrowException(list);
}
#define SWIG_exception(a,b) SWIG_exception_((a),(b))
%}
#endif
#ifdef SWIGCSHARP
%{
SWIGINTERN void SWIG_CSharpException(int code, const char *msg) {
@ -258,6 +273,7 @@ SWIGINTERN void SWIG_DThrowException(int code, const char *msg) {
}
*/
%{
#include <typeinfo>
#include <stdexcept>
%}
%define SWIG_CATCH_STDEXCEPT
@ -274,6 +290,8 @@ SWIGINTERN void SWIG_DThrowException(int code, const char *msg) {
SWIG_exception(SWIG_IndexError, e.what() );
} catch (std::runtime_error& e) {
SWIG_exception(SWIG_RuntimeError, e.what() );
} catch (std::bad_cast& e) {
SWIG_exception(SWIG_TypeError, e.what() );
} catch (std::exception& e) {
SWIG_exception(SWIG_SystemError, e.what() );
}

View file

@ -1,39 +0,0 @@
%{
#include <gcj/cni.h>
%}
%include <gcj/javaprims.i>
extern void JvInitClass (jclass cls);
extern jstring JvAllocString (jsize sz);
extern jstring JvNewString (const jchar *chars, jsize len);
extern jstring JvNewStringLatin1 (const char *bytes, jsize len);
extern jstring JvNewStringLatin1 (const char *bytes);
extern jchar* JvGetStringChars (jstring str);
extern jsize JvGetStringUTFLength (jstring string);
extern jsize JvGetStringUTFRegion (jstring str, jsize start, jsize len, char *buf);
extern jstring JvNewStringUTF (const char *bytes);
extern void *JvMalloc (jsize size);
extern void JvFree (void *ptr);
extern jint JvCreateJavaVM (JvVMInitArgs* vm_args);
extern java::lang::Thread* JvAttachCurrentThread (jstring name, java::lang::ThreadGroup* group);
extern java::lang::Thread* JvAttachCurrentThreadAsDaemon (jstring name, java::lang::ThreadGroup* group);
extern jint JvDetachCurrentThread (void);
%include <gcj/cni.swg>

View file

@ -1,14 +0,0 @@
/* -----------------------------------------------------------------------------
* cni.swg
* ----------------------------------------------------------------------------- */
#ifdef SWIG
#define __attribute__(...)
%ignore class$;
#pragma SWIG nowarn=313,402
%nodefaultdtor;
#endif

View file

@ -1,422 +0,0 @@
%include <stdint.i>
typedef int8_t jbyte;
typedef int16_t jshort;
typedef int32_t jint;
typedef int64_t jlong;
typedef float jfloat;
typedef double jdouble;
typedef jint jsize;
typedef int8_t jboolean;
extern "Java"
{
namespace java
{
namespace io
{
class BufferedInputStream;
class BufferedOutputStream;
class BufferedReader;
class BufferedWriter;
class ByteArrayInputStream;
class ByteArrayOutputStream;
class CharArrayReader;
class CharArrayWriter;
class CharConversionException;
class DataInput;
class DataInputStream;
class DataOutput;
class DataOutputStream;
class EOFException;
class Externalizable;
class File;
class FileDescriptor;
class FileFilter;
class FileInputStream;
class FileNotFoundException;
class FileOutputStream;
class FilePermission;
class FileReader;
class FileWriter;
class FilenameFilter;
class FilterInputStream;
class FilterOutputStream;
class FilterReader;
class FilterWriter;
class IOException;
class InputStream;
class InputStreamReader;
class InterfaceComparator;
class InterruptedIOException;
class InvalidClassException;
class InvalidObjectException;
class LineNumberInputStream;
class LineNumberReader;
class MemberComparator;
class NotActiveException;
class NotSerializableException;
class ObjectInput;
class ObjectInputStream;
class ObjectInputStream$GetField;
class ObjectInputValidation;
class ObjectOutput;
class ObjectOutputStream;
class ObjectOutputStream$PutField;
class ObjectStreamClass;
class ObjectStreamConstants;
class ObjectStreamException;
class ObjectStreamField;
class OptionalDataException;
class OutputStream;
class OutputStreamWriter;
class PipedInputStream;
class PipedOutputStream;
class PipedReader;
class PipedWriter;
class PrintStream;
class PrintWriter;
class PushbackInputStream;
class PushbackReader;
class RandomAccessFile;
class Reader;
class SequenceInputStream;
class Serializable;
class SerializablePermission;
class StreamCorruptedException;
class StreamTokenizer;
class StringBufferInputStream;
class StringReader;
class StringWriter;
class SyncFailedException;
class UTFDataFormatException;
class UnsupportedEncodingException;
class VMObjectStreamClass;
class ValidatorAndPriority;
class WriteAbortedException;
class Writer;
}
namespace lang
{
class AbstractMethodError;
class ArithmeticException;
class ArrayIndexOutOfBoundsException;
class ArrayStoreException;
class AssertionError;
class Boolean;
class Byte;
class CharSequence;
class Character;
class Character$Subset;
class Character$UnicodeBlock;
class Class;
class ClassCastException;
class ClassCircularityError;
class ClassFormatError;
class ClassLoader;
class ClassNotFoundException;
class CloneNotSupportedException;
class Cloneable;
class Comparable;
class Compiler;
class ConcreteProcess;
class Double;
class Error;
class Exception;
class ExceptionInInitializerError;
class Float;
class IllegalAccessError;
class IllegalAccessException;
class IllegalArgumentException;
class IllegalMonitorStateException;
class IllegalStateException;
class IllegalThreadStateException;
class IncompatibleClassChangeError;
class IndexOutOfBoundsException;
class InheritableThreadLocal;
class InstantiationError;
class InstantiationException;
class Integer;
class InternalError;
class InterruptedException;
class LinkageError;
class Long;
class Math;
class NegativeArraySizeException;
class NoClassDefFoundError;
class NoSuchFieldError;
class NoSuchFieldException;
class NoSuchMethodError;
class NoSuchMethodException;
class NullPointerException;
class Number;
class NumberFormatException;
class Object;
class OutOfMemoryError;
class Package;
class Process;
class Runnable;
class Runtime;
class RuntimeException;
class RuntimePermission;
class SecurityContext;
class SecurityException;
class SecurityManager;
class Short;
class StackOverflowError;
class StackTraceElement;
class StrictMath;
class String;
class String$CaseInsensitiveComparator;
class StringBuffer;
class StringIndexOutOfBoundsException;
class System;
class Thread;
class ThreadDeath;
class ThreadGroup;
class ThreadLocal;
class Throwable;
class UnknownError;
class UnsatisfiedLinkError;
class UnsupportedClassVersionError;
class UnsupportedOperationException;
class VMClassLoader;
class VMSecurityManager;
class VMThrowable;
class VerifyError;
class VirtualMachineError;
class Void;
namespace ref
{
class PhantomReference;
class Reference;
class ReferenceQueue;
class SoftReference;
class WeakReference;
}
namespace reflect
{
class AccessibleObject;
class Array;
class Constructor;
class Field;
class InvocationHandler;
class InvocationTargetException;
class Member;
class Method;
class Modifier;
class Proxy;
class Proxy$ClassFactory;
class Proxy$ProxyData;
class Proxy$ProxySignature;
class Proxy$ProxyType;
class ReflectPermission;
class UndeclaredThrowableException;
}
}
namespace util
{
class AbstractCollection;
class AbstractList;
class AbstractMap;
class AbstractMap$BasicMapEntry;
class AbstractSequentialList;
class AbstractSet;
class ArrayList;
class Arrays;
class Arrays$ArrayList;
class BitSet;
class Calendar;
class Collection;
class Collections;
class Collections$CopiesList;
class Collections$EmptyList;
class Collections$EmptyMap;
class Collections$EmptySet;
class Collections$ReverseComparator;
class Collections$SingletonList;
class Collections$SingletonMap;
class Collections$SingletonSet;
class Collections$SynchronizedCollection;
class Collections$SynchronizedIterator;
class Collections$SynchronizedList;
class Collections$SynchronizedListIterator;
class Collections$SynchronizedMap;
class Collections$SynchronizedMapEntry;
class Collections$SynchronizedRandomAccessList;
class Collections$SynchronizedSet;
class Collections$SynchronizedSortedMap;
class Collections$SynchronizedSortedSet;
class Collections$UnmodifiableCollection;
class Collections$UnmodifiableEntrySet;
class Collections$UnmodifiableIterator;
class Collections$UnmodifiableList;
class Collections$UnmodifiableListIterator;
class Collections$UnmodifiableMap;
class Collections$UnmodifiableRandomAccessList;
class Collections$UnmodifiableSet;
class Collections$UnmodifiableSortedMap;
class Collections$UnmodifiableSortedSet;
class Comparator;
class ConcurrentModificationException;
class Currency;
class Date;
class Dictionary;
class EmptyStackException;
class Enumeration;
class EventListener;
class EventListenerProxy;
class EventObject;
class GregorianCalendar;
class HashMap;
class HashMap$HashEntry;
class HashMap$HashIterator;
class HashSet;
class Hashtable;
class Hashtable$Enumerator;
class Hashtable$HashEntry;
class Hashtable$HashIterator;
class IdentityHashMap;
class IdentityHashMap$IdentityEntry;
class IdentityHashMap$IdentityIterator;
class Iterator;
class LinkedHashMap;
class LinkedHashMap$LinkedHashEntry;
class LinkedHashSet;
class LinkedList;
class LinkedList$Entry;
class LinkedList$LinkedListItr;
class List;
class ListIterator;
class ListResourceBundle;
class Locale;
class Map;
class Map$Entry;
class Map$Map;
class MissingResourceException;
class MyResources;
class NoSuchElementException;
class Observable;
class Observer;
class Properties;
class PropertyPermission;
class PropertyPermissionCollection;
class PropertyResourceBundle;
class Random;
class RandomAccess;
class RandomAccessSubList;
class ResourceBundle;
class Set;
class SimpleTimeZone;
class SortedMap;
class SortedSet;
class Stack;
class StringTokenizer;
class SubList;
class TimeZone;
class Timer;
class Timer$Scheduler;
class Timer$TaskQueue;
class TimerTask;
class TooManyListenersException;
class TreeMap;
class TreeMap$Node;
class TreeMap$SubMap;
class TreeMap$TreeIterator;
class TreeSet;
class Vector;
class WeakHashMap;
class WeakHashMap$WeakBucket;
class WeakHashMap$WeakEntry;
class WeakHashMap$WeakEntrySet;
namespace jar
{
class Attributes;
class Attributes$Name;
class JarEntry;
class JarException;
class JarFile;
class JarFile$JarEnumeration;
class JarInputStream;
class JarOutputStream;
class Manifest;
}
namespace logging
{
class ConsoleHandler;
class ErrorManager;
class FileHandler;
class Filter;
class Formatter;
class Handler;
class Level;
class LogManager;
class LogRecord;
class Logger;
class LoggingPermission;
class MemoryHandler;
class SimpleFormatter;
class SocketHandler;
class StreamHandler;
class XMLFormatter;
}
namespace prefs
{
class AbstractPreferences;
class BackingStoreException;
class InvalidPreferencesFormatException;
class NodeChangeEvent;
class NodeChangeListener;
class PreferenceChangeEvent;
class PreferenceChangeListener;
class Preferences;
class PreferencesFactory;
}
namespace regex
{
class Matcher;
class Pattern;
class PatternSyntaxException;
}
namespace zip
{
class Adler32;
class CRC32;
class CheckedInputStream;
class CheckedOutputStream;
class Checksum;
class DataFormatException;
class Deflater;
class DeflaterOutputStream;
class GZIPInputStream;
class GZIPOutputStream;
class Inflater;
class InflaterInputStream;
class ZipConstants;
class ZipEntry;
class ZipException;
class ZipFile;
class ZipFile$PartialInputStream;
class ZipFile$ZipEntryEnumeration;
class ZipInputStream;
class ZipOutputStream;
}
}
}
}
typedef class java::lang::Object* jobject;
typedef class java::lang::Class* jclass;
typedef class java::lang::Throwable* jthrowable;
typedef class java::lang::String* jstring;
%include <gcj/cni.swg>

80
Lib/go/director.swg Normal file
View file

@ -0,0 +1,80 @@
/* -----------------------------------------------------------------------------
* director.swg
*
* This file contains support for director classes so that Go proxy
* methods can be called from C++.
* ----------------------------------------------------------------------------- */
#include <exception>
#include <map>
namespace Swig {
class DirectorException : public std::exception {
};
}
/* Handle memory management for directors. */
namespace {
struct GCItem {
virtual ~GCItem() {}
};
struct GCItem_var {
GCItem_var(GCItem *item = 0) : _item(item) {
}
GCItem_var& operator=(GCItem *item) {
GCItem *tmp = _item;
_item = item;
delete tmp;
return *this;
}
~GCItem_var() {
delete _item;
}
GCItem* operator->() {
return _item;
}
private:
GCItem *_item;
};
template <typename Type>
struct GCItem_T : GCItem {
GCItem_T(Type *ptr) : _ptr(ptr) {
}
virtual ~GCItem_T() {
delete _ptr;
}
private:
Type *_ptr;
};
}
class Swig_memory {
public:
template <typename Type>
void swig_acquire_pointer(Type* vptr) {
if (vptr) {
swig_owner[vptr] = new GCItem_T<Type>(vptr);
}
}
private:
typedef std::map<void *, GCItem_var> swig_ownership_map;
swig_ownership_map swig_owner;
};
template <typename Type>
static void swig_acquire_pointer(Swig_memory** pmem, Type* ptr) {
if (!pmem) {
*pmem = new Swig_memory;
}
(*pmem)->swig_acquire_pointer(ptr);
}

View file

@ -341,8 +341,6 @@
%typemap(directorout) SWIGTYPE *
%{ $result = *($&1_ltype)&$input; %}
%apply SWIGTYPE * { SWIGTYPE *const }
/* Pointer references. */
%typemap(gotype) SWIGTYPE *const&
@ -382,6 +380,11 @@
%typemap(directorout) SWIGTYPE &
%{ *($&1_ltype)&$result = $input; %}
%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE *const&
%{ static $*1_ltype swig_temp;
swig_temp = *($1_ltype)&$input;
$result = &swig_temp; %}
%typemap(gotype) SWIGTYPE &&
%{$gotypename%}
@ -692,6 +695,10 @@
SWIGTYPE (CLASS::*)
""
%apply SWIGTYPE * { SWIGTYPE *const }
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
/* Go keywords. */
%include <gokw.swg>

View file

@ -346,75 +346,6 @@ type _swig_fnptr *byte
type _swig_memberptr *byte
%}
/* Handle memory management for directors. */
%insert(director) %{
#include <map>
namespace {
struct GCItem {
virtual ~GCItem() {}
};
struct GCItem_var {
GCItem_var(GCItem *item = 0) : _item(item) {
}
GCItem_var& operator=(GCItem *item) {
GCItem *tmp = _item;
_item = item;
delete tmp;
return *this;
}
~GCItem_var() {
delete _item;
}
GCItem* operator->() {
return _item;
}
private:
GCItem *_item;
};
template <typename Type>
struct GCItem_T : GCItem {
GCItem_T(Type *ptr) : _ptr(ptr) {
}
virtual ~GCItem_T() {
delete _ptr;
}
private:
Type *_ptr;
};
}
class Swig_memory {
public:
template <typename Type>
void swig_acquire_pointer(Type* vptr) {
if (vptr) {
swig_owner[vptr] = new GCItem_T<Type>(vptr);
}
}
private:
typedef std::map<void *, GCItem_var> swig_ownership_map;
swig_ownership_map swig_owner;
};
template <typename Type>
static void swig_acquire_pointer(Swig_memory** pmem, Type* ptr) {
if (!pmem) {
*pmem = new Swig_memory;
}
(*pmem)->swig_acquire_pointer(ptr);
}
%}
/* For directors we need C++ to track a Go pointer. Since we can't
pass a Go pointer into C++, we use a map to track the pointers on
the Go side. */

View file

@ -7,6 +7,7 @@
* ----------------------------------------------------------------------------- */
%{
#include <typeinfo>
#include <stdexcept>
%}
@ -16,6 +17,7 @@ namespace std
struct exception {};
}
%typemap(throws) std::bad_cast %{_swig_gopanic($1.what());%}
%typemap(throws) std::bad_exception %{_swig_gopanic($1.what());%}
%typemap(throws) std::domain_error %{_swig_gopanic($1.what());%}
%typemap(throws) std::exception %{_swig_gopanic($1.what());%}

View file

@ -1,5 +1,5 @@
/* -----------------------------------------------------------------------------
* std_vector.i
* std_list.i
* ----------------------------------------------------------------------------- */
%{
@ -9,7 +9,7 @@
namespace std {
template<class T, class Alloc = allocator<T> >
template<class T>
class list {
public:
typedef size_t size_type;
@ -19,9 +19,10 @@ namespace std {
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef Alloc allocator_type;
list();
list(const list& other);
size_type size() const;
bool empty() const;
%rename(isEmpty) empty;

View file

@ -20,22 +20,28 @@
namespace std {
template<class K, class T> class map {
template<class K, class T, class C = std::less<K> > class map {
// add typemaps here
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef K key_type;
typedef T mapped_type;
typedef std::pair< const K, T > value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
map();
map(const map<K,T> &);
map(const map& other);
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);
std::map< K, T, C >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
@ -45,14 +51,14 @@ namespace std {
(*self)[key] = x;
}
void del(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
std::map< K, T, C >::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);
std::map< K, T, C >::iterator i = self->find(key);
return i != self->end();
}
}

View file

@ -18,12 +18,14 @@
namespace std {
template<class T, class U> struct pair {
typedef T first_type;
typedef U second_type;
pair();
pair(T first, U second);
pair(const pair& p);
pair(const pair& other);
template <class U1, class U2> pair(const pair<U1, U2> &p);
template <class U1, class U2> pair(const pair<U1, U2> &other);
T first;
U second;

View file

@ -12,10 +12,17 @@ namespace std {
template<class T> class vector {
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;
vector();
vector(size_type n);
vector(const vector& other);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);
@ -46,10 +53,17 @@ namespace std {
template<> class vector<bool> {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef bool value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef bool const_reference;
vector();
vector(size_type n);
vector(const vector& other);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);

View file

@ -7,3 +7,4 @@
%include <std_vector.i>
%include <std_map.i>
%include <std_pair.i>

View file

@ -8,6 +8,7 @@
#define SWIGGUILE_SCM
%runtime "swigrun.swg" // Common C API type-checking code
%runtime "swigerrors.swg" // SWIG errors
%runtime "guile_scm_run.swg"
%include <guile.i>
@ -26,10 +27,10 @@
else { \
if (!gswig_list_p) { \
gswig_list_p = 1; \
gswig_result = scm_listify(gswig_result, object, SCM_UNDEFINED); \
gswig_result = scm_list_n(gswig_result, object, SCM_UNDEFINED); \
} \
else \
gswig_result = scm_append(scm_listify(gswig_result, scm_listify(object, SCM_UNDEFINED), SCM_UNDEFINED)); \
gswig_result = scm_append(scm_list_n(gswig_result, scm_list_n(object, SCM_UNDEFINED), SCM_UNDEFINED)); \
}
%}

View file

@ -24,6 +24,8 @@ scm_module_variable (SCM module, SCM sym)
return scm_sym2var (sym, scm_module_lookup_closure (module), SCM_BOOL_F);
}
#define scm_to_utf8_string scm_to_locale_string
#define scm_from_utf8_string scm_from_locale_string
#endif
#if SCM_MAJOR_VERSION >= 2
@ -40,10 +42,6 @@ typedef struct swig_guile_clientdata {
SCM goops_class;
} swig_guile_clientdata;
#if SCM_MAJOR_VERSION <= 2
#define scm_to_utf8_string scm_to_locale_string
#define scm_from_utf8_string scm_from_locale_string
#endif
#define SWIG_scm2str(s) \
SWIG_Guile_scm2newstr(s, NULL)
#define SWIG_str02scm(str) \
@ -101,6 +99,7 @@ SWIG_Guile_scm2newstr(SCM str, size_t *len) {
static int swig_initialized = 0;
static scm_t_bits swig_tag = 0;
static scm_t_bits swig_collectable_tag = 0;
static scm_t_bits swig_finalized_tag = 0;
static scm_t_bits swig_destroyed_tag = 0;
static scm_t_bits swig_member_function_tag = 0;
static SCM swig_make_func = SCM_EOL;
@ -165,7 +164,19 @@ SWIG_Guile_PointerType(SCM object)
}
else scm_wrong_type_arg("SWIG-Guile-PointerType", 1, object);
}
SWIGINTERN int
SWIG_Guile_IsValidSmob(SCM smob)
{
/* We do not accept smobs representing destroyed pointers, but we have to
allow finalized smobs because Guile >= 2.0.12 sets all smob instances
to the 'finalized' type before calling their 'free' function. This change
was introduced to Guile in commit 8dff3af087c6eaa83ae0d72aa8b22aef5c65d65d */
return SCM_SMOB_PREDICATE(swig_tag, smob)
|| SCM_SMOB_PREDICATE(swig_collectable_tag, smob)
|| SCM_SMOB_PREDICATE(swig_finalized_tag, smob);
}
SWIGINTERN int
SWIG_Guile_ConvertPtr(SCM s, void **result, swig_type_info *type, int flags)
{
@ -175,9 +186,13 @@ SWIG_Guile_ConvertPtr(SCM s, void **result, swig_type_info *type, int flags)
if (SCM_NULLP(smob)) {
*result = NULL;
return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
#if SCM_MAJOR_VERSION >= 2
} else if (SCM_POINTER_P(s)) {
*result = SCM_POINTER_VALUE(s);
return SWIG_OK;
} else if (SCM_SMOB_PREDICATE(swig_tag, smob) || SCM_SMOB_PREDICATE(swig_collectable_tag, smob)) {
/* we do not accept smobs representing destroyed pointers */
#endif /* if SCM_MAJOR_VERSION >= 2 */
} else if (SWIG_Guile_IsValidSmob(smob)) {
from = (swig_type_info *) SCM_CELL_WORD_2(smob);
if (!from) return SWIG_ERROR;
if (type) {
@ -236,7 +251,7 @@ SWIG_Guile_MarkPointerNoncollectable(SCM s)
{
SCM smob = SWIG_Guile_GetSmob(s);
if (!SCM_NULLP(smob)) {
if (SCM_SMOB_PREDICATE(swig_tag, smob) || SCM_SMOB_PREDICATE(swig_collectable_tag, smob)) {
if (SWIG_Guile_IsValidSmob(smob)) {
SCM_SET_CELL_TYPE(smob, swig_tag);
}
else scm_wrong_type_arg(NULL, 0, s);
@ -249,7 +264,7 @@ SWIG_Guile_MarkPointerDestroyed(SCM s)
{
SCM smob = SWIG_Guile_GetSmob(s);
if (!SCM_NULLP(smob)) {
if (SCM_SMOB_PREDICATE(swig_tag, smob) || SCM_SMOB_PREDICATE(swig_collectable_tag, smob)) {
if (SWIG_Guile_IsValidSmob(smob)) {
SCM_SET_CELL_TYPE(smob, swig_destroyed_tag);
}
else scm_wrong_type_arg(NULL, 0, s);
@ -416,6 +431,8 @@ SWIG_Guile_Init ()
scm_set_smob_print(swig_collectable_tag, print_collectable_swig);
scm_set_smob_equalp(swig_collectable_tag, equalp_swig);
scm_set_smob_free(swig_collectable_tag, free_swig);
/* For Guile >= 2.0.12. See libguile/smob.c:clear_smobnum */
swig_finalized_tag = swig_collectable_tag & ~0xff00;
}
if (ensure_smob_tag(swig_module, &swig_destroyed_tag,
"destroyed-swig-pointer", "destroyed-swig-pointer-tag")) {

View file

@ -12,11 +12,6 @@
extern "C" {
#endif
/* Debugger interface (don't change the order of the following lines) */
#define GDB_TYPE SCM
#include <libguile/gdb_interface.h>
GDB_INTERFACE;
static void
inner_main(void *closure, int argc, char **argv)
{

View file

@ -14,7 +14,8 @@
%{
#include <string>
inline std::string SWIG_scm2string(SCM x) {
SWIGINTERNINLINE
std::string SWIG_scm2string(SCM x) {
char* temp;
temp = SWIG_scm2str(x);
std::string s(temp);

View file

@ -1,6 +1,7 @@
// TODO: STL exception handling
// Note that the generic std_except.i file did not work
%{
#include <typeinfo>
#include <stdexcept>
%}

View file

@ -40,12 +40,12 @@
namespace std {
template<class K, class T> class map {
%typemap(in) map<K,T> {
template<class K, class T, class C = std::less<K> > class map {
%typemap(in) map< K, T, C > {
if (scm_is_null($input)) {
$1 = std::map< K, T >();
$1 = std::map< K, T, C >();
} else if (scm_is_pair($input)) {
$1 = std::map< K, T >();
$1 = std::map< K, T, C >();
SCM alist = $input;
while (!scm_is_null(alist)) {
K* k;
@ -72,13 +72,13 @@ namespace std {
SWIG_MustGetPtr($input,$&1_descriptor,$argnum, 0));
}
}
%typemap(in) const map<K,T>& (std::map<K,T> temp),
const map<K,T>* (std::map<K,T> temp) {
%typemap(in) const map< K, T, C >& (std::map< K, T, C > temp),
const map< K, T, C >* (std::map< K, T, C > temp) {
if (scm_is_null($input)) {
temp = std::map< K, T >();
temp = std::map< K, T, C >();
$1 = &temp;
} else if (scm_is_pair($input)) {
temp = std::map< K, T >();
temp = std::map< K, T, C >();
$1 = &temp;
SCM alist = $input;
while (!scm_is_null(alist)) {
@ -105,9 +105,9 @@ namespace std {
$1 = ($1_ltype) SWIG_MustGetPtr($input,$1_descriptor,$argnum, 0);
}
}
%typemap(out) map<K,T> {
%typemap(out) map< K, T, C > {
SCM alist = SCM_EOL;
for (std::map< K, T >::reverse_iterator i=$i.rbegin(); i!=$i.rend(); ++i) {
for (std::map< K, T, C >::reverse_iterator i=$1.rbegin(); i!=$1.rend(); ++i) {
K* key = new K(i->first);
T* val = new T(i->second);
SCM k = SWIG_NewPointerObj(key,$descriptor(K *), 1);
@ -117,7 +117,7 @@ namespace std {
}
$result = alist;
}
%typecheck(SWIG_TYPECHECK_MAP) map<K,T> {
%typecheck(SWIG_TYPECHECK_MAP) map< K, T, C > {
/* native sequence? */
if (scm_is_null($input)) {
/* an empty sequence can be of any type */
@ -153,7 +153,7 @@ namespace std {
}
} else {
/* wrapped map? */
std::map< K, T >* m;
std::map< K, T, C >* m;
if (SWIG_ConvertPtr($input,(void **) &m,
$&1_descriptor, 0) == 0)
$1 = 1;
@ -161,8 +161,8 @@ namespace std {
$1 = 0;
}
}
%typecheck(SWIG_TYPECHECK_MAP) const map<K,T>&,
const map<K,T>* {
%typecheck(SWIG_TYPECHECK_MAP) const map< K, T, C >&,
const map< K, T, C >* {
/* native sequence? */
if (scm_is_null($input)) {
/* an empty sequence can be of any type */
@ -198,7 +198,7 @@ namespace std {
}
} else {
/* wrapped map? */
std::map< K, T >* m;
std::map< K, T, C >* m;
if (SWIG_ConvertPtr($input,(void **) &m,
$1_descriptor, 0) == 0)
$1 = 1;
@ -218,15 +218,21 @@ namespace std {
typedef ptrdiff_t difference_type;
typedef K key_type;
typedef T mapped_type;
typedef std::pair< const K, T > value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
map();
map(const map< K, T> &);
map(const map& other);
unsigned int size() const;
bool empty() const;
void clear();
%extend {
const T& __getitem__(const K& key) throw (std::out_of_range) {
std::map< K, T >::iterator i = self->find(key);
std::map< K, T, C >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
@ -236,19 +242,19 @@ namespace std {
(*self)[key] = x;
}
void __delitem__(const K& key) throw (std::out_of_range) {
std::map< K, T >::iterator i = self->find(key);
std::map< K, T, C >::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);
std::map< K, T, C >::iterator i = self->find(key);
return i != self->end();
}
SCM keys() {
SCM result = SCM_EOL;
for (std::map< K, T >::reverse_iterator i=self->rbegin(); i!=self->rend(); ++i) {
for (std::map< K, T, C >::reverse_iterator i=self->rbegin(); i!=self->rend(); ++i) {
K* key = new K(i->first);
SCM k = SWIG_NewPointerObj(key,$descriptor(K *), 1);
result = scm_cons(k,result);
@ -263,12 +269,12 @@ namespace std {
%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
template<class T> class map<K,T> {
%typemap(in) map<K,T> {
template<class T> class map< K, T, C > {
%typemap(in) map< K, T, C > {
if (scm_is_null($input)) {
$1 = std::map< K, T >();
$1 = std::map< K, T, C >();
} else if (scm_is_pair($input)) {
$1 = std::map< K, T >();
$1 = std::map< K, T, C >();
SCM alist = $input;
while (!scm_is_null(alist)) {
T* x;
@ -280,7 +286,7 @@ namespace std {
val = SCM_CDR(entry);
if (!CHECK(key))
SWIG_exception(SWIG_TypeError,
"map<" #K "," #T "> expected");
"map<" #K "," #T "," #C "> expected");
if (SWIG_ConvertPtr(val,(void**) &x,
$descriptor(T *), 0) != 0) {
if (!scm_is_pair(val))
@ -296,13 +302,13 @@ namespace std {
SWIG_MustGetPtr($input,$&1_descriptor,$argnum, 0));
}
}
%typemap(in) const map<K,T>& (std::map<K,T> temp),
const map<K,T>* (std::map<K,T> temp) {
%typemap(in) const map< K, T, C >& (std::map< K, T, C > temp),
const map< K, T, C >* (std::map< K, T, C > temp) {
if (scm_is_null($input)) {
temp = std::map< K, T >();
temp = std::map< K, T, C >();
$1 = &temp;
} else if (scm_is_pair($input)) {
temp = std::map< K, T >();
temp = std::map< K, T, C >();
$1 = &temp;
SCM alist = $input;
while (!scm_is_null(alist)) {
@ -315,7 +321,7 @@ namespace std {
val = SCM_CDR(entry);
if (!CHECK(key))
SWIG_exception(SWIG_TypeError,
"map<" #K "," #T "> expected");
"map<" #K "," #T "," #C "> expected");
if (SWIG_ConvertPtr(val,(void**) &x,
$descriptor(T *), 0) != 0) {
if (!scm_is_pair(val))
@ -330,9 +336,9 @@ namespace std {
$1 = ($1_ltype) SWIG_MustGetPtr($input,$1_descriptor,$argnum, 0);
}
}
%typemap(out) map<K,T> {
%typemap(out) map< K, T, C > {
SCM alist = SCM_EOL;
for (std::map< K, T >::reverse_iterator i=$1.rbegin(); i!=$1.rend(); ++i) {
for (std::map< K, T, C >::reverse_iterator i=$1.rbegin(); i!=$1.rend(); ++i) {
T* val = new T(i->second);
SCM k = CONVERT_TO(i->first);
SCM x = SWIG_NewPointerObj(val,$descriptor(T *), 1);
@ -341,7 +347,7 @@ namespace std {
}
$result = alist;
}
%typecheck(SWIG_TYPECHECK_MAP) map<K,T> {
%typecheck(SWIG_TYPECHECK_MAP) map< K, T, C > {
// native sequence?
if (scm_is_null($input)) {
/* an empty sequence can be of any type */
@ -375,7 +381,7 @@ namespace std {
}
} else {
// wrapped map?
std::map< K, T >* m;
std::map< K, T, C >* m;
if (SWIG_ConvertPtr($input,(void **) &m,
$&1_descriptor, 0) == 0)
$1 = 1;
@ -383,8 +389,8 @@ namespace std {
$1 = 0;
}
}
%typecheck(SWIG_TYPECHECK_MAP) const map<K,T>&,
const map<K,T>* {
%typecheck(SWIG_TYPECHECK_MAP) const map< K, T, C >&,
const map< K, T, C >* {
// native sequence?
if (scm_is_null($input)) {
/* an empty sequence can be of any type */
@ -418,7 +424,7 @@ namespace std {
}
} else {
// wrapped map?
std::map< K, T >* m;
std::map< K, T, C >* m;
if (SWIG_ConvertPtr($input,(void **) &m,
$1_descriptor, 0) == 0)
$1 = 1;
@ -434,15 +440,25 @@ 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;
typedef std::pair< const K, T > value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
map();
map(const map< K, T > &);
map(const map& other);
unsigned int size() const;
bool empty() const;
void clear();
%extend {
T& __getitem__(K key) throw (std::out_of_range) {
std::map< K, T >::iterator i = self->find(key);
std::map< K, T, C >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
@ -452,19 +468,19 @@ namespace std {
(*self)[key] = x;
}
void __delitem__(K key) throw (std::out_of_range) {
std::map< K, T >::iterator i = self->find(key);
std::map< K, T, C >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
else
throw std::out_of_range("key not found");
}
bool has_key(K key) {
std::map< K, T >::iterator i = self->find(key);
std::map< K, T, C >::iterator i = self->find(key);
return i != self->end();
}
SCM keys() {
SCM result = SCM_EOL;
for (std::map< K, T >::reverse_iterator i=self->rbegin(); i!=self->rend(); ++i) {
for (std::map< K, T, C >::reverse_iterator i=self->rbegin(); i!=self->rend(); ++i) {
SCM k = CONVERT_TO(i->first);
result = scm_cons(k,result);
}
@ -475,12 +491,12 @@ namespace std {
%enddef
%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
template<class K> class map<K,T> {
%typemap(in) map<K,T> {
template<class K> class map< K, T, C > {
%typemap(in) map< K, T, C > {
if (scm_is_null($input)) {
$1 = std::map< K, T >();
$1 = std::map< K, T, C >();
} else if (scm_is_pair($input)) {
$1 = std::map< K, T >();
$1 = std::map< K, T, C >();
SCM alist = $input;
while (!scm_is_null(alist)) {
K* k;
@ -497,7 +513,7 @@ namespace std {
val = SCM_CAR(val);
if (!CHECK(val))
SWIG_exception(SWIG_TypeError,
"map<" #K "," #T "> expected");
"map<" #K "," #T "," #C "> expected");
}
(($1_type &)$1)[*k] = CONVERT_FROM(val);
alist = SCM_CDR(alist);
@ -507,13 +523,13 @@ namespace std {
SWIG_MustGetPtr($input,$&1_descriptor,$argnum, 0));
}
}
%typemap(in) const map<K,T>& (std::map<K,T> temp),
const map<K,T>* (std::map<K,T> temp) {
%typemap(in) const map< K, T, C >& (std::map< K, T, C > temp),
const map< K, T, C >* (std::map< K, T, C > temp) {
if (scm_is_null($input)) {
temp = std::map< K, T >();
temp = std::map< K, T, C >();
$1 = &temp;
} else if (scm_is_pair($input)) {
temp = std::map< K, T >();
temp = std::map< K, T, C >();
$1 = &temp;
SCM alist = $input;
while (!scm_is_null(alist)) {
@ -531,7 +547,7 @@ namespace std {
val = SCM_CAR(val);
if (!CHECK(val))
SWIG_exception(SWIG_TypeError,
"map<" #K "," #T "> expected");
"map<" #K "," #T "," #C "> expected");
}
temp[*k] = CONVERT_FROM(val);
alist = SCM_CDR(alist);
@ -540,9 +556,9 @@ namespace std {
$1 = ($1_ltype) SWIG_MustGetPtr($input,$1_descriptor,$argnum, 0);
}
}
%typemap(out) map<K,T> {
%typemap(out) map< K, T, C > {
SCM alist = SCM_EOL;
for (std::map< K, T >::reverse_iterator i=$1.rbegin(); i!=$1.rend(); ++i) {
for (std::map< K, T, C >::reverse_iterator i=$1.rbegin(); i!=$1.rend(); ++i) {
K* key = new K(i->first);
SCM k = SWIG_NewPointerObj(key,$descriptor(K *), 1);
SCM x = CONVERT_TO(i->second);
@ -551,7 +567,7 @@ namespace std {
}
$result = alist;
}
%typecheck(SWIG_TYPECHECK_MAP) map<K,T> {
%typecheck(SWIG_TYPECHECK_MAP) map< K, T, C > {
// native sequence?
if (scm_is_null($input)) {
/* an empty sequence can be of any type */
@ -583,7 +599,7 @@ namespace std {
}
} else {
// wrapped map?
std::map< K, T >* m;
std::map< K, T, C >* m;
if (SWIG_ConvertPtr($input,(void **) &m,
$&1_descriptor, 0) == 0)
$1 = 1;
@ -591,8 +607,8 @@ namespace std {
$1 = 0;
}
}
%typecheck(SWIG_TYPECHECK_MAP) const map<K,T>&,
const map<K,T>* {
%typecheck(SWIG_TYPECHECK_MAP) const map< K, T, C >&,
const map< K, T, C >* {
// native sequence?
if (scm_is_null($input)) {
/* an empty sequence can be of any type */
@ -624,7 +640,7 @@ namespace std {
}
} else {
// wrapped map?
std::map< K, T >* m;
std::map< K, T, C >* m;
if (SWIG_ConvertPtr($input,(void **) &m,
$1_descriptor, 0) == 0)
$1 = 1;
@ -640,15 +656,25 @@ 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;
typedef std::pair< const K, T > value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
map();
map(const map< K, T > &);
map(const map& other);
unsigned int size() const;
bool empty() const;
void clear();
%extend {
T __getitem__(const K& key) throw (std::out_of_range) {
std::map< K, T >::iterator i = self->find(key);
std::map< K, T, C >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
@ -658,19 +684,19 @@ namespace std {
(*self)[key] = x;
}
void __delitem__(const K& key) throw (std::out_of_range) {
std::map< K, T >::iterator i = self->find(key);
std::map< K, T, C >::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);
std::map< K, T, C >::iterator i = self->find(key);
return i != self->end();
}
SCM keys() {
SCM result = SCM_EOL;
for (std::map< K, T >::reverse_iterator i=self->rbegin(); i!=self->rend(); ++i) {
for (std::map< K, T, C >::reverse_iterator i=self->rbegin(); i!=self->rend(); ++i) {
K* key = new K(i->first);
SCM k = SWIG_NewPointerObj(key,$descriptor(K *), 1);
result = scm_cons(k,result);
@ -683,12 +709,12 @@ namespace std {
%define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO,
T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO)
template<> class map<K,T> {
%typemap(in) map<K,T> {
template<> class map< K, T, C > {
%typemap(in) map< K, T, C > {
if (scm_is_null($input)) {
$1 = std::map< K, T >();
$1 = std::map< K, T, C >();
} else if (scm_is_pair($input)) {
$1 = std::map< K, T >();
$1 = std::map< K, T, C >();
SCM alist = $input;
while (!scm_is_null(alist)) {
SCM entry, key, val;
@ -699,14 +725,14 @@ namespace std {
val = SCM_CDR(entry);
if (!CHECK_K(key))
SWIG_exception(SWIG_TypeError,
"map<" #K "," #T "> expected");
"map<" #K "," #T "," #C "> expected");
if (!CHECK_T(val)) {
if (!scm_is_pair(val))
SWIG_exception(SWIG_TypeError,"alist expected");
val = SCM_CAR(val);
if (!CHECK_T(val))
SWIG_exception(SWIG_TypeError,
"map<" #K "," #T "> expected");
"map<" #K "," #T "," #C "> expected");
}
(($1_type &)$1)[CONVERT_K_FROM(key)] =
CONVERT_T_FROM(val);
@ -717,13 +743,13 @@ namespace std {
SWIG_MustGetPtr($input,$&1_descriptor,$argnum, 0));
}
}
%typemap(in) const map<K,T>& (std::map<K,T> temp),
const map<K,T>* (std::map<K,T> temp) {
%typemap(in) const map< K, T, C >& (std::map< K, T, C > temp),
const map< K, T, C >* (std::map< K, T, C > temp) {
if (scm_is_null($input)) {
temp = std::map< K, T >();
temp = std::map< K, T, C >();
$1 = &temp;
} else if (scm_is_pair($input)) {
temp = std::map< K, T >();
temp = std::map< K, T, C >();
$1 = &temp;
SCM alist = $input;
while (!scm_is_null(alist)) {
@ -735,14 +761,14 @@ namespace std {
val = SCM_CDR(entry);
if (!CHECK_K(key))
SWIG_exception(SWIG_TypeError,
"map<" #K "," #T "> expected");
"map<" #K "," #T "," #C "> expected");
if (!CHECK_T(val)) {
if (!scm_is_pair(val))
SWIG_exception(SWIG_TypeError,"alist expected");
val = SCM_CAR(val);
if (!CHECK_T(val))
SWIG_exception(SWIG_TypeError,
"map<" #K "," #T "> expected");
"map<" #K "," #T "," #C "> expected");
}
temp[CONVERT_K_FROM(key)] = CONVERT_T_FROM(val);
alist = SCM_CDR(alist);
@ -751,9 +777,9 @@ namespace std {
$1 = ($1_ltype) SWIG_MustGetPtr($input,$1_descriptor,$argnum, 0);
}
}
%typemap(out) map<K,T> {
%typemap(out) map< K, T, C > {
SCM alist = SCM_EOL;
for (std::map< K, T >::reverse_iterator i=$1.rbegin(); i!=$1.rend(); ++i) {
for (std::map< K, T, C >::reverse_iterator i=$1.rbegin(); i!=$1.rend(); ++i) {
SCM k = CONVERT_K_TO(i->first);
SCM x = CONVERT_T_TO(i->second);
SCM entry = scm_cons(k,x);
@ -761,7 +787,7 @@ namespace std {
}
$result = alist;
}
%typecheck(SWIG_TYPECHECK_MAP) map<K,T> {
%typecheck(SWIG_TYPECHECK_MAP) map< K, T, C > {
// native sequence?
if (scm_is_null($input)) {
/* an empty sequence can be of any type */
@ -792,7 +818,7 @@ namespace std {
}
} else {
// wrapped map?
std::map< K, T >* m;
std::map< K, T, C >* m;
if (SWIG_ConvertPtr($input,(void **) &m,
$&1_descriptor, 0) == 0)
$1 = 1;
@ -800,8 +826,8 @@ namespace std {
$1 = 0;
}
}
%typecheck(SWIG_TYPECHECK_MAP) const map<K,T>&,
const map<K,T>* {
%typecheck(SWIG_TYPECHECK_MAP) const map< K, T, C >&,
const map< K, T, C >* {
// native sequence?
if (scm_is_null($input)) {
/* an empty sequence can be of any type */
@ -832,7 +858,7 @@ namespace std {
}
} else {
// wrapped map?
std::map< K, T >* m;
std::map< K, T, C >* m;
if (SWIG_ConvertPtr($input,(void **) &m,
$1_descriptor, 0) == 0)
$1 = 1;
@ -848,15 +874,25 @@ 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;
typedef std::pair< const K, T > value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
map();
map(const map< K, T> &);
map(const map& other);
unsigned int size() const;
bool empty() const;
void clear();
%extend {
T __getitem__(K key) throw (std::out_of_range) {
std::map< K, T >::iterator i = self->find(key);
std::map< K, T, C >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
@ -866,19 +902,19 @@ namespace std {
(*self)[key] = x;
}
void __delitem__(K key) throw (std::out_of_range) {
std::map< K, T >::iterator i = self->find(key);
std::map< K, T, C >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
else
throw std::out_of_range("key not found");
}
bool has_key(K key) {
std::map< K, T >::iterator i = self->find(key);
std::map< K, T, C >::iterator i = self->find(key);
return i != self->end();
}
SCM keys() {
SCM result = SCM_EOL;
for (std::map< K, T >::reverse_iterator i=self->rbegin(); i!=self->rend(); ++i) {
for (std::map< K, T, C >::reverse_iterator i=self->rbegin(); i!=self->rend(); ++i) {
SCM k = CONVERT_K_TO(i->first);
result = scm_cons(k,result);
}

View file

@ -113,11 +113,15 @@ namespace std {
$1 = 0;
}
}
typedef T first_type;
typedef U second_type;
pair();
pair(T first, U second);
pair(const pair& p);
pair(const pair& other);
template <class U1, class U2> pair(const pair<U1, U2> &p);
template <class U1, class U2> pair(const pair<U1, U2> &other);
T first;
U second;
@ -217,9 +221,9 @@ namespace std {
}
pair();
pair(T first, U second);
pair(const pair& p);
pair(const pair& other);
template <class U1, class U2> pair(const pair<U1, U2> &p);
template <class U1, class U2> pair(const pair<U1, U2> &other);
T first;
U second;
@ -317,9 +321,9 @@ namespace std {
}
pair();
pair(T first, U second);
pair(const pair& p);
pair(const pair& other);
template <class U1, class U2> pair(const pair<U1, U2> &p);
template <class U1, class U2> pair(const pair<U1, U2> &other);
T first;
U second;
@ -408,9 +412,9 @@ namespace std {
}
pair();
pair(T first, U second);
pair(const pair& p);
pair(const pair& other);
template <class U1, class U2> pair(const pair<U1, U2> &p);
template <class U1, class U2> pair(const pair<U1, U2> &other);
T first;
U second;

View file

@ -187,9 +187,18 @@ namespace std {
}
}
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;
vector(unsigned int size = 0);
vector(unsigned int size, const T& value);
vector(const vector<T>&);
vector(const vector& other);
%rename(length) size;
unsigned int size() const;
%rename("empty?") empty;
@ -351,9 +360,18 @@ namespace std {
}
}
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;
vector(unsigned int size = 0);
vector(unsigned int size, const T& value);
vector(const vector<T>&);
vector(const vector& other);
%rename(length) size;
unsigned int size() const;
%rename("empty?") empty;

View file

@ -1,7 +1,5 @@
/* -----------------------------------------------------------------------------
* stl.i
*
* Initial STL definition. extended as needed in each language
* ----------------------------------------------------------------------------- */
%include <std_common.i>

View file

@ -69,13 +69,13 @@
%typemap(throws) SWIGTYPE {
$&ltype temp = new $ltype($1);
scm_throw(scm_from_locale_symbol((char *) "swig-exception"),
scm_listify(SWIG_NewPointerObj(temp, $&descriptor, 1),
scm_list_n(SWIG_NewPointerObj(temp, $&descriptor, 1),
SCM_UNDEFINED));
}
%typemap(throws) SWIGTYPE & {
scm_throw(scm_from_locale_symbol((char *) "swig-exception"),
scm_listify(SWIG_NewPointerObj(&$1, $descriptor, 1),
scm_list_n(SWIG_NewPointerObj(&$1, $descriptor, 1),
SCM_UNDEFINED));
}
@ -87,13 +87,13 @@
%typemap(throws) SWIGTYPE * {
scm_throw(scm_from_locale_symbol((char *) "swig-exception"),
scm_listify(SWIG_NewPointerObj($1, $descriptor, 1),
scm_list_n(SWIG_NewPointerObj($1, $descriptor, 1),
SCM_UNDEFINED));
}
%typemap(throws) SWIGTYPE [] {
scm_throw(scm_from_locale_symbol((char *) "swig-exception"),
scm_listify(SWIG_NewPointerObj($1, $descriptor, 1),
scm_list_n(SWIG_NewPointerObj($1, $descriptor, 1),
SCM_UNDEFINED));
}
@ -176,7 +176,7 @@
%typemap(varout) enum SWIGTYPE { $result = scm_from_long((int)$1); }
%typemap(throws) enum SWIGTYPE {
scm_throw(scm_from_locale_symbol((char *) "swig-exception"),
scm_listify(scm_from_long((int)$1), SCM_UNDEFINED));
scm_list_n(scm_from_long((int)$1), SCM_UNDEFINED));
}
/* The SIMPLE_MAP_WITH_EXPR macro below defines the whole set of
@ -225,7 +225,7 @@
%typemap(throws) C_NAME {
C_NAME swig_c_value = $1;
scm_throw(scm_from_locale_symbol((char *) "swig-exception"),
scm_listify(C_TO_SCM_EXPR, SCM_UNDEFINED));
scm_list_n(C_TO_SCM_EXPR, SCM_UNDEFINED));
}
%enddef
@ -269,7 +269,7 @@
/* Throw typemap */
%typemap(throws) C_NAME {
scm_throw(scm_from_locale_symbol((char *) "swig-exception"),
scm_listify(C_TO_SCM($1), SCM_UNDEFINED));
scm_list_n(C_TO_SCM($1), SCM_UNDEFINED));
}
%enddef
@ -344,7 +344,7 @@ SIMPLE_MAP(unsigned long long, scm_to_ulong_long, scm_from_ulong_long, integer);
%typemap(throws) char * {
scm_throw(scm_from_locale_symbol((char *) "swig-exception"),
scm_listify(SWIG_str02scm($1), SCM_UNDEFINED));
scm_list_n(SWIG_str02scm($1), SCM_UNDEFINED));
}
/* Void */
@ -444,15 +444,21 @@ typedef unsigned long SCM;
$1 = scm_is_string($input) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] {
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE [] {
void *ptr;
int res = SWIG_ConvertPtr($input, &ptr, $1_descriptor, 0);
$1 = SWIG_CheckState(res);
}
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE &, SWIGTYPE && {
void *ptr;
int res = SWIG_ConvertPtr($input, &ptr, $1_descriptor, SWIG_POINTER_NO_NULL);
$1 = SWIG_CheckState(res);
}
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE {
void *ptr;
int res = SWIG_ConvertPtr($input, &ptr, $&descriptor, 0);
int res = SWIG_ConvertPtr($input, &ptr, $&descriptor, SWIG_POINTER_NO_NULL);
$1 = SWIG_CheckState(res);
}
@ -468,5 +474,7 @@ typedef unsigned long SCM;
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
/* typemaps.i ends here */

View file

@ -44,18 +44,16 @@ struct 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(, 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(, TYPE)
SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(const, TYPE)
%enddef

View file

@ -337,7 +337,8 @@ JAVA_ARRAYS_TYPEMAPS(double, double, jdouble, Double, "[D") /* double[ANY] *
/* Add some code to the proxy class of the array type for converting between type used in
* JNI class (long[]) and type used in proxy class ( ARRAYSOFCLASSES[] ) */
%typemap(javacode) ARRAYSOFCLASSES %{
%extend ARRAYSOFCLASSES {
%proxycode %{
protected static long[] cArrayUnwrap($javaclassname[] arrayWrapper) {
long[] cArray = new long[arrayWrapper.length];
for (int i=0; i<arrayWrapper.length; i++)
@ -352,6 +353,7 @@ JAVA_ARRAYS_TYPEMAPS(double, double, jdouble, Double, "[D") /* double[ANY] *
return arrayWrapper;
}
%}
}
%enddef /* JAVA_ARRAYSOFCLASSES */

View file

@ -29,26 +29,26 @@
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null $1_type");
return $null;
}
$1 = *argp;
$1 = *argp;
%}
%typemap(out, fragment="SWIG_intrusive_deleter") CONST TYPE %{
%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 >());
*(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);
$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 >());
*(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;
}
@ -63,70 +63,70 @@
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 & %{
%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 >());
*(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) %{
%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;
$1 = &temp;
%}
%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") TYPE *CONST& %{
%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 >());
*(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) %{
%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);
$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 > %{
%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;
*(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;
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(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) %{
%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;
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 {
@ -140,21 +140,21 @@
$1 = *temp;
}
%}
%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & %{
%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) %{
%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;
smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input;
temp = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true);
$1 = &temp;
$1 = &temp;
} else {
$1 = &tempnull;
}
@ -163,17 +163,17 @@
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 > * %{
%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;
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) %{
%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) {
@ -185,14 +185,14 @@
%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 > *& %{
%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::*) %{
@ -208,7 +208,7 @@
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 >,
%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 > *,
@ -264,7 +264,7 @@
// Base proxy classes
%typemap(javabody) TYPE %{
private transient long swigCPtr;
private boolean swigCMemOwnBase;
private transient boolean swigCMemOwnBase;
PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
swigCMemOwnBase = cMemoryOwn;
@ -279,7 +279,7 @@
// Derived proxy classes
%typemap(javabody_derived) TYPE %{
private transient long swigCPtr;
private boolean swigCMemOwnDerived;
private transient boolean swigCMemOwnDerived;
PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
super($imclassname.$javaclazznameSWIGSmartPtrUpcast(cPtr), true);
@ -341,7 +341,7 @@
return $null;
}
$1 = *argp; %}
%typemap(out) CONST TYPE
%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
@ -371,11 +371,11 @@
%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;
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(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
@ -414,7 +414,7 @@
// Base proxy classes
%typemap(javabody) TYPE %{
private transient long swigCPtr;
private boolean swigCMemOwnBase;
private transient boolean swigCMemOwnBase;
PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
swigCMemOwnBase = cMemoryOwn;
@ -429,7 +429,7 @@
// Derived proxy classes
%typemap(javabody_derived) TYPE %{
private transient long swigCPtr;
private boolean swigCMemOwnDerived;
private transient boolean swigCMemOwnDerived;
PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
super($imclassname.$javaclazznameSWIGSmartPtrUpcast(cPtr), true);
@ -467,6 +467,17 @@
%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"
// Typecheck typemaps
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *")
TYPE CONST,
TYPE CONST &,
TYPE CONST *,
TYPE *CONST&,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *&
""
%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
%enddef

View file

@ -14,7 +14,7 @@
%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
// destructor wrapper customisation
%feature("unref") TYPE
%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;"
@ -28,9 +28,22 @@
return $null;
}
$1 = *argp; %}
%typemap(out) CONST TYPE
%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)); %}
%typemap(directorin,descriptor="L$packagepath/$&javaclassname;") CONST TYPE
%{ $input = 0;
*((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (new $1_ltype((const $1_ltype &)$1)); %}
%typemap(directorout) CONST TYPE
%{ if (!$input) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null $1_type");
return $null;
}
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input;
$result = *smartarg->get();
%}
// 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;
@ -39,6 +52,16 @@
*(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;
%}
%typemap(directorin,descriptor="L$packagepath/$javaclassname;") CONST TYPE *
%{ $input = 0;
if ($1) {
*((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ($1 SWIG_NO_NULL_DELETER_0);
} %}
%typemap(directorout) CONST TYPE * %{
#error "typemaps for $1_type not available"
%}
// 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);
@ -49,6 +72,14 @@
%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); %}
%typemap(directorin,descriptor="L$packagepath/$javaclassname;") CONST TYPE &
%{ $input = 0;
*((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (&$1 SWIG_NO_NULL_DELETER_0); %}
%typemap(directorout) CONST TYPE & %{
#error "typemaps for $1_type not available"
%}
// 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);
@ -56,18 +87,50 @@
%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(directorin,descriptor="L$packagepath/$*javaclassname;") TYPE *CONST&
%{ $input = 0;
if ($1) {
*((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ($1 SWIG_NO_NULL_DELETER_0);
} %}
%typemap(directorout) TYPE *CONST& %{
#error "typemaps for $1_type not available"
%}
// shared_ptr by value
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ($&1_type argp)
%{ argp = *($&1_ltype*)&$input;
%{ argp = *($&1_ltype*)&$input;
if (argp) $1 = *argp; %}
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >
%{ *($&1_ltype*)&$result = $1 ? new $1_ltype($1) : 0; %}
%typemap(directorin,descriptor="L$packagepath/$typemap(jstype, TYPE);") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >
%{ $input = 0;
if ($1) {
*((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1);
} %}
%typemap(directorout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >
%{ if ($input) {
$&1_type smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input;
$result = *smartarg;
} %}
// shared_ptr by reference
%typemap(in) 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 > &
%{ *($&1_ltype)&$result = *$1 ? new $*1_ltype(*$1) : 0; %}
%{ *($&1_ltype)&$result = *$1 ? new $*1_ltype(*$1) : 0; %}
%typemap(directorin,descriptor="L$packagepath/$typemap(jstype, TYPE);") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &
%{ $input = 0;
if ($1) {
*((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1);
} %}
%typemap(directorout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{
#error "typemaps for $1_type not available"
%}
// shared_ptr by pointer
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * ($*1_ltype tempnull)
@ -76,12 +139,32 @@
%{ *($&1_ltype)&$result = ($1 && *$1) ? new $*1_ltype(*$1) : 0;
if ($owner) delete $1; %}
%typemap(directorin,descriptor="L$packagepath/$typemap(jstype, TYPE);") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *
%{ $input = 0;
if ($1 && *$1) {
*((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1);
} %}
%typemap(directorout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{
#error "typemaps for $1_type not available"
%}
// 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; %}
%{ *($1_ltype)&$result = (*$1 && **$1) ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(**$1) : 0; %}
%typemap(directorin,descriptor="L$packagepath/$typemap(jstype, TYPE);") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *&
%{ $input = 0;
if ($1 && *$1) {
*((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1);
} %}
%typemap(directorout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{
#error "typemaps for $1_type not available"
%}
// various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug
%typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{
@ -92,20 +175,20 @@
%}
%typemap (jni) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
%typemap (jni) 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 > *& "jlong"
%typemap (jtype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
%typemap (jtype) 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 > *& "long"
%typemap (jstype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
%typemap (jstype) 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(jstype, TYPE)"
%typemap(javain) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
%typemap(javain) 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(jstype, TYPE).getCPtr($javainput)"
@ -143,6 +226,18 @@
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
%typemap(javadirectorout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "$typemap(jstype, TYPE).getCPtr($javacall)"
%typemap(javadirectorin) CONST TYPE,
CONST TYPE *,
CONST TYPE &,
TYPE *CONST& "($jniinput == 0) ? null : new $typemap(jstype, TYPE)($jniinput, true)"
%typemap(javadirectorin) 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 > *& "($jniinput == 0) ? null : new $typemap(jstype, TYPE)($jniinput, true)"
// Base proxy classes
%typemap(javabody) TYPE %{
private transient long swigCPtr;
@ -156,12 +251,16 @@
CPTR_VISIBILITY static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
CPTR_VISIBILITY void swigSetCMemOwn(boolean own) {
swigCMemOwn = own;
}
%}
// Derived proxy classes
%typemap(javabody_derived) TYPE %{
private transient long swigCPtr;
private boolean swigCMemOwnDerived;
private transient boolean swigCMemOwnDerived;
PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
super($imclassname.$javaclazznameSWIGSmartPtrUpcast(cPtr), true);
@ -172,6 +271,11 @@
CPTR_VISIBILITY static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
CPTR_VISIBILITY void swigSetCMemOwn(boolean own) {
swigCMemOwnDerived = own;
super.swigSetCMemOwn(own);
}
%}
%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") TYPE {
@ -195,6 +299,38 @@
super.delete();
}
%typemap(directordisconnect, methodname="swigDirectorDisconnect") TYPE %{
protected void $methodname() {
swigSetCMemOwn(false);
$jnicall;
}
%}
%typemap(directorowner_release, methodname="swigReleaseOwnership") TYPE %{
public void $methodname() {
swigSetCMemOwn(false);
$jnicall;
}
%}
%typemap(directorowner_take, methodname="swigTakeOwnership") TYPE %{
public void $methodname() {
swigSetCMemOwn(true);
$jnicall;
}
%}
// Typecheck typemaps
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *")
TYPE CONST,
TYPE CONST &,
TYPE CONST *,
TYPE *CONST&,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *&
""
%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
%enddef

View file

@ -5,12 +5,52 @@
* methods can be called from C++.
* ----------------------------------------------------------------------------- */
#if defined(DEBUG_DIRECTOR_OWNED) || defined(DEBUG_DIRECTOR_EXCEPTION)
#if defined(DEBUG_DIRECTOR_OWNED) || defined(DEBUG_DIRECTOR_EXCEPTION) || defined(DEBUG_DIRECTOR_THREAD_NAME)
#include <iostream>
#endif
#include <exception>
#if defined(SWIG_JAVA_USE_THREAD_NAME)
#if !defined(SWIG_JAVA_GET_THREAD_NAME)
namespace Swig {
SWIGINTERN int GetThreadName(char *name, size_t len);
}
#if defined(__linux__)
#include <sys/prctl.h>
SWIGINTERN int Swig::GetThreadName(char *name, size_t len) {
(void)len;
#if defined(PR_GET_NAME)
return prctl(PR_GET_NAME, (unsigned long)name, 0, 0, 0);
#else
(void)name;
return 1;
#endif
}
#elif defined(__unix__) || defined(__APPLE__)
#include <pthread.h>
SWIGINTERN int Swig::GetThreadName(char *name, size_t len) {
return pthread_getname_np(pthread_self(), name, len);
}
#else
SWIGINTERN int Swig::GetThreadName(char *name, size_t len) {
(void)len;
(void)name;
return 1;
}
#endif
#endif
#endif
namespace Swig {
/* Java object wrapper */
@ -139,12 +179,27 @@ namespace Swig {
void **jenv = (void **)&jenv_;
#endif
env_status = director_->swig_jvm_->GetEnv((void **)&jenv_, JNI_VERSION_1_2);
JavaVMAttachArgs args;
args.version = JNI_VERSION_1_2;
args.group = NULL;
args.name = NULL;
#if defined(SWIG_JAVA_USE_THREAD_NAME)
char thread_name[64]; // MAX_TASK_COMM_LEN=16 is hard-coded in the Linux kernel and MacOS has MAXTHREADNAMESIZE=64.
if (Swig::GetThreadName(thread_name, sizeof(thread_name)) == 0) {
args.name = thread_name;
#if defined(DEBUG_DIRECTOR_THREAD_NAME)
std::cout << "JNIEnvWrapper: thread name: " << thread_name << std::endl;
} else {
std::cout << "JNIEnvWrapper: Couldn't set Java thread name" << std::endl;
#endif
}
#endif
#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(jenv, NULL);
director_->swig_jvm_->AttachCurrentThreadAsDaemon(jenv, &args);
#else
director_->swig_jvm_->AttachCurrentThread(jenv, NULL);
director_->swig_jvm_->AttachCurrentThread(jenv, &args);
#endif
}
~JNIEnvWrapper() {
@ -259,8 +314,10 @@ namespace Swig {
JavaExceptionMessage(JNIEnv *jenv, jthrowable throwable) : message_(jenv, exceptionMessageFromThrowable(jenv, throwable)) {
}
const char *message() const {
return message_.c_str("Could not get exception message in JavaExceptionMessage");
// Return a C string of the exception message in the jthrowable passed in the constructor
// If no message is available, null_string is return instead
const char *message(const char *null_string = "Could not get exception message in JavaExceptionMessage") const {
return message_.c_str(null_string);
}
private:
@ -294,10 +351,11 @@ namespace Swig {
public:
// Construct exception from a Java throwable
DirectorException(JNIEnv *jenv, jthrowable throwable) : classname_(0), msg_(0) {
DirectorException(JNIEnv *jenv, jthrowable throwable) : jenv_(jenv), throwable_(throwable), classname_(0), msg_(0) {
// Call Java method Object.getClass().getName() to obtain the throwable's class name (delimited by '/')
if (throwable) {
if (jenv && throwable) {
jenv->ExceptionClear(); // Cannot invoke methods with any pending exceptions
jclass throwclz = jenv->GetObjectClass(throwable);
if (throwclz) {
jclass clzclz = jenv->GetObjectClass(throwclz);
@ -318,11 +376,11 @@ namespace Swig {
}
JavaExceptionMessage exceptionmsg(jenv, throwable);
msg_ = copystr(exceptionmsg.message());
msg_ = copystr(exceptionmsg.message(0));
}
// More general constructor for handling as a java.lang.RuntimeException
DirectorException(const char *msg) : classname_(0), msg_(copystr(msg ? msg : "Unspecified DirectorException message")) {
DirectorException(const char *msg) : jenv_(0), throwable_(0), classname_(0), msg_(msg ? copystr(msg) : 0) {
}
~DirectorException() throw() {
@ -331,31 +389,53 @@ namespace Swig {
}
const char *what() const throw() {
return msg_;
return msg_ ? msg_ : "Unspecified DirectorException message";
}
// Reconstruct and raise/throw the Java Exception that caused the DirectorException
// Note that any error in the JNI exception handling results in a Java RuntimeException
void raiseJavaException(JNIEnv *jenv) const {
void throwException(JNIEnv *jenv) const {
if (jenv) {
jenv->ExceptionClear();
if (jenv == jenv_ && throwable_) {
// Throw original exception if not already pending
jthrowable throwable = jenv->ExceptionOccurred();
if (throwable && jenv->IsSameObject(throwable, throwable_) == JNI_FALSE) {
jenv->ExceptionClear();
throwable = 0;
}
if (!throwable)
jenv->Throw(throwable_);
} else {
// Try and reconstruct original exception, but original stacktrace is not reconstructed
jenv->ExceptionClear();
jmethodID ctorMethodID = 0;
jclass throwableclass = 0;
if (classname_) {
throwableclass = jenv->FindClass(classname_);
if (throwableclass)
ctorMethodID = jenv->GetMethodID(throwableclass, "<init>", "(Ljava/lang/String;)V");
}
jmethodID ctorMethodID = 0;
jclass throwableclass = 0;
if (classname_) {
throwableclass = jenv->FindClass(classname_);
if (throwableclass)
ctorMethodID = jenv->GetMethodID(throwableclass, "<init>", "(Ljava/lang/String;)V");
}
if (ctorMethodID) {
jenv->ThrowNew(throwableclass, what());
} else {
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, what());
}
if (ctorMethodID) {
jenv->ThrowNew(throwableclass, what());
} else {
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, what());
}
}
}
}
// Deprecated - use throwException
void raiseJavaException(JNIEnv *jenv) const {
throwException(jenv);
}
// Create and throw the DirectorException
static void raise(JNIEnv *jenv, jthrowable throwable) {
throw DirectorException(jenv, throwable);
}
private:
static char *copypath(const char *srcmsg) {
char *target = copystr(srcmsg);
@ -376,11 +456,14 @@ namespace Swig {
return target;
}
JNIEnv *jenv_;
jthrowable throwable_;
const char *classname_;
const char *msg_;
};
// Helper method to determine if a Java throwable matches a particular Java class type
// Note side effect of clearing any pending exceptions
SWIGINTERN bool ExceptionMatches(JNIEnv *jenv, jthrowable throwable, const char *classname) {
bool matches = false;

View file

@ -54,6 +54,14 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
}
}
%fragment("SWIG_JavaIntFromSize_t", "header") {
/* Check for overflow converting to Java int (always signed 32-bit) from (unsigned variable-bit) size_t */
SWIGINTERN jint SWIG_JavaIntFromSize_t(size_t size) {
static const jint JINT_MAX = 0x7FFFFFFF;
return (size > (size_t)JINT_MAX) ? -1 : (jint)size;
}
}
/* Primitive types */
%typemap(jni) bool, const bool & "jboolean"
%typemap(jni) char, const char & "jchar"
@ -103,6 +111,21 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%typemap(jstype) double, const double & "double"
%typemap(jstype) void "void"
%typemap(jboxtype) bool, const bool & "Boolean"
%typemap(jboxtype) char, const char & "Character"
%typemap(jboxtype) signed char, const signed char & "Byte"
%typemap(jboxtype) unsigned char, const unsigned char & "Short"
%typemap(jboxtype) short, const short & "Short"
%typemap(jboxtype) unsigned short, const unsigned short & "Integer"
%typemap(jboxtype) int, const int & "Integer"
%typemap(jboxtype) unsigned int, const unsigned int & "Long"
%typemap(jboxtype) long, const long & "Integer"
%typemap(jboxtype) unsigned long, const unsigned long & "Long"
%typemap(jboxtype) long long, const long long & "Long"
%typemap(jboxtype) unsigned long long, const unsigned long long & "java.math.BigInteger"
%typemap(jboxtype) float, const float & "Float"
%typemap(jboxtype) double, const double & "Double"
%typemap(jni) char *, char *&, char[ANY], char[] "jstring"
%typemap(jtype) char *, char *&, char[ANY], char[] "String"
%typemap(jstype) char *, char *&, char[ANY], char[] "String"
@ -137,7 +160,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%typemap(jtype) jfloat "float"
%typemap(jtype) jdouble "double"
%typemap(jtype) jstring "String"
%typemap(jtype) jobject "Object"
%typemap(jtype) jobject "java.lang.Object"
%typemap(jtype) jbooleanArray "boolean[]"
%typemap(jtype) jcharArray "char[]"
%typemap(jtype) jbyteArray "byte[]"
@ -146,7 +169,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%typemap(jtype) jlongArray "long[]"
%typemap(jtype) jfloatArray "float[]"
%typemap(jtype) jdoubleArray "double[]"
%typemap(jtype) jobjectArray "Object[]"
%typemap(jtype) jobjectArray "java.lang.Object[]"
%typemap(jstype) jboolean "boolean"
%typemap(jstype) jchar "char"
@ -157,7 +180,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%typemap(jstype) jfloat "float"
%typemap(jstype) jdouble "double"
%typemap(jstype) jstring "String"
%typemap(jstype) jobject "Object"
%typemap(jstype) jobject "java.lang.Object"
%typemap(jstype) jbooleanArray "boolean[]"
%typemap(jstype) jcharArray "char[]"
%typemap(jstype) jbyteArray "byte[]"
@ -166,12 +189,13 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%typemap(jstype) jlongArray "long[]"
%typemap(jstype) jfloatArray "float[]"
%typemap(jstype) jdoubleArray "double[]"
%typemap(jstype) jobjectArray "Object[]"
%typemap(jstype) jobjectArray "java.lang.Object[]"
/* Non primitive types */
%typemap(jni) SWIGTYPE "jlong"
%typemap(jtype) SWIGTYPE "long"
%typemap(jstype) SWIGTYPE "$&javaclassname"
%typemap(jboxtype) SWIGTYPE "$typemap(jstype, $1_type)"
%typemap(jni) SWIGTYPE [] "jlong"
%typemap(jtype) SWIGTYPE [] "long"
@ -363,11 +387,13 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
bigint = JCALL3(NewObject, jenv, clazz, mid, ba);
JCALL1(DeleteLocalRef, jenv, ba);
$result = bigint;
}
/* Convert to BigInteger (see out typemap) */
%typemap(directorin, descriptor="Ljava/math/BigInteger;") unsigned long long, const unsigned long long & {
%typemap(directorin, descriptor="Ljava/math/BigInteger;", noblock=1) unsigned long long, const unsigned long long & {
{
jbyteArray ba = JCALL1(NewByteArray, jenv, 9);
jbyte* bae = JCALL2(GetByteArrayElements, jenv, ba, 0);
jclass clazz = JCALL1(FindClass, jenv, "java/math/BigInteger");
@ -382,8 +408,10 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
bigint = JCALL3(NewObject, jenv, clazz, mid, ba);
JCALL1(DeleteLocalRef, jenv, ba);
$input = bigint;
}
Swig::LocalRefGuard $1_refguard(jenv, $input); }
%typemap(javadirectorin) unsigned long long "$jniinput"
%typemap(javadirectorout) unsigned long long "$javacall"
@ -611,6 +639,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
bigint = JCALL3(NewObject, jenv, clazz, mid, ba);
JCALL1(DeleteLocalRef, jenv, ba);
$result = bigint;
}
@ -1022,6 +1051,14 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%{ SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1);
return $null; %}
/* For methods to raise/throw the original Java exception thrown in a director method */
%typemap(throws) Swig::DirectorException
%{ $1.throwException(jenv);
return $null; %}
/* Java to C++ DirectorException should already be handled. Suppress warning and do nothing in the
event a user specifies a global: %catches(Swig::DirectorException); */
%typemap(directorthrows) Swig::DirectorException ""
/* Typemaps for code generation in proxy classes and Java type wrapper classes */
@ -1144,6 +1181,14 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
$1 = ($1_ltype)&temp; %}
%typemap(out) SWIGTYPE *const&
%{ *($1_ltype)&$result = *$1; %}
%typemap(directorin,descriptor="L$packagepath/$*javaclassname;") SWIGTYPE *const&
%{ *(($1_ltype)&$input) = ($*1_ltype) $1; %}
%typemap(directorout, warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) SWIGTYPE *const&
%{ static $*1_ltype swig_temp;
swig_temp = *($1_ltype)&$input;
$result = &swig_temp; %}
%typemap(javadirectorin) SWIGTYPE *const& "($jniinput == 0) ? null : new $*javaclassname($jniinput, false)"
%typemap(javadirectorout) SWIGTYPE *const& "$*javaclassname.getCPtr($javacall)"
/* Typemaps used for the generation of proxy and type wrapper class code */
%typemap(javabase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
@ -1206,7 +1251,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%}
%typemap(javabody) TYPE (CLASS::*) %{
private String swigCMemberPtr;
private transient String swigCMemberPtr;
PTRCTOR_VISIBILITY $javaclassname(String cMemberPtr, @SuppressWarnings("unused") boolean futureUse) {
swigCMemberPtr = cMemberPtr;
@ -1228,6 +1273,7 @@ SWIG_JAVABODY_PROXY(protected, protected, SWIGTYPE)
SWIG_JAVABODY_TYPEWRAPPER(protected, protected, protected, SWIGTYPE)
%typemap(javafinalize) SWIGTYPE %{
@SuppressWarnings("deprecation")
protected void finalize() {
delete();
}
@ -1255,7 +1301,7 @@ SWIG_JAVABODY_TYPEWRAPPER(protected, protected, protected, SWIGTYPE)
*/
%define SWIG_PROXY_CONSTRUCTOR(OWNERSHIP, WEAKREF, TYPENAME...)
%typemap(javaconstruct,directorconnect="\n $imclassname.$javaclazznamedirector_connect(this, swigCPtr, swigCMemOwn, WEAKREF);") TYPENAME {
%typemap(javaconstruct,directorconnect="\n $imclassname.$javaclazznamedirector_connect(this, swigCPtr, OWNERSHIP, WEAKREF);") TYPENAME {
this($imcall, OWNERSHIP);$directorconnect
}
%enddef
@ -1267,7 +1313,7 @@ SWIG_PROXY_CONSTRUCTOR(true, false, TYPENAME)
// Set the default for SWIGTYPE: Java owns the C/C++ object.
SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE)
%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") SWIGTYPE {
%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized", parameters="") SWIGTYPE {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
@ -1277,7 +1323,7 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE)
}
}
%typemap(javadestruct_derived, methodname="delete", methodmodifiers="public synchronized") SWIGTYPE {
%typemap(javadestruct_derived, methodname="delete", methodmodifiers="public synchronized", parameters="") SWIGTYPE {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
@ -1317,6 +1363,7 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE)
#define %javaexception(exceptionclasses) %feature("except",throws=exceptionclasses)
#define %nojavaexception %feature("except","0",throws="")
#define %clearjavaexception %feature("except","",throws="")
#define %proxycode %insert("proxycode")
%pragma(java) jniclassclassmodifiers="public class"
%pragma(java) moduleclassmodifiers="public class"
@ -1332,14 +1379,16 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE)
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*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) {
%typemap(jni) (const char *STRING, size_t LENGTH) "jbyteArray"
%typemap(jtype) (const char *STRING, size_t LENGTH) "byte[]"
%typemap(jstype) (const char *STRING, size_t LENGTH) "byte[]"
%typemap(javain) (const char *STRING, size_t LENGTH) "$javainput"
%typemap(freearg) (const char *STRING, size_t LENGTH) ""
%typemap(in) (const char *STRING, size_t LENGTH) {
if ($input) {
$1 = ($1_ltype) JCALL2(GetByteArrayElements, jenv, $input, 0);
$2 = ($2_type) JCALL1(GetArrayLength, jenv, $input);
@ -1348,18 +1397,26 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE)
$2 = 0;
}
}
%typemap(argout) (const char *STRING, size_t LENGTH) {
if ($input) JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, JNI_ABORT);
}
%typemap(directorin, descriptor="[B", noblock=1) (const char *STRING, size_t LENGTH) {
$input = 0;
if ($1) {
$input = JCALL1(NewByteArray, jenv, (jsize)$2);
if (!$input) return $null;
JCALL4(SetByteArrayRegion, jenv, $input, 0, (jsize)$2, (jbyte *)$1);
}
Swig::LocalRefGuard $1_refguard(jenv, $input);
}
%typemap(javadirectorin, descriptor="[B") (const char *STRING, size_t LENGTH) "$jniinput"
%apply (const char *STRING, size_t LENGTH) { (char *STRING, size_t LENGTH) }
/* Enable write-back for non-const version */
%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((jsize)$2);
(jenv)->SetByteArrayRegion(jb, 0, (jsize)$2, (jbyte *)$1);
$input = jb;
}
%typemap(directorargout) (char *STRING, size_t LENGTH)
%{(jenv)->GetByteArrayRegion($input, 0, (jsize)$2, (jbyte *)$1);
(jenv)->DeleteLocalRef($input);%}
%typemap(javadirectorin, descriptor="[B") (char *STRING, size_t LENGTH) "$jniinput"
%typemap(directorargout, noblock=1) (char *STRING, size_t LENGTH)
{ if ($input && $1) JCALL4(GetByteArrayRegion, jenv, $input, 0, (jsize)$2, (jbyte *)$1); }
%apply (char *STRING, size_t LENGTH) { (char *STRING, int LENGTH) }
/* java keywords */

View file

@ -8,15 +8,17 @@ namespace std {
template<class T, size_t N> class array {
public:
typedef T& reference;
typedef const T& const_reference;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T value_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
array();
array(const array& other);
size_type size() const;
%rename(isEmpty) empty;
bool empty() const;

View file

@ -7,6 +7,7 @@
* ----------------------------------------------------------------------------- */
%{
#include <typeinfo>
#include <stdexcept>
%}
@ -16,6 +17,7 @@ namespace std
struct exception {};
}
%typemap(throws) std::bad_cast "SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1.what());\n return $null;"
%typemap(throws) std::bad_exception "SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1.what());\n return $null;"
%typemap(throws) std::domain_error "SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1.what());\n return $null;"
%typemap(throws) std::exception "SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1.what());\n return $null;"

225
Lib/java/std_list.i Normal file
View file

@ -0,0 +1,225 @@
/* -----------------------------------------------------------------------------
* std_list.i
*
* SWIG typemaps for std::list.
* The Java proxy class extends java.util.AbstractSequentialList. The std::list
* container looks and feels much like a java.util.LinkedList from Java.
* ----------------------------------------------------------------------------- */
%include <std_common.i>
%{
#include <list>
#include <stdexcept>
%}
%fragment("SWIG_ListSize", "header", fragment="SWIG_JavaIntFromSize_t") {
SWIGINTERN jint SWIG_ListSize(size_t size) {
jint sz = SWIG_JavaIntFromSize_t(size);
if (sz == -1)
throw std::out_of_range("list size is too large to fit into a Java int");
return sz;
}
}
%javamethodmodifiers std::list::begin "private";
%javamethodmodifiers std::list::insert "private";
%javamethodmodifiers std::list::doSize "private";
%javamethodmodifiers std::list::doPreviousIndex "private";
%javamethodmodifiers std::list::doNextIndex "private";
%javamethodmodifiers std::list::doHasNext "private";
// Match Java style better:
%rename(Iterator) std::list::iterator;
%nodefaultctor std::list::iterator;
namespace std {
template <typename T> class list {
%typemap(javabase) std::list<T> "java.util.AbstractSequentialList<$typemap(jboxtype, T)>"
%proxycode %{
public $javaclassname(java.util.Collection c) {
this();
java.util.ListIterator<$typemap(jboxtype, T)> it = listIterator(0);
// Special case the "copy constructor" here to avoid lots of cross-language calls
for (java.lang.Object o : c) {
it.add(($typemap(jboxtype, T))o);
}
}
public int size() {
return doSize();
}
public boolean add($typemap(jboxtype, T) value) {
addLast(value);
return true;
}
public java.util.ListIterator<$typemap(jboxtype, T)> listIterator(int index) {
return new java.util.ListIterator<$typemap(jboxtype, T)>() {
private Iterator pos;
private Iterator last;
private java.util.ListIterator<$typemap(jboxtype, T)> init(int index) {
if (index < 0 || index > $javaclassname.this.size())
throw new IndexOutOfBoundsException("Index: " + index);
pos = $javaclassname.this.begin();
pos = pos.advance_unchecked(index);
return this;
}
public void add($typemap(jboxtype, T) v) {
// Technically we can invalidate last here, but this makes more sense
last = $javaclassname.this.insert(pos, v);
}
public void set($typemap(jboxtype, T) v) {
if (null == last) {
throw new IllegalStateException();
}
last.set_unchecked(v);
}
public void remove() {
if (null == last) {
throw new IllegalStateException();
}
$javaclassname.this.remove(last);
last = null;
}
public int previousIndex() {
return $javaclassname.this.doPreviousIndex(pos);
}
public int nextIndex() {
return $javaclassname.this.doNextIndex(pos);
}
public $typemap(jboxtype, T) previous() {
if (previousIndex() < 0) {
throw new java.util.NoSuchElementException();
}
last = pos;
pos = pos.previous_unchecked();
return last.deref_unchecked();
}
public $typemap(jboxtype, T) next() {
if (!hasNext()) {
throw new java.util.NoSuchElementException();
}
last = pos;
pos = pos.next_unchecked();
return last.deref_unchecked();
}
public boolean hasPrevious() {
// This call to previousIndex() will be much slower than the hasNext() implementation, but it's simpler like this with C++ forward iterators
return previousIndex() != -1;
}
public boolean hasNext() {
return $javaclassname.this.doHasNext(pos);
}
}.init(index);
}
%}
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;
/*
* We'd actually be better off having the nested class *not* be static in the wrapper
* output, but this doesn't actually remove the $static from the nested class still.
* (This would allow us to somewhat simplify the implementation of the ListIterator
* interface and give "natural" semantics to Java users of the C++ iterator)
*/
//%typemap(javaclassmodifiers) iterator "public class"
//%typemap(javainterfaces) iterator "java.util.ListIterator<$typemap(jboxtype, T)>"
struct iterator {
%extend {
void set_unchecked(const T &v) {
**$self = v;
}
iterator next_unchecked() const {
std::list<T>::iterator ret = *$self;
++ret;
return ret;
}
iterator previous_unchecked() const {
std::list<T>::iterator ret = *$self;
--ret;
return ret;
}
T deref_unchecked() const {
return **$self;
}
iterator advance_unchecked(size_type index) const {
std::list<T>::iterator ret = *$self;
std::advance(ret, index);
return ret;
}
}
};
list();
list(const list& other);
%rename(isEmpty) empty;
bool empty() const;
void clear();
%rename(remove) erase;
iterator erase(iterator pos);
%rename(removeLast) pop_back;
void pop_back();
%rename(removeFirst) pop_front;
void pop_front();
%rename(addLast) push_back;
void push_back(const T &value);
%rename(addFirst) push_front;
void push_front(const T &value);
iterator begin();
iterator end();
iterator insert(iterator pos, const T &value);
%extend {
%fragment("SWIG_ListSize");
list(jint count, const T &value) throw (std::out_of_range) {
if (count < 0)
throw std::out_of_range("list count must be positive");
return new std::list<T>(static_cast<std::list<T>::size_type>(count), value);
}
jint doSize() const throw (std::out_of_range) {
return SWIG_ListSize(self->size());
}
jint doPreviousIndex(const iterator &pos) const throw (std::out_of_range) {
return pos == self->begin() ? -1 : SWIG_ListSize(std::distance(self->begin(), static_cast<std::list<T>::const_iterator>(pos)));
}
jint doNextIndex(const iterator &pos) const throw (std::out_of_range) {
return pos == self->end() ? SWIG_ListSize(self->size()) : SWIG_ListSize(std::distance(self->begin(), static_cast<std::list<T>::const_iterator>(pos)));
}
bool doHasNext(const iterator &pos) const {
return pos != $self->end();
}
}
};
}

View file

@ -2,6 +2,8 @@
* std_map.i
*
* SWIG typemaps for std::map
* The Java proxy class extends java.util.AbstractMap. The std::map
* container looks and feels much like a java.util.HashMap from Java.
* ----------------------------------------------------------------------------- */
%include <std_common.i>
@ -12,52 +14,200 @@
%{
#include <map>
#include <algorithm>
#include <stdexcept>
%}
// exported class
%fragment("SWIG_MapSize", "header", fragment="SWIG_JavaIntFromSize_t") {
SWIGINTERN jint SWIG_MapSize(size_t size) {
jint sz = SWIG_JavaIntFromSize_t(size);
if (sz == -1) {
throw std::out_of_range("map size is too large to fit into a Java int");
}
return sz;
}
}
%javamethodmodifiers std::map::sizeImpl "private";
%javamethodmodifiers std::map::containsImpl "private";
%javamethodmodifiers std::map::putUnchecked "private";
%javamethodmodifiers std::map::removeUnchecked "private";
%javamethodmodifiers std::map::find "private";
%javamethodmodifiers std::map::begin "private";
%javamethodmodifiers std::map::end "private";
%rename(Iterator) std::map::iterator;
%nodefaultctor std::map::iterator;
%javamethodmodifiers std::map::iterator::getNextUnchecked "private";
%javamethodmodifiers std::map::iterator::isNot "private";
%javamethodmodifiers std::map::iterator::getKey "private";
%javamethodmodifiers std::map::iterator::getValue "private";
%javamethodmodifiers std::map::iterator::setValue "private";
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();
}
template<class K, class T, class C = std::less< K> > class map {
%typemap(javabase) std::map< K, T, C >
"java.util.AbstractMap<$typemap(jboxtype, K), $typemap(jboxtype, T)>"
%proxycode %{
public int size() {
return sizeImpl();
}
public boolean containsKey(java.lang.Object key) {
if (!(key instanceof $typemap(jboxtype, K))) {
return false;
}
return containsImpl(($typemap(jboxtype, K))key);
}
public $typemap(jboxtype, T) get(java.lang.Object key) {
if (!(key instanceof $typemap(jboxtype, K))) {
return null;
}
Iterator itr = find(($typemap(jboxtype, K)) key);
if (itr.isNot(end())) {
return itr.getValue();
}
return null;
}
public $typemap(jboxtype, T) put($typemap(jboxtype, K) key, $typemap(jboxtype, T) value) {
Iterator itr = find(($typemap(jboxtype, K)) key);
if (itr.isNot(end())) {
$typemap(jboxtype, T) oldValue = itr.getValue();
itr.setValue(value);
return oldValue;
} else {
putUnchecked(key, value);
return null;
}
}
public $typemap(jboxtype, T) remove(java.lang.Object key) {
if (!(key instanceof $typemap(jboxtype, K))) {
return null;
}
Iterator itr = find(($typemap(jboxtype, K)) key);
if (itr.isNot(end())) {
$typemap(jboxtype, T) oldValue = itr.getValue();
removeUnchecked(itr);
return oldValue;
} else {
return null;
}
}
public java.util.Set<Entry<$typemap(jboxtype, K), $typemap(jboxtype, T)>> entrySet() {
java.util.Set<Entry<$typemap(jboxtype, K), $typemap(jboxtype, T)>> setToReturn =
new java.util.HashSet<Entry<$typemap(jboxtype, K), $typemap(jboxtype, T)>>();
Iterator itr = begin();
final Iterator end = end();
while (itr.isNot(end)) {
setToReturn.add(new Entry<$typemap(jboxtype, K), $typemap(jboxtype, T)>() {
private Iterator iterator;
private Entry<$typemap(jboxtype, K), $typemap(jboxtype, T)> init(Iterator iterator) {
this.iterator = iterator;
return this;
}
public $typemap(jboxtype, K) getKey() {
return iterator.getKey();
}
public $typemap(jboxtype, T) getValue() {
return iterator.getValue();
}
public $typemap(jboxtype, T) setValue($typemap(jboxtype, T) newValue) {
$typemap(jboxtype, T) oldValue = iterator.getValue();
iterator.setValue(newValue);
return oldValue;
}
}.init(itr));
itr = itr.getNextUnchecked();
}
return setToReturn;
}
%}
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef K key_type;
typedef T mapped_type;
typedef std::pair< const K, T > value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
map();
map(const map& other);
struct iterator {
%typemap(javaclassmodifiers) iterator "protected class"
%extend {
std::map< K, T, C >::iterator getNextUnchecked() {
std::map< K, T, C >::iterator copy = (*$self);
return ++copy;
}
bool isNot(iterator other) const {
return (*$self != other);
}
K getKey() const {
return (*$self)->first;
}
T getValue() const {
return (*$self)->second;
}
void setValue(const T& newValue) {
(*$self)->second = newValue;
}
}
};
%rename(isEmpty) empty;
bool empty() const;
void clear();
iterator find(const K& key);
iterator begin();
iterator end();
%extend {
%fragment("SWIG_MapSize");
jint sizeImpl() const throw (std::out_of_range) {
return SWIG_MapSize(self->size());
}
bool containsImpl(const K& key) {
return (self->count(key) > 0);
}
void putUnchecked(const K& key, const T& value) {
(*self)[key] = value;
}
void removeUnchecked(const std::map< K, T, C >::iterator itr) {
self->erase(itr);
}
}
};
// Legacy macros (deprecated)
%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
#warning "specialize_std_map_on_key ignored - macro is deprecated and no longer necessary"

View file

@ -18,12 +18,15 @@
namespace std {
template<class T, class U> struct pair {
typedef T first_type;
typedef U second_type;
pair();
pair(T first, U second);
pair(const pair& p);
pair(const pair& other);
template <class U1, class U2> pair(const pair<U1, U2> &p);
template <class U1, class U2> pair(const pair<U1, U2> &other);
T first;
U second;

203
Lib/java/std_set.i Normal file
View file

@ -0,0 +1,203 @@
/* -----------------------------------------------------------------------------
* std_set.i
*
* SWIG typemaps for std::set
* The Java proxy class extends java.util.AbstractSet. The std::set
* container looks and feels much like a java.util.HashSet from Java.
* ----------------------------------------------------------------------------- */
%include <std_common.i>
// ------------------------------------------------------------------------
// std::set
// ------------------------------------------------------------------------
%{
#include <set>
#include <stdexcept>
%}
%fragment("SWIG_SetSize", "header", fragment="SWIG_JavaIntFromSize_t") {
SWIGINTERN jint SWIG_SetSize(size_t size) {
jint sz = SWIG_JavaIntFromSize_t(size);
if (sz == -1) {
throw std::out_of_range("set size is too large to fit into a Java int");
}
return sz;
}
}
%javamethodmodifiers std::set::sizeImpl "private";
%javamethodmodifiers std::set::containsImpl "private";
%javamethodmodifiers std::set::removeImpl "private";
%javamethodmodifiers std::set::hasNextImpl "private";
%javamethodmodifiers std::set::begin "private";
%javamethodmodifiers std::set::end "private";
%rename(Iterator) std::set::iterator;
%nodefaultctor std::set::iterator;
%javamethodmodifiers std::set::iterator::incrementUnchecked "private";
%javamethodmodifiers std::set::iterator::derefUnchecked "private";
%javamethodmodifiers std::set::iterator::isNot "private";
namespace std {
template <class T>
class set {
%typemap(javabase) std::set<T> "java.util.AbstractSet<$typemap(jboxtype, T)>"
%proxycode %{
public $javaclassname(java.util.Collection<? extends $typemap(jboxtype, T)> collection) {
this();
addAll(collection);
}
public int size() {
return sizeImpl();
}
public boolean add($typemap(jboxtype, T) key) {
return addImpl(key);
}
public boolean addAll(java.util.Collection<? extends $typemap(jboxtype, T)> collection) {
boolean didAddElement = false;
for (java.lang.Object object : collection) {
didAddElement |= add(($typemap(jboxtype, T))object);
}
return didAddElement;
}
public java.util.Iterator<$typemap(jboxtype, T)> iterator() {
return new java.util.Iterator<$typemap(jboxtype, T)>() {
private Iterator curr;
private Iterator end;
private java.util.Iterator<$typemap(jboxtype, T)> init() {
curr = $javaclassname.this.begin();
end = $javaclassname.this.end();
return this;
}
public $typemap(jboxtype, T) next() {
if (!hasNext()) {
throw new java.util.NoSuchElementException();
}
// Save the current position, increment it,
// then return the value at the position before the increment.
final $typemap(jboxtype, T) currValue = curr.derefUnchecked();
curr.incrementUnchecked();
return currValue;
}
public boolean hasNext() {
return curr.isNot(end);
}
}.init();
}
public boolean containsAll(java.util.Collection<?> collection) {
for (java.lang.Object object : collection) {
if (!contains(object)) {
return false;
}
}
return true;
}
public boolean contains(java.lang.Object object) {
if (!(object instanceof $typemap(jboxtype, T))) {
return false;
}
return containsImpl(($typemap(jboxtype, T))object);
}
public boolean removeAll(java.util.Collection<?> collection) {
boolean didRemoveElement = false;
for (java.lang.Object object : collection) {
didRemoveElement |= remove(object);
}
return didRemoveElement;
}
public boolean remove(java.lang.Object object) {
if (!(object instanceof $typemap(jboxtype, T))) {
return false;
}
return removeImpl(($typemap(jboxtype, T))object);
}
%}
public:
struct iterator {
%typemap(javaclassmodifiers) iterator "protected class"
%extend {
void incrementUnchecked() {
++(*$self);
}
T derefUnchecked() const {
return **$self;
}
bool isNot(iterator other) const {
return (*$self != other);
}
}
};
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T key_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;
set();
set(const set& other);
%rename(isEmpty) empty;
bool empty() const;
void clear();
iterator begin();
iterator end();
%extend {
%fragment("SWIG_SetSize");
// Returns whether item was inserted.
bool addImpl(const T& key) {
return self->insert(key).second;
}
// Returns whether set contains key.
bool containsImpl(const T& key) {
return (self->count(key) > 0);
}
// Returns whether the item was erased.
bool removeImpl(const T& key) {
return (self->erase(key) > 0);
}
jint sizeImpl() const throw (std::out_of_range) {
return SWIG_SetSize(self->size());
}
bool hasNextImpl(const iterator& itr) const {
return (itr != $self->end());
}
}
};
}

View file

@ -0,0 +1,211 @@
/* -----------------------------------------------------------------------------
* std_unordered_map.i
*
* SWIG typemaps for std::unordered_map
* The Java proxy class extends java.util.AbstractMap. The std::unordered_map
* container looks and feels much like a java.util.HashMap from Java.
* ----------------------------------------------------------------------------- */
%include <std_common.i>
// ------------------------------------------------------------------------
// std::unordered_map
// ------------------------------------------------------------------------
%{
#include <unordered_map>
#include <stdexcept>
%}
%fragment("SWIG_MapSize", "header", fragment="SWIG_JavaIntFromSize_t") {
SWIGINTERN jint SWIG_MapSize(size_t size) {
jint sz = SWIG_JavaIntFromSize_t(size);
if (sz == -1) {
throw std::out_of_range("map size is too large to fit into a Java int");
}
return sz;
}
}
%javamethodmodifiers std::unordered_map::sizeImpl "private";
%javamethodmodifiers std::unordered_map::containsImpl "private";
%javamethodmodifiers std::unordered_map::putUnchecked "private";
%javamethodmodifiers std::unordered_map::removeUnchecked "private";
%javamethodmodifiers std::unordered_map::find "private";
%javamethodmodifiers std::unordered_map::begin "private";
%javamethodmodifiers std::unordered_map::end "private";
%rename(Iterator) std::unordered_map::iterator;
%nodefaultctor std::unordered_map::iterator;
%javamethodmodifiers std::unordered_map::iterator::getNextUnchecked "private";
%javamethodmodifiers std::unordered_map::iterator::isNot "private";
%javamethodmodifiers std::unordered_map::iterator::getKey "private";
%javamethodmodifiers std::unordered_map::iterator::getValue "private";
%javamethodmodifiers std::unordered_map::iterator::setValue "private";
namespace std {
template<class K, class T> class unordered_map {
%typemap(javabase) std::unordered_map<K, T>
"java.util.AbstractMap<$typemap(jboxtype, K), $typemap(jboxtype, T)>"
%proxycode %{
public int size() {
return sizeImpl();
}
public boolean containsKey(java.lang.Object key) {
if (!(key instanceof $typemap(jboxtype, K))) {
return false;
}
return containsImpl(($typemap(jboxtype, K))key);
}
public $typemap(jboxtype, T) get(java.lang.Object key) {
if (!(key instanceof $typemap(jboxtype, K))) {
return null;
}
Iterator itr = find(($typemap(jboxtype, K)) key);
if (itr.isNot(end())) {
return itr.getValue();
}
return null;
}
public $typemap(jboxtype, T) put($typemap(jboxtype, K) key, $typemap(jboxtype, T) value) {
Iterator itr = find(($typemap(jboxtype, K)) key);
if (itr.isNot(end())) {
$typemap(jboxtype, T) oldValue = itr.getValue();
itr.setValue(value);
return oldValue;
} else {
putUnchecked(key, value);
return null;
}
}
public $typemap(jboxtype, T) remove(java.lang.Object key) {
if (!(key instanceof $typemap(jboxtype, K))) {
return null;
}
Iterator itr = find(($typemap(jboxtype, K)) key);
if (itr.isNot(end())) {
$typemap(jboxtype, T) oldValue = itr.getValue();
removeUnchecked(itr);
return oldValue;
} else {
return null;
}
}
public java.util.Set<Entry<$typemap(jboxtype, K), $typemap(jboxtype, T)>> entrySet() {
java.util.Set<Entry<$typemap(jboxtype, K), $typemap(jboxtype, T)>> setToReturn =
new java.util.HashSet<Entry<$typemap(jboxtype, K), $typemap(jboxtype, T)>>();
Iterator itr = begin();
final Iterator end = end();
while (itr.isNot(end)) {
setToReturn.add(new Entry<$typemap(jboxtype, K), $typemap(jboxtype, T)>() {
private Iterator iterator;
private Entry<$typemap(jboxtype, K), $typemap(jboxtype, T)> init(Iterator iterator) {
this.iterator = iterator;
return this;
}
public $typemap(jboxtype, K) getKey() {
return iterator.getKey();
}
public $typemap(jboxtype, T) getValue() {
return iterator.getValue();
}
public $typemap(jboxtype, T) setValue($typemap(jboxtype, T) newValue) {
$typemap(jboxtype, T) oldValue = iterator.getValue();
iterator.setValue(newValue);
return oldValue;
}
}.init(itr));
itr = itr.getNextUnchecked();
}
return setToReturn;
}
%}
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef K key_type;
typedef T mapped_type;
typedef std::pair< const K, T > value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
unordered_map();
unordered_map(const unordered_map& other);
struct iterator {
%typemap(javaclassmodifiers) iterator "protected class"
%extend {
std::unordered_map< K, T >::iterator getNextUnchecked() {
std::unordered_map< K, T >::iterator copy = (*$self);
return ++copy;
}
bool isNot(iterator other) const {
return (*$self != other);
}
K getKey() const {
return (*$self)->first;
}
T getValue() const {
return (*$self)->second;
}
void setValue(const T& newValue) {
(*$self)->second = newValue;
}
}
};
%rename(isEmpty) empty;
bool empty() const;
void clear();
iterator find(const K& key);
iterator begin();
iterator end();
%extend {
%fragment("SWIG_MapSize");
jint sizeImpl() const throw (std::out_of_range) {
return SWIG_MapSize(self->size());
}
bool containsImpl(const K& key) {
return (self->count(key) > 0);
}
void putUnchecked(const K& key, const T& value) {
(*self)[key] = value;
}
void removeUnchecked(const std::unordered_map< K, T >::iterator itr) {
self->erase(itr);
}
}
};
}

View file

@ -0,0 +1,199 @@
/* -----------------------------------------------------------------------------
* std_unordered_set.i
*
* SWIG typemaps for std::unordered_set
* The Java proxy class extends java.util.AbstractSet. The std::unordered_set
* container looks and feels much like a java.util.HashSet from Java.
* ----------------------------------------------------------------------------- */
%include <std_common.i>
// ------------------------------------------------------------------------
// std::unordered_set
// ------------------------------------------------------------------------
%{
#include <unordered_set>
#include <stdexcept>
%}
%fragment("SWIG_UnorderedSetSize", "header", fragment="SWIG_JavaIntFromSize_t") {
SWIGINTERN jint SWIG_UnorderedSetSize(size_t size) {
jint sz = SWIG_JavaIntFromSize_t(size);
if (sz == -1) {
throw std::out_of_range("unordered_set size is too large to fit into a Java int");
}
return sz;
}
}
%javamethodmodifiers std::unordered_set::sizeImpl "private";
%javamethodmodifiers std::unordered_set::containsImpl "private";
%javamethodmodifiers std::unordered_set::removeImpl "private";
%javamethodmodifiers std::unordered_set::hasNextImpl "private";
%javamethodmodifiers std::unordered_set::begin "private";
%javamethodmodifiers std::unordered_set::end "private";
%rename(Iterator) std::unordered_set::iterator;
%nodefaultctor std::unordered_set::iterator;
%javamethodmodifiers std::unordered_set::iterator::incrementUnchecked "private";
%javamethodmodifiers std::unordered_set::iterator::derefUnchecked "private";
%javamethodmodifiers std::unordered_set::iterator::isNot "private";
namespace std {
template <class Key>
class unordered_set {
%typemap(javabase) std::unordered_set<Key> "java.util.AbstractSet<$typemap(jboxtype, Key)>"
%proxycode %{
public $javaclassname(java.util.Collection<? extends $typemap(jboxtype, Key)> collection) {
this();
addAll(collection);
}
public int size() {
return sizeImpl();
}
public boolean addAll(java.util.Collection<? extends $typemap(jboxtype, Key)> collection) {
boolean didAddElement = false;
for (java.lang.Object object : collection) {
didAddElement |= add(($typemap(jboxtype, Key))object);
}
return didAddElement;
}
public java.util.Iterator<$typemap(jboxtype, Key)> iterator() {
return new java.util.Iterator<$typemap(jboxtype, Key)>() {
private Iterator curr;
private Iterator end;
private java.util.Iterator<$typemap(jboxtype, Key)> init() {
curr = $javaclassname.this.begin();
end = $javaclassname.this.end();
return this;
}
public $typemap(jboxtype, Key) next() {
if (!hasNext()) {
throw new java.util.NoSuchElementException();
}
// Save the current position, increment it,
// then return the value at the position before the increment.
final $typemap(jboxtype, Key) currValue = curr.derefUnchecked();
curr.incrementUnchecked();
return currValue;
}
public boolean hasNext() {
return curr.isNot(end);
}
}.init();
}
public boolean containsAll(java.util.Collection<?> collection) {
for (java.lang.Object object : collection) {
if (!contains(object)) {
return false;
}
}
return true;
}
public boolean contains(java.lang.Object object) {
if (!(object instanceof $typemap(jboxtype, Key))) {
return false;
}
return containsImpl(($typemap(jboxtype, Key))object);
}
public boolean removeAll(java.util.Collection<?> collection) {
boolean didRemoveElement = false;
for (java.lang.Object object : collection) {
didRemoveElement |= remove(object);
}
return didRemoveElement;
}
public boolean remove(java.lang.Object object) {
if (!(object instanceof $typemap(jboxtype, Key))) {
return false;
}
return removeImpl(($typemap(jboxtype, Key))object);
}
%}
public:
struct iterator {
%typemap(javaclassmodifiers) iterator "protected class"
%extend {
void incrementUnchecked() {
++(*$self);
}
Key derefUnchecked() const {
return **$self;
}
bool isNot(iterator other) const {
return (*$self != other);
}
}
};
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef Key value_type;
typedef Key key_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
unordered_set();
unordered_set(const unordered_set& other);
%rename(isEmpty) empty;
bool empty() const;
void clear();
iterator begin();
iterator end();
%extend {
%fragment("SWIG_UnorderedSetSize");
// Returns whether item was inserted.
bool add(const Key& key) {
return self->insert(key).second;
}
// Returns whether set contains key.
bool containsImpl(const Key& key) {
return (self->count(key) > 0);
}
// Returns whether the item was erased.
bool removeImpl(const Key& key) {
return (self->erase(key) > 0);
}
jint sizeImpl() const throw (std::out_of_range) {
return SWIG_UnorderedSetSize(self->size());
}
bool hasNextImpl(const iterator& itr) const {
return (itr != $self->end());
}
}
};
}

View file

@ -1,5 +1,10 @@
/* -----------------------------------------------------------------------------
* std_vector.i
*
* SWIG typemaps for std::vector.
* The Java proxy class extends java.util.AbstractList and implements
* java.util.RandomAccess. The std::vector container looks and feels much like a
* java.util.ArrayList from Java.
* ----------------------------------------------------------------------------- */
%include <std_common.i>
@ -9,77 +14,172 @@
#include <stdexcept>
%}
namespace std {
template<class T> class vector {
public:
typedef size_t size_type;
typedef T value_type;
typedef const value_type& const_reference;
vector();
vector(size_type n);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);
%rename(isEmpty) empty;
bool empty() const;
void clear();
%rename(add) push_back;
void push_back(const value_type& x);
%extend {
const_reference get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, const value_type& val) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = val;
else
throw std::out_of_range("vector index out of range");
}
%fragment("SWIG_VectorSize", "header", fragment="SWIG_JavaIntFromSize_t") {
SWIGINTERN jint SWIG_VectorSize(size_t size) {
jint sz = SWIG_JavaIntFromSize_t(size);
if (sz == -1)
throw std::out_of_range("vector size is too large to fit into a Java int");
return sz;
}
}
%define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CTYPE, CONST_REFERENCE)
%typemap(javabase) std::vector< CTYPE > "java.util.AbstractList<$typemap(jboxtype, CTYPE)>"
%typemap(javainterfaces) std::vector< CTYPE > "java.util.RandomAccess"
%proxycode %{
public $javaclassname($typemap(jstype, CTYPE)[] initialElements) {
this();
reserve(initialElements.length);
for ($typemap(jstype, CTYPE) element : initialElements) {
add(element);
}
}
public $javaclassname(Iterable<$typemap(jboxtype, CTYPE)> initialElements) {
this();
for ($typemap(jstype, CTYPE) element : initialElements) {
add(element);
}
}
public $typemap(jboxtype, CTYPE) get(int index) {
return doGet(index);
}
public $typemap(jboxtype, CTYPE) set(int index, $typemap(jboxtype, CTYPE) e) {
return doSet(index, e);
}
public boolean add($typemap(jboxtype, CTYPE) e) {
modCount++;
doAdd(e);
return true;
}
public void add(int index, $typemap(jboxtype, CTYPE) e) {
modCount++;
doAdd(index, e);
}
public $typemap(jboxtype, CTYPE) remove(int index) {
modCount++;
return doRemove(index);
}
protected void removeRange(int fromIndex, int toIndex) {
modCount++;
doRemoveRange(fromIndex, toIndex);
}
public int size() {
return doSize();
}
%}
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef CTYPE value_type;
typedef CTYPE *pointer;
typedef CTYPE const *const_pointer;
typedef CTYPE &reference;
typedef CONST_REFERENCE const_reference;
vector();
vector(const vector &other);
size_type capacity() const;
void reserve(size_type n) throw (std::length_error);
%rename(isEmpty) empty;
bool empty() const;
void clear();
%extend {
%fragment("SWIG_VectorSize");
vector(jint count, const CTYPE &value) throw (std::out_of_range) {
if (count < 0)
throw std::out_of_range("vector count must be positive");
return new std::vector< CTYPE >(static_cast<std::vector< CTYPE >::size_type>(count), value);
}
jint doSize() const throw (std::out_of_range) {
return SWIG_VectorSize(self->size());
}
void doAdd(const value_type& x) {
self->push_back(x);
}
void doAdd(jint index, const value_type& x) throw (std::out_of_range) {
jint size = static_cast<jint>(self->size());
if (0 <= index && index <= size) {
self->insert(self->begin() + index, x);
} else {
throw std::out_of_range("vector index out of range");
}
}
value_type doRemove(jint index) throw (std::out_of_range) {
jint size = static_cast<jint>(self->size());
if (0 <= index && index < size) {
CTYPE const old_value = (*self)[index];
self->erase(self->begin() + index);
return old_value;
} else {
throw std::out_of_range("vector index out of range");
}
}
CONST_REFERENCE doGet(jint index) throw (std::out_of_range) {
jint size = static_cast<jint>(self->size());
if (index >= 0 && index < size)
return (*self)[index];
else
throw std::out_of_range("vector index out of range");
}
value_type doSet(jint index, const value_type& val) throw (std::out_of_range) {
jint size = static_cast<jint>(self->size());
if (index >= 0 && index < size) {
CTYPE const old_value = (*self)[index];
(*self)[index] = val;
return old_value;
}
else
throw std::out_of_range("vector index out of range");
}
void doRemoveRange(jint fromIndex, jint toIndex) throw (std::out_of_range) {
jint size = static_cast<jint>(self->size());
if (0 <= fromIndex && fromIndex <= toIndex && toIndex <= size) {
self->erase(self->begin() + fromIndex, self->begin() + toIndex);
} else {
throw std::out_of_range("vector index out of range");
}
}
}
%enddef
%javamethodmodifiers std::vector::doSize "private";
%javamethodmodifiers std::vector::doAdd "private";
%javamethodmodifiers std::vector::doGet "private";
%javamethodmodifiers std::vector::doSet "private";
%javamethodmodifiers std::vector::doRemove "private";
%javamethodmodifiers std::vector::doRemoveRange "private";
namespace std {
template<class T> class vector {
SWIG_STD_VECTOR_MINIMUM_INTERNAL(T, const value_type&)
};
// bool specialization
template<> class vector<bool> {
public:
typedef size_t size_type;
typedef bool value_type;
typedef bool const_reference;
vector();
vector(size_type n);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);
%rename(isEmpty) empty;
bool empty() const;
void clear();
%rename(add) push_back;
void push_back(const value_type& x);
%extend {
bool get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, const value_type& val) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = val;
else
throw std::out_of_range("vector index out of range");
}
}
SWIG_STD_VECTOR_MINIMUM_INTERNAL(bool, bool)
};
}
%define specialize_std_vector(T)
#warning "specialize_std_vector - specialization for type T no longer needed"
%enddef

View file

@ -59,15 +59,16 @@ class wstring;
jenv->ReleaseStringChars($input, $1_pstr);
%}
%typemap(directorin,descriptor="Ljava/lang/String;") wstring {
%typemap(directorin,descriptor="Ljava/lang/String;") wstring %{
jsize $1_len = $1.length();
jchar *conv_buf = new jchar[$1_len];
jchar *$1_conv_buf = new jchar[$1_len];
for (jsize i = 0; i < $1_len; ++i) {
conv_buf[i] = (jchar)$1[i];
$1_conv_buf[i] = (jchar)$1[i];
}
$input = jenv->NewString(conv_buf, $1_len);
delete [] conv_buf;
}
$input = jenv->NewString($1_conv_buf, $1_len);
Swig::LocalRefGuard $1_refguard(jenv, $input);
delete [] $1_conv_buf;
%}
%typemap(out) wstring
%{jsize $1_len = $1.length();
@ -136,15 +137,16 @@ class wstring;
$result = &$1_str;
jenv->ReleaseStringChars($input, $1_pstr); %}
%typemap(directorin,descriptor="Ljava/lang/String;") const wstring & {
%typemap(directorin,descriptor="Ljava/lang/String;") const wstring & %{
jsize $1_len = $1.length();
jchar *conv_buf = new jchar[$1_len];
jchar *$1_conv_buf = new jchar[$1_len];
for (jsize i = 0; i < $1_len; ++i) {
conv_buf[i] = (jchar)($1)[i];
$1_conv_buf[i] = (jchar)($1)[i];
}
$input = jenv->NewString(conv_buf, $1_len);
delete [] conv_buf;
}
$input = jenv->NewString($1_conv_buf, $1_len);
Swig::LocalRefGuard $1_refguard(jenv, $input);
delete [] $1_conv_buf;
%}
%typemap(out) const wstring &
%{jsize $1_len = $1->length();

View file

@ -187,6 +187,8 @@ 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)
{
@ -204,29 +206,57 @@ There are no char *OUTPUT typemaps, however you can apply the signed char * type
%typemap(freearg) TYPE *OUTPUT, TYPE &OUTPUT ""
%typemap(argout) TYPE *OUTPUT, TYPE &OUTPUT
%typemap(argout) TYPE *OUTPUT, TYPE &OUTPUT
{
JNITYPE jvalue = (JNITYPE)temp$argnum;
JCALL4(Set##JAVATYPE##ArrayRegion, jenv, $input, 0, 1, &jvalue);
}
%typemap(directorin,descriptor=JNIDESC) TYPE &OUTPUT %{
$input = JCALL1(New##JAVATYPE##Array, jenv, 1);
if (!$input) return $null;
Swig::LocalRefGuard $1_refguard(jenv, $input); %}
%typemap(directorin,descriptor=JNIDESC) TYPE *OUTPUT %{
if ($1) {
$input = JCALL1(New##JAVATYPE##Array, jenv, 1);
if (!$input) return $null;
}
Swig::LocalRefGuard $1_refguard(jenv, $input); %}
%typemap(directorargout, noblock=1) TYPE &OUTPUT
{
JNITYPE $1_jvalue;
JCALL4(Get##JAVATYPE##ArrayRegion, jenv, $input, 0, 1, &$1_jvalue);
$result = ($*1_ltype)$1_jvalue;
}
%typemap(directorargout, noblock=1) TYPE *OUTPUT
{
if ($result) {
JNITYPE $1_jvalue;
JCALL4(Get##JAVATYPE##ArrayRegion, jenv, $input, 0, 1, &$1_jvalue);
*$result = ($*1_ltype)$1_jvalue;
}
}
%typemap(typecheck) TYPE *OUTPUT = TYPECHECKTYPE;
%typemap(typecheck) TYPE &OUTPUT = TYPECHECKTYPE;
%enddef
OUTPUT_TYPEMAP(bool, jboolean, boolean, Boolean, "[Ljava/lang/Boolean;", jbooleanArray);
OUTPUT_TYPEMAP(signed char, jbyte, byte, Byte, "[Ljava/lang/Byte;", jbyteArray);
OUTPUT_TYPEMAP(unsigned char, jshort, short, Short, "[Ljava/lang/Short;", jshortArray);
OUTPUT_TYPEMAP(short, jshort, short, Short, "[Ljava/lang/Short;", jshortArray);
OUTPUT_TYPEMAP(unsigned short, jint, int, Int, "[Ljava/lang/Integer;", jintArray);
OUTPUT_TYPEMAP(int, jint, int, Int, "[Ljava/lang/Integer;", jintArray);
OUTPUT_TYPEMAP(unsigned int, jlong, long, Long, "[Ljava/lang/Long;", jlongArray);
OUTPUT_TYPEMAP(long, jint, int, Int, "[Ljava/lang/Integer;", jintArray);
OUTPUT_TYPEMAP(unsigned long, jlong, long, Long, "[Ljava/lang/Long;", jlongArray);
OUTPUT_TYPEMAP(long long, jlong, long, Long, "[Ljava/lang/Long;", jlongArray);
OUTPUT_TYPEMAP(unsigned long long, jobject, java.math.BigInteger, NOTUSED, "[Ljava/lang/BigInteger;", SWIGBIGINTEGERARRAY);
OUTPUT_TYPEMAP(float, jfloat, float, Float, "[Ljava/lang/Float;", jfloatArray);
OUTPUT_TYPEMAP(double, jdouble, double, Double, "[Ljava/lang/Double;", jdoubleArray);
OUTPUT_TYPEMAP(bool, jboolean, boolean, Boolean, "[Z", jbooleanArray);
OUTPUT_TYPEMAP(signed char, jbyte, byte, Byte, "[B", jbyteArray);
OUTPUT_TYPEMAP(unsigned char, jshort, short, Short, "[S", jshortArray);
OUTPUT_TYPEMAP(short, jshort, short, Short, "[S", jshortArray);
OUTPUT_TYPEMAP(unsigned short, jint, int, Int, "[I", jintArray);
OUTPUT_TYPEMAP(int, jint, int, Int, "[I", jintArray);
OUTPUT_TYPEMAP(unsigned int, jlong, long, Long, "[J", jlongArray);
OUTPUT_TYPEMAP(long, jint, int, Int, "[I", jintArray);
OUTPUT_TYPEMAP(unsigned long, jlong, long, Long, "[J", jlongArray);
OUTPUT_TYPEMAP(long long, jlong, long, Long, "[J", jlongArray);
OUTPUT_TYPEMAP(unsigned long long, jobject, java.math.BigInteger, Object, "[Ljava/math/BigInteger;", jobjectArray);
OUTPUT_TYPEMAP(float, jfloat, float, Float, "[F", jfloatArray);
OUTPUT_TYPEMAP(double, jdouble, double, Double, "[D", jdoubleArray);
#undef OUTPUT_TYPEMAP
@ -244,6 +274,23 @@ OUTPUT_TYPEMAP(double, jdouble, double, Double, "[Ljava/lang/Double;", jdoubleAr
$1 = &temp;
}
%typemap(directorargout, noblock=1) bool &OUTPUT
{
jboolean $1_jvalue;
JCALL4(GetBooleanArrayRegion, jenv, $input, 0, 1, &$1_jvalue);
$result = $1_jvalue ? true : false;
}
%typemap(directorargout, noblock=1) bool *OUTPUT
{
if ($result) {
jboolean $1_jvalue;
JCALL4(GetBooleanArrayRegion, jenv, $input, 0, 1, &$1_jvalue);
*$result = $1_jvalue ? true : false;
}
}
/* 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 */
@ -262,6 +309,7 @@ OUTPUT_TYPEMAP(double, jdouble, double, Double, "[Ljava/lang/Double;", jdoubleAr
JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
bigint = JCALL3(NewObject, jenv, clazz, mid, ba);
JCALL1(DeleteLocalRef, jenv, ba);
JCALL3(SetObjectArrayElement, jenv, $input, 0, bigint);
}
@ -330,6 +378,8 @@ 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) {
@ -348,24 +398,54 @@ 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(directorin,descriptor=JNIDESC) TYPE &INOUT %{
$input = JCALL1(New##JAVATYPE##Array, jenv, 1);
if (!$input) return $null;
JNITYPE $1_jvalue = (JNITYPE)$1;
JCALL4(Set##JAVATYPE##ArrayRegion, jenv, $input, 0, 1, &$1_jvalue);
Swig::LocalRefGuard $1_refguard(jenv, $input); %}
%typemap(directorin,descriptor=JNIDESC) TYPE *INOUT %{
if ($1) {
$input = JCALL1(New##JAVATYPE##Array, jenv, 1);
if (!$input) return $null;
JNITYPE $1_jvalue = (JNITYPE)*$1;
JCALL4(Set##JAVATYPE##ArrayRegion, jenv, $input, 0, 1, &$1_jvalue);
}
Swig::LocalRefGuard $1_refguard(jenv, $input); %}
%typemap(directorargout, noblock=1) TYPE &INOUT
{
JCALL4(Get##JAVATYPE##ArrayRegion, jenv, $input, 0, 1, &$1_jvalue);
$result = ($*1_ltype)$1_jvalue;
}
%typemap(directorargout, noblock=1) TYPE *INOUT
{
if ($result) {
JNITYPE $1_jvalue;
JCALL4(Get##JAVATYPE##ArrayRegion, jenv, $input, 0, 1, &$1_jvalue);
*$result = ($*1_ltype)$1_jvalue;
}
}
%typemap(typecheck) TYPE *INOUT = TYPECHECKTYPE;
%typemap(typecheck) TYPE &INOUT = TYPECHECKTYPE;
%enddef
INOUT_TYPEMAP(bool, jboolean, boolean, Boolean, "[Ljava/lang/Boolean;", jbooleanArray);
INOUT_TYPEMAP(signed char, jbyte, byte, Byte, "[Ljava/lang/Byte;", jbyteArray);
INOUT_TYPEMAP(unsigned char, jshort, short, Short, "[Ljava/lang/Short;", jshortArray);
INOUT_TYPEMAP(short, jshort, short, Short, "[Ljava/lang/Short;", jshortArray);
INOUT_TYPEMAP(unsigned short, jint, int, Int, "[Ljava/lang/Integer;", jintArray);
INOUT_TYPEMAP(int, jint, int, Int, "[Ljava/lang/Integer;", jintArray);
INOUT_TYPEMAP(unsigned int, jlong, long, Long, "[Ljava/lang/Long;", jlongArray);
INOUT_TYPEMAP(long, jint, int, Int, "[Ljava/lang/Integer;", jintArray);
INOUT_TYPEMAP(unsigned long, jlong, long, Long, "[Ljava/lang/Long;", jlongArray);
INOUT_TYPEMAP(long long, jlong, long, Long, "[Ljava/lang/Long;", jlongArray);
INOUT_TYPEMAP(unsigned long long, jobject, java.math.BigInteger, NOTUSED, "[Ljava.math.BigInteger;", SWIGBIGINTEGERARRAY);
INOUT_TYPEMAP(float, jfloat, float, Float, "[Ljava/lang/Float;", jfloatArray);
INOUT_TYPEMAP(double, jdouble, double, Double, "[Ljava/lang/Double;", jdoubleArray);
INOUT_TYPEMAP(bool, jboolean, boolean, Boolean, "[Z", jbooleanArray);
INOUT_TYPEMAP(signed char, jbyte, byte, Byte, "[B", jbyteArray);
INOUT_TYPEMAP(unsigned char, jshort, short, Short, "[S", jshortArray);
INOUT_TYPEMAP(short, jshort, short, Short, "[S", jshortArray);
INOUT_TYPEMAP(unsigned short, jint, int, Int, "[I", jintArray);
INOUT_TYPEMAP(int, jint, int, Int, "[I", jintArray);
INOUT_TYPEMAP(unsigned int, jlong, long, Long, "[J", jlongArray);
INOUT_TYPEMAP(long, jint, int, Int, "[I", jintArray);
INOUT_TYPEMAP(unsigned long, jlong, long, Long, "[J", jlongArray);
INOUT_TYPEMAP(long long, jlong, long, Long, "[J", jlongArray);
INOUT_TYPEMAP(unsigned long long, jobject, java.math.BigInteger, Object, "[java/math/BigInteger;", jobjectArray);
INOUT_TYPEMAP(float, jfloat, float, Float, "[F", jfloatArray);
INOUT_TYPEMAP(double, jdouble, double, Double, "[D", jdoubleArray);
#undef INOUT_TYPEMAP
@ -390,6 +470,22 @@ INOUT_TYPEMAP(double, jdouble, double, Double, "[Ljava/lang/Double;", jdoubleArr
JCALL3(ReleaseBooleanArrayElements, jenv, $input , (jboolean *)jbtemp$argnum, 0);
}
%typemap(directorargout, noblock=1) bool &INOUT
{
JCALL4(GetBooleanArrayRegion, jenv, $input, 0, 1, &$1_jvalue);
$result = $1_jvalue ? true : false;
}
%typemap(directorargout, noblock=1) bool *INOUT
{
if ($result) {
jboolean $1_jvalue;
JCALL4(GetBooleanArrayRegion, jenv, $input, 0, 1, &$1_jvalue);
*$result = $1_jvalue ? true : false;
}
}
/* Override the typemap in the INOUT_TYPEMAP macro for unsigned long long */
%typemap(in) unsigned long long *INOUT ($*1_ltype temp), unsigned long long &INOUT ($*1_ltype temp) {
jobject bigint;

View file

@ -129,7 +129,7 @@
/*
* char *BYTE typemaps.
* These are input typemaps for mapping a Java byte[] array to a C char array.
* Note that as a Java array is used and thus passeed by reference, the C routine
* Note that as a Java array is used and thus passed by reference, the C routine
* can return data to Java via the parameter.
*
* Example usage wrapping:

View file

@ -32,6 +32,7 @@ static JSObjectRef $jswrapper(JSContextRef context, JSObjectRef ctorObject,
size_t argc, const JSValueRef argv[], JSValueRef* exception)
{
SWIG_exception(SWIG_ERROR, "Class $jsname can not be instantiated");
fail:
return 0;
}
%}
@ -387,7 +388,7 @@ static JSStaticFunction $jsmangledname_functions[] = {
* jsc_nspace_declaration: template for a namespace declaration
* - $jsnspace: mangled name of the namespace
* - $jsglobalvariables: list of variable entries
* - $jsglobalfunctions: list if fuction entries
* - $jsglobalfunctions: list of function entries
* ----------------------------------------------------------------------------- */
%fragment ("jsc_nspace_declaration", "templates")
%{

View file

@ -53,7 +53,7 @@ SWIGINTERN bool JS_veto_set_variable(JSContextRef context, JSObjectRef thisObjec
} else {
SWIG_exception(SWIG_ERROR, msg);
}
fail:
return false;
}

View file

@ -4,7 +4,7 @@
* ---------------------------------------------------------------------------*/
#define SWIG_Error(code, msg) SWIG_JSC_exception(context, exception, code, msg)
#define SWIG_exception(code, msg) SWIG_JSC_exception(context, exception, code, msg)
#define SWIG_exception(code, msg) do { SWIG_JSC_exception(context, exception, code, msg); SWIG_fail; } while (0)
#define SWIG_fail goto fail
SWIGRUNTIME void SWIG_Javascript_Raise(JSContextRef context, JSValueRef *exception, const char* type) {
@ -150,7 +150,7 @@ SWIGRUNTIME int SWIG_JSC_ConvertPtr(JSContextRef context, JSValueRef valRef, voi
/* special case: JavaScript null => C NULL pointer */
if(JSValueIsNull(context, valRef)) {
*ptr=0;
return SWIG_OK;
return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
}
if(!JSValueIsObject(context, valRef)) {

View file

@ -8,6 +8,13 @@
#include <complex>
%}
namespace std {
%naturalvar complex;
template<typename T> class complex;
%template() complex<double>;
%template() complex<float>;
}
/* defining the complex as/from converters */
%swig_cplxdbl_convn(std::complex<double>, std::complex<double>, std::real, std::imag)

View file

@ -20,22 +20,29 @@
namespace std {
template<class K, class T> class map {
template<class K, class T, class C = std::less<K> > class map {
// add typemaps here
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef K key_type;
typedef T mapped_type;
typedef std::pair< const K, T > value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
map();
map(const map<K,T> &);
map(const map& other);
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);
std::map< K, T, C >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
@ -45,14 +52,14 @@ namespace std {
(*self)[key] = x;
}
void del(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
std::map< K, T, C >::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);
std::map< K, T, C >::iterator i = self->find(key);
return i != self->end();
}
}

View file

@ -18,12 +18,14 @@
namespace std {
template<class T, class U> struct pair {
typedef T first_type;
typedef U second_type;
pair();
pair(T first, U second);
pair(const pair& p);
pair(const pair& other);
template <class U1, class U2> pair(const pair<U1, U2> &p);
template <class U1, class U2> pair(const pair<U1, U2> &other);
T first;
U second;

View file

@ -14,10 +14,17 @@ namespace std {
template<class T> class vector {
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;
vector();
vector(size_type n);
vector(const vector& other);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);
@ -48,10 +55,17 @@ namespace std {
template<> class vector<bool> {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef bool value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef bool const_reference;
vector();
vector(size_type n);
vector(const vector& other);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);

View file

@ -36,6 +36,7 @@ static SwigV8ReturnValue $jswrapper(const SwigV8Arguments &args) {
SWIGV8_HANDLESCOPE();
SWIG_exception(SWIG_ERROR, "Class $jsname can not be instantiated");
fail:
SWIGV8_RETURN(SWIGV8_UNDEFINED());
}
%}
@ -132,10 +133,13 @@ static void $jswrapper(v8::Isolate *isolate, v8::Persistent<v8::Value> object, v
SWIGV8_Proxy *proxy = static_cast<SWIGV8_Proxy *>(parameter);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
static void $jswrapper(v8::Isolate *isolate, v8::Persistent<v8::Object> *object, SWIGV8_Proxy *proxy) {
#else
#elif (V8_MAJOR_VERSION-0) < 5
static void $jswrapper(const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &data) {
v8::Local<v8::Object> object = data.GetValue();
SWIGV8_Proxy *proxy = data.GetParameter();
#else
static void $jswrapper(const v8::WeakCallbackInfo<SWIGV8_Proxy> &data) {
SWIGV8_Proxy *proxy = data.GetParameter();
#endif
if(proxy->swigCMemOwn && proxy->swigCObject) {
@ -146,7 +150,9 @@ static void $jswrapper(const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &dat
}
delete proxy;
#if (V8_MAJOR_VERSION-0) < 5
object.Clear();
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
object.Dispose();
@ -154,7 +160,7 @@ static void $jswrapper(const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &dat
object.Dispose(isolate);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100)
object->Dispose(isolate);
#else
#elif (V8_MAJOR_VERSION-0) < 5
object->Dispose();
#endif
}
@ -176,10 +182,13 @@ static void $jswrapper(v8::Isolate *isolate, v8::Persistent<v8::Value> object, v
SWIGV8_Proxy *proxy = static_cast<SWIGV8_Proxy *>(parameter);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
static void $jswrapper(v8::Isolate *isolate, v8::Persistent< v8::Object> *object, SWIGV8_Proxy *proxy) {
#else
#elif (V8_MAJOR_VERSION-0) < 5
static void $jswrapper(const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &data) {
v8::Local<v8::Object> object = data.GetValue();
SWIGV8_Proxy *proxy = data.GetParameter();
#else
static void $jswrapper(const v8::WeakCallbackInfo<SWIGV8_Proxy> &data) {
SWIGV8_Proxy *proxy = data.GetParameter();
#endif
if(proxy->swigCMemOwn && proxy->swigCObject) {
@ -196,7 +205,7 @@ static void $jswrapper(const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &dat
object->Dispose(isolate);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
object->Dispose();
#else
#elif (V8_MAJOR_VERSION-0) < 5
object.Clear();
#endif
}
@ -210,7 +219,11 @@ static void $jswrapper(const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &dat
* ----------------------------------------------------------------------------- */
%fragment("js_getter", "templates")
%{
#if (V8_MAJOR_VERSION-0) < 5
static SwigV8ReturnValue $jswrapper(v8::Local<v8::String> property, const SwigV8PropertyCallbackInfo &info) {
#else
static SwigV8ReturnValue $jswrapper(v8::Local<v8::Name> property, const SwigV8PropertyCallbackInfo &info) {
#endif
SWIGV8_HANDLESCOPE();
v8::Handle<v8::Value> jsresult;
@ -232,8 +245,11 @@ fail:
* ----------------------------------------------------------------------------- */
%fragment("js_setter", "templates")
%{
static void $jswrapper(v8::Local<v8::String> property, v8::Local<v8::Value> value,
const SwigV8PropertyCallbackInfoVoid &info) {
#if (V8_MAJOR_VERSION-0) < 5
static void $jswrapper(v8::Local<v8::String> property, v8::Local<v8::Value> value, const SwigV8PropertyCallbackInfoVoid &info) {
#else
static void $jswrapper(v8::Local<v8::Name> property, v8::Local<v8::Value> value, const SwigV8PropertyCallbackInfoVoid &info) {
#endif
SWIGV8_HANDLESCOPE();
$jslocals

View file

@ -17,7 +17,7 @@ SWIG_From_dec(Type)(%ifcplusplus(const Type&, Type) c)
{
SWIGV8_HANDLESCOPE_ESC();
v8::Local<v8::Array> vals = SWIGV8_ARRAY_NEW(2);
v8::Local<v8::Array> vals = SWIGV8_ARRAY_NEW();
vals->Set(0, SWIG_From(double)(Real(c)));
vals->Set(1, SWIG_From(double)(Imag(c)));

View file

@ -6,11 +6,16 @@ typedef v8::InvocationCallback SwigV8FunctionCallback;
typedef v8::AccessorGetter SwigV8AccessorGetterCallback;
typedef v8::AccessorSetter SwigV8AccessorSetterCallback;
typedef v8::AccessorInfo SwigV8PropertyCallbackInfoVoid;
#else
#elif (V8_MAJOR_VERSION-0) < 5
typedef v8::FunctionCallback SwigV8FunctionCallback;
typedef v8::AccessorGetterCallback SwigV8AccessorGetterCallback;
typedef v8::AccessorSetterCallback SwigV8AccessorSetterCallback;
typedef v8::PropertyCallbackInfo<void> SwigV8PropertyCallbackInfoVoid;
#else
typedef v8::FunctionCallback SwigV8FunctionCallback;
typedef v8::AccessorNameGetterCallback SwigV8AccessorGetterCallback;
typedef v8::AccessorNameSetterCallback SwigV8AccessorSetterCallback;
typedef v8::PropertyCallbackInfo<void> SwigV8PropertyCallbackInfoVoid;
#endif
/**
@ -65,24 +70,43 @@ SWIGRUNTIME void SWIGV8_AddStaticFunction(v8::Handle<v8::Object> obj, const char
*/
SWIGRUNTIME void SWIGV8_AddStaticVariable(v8::Handle<v8::Object> obj, const char* symbol,
SwigV8AccessorGetterCallback getter, SwigV8AccessorSetterCallback setter) {
#if (V8_MAJOR_VERSION-0) < 5
obj->SetAccessor(SWIGV8_SYMBOL_NEW(symbol), getter, setter);
#else
obj->SetAccessor(SWIGV8_CURRENT_CONTEXT(), SWIGV8_SYMBOL_NEW(symbol), getter, setter);
#endif
}
SWIGRUNTIME void JS_veto_set_variable(v8::Local<v8::String> property, v8::Local<v8::Value> value,
const SwigV8PropertyCallbackInfoVoid& info)
#if (V8_MAJOR_VERSION-0) < 5
SWIGRUNTIME void JS_veto_set_variable(v8::Local<v8::String> property, v8::Local<v8::Value> value, const SwigV8PropertyCallbackInfoVoid& info)
#else
SWIGRUNTIME void JS_veto_set_variable(v8::Local<v8::Name> property, v8::Local<v8::Value> value, const SwigV8PropertyCallbackInfoVoid& info)
#endif
{
char buffer[256];
char msg[512];
int res;
#if (V8_MAJOR_VERSION-0) < 5
property->WriteUtf8(buffer, 256);
res = sprintf(msg, "Tried to write read-only variable: %s.", buffer);
#else
v8::Local<v8::String> sproperty;
if (property->ToString(SWIGV8_CURRENT_CONTEXT()).ToLocal(&sproperty)) {
SWIGV8_WRITE_UTF8(sproperty, buffer, 256);
res = sprintf(msg, "Tried to write read-only variable: %s.", buffer);
}
else {
res = -1;
}
#endif
if(res<0) {
SWIG_exception(SWIG_ERROR, "Tried to write read-only variable.");
} else {
SWIG_exception(SWIG_ERROR, msg);
}
fail: ;
}
%} // v8_helper_functions

View file

@ -1,21 +1,35 @@
%insert(init) %{
%insert(header) %{
#include <assert.h>
%}
%insert(init) %{
SWIGRUNTIME void
SWIG_V8_SetModule(void *, swig_module_info *swig_module) {
v8::Local<v8::Object> global_obj = SWIGV8_CURRENT_CONTEXT()->Global();
v8::Local<v8::External> mod = SWIGV8_EXTERNAL_NEW(swig_module);
assert(!mod.IsEmpty());
#if (V8_MAJOR_VERSION-0) < 5
global_obj->SetHiddenValue(SWIGV8_STRING_NEW("swig_module_info_data"), mod);
#else
v8::Local<v8::Private> privateKey = v8::Private::ForApi(v8::Isolate::GetCurrent(), SWIGV8_STRING_NEW("swig_module_info_data"));
global_obj->SetPrivate(SWIGV8_CURRENT_CONTEXT(), privateKey, mod);
#endif
}
SWIGRUNTIME swig_module_info *
SWIG_V8_GetModule(void *) {
v8::Local<v8::Object> global_obj = SWIGV8_CURRENT_CONTEXT()->Global();
#if (V8_MAJOR_VERSION-0) < 5
v8::Local<v8::Value> moduleinfo = global_obj->GetHiddenValue(SWIGV8_STRING_NEW("swig_module_info_data"));
#else
v8::Local<v8::Private> privateKey = v8::Private::ForApi(v8::Isolate::GetCurrent(), SWIGV8_STRING_NEW("swig_module_info_data"));
v8::Local<v8::Value> moduleinfo;
if (!global_obj->GetPrivate(SWIGV8_CURRENT_CONTEXT(), privateKey).ToLocal(&moduleinfo))
return 0;
#endif
if (moduleinfo.IsEmpty())
if (moduleinfo.IsEmpty() || moduleinfo->IsNull() || moduleinfo->IsUndefined())
{
// It's not yet loaded
return 0;
@ -23,7 +37,7 @@ SWIG_V8_GetModule(void *) {
v8::Local<v8::External> moduleinfo_extern = v8::Local<v8::External>::Cast(moduleinfo);
if (moduleinfo_extern.IsEmpty())
if (moduleinfo_extern.IsEmpty() || moduleinfo_extern->IsNull() || moduleinfo_extern->IsUndefined())
{
// Something's not right
return 0;

View file

@ -22,7 +22,7 @@ int SWIG_AsVal_dec(bool)(v8::Handle<v8::Value> obj, bool *val)
return SWIG_ERROR;
}
if (val) *val = obj->BooleanValue();
if (val) *val = SWIGV8_BOOLEAN_VALUE(obj);
return SWIG_OK;
}
}
@ -44,7 +44,7 @@ int SWIG_AsVal_dec(int)(v8::Handle<v8::Value> valRef, int* val)
if (!valRef->IsNumber()) {
return SWIG_TypeError;
}
if(val) *val = valRef->IntegerValue();
if(val) *val = SWIGV8_INTEGER_VALUE(valRef);
return SWIG_OK;
}
@ -68,7 +68,7 @@ int SWIG_AsVal_dec(long)(v8::Handle<v8::Value> obj, long* val)
if (!obj->IsNumber()) {
return SWIG_TypeError;
}
if(val) *val = (long) obj->IntegerValue();
if(val) *val = (long) SWIGV8_INTEGER_VALUE(obj);
return SWIG_OK;
}
@ -95,7 +95,7 @@ int SWIG_AsVal_dec(unsigned long)(v8::Handle<v8::Value> obj, unsigned long *val)
return SWIG_TypeError;
}
long longVal = (long) obj->NumberValue();
long longVal = (long) SWIGV8_NUMBER_VALUE(obj);
if(longVal < 0) {
return SWIG_OverflowError;
@ -133,7 +133,7 @@ int SWIG_AsVal_dec(long long)(v8::Handle<v8::Value> obj, long long* val)
if (!obj->IsNumber()) {
return SWIG_TypeError;
}
if(val) *val = (long long) obj->IntegerValue();
if(val) *val = (long long) SWIGV8_INTEGER_VALUE(obj);
return SWIG_OK;
}
@ -168,7 +168,7 @@ int SWIG_AsVal_dec(unsigned long long)(v8::Handle<v8::Value> obj, unsigned long
return SWIG_TypeError;
}
long long longVal = (long long) obj->NumberValue();
long long longVal = (long long) SWIGV8_NUMBER_VALUE(obj);
if(longVal < 0) {
return SWIG_OverflowError;
@ -198,7 +198,7 @@ int SWIG_AsVal_dec(double)(v8::Handle<v8::Value> obj, double *val)
if(!obj->IsNumber()) {
return SWIG_TypeError;
}
if(val) *val = obj->NumberValue();
if(val) *val = SWIGV8_NUMBER_VALUE(obj);
return SWIG_OK;
}

View file

@ -91,13 +91,39 @@ typedef v8::PropertyCallbackInfo<v8::Value> SwigV8PropertyCallbackInfo;
#define SWIGV8_SET_CLASS_TEMPL(class_templ, class) class_templ.Reset(v8::Isolate::GetCurrent(), class);
#endif
#ifdef NODE_VERSION
#if NODE_VERSION_AT_LEAST(10, 12, 0)
#define SWIG_NODE_AT_LEAST_1012
#endif
#endif
//Necessary to check Node.js version because V8 API changes are backported in Node.js
#if (defined(NODE_VERSION) && !defined(SWIG_NODE_AT_LEAST_1012)) || \
(!defined(NODE_VERSION) && (V8_MAJOR_VERSION-0) < 7)
#define SWIGV8_TO_OBJECT(handle) (handle)->ToObject()
#define SWIGV8_TO_STRING(handle) (handle)->ToString()
#define SWIGV8_NUMBER_VALUE(handle) (handle)->NumberValue()
#define SWIGV8_INTEGER_VALUE(handle) (handle)->IntegerValue()
#define SWIGV8_BOOLEAN_VALUE(handle) (handle)->BooleanValue()
#define SWIGV8_WRITE_UTF8(handle, buffer, len) (handle)->WriteUtf8(buffer, len)
#define SWIGV8_UTF8_LENGTH(handle) (handle)->Utf8Length()
#else
#define SWIGV8_TO_OBJECT(handle) (handle)->ToObject(SWIGV8_CURRENT_CONTEXT()).ToLocalChecked()
#define SWIGV8_TO_STRING(handle) (handle)->ToString(SWIGV8_CURRENT_CONTEXT()).ToLocalChecked()
#define SWIGV8_NUMBER_VALUE(handle) (handle)->NumberValue(SWIGV8_CURRENT_CONTEXT()).ToChecked()
#define SWIGV8_INTEGER_VALUE(handle) (handle)->IntegerValue(SWIGV8_CURRENT_CONTEXT()).ToChecked()
#define SWIGV8_BOOLEAN_VALUE(handle) (handle)->BooleanValue(SWIGV8_CURRENT_CONTEXT()).ToChecked()
#define SWIGV8_WRITE_UTF8(handle, buffer, len) (handle)->WriteUtf8(v8::Isolate::GetCurrent(), buffer, len)
#define SWIGV8_UTF8_LENGTH(handle) (handle)->Utf8Length(v8::Isolate::GetCurrent())
#endif
/* ---------------------------------------------------------------------------
* Error handling
*
* ---------------------------------------------------------------------------*/
#define SWIG_Error(code, msg) SWIGV8_ErrorHandler.error(code, msg)
#define SWIG_exception(code, msg) SWIGV8_ErrorHandler.error(code, msg)
#define SWIG_exception(code, msg) do { SWIGV8_ErrorHandler.error(code, msg); SWIG_fail; } while (0)
#define SWIG_fail goto fail
#define SWIGV8_OVERLOAD false
@ -109,11 +135,11 @@ SWIGINTERN void SWIG_V8_Raise(const char *msg) {
Note: There are two contexts for handling errors.
A static V8ErrorHandler is used in not overloaded methods.
For overloaded methods the throwing type checking mechanism is used
during dispatching. As V8 exceptions can not be resetted properly
during dispatching. As V8 exceptions can not be reset properly
the trick is to use a dynamic ErrorHandler with same local name as the global
one.
- See defintion of SWIG_Error above.
- See definition of SWIG_Error above.
- See code templates 'JS_function_dispatcher', 'JS_functionwrapper_overload',
and 'JS_function_dispatch_case' in javascriptcode.swg
@ -193,8 +219,10 @@ public:
void (*dtor) (v8::Isolate *isolate, v8::Persistent< v8::Value> object, void *parameter);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
void (*dtor) (v8::Isolate *isolate, v8::Persistent< v8::Object > *object, SWIGV8_Proxy *proxy);
#else
#elif (V8_MAJOR_VERSION-0) < 5
void (*dtor) (const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &data);
#else
void (*dtor) (const v8::WeakCallbackInfo<SWIGV8_Proxy> &data);
#endif
};
@ -241,9 +269,12 @@ SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(v8::Isolate *, v8::Persistent< v8::Val
SWIGV8_Proxy *proxy = static_cast<SWIGV8_Proxy *>(parameter);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(v8::Isolate *, v8::Persistent< v8::Object > *object, SWIGV8_Proxy *proxy) {
#else
#elif (V8_MAJOR_VERSION-0) < 5
SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &data) {
SWIGV8_Proxy *proxy = data.GetParameter();
#else
SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(const v8::WeakCallbackInfo<SWIGV8_Proxy> &data) {
SWIGV8_Proxy *proxy = data.GetParameter();
#endif
delete proxy;
@ -253,7 +284,7 @@ SWIGRUNTIME int SWIG_V8_GetInstancePtr(v8::Handle<v8::Value> valRef, void **ptr)
if(!valRef->IsObject()) {
return SWIG_TypeError;
}
v8::Handle<v8::Object> objRef = valRef->ToObject();
v8::Handle<v8::Object> objRef = SWIGV8_TO_OBJECT(valRef);
if(objRef->InternalFieldCount() < 1) return SWIG_ERROR;
@ -312,12 +343,18 @@ SWIGRUNTIME void SWIGV8_SetPrivateData(v8::Handle<v8::Object> obj, void *ptr, sw
} else {
cdata->handle.MakeWeak(cdata, SWIGV8_Proxy_DefaultDtor);
}
#else
#elif (V8_MAJOR_VERSION-0) < 5
if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) {
cdata->handle.SetWeak(cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor);
} else {
cdata->handle.SetWeak(cdata, SWIGV8_Proxy_DefaultDtor);
}
#else
if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) {
cdata->handle.SetWeak(cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor, v8::WeakCallbackType::kParameter);
} else {
cdata->handle.SetWeak(cdata, SWIGV8_Proxy_DefaultDtor, v8::WeakCallbackType::kParameter);
}
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
@ -336,12 +373,12 @@ SWIGRUNTIME int SWIG_V8_ConvertPtr(v8::Handle<v8::Value> valRef, void **ptr, swi
/* special case: JavaScript null => C NULL pointer */
if(valRef->IsNull()) {
*ptr=0;
return SWIG_OK;
return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
}
if(!valRef->IsObject()) {
return SWIG_TypeError;
}
v8::Handle<v8::Object> objRef = valRef->ToObject();
v8::Handle<v8::Object> objRef = SWIGV8_TO_OBJECT(valRef);
return SWIG_V8_ConvertInstancePtr(objRef, ptr, info, flags);
}
@ -468,10 +505,17 @@ SWIGRUNTIMEINLINE
int SwigV8Packed_Check(v8::Handle<v8::Value> valRef) {
SWIGV8_HANDLESCOPE();
v8::Handle<v8::Object> objRef = valRef->ToObject();
v8::Handle<v8::Object> objRef = SWIGV8_TO_OBJECT(valRef);
if(objRef->InternalFieldCount() < 1) return false;
#if (V8_MAJOR_VERSION-0) < 5
v8::Handle<v8::Value> flag = objRef->GetHiddenValue(SWIGV8_STRING_NEW("__swig__packed_data__"));
return (flag->IsBoolean() && flag->BooleanValue());
#else
v8::Local<v8::Private> privateKey = v8::Private::ForApi(v8::Isolate::GetCurrent(), SWIGV8_STRING_NEW("__swig__packed_data__"));
v8::Local<v8::Value> flag;
if (!objRef->GetPrivate(SWIGV8_CURRENT_CONTEXT(), privateKey).ToLocal(&flag))
return false;
#endif
return (flag->IsBoolean() && SWIGV8_BOOLEAN_VALUE(flag));
}
SWIGRUNTIME
@ -481,7 +525,7 @@ swig_type_info *SwigV8Packed_UnpackData(v8::Handle<v8::Value> valRef, void *ptr,
SwigV8PackedData *sobj;
v8::Handle<v8::Object> objRef = valRef->ToObject();
v8::Handle<v8::Object> objRef = SWIGV8_TO_OBJECT(valRef);
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031511)
v8::Handle<v8::Value> cdataRef = objRef->GetInternalField(0);
@ -519,10 +563,13 @@ SWIGRUNTIME void _wrap_SwigV8PackedData_delete(v8::Isolate *isolate, v8::Persist
SwigV8PackedData *cdata = static_cast<SwigV8PackedData *>(parameter);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
SWIGRUNTIME void _wrap_SwigV8PackedData_delete(v8::Isolate *isolate, v8::Persistent<v8::Object> *object, SwigV8PackedData *cdata) {
#else
#elif (V8_MAJOR_VERSION-0) < 5
SWIGRUNTIME void _wrap_SwigV8PackedData_delete(const v8::WeakCallbackData<v8::Object, SwigV8PackedData> &data) {
v8::Local<v8::Object> object = data.GetValue();
SwigV8PackedData *cdata = data.GetParameter();
#else
SWIGRUNTIME void _wrap_SwigV8PackedData_delete(const v8::WeakCallbackInfo<SwigV8PackedData> &data) {
SwigV8PackedData *cdata = data.GetParameter();
#endif
delete cdata;
@ -537,7 +584,7 @@ SWIGRUNTIME void _wrap_SwigV8PackedData_delete(const v8::WeakCallbackData<v8::Ob
object->Dispose(isolate);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
object->Dispose();
#else
#elif (V8_MAJOR_VERSION-0) < 5
object.Clear();
#endif
}
@ -550,7 +597,12 @@ v8::Handle<v8::Value> SWIGV8_NewPackedObj(void *data, size_t size, swig_type_inf
// v8::Handle<v8::Object> obj = SWIGV8_OBJECT_NEW();
v8::Local<v8::Object> obj = SWIGV8_OBJECT_NEW();
#if (V8_MAJOR_VERSION-0) < 5
obj->SetHiddenValue(SWIGV8_STRING_NEW("__swig__packed_data__"), SWIGV8_BOOLEAN_NEW(true));
#else
v8::Local<v8::Private> privateKey = v8::Private::ForApi(v8::Isolate::GetCurrent(), SWIGV8_STRING_NEW("__swig__packed_data__"));
obj->SetPrivate(SWIGV8_CURRENT_CONTEXT(), privateKey, SWIGV8_BOOLEAN_NEW(true));
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031511)
obj->SetPointerInInternalField(0, cdata);
@ -573,9 +625,11 @@ v8::Handle<v8::Value> SWIGV8_NewPackedObj(void *data, size_t size, swig_type_inf
cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, _wrap_SwigV8PackedData_delete);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
cdata->handle.MakeWeak(cdata, _wrap_SwigV8PackedData_delete);
#else
#elif (V8_MAJOR_VERSION-0) < 5
cdata->handle.SetWeak(cdata, _wrap_SwigV8PackedData_delete);
// v8::V8::SetWeak(&cdata->handle, cdata, _wrap_SwigV8PackedData_delete);
#else
cdata->handle.SetWeak(cdata, _wrap_SwigV8PackedData_delete, v8::WeakCallbackType::kParameter);
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)

View file

@ -44,6 +44,8 @@
#ifdef BUILDING_NODE_EXTENSION
%insert("runtime") %{
#include <node.h>
//Older version of node.h does not include this
#include <node_version.h>
%}
#endif

View file

@ -7,11 +7,11 @@ SWIGINTERN int
SWIG_AsCharPtrAndSize(v8::Handle<v8::Value> valRef, char** cptr, size_t* psize, int *alloc)
{
if(valRef->IsString()) {
v8::Handle<v8::String> js_str = valRef->ToString();
v8::Handle<v8::String> js_str = SWIGV8_TO_STRING(valRef);
size_t len = js_str->Utf8Length() + 1;
size_t len = SWIGV8_UTF8_LENGTH(js_str) + 1;
char* cstr = new char[len];
js_str->WriteUtf8(cstr, len);
SWIGV8_WRITE_UTF8(js_str, cstr, len);
if(alloc) *alloc = SWIG_NEWOBJ;
if(psize) *psize = len;
@ -20,7 +20,7 @@ SWIG_AsCharPtrAndSize(v8::Handle<v8::Value> valRef, char** cptr, size_t* psize,
return SWIG_OK;
} else {
if(valRef->IsObject()) {
v8::Handle<v8::Object> obj = valRef->ToObject();
v8::Handle<v8::Object> obj = SWIGV8_TO_OBJECT(valRef);
// try if the object is a wrapped char[]
swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
if (pchar_descriptor) {

View file

@ -8,6 +8,13 @@
#include <complex>
%}
namespace std {
%naturalvar complex;
template<typename T> class complex;
%template() complex<double>;
%template() complex<float>;
}
/* defining the complex as/from converters */
%swig_cplxdbl_convn(std::complex<double>, std::complex<double>, std::real, std::imag)

View file

@ -20,22 +20,28 @@
namespace std {
template<class K, class T> class map {
template<class K, class T, class C = std::less<K> > class map {
// add typemaps here
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef K key_type;
typedef T mapped_type;
typedef std::pair< const K, T > value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
map();
map(const map<K,T> &);
map(const map& other);
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);
std::map< K, T, C >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
@ -45,14 +51,14 @@ namespace std {
(*self)[key] = x;
}
void del(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
std::map< K, T, C >::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);
std::map< K, T, C >::iterator i = self->find(key);
return i != self->end();
}
}

View file

@ -17,12 +17,14 @@
namespace std {
template<class T, class U> struct pair {
typedef T first_type;
typedef U second_type;
pair();
pair(T first, U second);
pair(const pair& p);
pair(const pair& other);
template <class U1, class U2> pair(const pair<U1, U2> &p);
template <class U1, class U2> pair(const pair<U1, U2> &other);
T first;
U second;

View file

@ -14,10 +14,17 @@ namespace std {
template<class T> class vector {
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;
vector();
vector(size_type n);
vector(const vector& other);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);
@ -48,10 +55,17 @@ namespace std {
template<> class vector<bool> {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef bool value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef bool const_reference;
vector();
vector(size_type n);
vector(const vector& other);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);

View file

@ -33,7 +33,7 @@
%typemap(consttab) char *, const char *, char [], const char []
{SWIG_LUA_CONSTTAB_STRING("$symname", $value)}
// note: char is treated as a seperate special type
// note: char is treated as a separate special type
// signed char & unsigned char are numbers
%typemap(consttab) char
{SWIG_LUA_CONSTTAB_CHAR("$symname", $value)}

View file

@ -180,8 +180,8 @@ typedef struct swig_elua_entry {
* -------------------------------------------------------------------------- */
/* Push the string STR on the Lua stack, like lua_pushstring, but
prefixed with the the location of the innermost Lua call-point
(as formated by luaL_where). */
prefixed with the location of the innermost Lua call-point
(as formatted by luaL_where). */
SWIGRUNTIME void
SWIG_Lua_pusherrstring (lua_State *L, const char *str)
{
@ -191,8 +191,8 @@ SWIG_Lua_pusherrstring (lua_State *L, const char *str)
}
/* Push a formatted string generated from FMT and following args on
the Lua stack, like lua_pushfstring, but prefixed with the the
location of the innermost Lua call-point (as formated by luaL_where). */
the Lua stack, like lua_pushfstring, but prefixed with the
location of the innermost Lua call-point (as formatted by luaL_where). */
SWIGRUNTIME void
SWIG_Lua_pushferrstring (lua_State *L, const char *fmt, ...)
{
@ -289,7 +289,7 @@ to tell the two structures apart within SWIG, other than by looking at the type
typedef struct {
swig_type_info *type;
int own; /* 1 if owned & must be destroyed */
char data[1]; /* arbitary amount of data */
char data[1]; /* arbitrary amount of data */
} swig_lua_rawdata;
/* Common SWIG API */
@ -1765,7 +1765,12 @@ SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State *L,int index,void **ptr,swig_type
{
swig_lua_userdata *usr;
swig_cast_info *cast;
if (lua_isnil(L,index)){*ptr=0; return SWIG_OK;} /* special case: lua nil => NULL pointer */
/* special case: lua nil => NULL pointer */
if (lua_isnil(L,index))
{
*ptr=0;
return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
}
usr=(swig_lua_userdata*)lua_touserdata(L,index); /* get data */
if (usr)
{
@ -1860,7 +1865,7 @@ SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]) {
switch(constants[i].type) {
case SWIG_LUA_INT:
lua_pushstring(L,constants[i].name);
lua_pushinteger(L,(lua_Number)constants[i].lvalue);
lua_pushinteger(L,(lua_Integer)constants[i].lvalue);
lua_rawset(L,-3);
break;
case SWIG_LUA_FLOAT:
@ -1871,7 +1876,7 @@ SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]) {
case SWIG_LUA_CHAR:
lua_pushstring(L,constants[i].name);
{
char c = constants[i].lvalue;
char c = (char)constants[i].lvalue;
lua_pushlstring(L,&c,1);
}
lua_rawset(L,-3);

View file

@ -4,8 +4,9 @@
* all the runtime code for .
* ----------------------------------------------------------------------------- */
%runtime "swigrun.swg"; /* Common C API type-checking code */
%runtime "luarun.swg"; /* Lua runtime stuff */
%runtime "swigrun.swg" /* Common C API type-checking code */
%runtime "swigerrors.swg" /* SWIG errors */
%runtime "luarun.swg" /* Lua runtime stuff */
%insert(initbeforefunc) "swiginit.swg"

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