Merge branch 'master' into gsoc2017-php7-classes-via-c-api

This commit is contained in:
Olly Betts 2021-03-25 17:45:17 +13:00
commit 8ded9d8dae
1906 changed files with 50934 additions and 30001 deletions

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>
@ -24,9 +23,7 @@
%include <lua/luakw.swg>
%include <ocaml/ocamlkw.swg>
%include <perl5/perlkw.swg>
%include <php5/phpkw.swg>
%include <php/phpkw.swg>
%include <pike/pikekw.swg>
%include <python/pythonkw.swg>
%include <r/rkw.swg>
%include <ruby/rubykw.swg>

View file

@ -21,22 +21,7 @@ typedef struct SWIGCDATA {
}
%typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
#elif SWIGCHICKEN
%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 SWIGPHP5
%typemap(out) SWIGCDATA {
ZVAL_STRINGL($result, $1.data, $1.len, 1);
}
%typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
#elif SWIGPHP7
#elif SWIGPHP
%typemap(out) SWIGCDATA {
ZVAL_STRINGL($result, $1.data, $1.len);

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;
}
}

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

@ -31,6 +31,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_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,18 +82,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; %}
@ -75,6 +125,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;
@ -82,6 +139,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"
@ -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

View file

@ -855,6 +855,14 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
$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 *"
@ -867,6 +875,15 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
global::System.IntPtr ret = $imcall;$excode
return ret;
}
%typemap(csvarin, excode=SWIGEXCODE2) void *VOID_INT_PTR %{
set {
$imcall;$excode
} %}
%typemap(csvarout, excode=SWIGEXCODE2) void *VOID_INT_PTR %{
get {
global::System.IntPtr ret = $imcall;$excode
return ret;
} %}
%typemap(csdirectorin) void *VOID_INT_PTR "$iminput"
%typemap(csdirectorout) void *VOID_INT_PTR "$cscall"
@ -877,6 +894,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%typemap(csinterfaces) SWIGTYPE "global::System.IDisposable"
%typemap(csinterfaces) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
%typemap(csinterfaces_derived) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
%typemap(csinterfacemodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "public interface"
// csbody typemaps... these are in macros so that the visibility of the methods can be easily changed by users.
@ -951,17 +969,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) {
@ -970,11 +995,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) {
@ -983,8 +1007,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);
}
}

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

@ -192,9 +192,9 @@
else
throw std::out_of_range("index");
}
void setitem(int index, const_reference value) throw (std::out_of_range) {
void setitem(int index, const_reference val) throw (std::out_of_range) {
if (index>=0 && index<(int)$self->size())
(*$self)[index] = value;
(*$self)[index] = val;
else
throw std::out_of_range("index");
}

View file

@ -45,8 +45,11 @@ public:
%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_ltype temp), const std::complex<T> &($*1_ltype temp)
%{temp = std::complex< double >($input.real, $input.imag);
%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>

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

@ -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;

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

@ -13,18 +13,13 @@
*
* 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(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)
@ -114,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);
}
@ -195,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;
@ -206,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;
@ -231,9 +239,9 @@
else
throw std::out_of_range("index");
}
void setitem(int index, CTYPE const& value) throw (std::out_of_range) {
void setitem(int index, CTYPE const& val) throw (std::out_of_range) {
if (index>=0 && index<(int)$self->size())
(*$self)[index] = value;
(*$self)[index] = val;
else
throw std::out_of_range("index");
}
@ -343,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)
};
}
@ -376,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

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);
@ -52,7 +53,7 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterWStringCallback_$module(SWIG_CSharpWStri
// wchar_t
%typemap(ctype) wchar_t "wchar_t"
%typemap(imtype) wchar_t "char"
%typemap(imtype) wchar_t "char" // Requires adding CharSet=CharSet.Unicode to the DllImport to correctly marshal Unicode characters
%typemap(cstype) wchar_t "char"
%typemap(csin) wchar_t "$csinput"
@ -91,7 +92,7 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterWStringCallback_$module(SWIG_CSharpWStri
} %}
%typemap(csvarout, excode=SWIGEXCODE2) wchar_t * %{
get {
string ret = $imcall;$excode
string ret = global::System.Runtime.InteropServices.Marshal.PtrToStringUni($imcall);$excode
return ret;
} %}

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

@ -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

@ -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

@ -17,21 +17,27 @@
%}
namespace std {
template<class K, class T> class map {
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;
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
@ -41,14 +47,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 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

@ -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.");
}
@ -165,11 +172,11 @@ public void capacity(size_t value) {
// generation issue when using const pointers as vector elements (like
// std::vector< const int* >).
%extend {
void setElement(size_type index, CTYPE const& value) throw (std::out_of_range) {
void setElement(size_type index, CTYPE const& val) throw (std::out_of_range) {
if ((index < 0) || ($self->size() <= index)) {
throw std::out_of_range("Tried to set value of element with invalid index.");
}
(*$self)[index] = value;
(*$self)[index] = val;
}
}
@ -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.");
}
@ -517,11 +531,11 @@ int opApply(int delegate(ref size_t index, ref $typemap(dtype, CTYPE) value) dg)
// generation issue when using const pointers as vector elements (like
// std::vector< const int* >).
%extend {
void setElement(size_type index, CTYPE const& value) throw (std::out_of_range) {
void setElement(size_type index, CTYPE const& val) throw (std::out_of_range) {
if ((index < 0) || ($self->size() <= index)) {
throw std::out_of_range("Tried to set value of element with invalid index.");
}
(*$self)[index] = value;
(*$self)[index] = val;
}
}
@ -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

@ -40,9 +40,10 @@ private {
} else {
version(D_Version2) {
static import std.conv;
} else {
static import std.c.string;
}
static import std.string;
static import std.c.string;
}
version(D_Version2) {
@ -112,7 +113,7 @@ private {
version(Tango) {
import tango.sys.Common;
} else version(linux) {
import std.c.linux.linux;
import core.sys.posix.dlfcn;
} else {
extern(C) {
const RTLD_NOW = 2;

View file

@ -12,14 +12,7 @@
%insert("runtime") "swigerrors.swg"
#ifdef SWIGPHP5
%{
#include "zend_exceptions.h"
#define SWIG_exception(code, msg) do { zend_throw_exception(NULL, (char*)msg, code TSRMLS_CC); goto thrown; } while (0)
%}
#endif
#ifdef SWIGPHP7
#ifdef SWIGPHP
%{
#include "zend_exceptions.h"
#define SWIG_exception(code, msg) do { zend_throw_exception(NULL, (char*)msg, code); goto thrown; } while (0)
@ -134,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) {

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

@ -380,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%}

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

@ -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,14 +186,13 @@ SWIG_Guile_ConvertPtr(SCM s, void **result, swig_type_info *type, int flags)
if (SCM_NULLP(smob)) {
*result = NULL;
return SWIG_OK;
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;
#endif /* if SCM_MAJOR_VERSION >= 2 */
} else if (SCM_SMOB_PREDICATE(swig_tag, smob) || SCM_SMOB_PREDICATE(swig_collectable_tag, smob)) {
/* we do not accept smobs representing destroyed pointers */
} else if (SWIG_Guile_IsValidSmob(smob)) {
from = (swig_type_info *) SCM_CELL_WORD_2(smob);
if (!from) return SWIG_ERROR;
if (type) {
@ -241,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);
@ -254,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);
@ -421,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

@ -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);
}

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

@ -104,7 +104,7 @@ JAVA_ARRAYS_DECL(int, jint, Int, Int) /* int[] */
JAVA_ARRAYS_DECL(unsigned int, jlong, Long, Uint) /* unsigned int[] */
JAVA_ARRAYS_DECL(long, jint, Int, Long) /* long[] */
JAVA_ARRAYS_DECL(unsigned long, jlong, Long, Ulong) /* unsigned long[] */
JAVA_ARRAYS_DECL(jlong, jlong, Long, Longlong) /* long long[] */
JAVA_ARRAYS_DECL(long long, jlong, Long, Longlong) /* long long[] */
JAVA_ARRAYS_DECL(float, jfloat, Float, Float) /* float[] */
JAVA_ARRAYS_DECL(double, jdouble, Double, Double) /* double[] */
@ -128,7 +128,7 @@ JAVA_ARRAYS_IMPL(int, jint, Int, Int) /* int[] */
JAVA_ARRAYS_IMPL(unsigned int, jlong, Long, Uint) /* unsigned int[] */
JAVA_ARRAYS_IMPL(long, jint, Int, Long) /* long[] */
JAVA_ARRAYS_IMPL(unsigned long, jlong, Long, Ulong) /* unsigned long[] */
JAVA_ARRAYS_IMPL(jlong, jlong, Long, Longlong) /* long long[] */
JAVA_ARRAYS_IMPL(long long, jlong, Long, Longlong) /* long long[] */
JAVA_ARRAYS_IMPL(float, jfloat, Float, Float) /* float[] */
JAVA_ARRAYS_IMPL(double, jdouble, Double, Double) /* double[] */

View file

@ -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

@ -31,6 +31,19 @@
%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,6 +87,16 @@
%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;
@ -63,12 +104,34 @@
%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; %}
%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)
%{ $1 = $input ? *($&1_ltype)&$input : &tempnull; %}
@ -76,6 +139,16 @@
%{ *($&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;
@ -83,6 +156,16 @@
%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,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::*) %{
#error "typemaps for $1_type not available"
@ -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;
@ -225,6 +320,18 @@
}
%}
// 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() {
@ -160,6 +215,15 @@ namespace Swig {
}
};
struct SwigDirectorMethod {
const char *name;
const char *desc;
jmethodID methid;
SwigDirectorMethod(JNIEnv *jenv, jclass baseclass, const char *name, const char *desc) : name(name), desc(desc) {
methid = jenv->GetMethodID(baseclass, name, desc);
}
};
/* Java object wrapper */
JObjectWrapper swig_self_;
@ -183,6 +247,11 @@ namespace Swig {
}
}
jclass swig_new_global_ref(JNIEnv *jenv, const char *classname) {
jclass clz = jenv->FindClass(classname);
return clz ? (jclass)jenv->NewGlobalRef(clz) : 0;
}
public:
Director(JNIEnv *jenv) : swig_jvm_((JavaVM *) NULL), swig_self_() {
/* Acquire the Java VM pointer */
@ -259,8 +328,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 +365,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 +390,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 +403,49 @@ 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);
}
@ -380,11 +470,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

@ -160,7 +160,7 @@ SWIGINTERN jint SWIG_JavaIntFromSize_t(size_t size) {
%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[]"
@ -169,7 +169,7 @@ SWIGINTERN jint SWIG_JavaIntFromSize_t(size_t size) {
%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"
@ -180,7 +180,7 @@ SWIGINTERN jint SWIG_JavaIntFromSize_t(size_t size) {
%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[]"
@ -189,7 +189,7 @@ SWIGINTERN jint SWIG_JavaIntFromSize_t(size_t size) {
%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"
@ -1051,6 +1051,14 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); }
%{ 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 */
@ -1173,6 +1181,14 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); }
$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::*) ""
@ -1180,6 +1196,7 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); }
%typemap(javacode) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
%typemap(javaimports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
%typemap(javainterfaces) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
%typemap(javainterfacemodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "public interface"
/* javabody typemaps */
@ -1257,6 +1274,7 @@ SWIG_JAVABODY_PROXY(protected, protected, SWIGTYPE)
SWIG_JAVABODY_TYPEWRAPPER(protected, protected, protected, SWIGTYPE)
%typemap(javafinalize) SWIGTYPE %{
@SuppressWarnings("deprecation")
protected void finalize() {
delete();
}
@ -1296,7 +1314,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;
@ -1306,7 +1324,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;
@ -1366,12 +1384,12 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE)
%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);
@ -1380,10 +1398,10 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE)
$2 = 0;
}
}
%typemap(argout) (char *STRING, size_t LENGTH) {
if ($input) JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 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) (char *STRING, size_t LENGTH) {
%typemap(directorin, descriptor="[B", noblock=1) (const char *STRING, size_t LENGTH) {
$input = 0;
if ($1) {
$input = JCALL1(NewByteArray, jenv, (jsize)$2);
@ -1392,9 +1410,14 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE)
}
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(directorargout, noblock=1) (char *STRING, size_t LENGTH)
{ if ($input && $1) JCALL4(GetByteArrayRegion, jenv, $input, 0, (jsize)$2, (jbyte *)$1); }
%typemap(javadirectorin, descriptor="[B") (char *STRING, size_t LENGTH) "$jniinput"
%apply (char *STRING, size_t LENGTH) { (char *STRING, int LENGTH) }
/* java keywords */

View file

@ -5,7 +5,7 @@
* ----------------------------------------------------------------------------- */
/* JNI function calls require different calling conventions for C and C++. These JCALL macros are used so
/* JNI function calls require different calling conventions for C and C++. These JCALL macros are used so
* that the same typemaps can be used for generating code for both C and C++. The SWIG preprocessor can expand
* the macros thereby generating the correct calling convention. It is thus essential that all typemaps that
* use the macros are not within %{ %} brackets as they won't be run through the SWIG preprocessor. */
@ -30,18 +30,6 @@
#endif
%insert(runtime) %{
/* Fix for jlong on some versions of gcc on Windows */
#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
typedef long long __int64;
#endif
/* Fix for jlong on 64-bit x86 Solaris */
#if defined(__x86_64)
# ifdef _LP64
# undef _LP64
# endif
#endif
#include <jni.h>
#include <stdlib.h>
#include <string.h>
@ -50,15 +38,16 @@
%insert(runtime) %{
/* Support for throwing Java exceptions */
typedef enum {
SWIG_JavaOutOfMemoryError = 1,
SWIG_JavaIOException,
SWIG_JavaRuntimeException,
SWIG_JavaOutOfMemoryError = 1,
SWIG_JavaIOException,
SWIG_JavaRuntimeException,
SWIG_JavaIndexOutOfBoundsException,
SWIG_JavaArithmeticException,
SWIG_JavaIllegalArgumentException,
SWIG_JavaNullPointerException,
SWIG_JavaDirectorPureVirtual,
SWIG_JavaUnknownError
SWIG_JavaUnknownError,
SWIG_JavaIllegalStateException,
} SWIG_JavaExceptionCodes;
typedef struct {
@ -80,6 +69,7 @@ static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionC
{ SWIG_JavaNullPointerException, "java/lang/NullPointerException" },
{ SWIG_JavaDirectorPureVirtual, "java/lang/RuntimeException" },
{ SWIG_JavaUnknownError, "java/lang/UnknownError" },
{ SWIG_JavaIllegalStateException, "java/lang/IllegalStateException" },
{ (SWIG_JavaExceptionCodes)0, "java/lang/UnknownError" }
};
const SWIG_JavaExceptions_t *except_ptr = java_exceptions;

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;
@ -29,10 +31,10 @@ namespace std {
else
throw std::out_of_range("array index out of range");
}
void set(int i, const value_type& value) throw (std::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] = value;
(*self)[i] = val;
else
throw std::out_of_range("array index out of range");
}

View file

@ -43,7 +43,7 @@ namespace std {
this();
java.util.ListIterator<$typemap(jboxtype, T)> it = listIterator(0);
// Special case the "copy constructor" here to avoid lots of cross-language calls
for (Object o : c) {
for (java.lang.Object o : c) {
it.add(($typemap(jboxtype, T))o);
}
}
@ -130,8 +130,12 @@ namespace std {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T value_type;
typedef T &reference;
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
@ -173,7 +177,8 @@ namespace std {
};
list();
list(const list &other);
list(const list& other);
%rename(isEmpty) empty;
bool empty() const;
void clear();
@ -193,11 +198,6 @@ namespace std {
%extend {
%fragment("SWIG_ListSize");
list(jint count) 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));
}
list(jint count, const T &value) throw (std::out_of_range) {
if (count < 0)

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,48 +14,199 @@
%{
#include <map>
#include <algorithm>
#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::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 {
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 {
unsigned int size() const;
bool empty() const;
void clear();
%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 {
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");
std::map< K, T, C >::iterator getNextUnchecked() {
std::map< K, T, C >::iterator copy = (*$self);
return ++copy;
}
void set(const K& key, const T& x) {
(*self)[key] = x;
bool isNot(iterator other) const {
return (*$self != other);
}
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");
K getKey() const {
return (*$self)->first;
}
bool has_key(const K& key) {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
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)

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

@ -23,12 +23,14 @@ SWIGINTERN jint SWIG_VectorSize(size_t size) {
}
}
%define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CTYPE, CREF_TYPE)
%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);
}
@ -79,13 +81,14 @@ SWIGINTERN jint SWIG_VectorSize(size_t size) {
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef CTYPE value_type;
typedef CTYPE &reference;
typedef CREF_TYPE const_reference;
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;
@ -93,11 +96,6 @@ SWIGINTERN jint SWIG_VectorSize(size_t size) {
void clear();
%extend {
%fragment("SWIG_VectorSize");
vector(jint count) 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));
}
vector(jint count, const CTYPE &value) throw (std::out_of_range) {
if (count < 0)
@ -109,21 +107,21 @@ SWIGINTERN jint SWIG_VectorSize(size_t size) {
return SWIG_VectorSize(self->size());
}
void doAdd(const value_type& value) {
self->push_back(value);
void doAdd(const value_type& x) {
self->push_back(x);
}
void doAdd(jint index, const value_type& value) throw (std::out_of_range) {
const jint size = static_cast<std::vector< CTYPE >::size_type>(self->size());
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, value);
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) {
const jint size = static_cast<std::vector< CTYPE >::size_type>(self->size());
jint size = static_cast<jint>(self->size());
if (0 <= index && index < size) {
CTYPE const old_value = (*self)[index];
self->erase(self->begin() + index);
@ -133,19 +131,19 @@ SWIGINTERN jint SWIG_VectorSize(size_t size) {
}
}
CREF_TYPE doGet(jint index) throw (std::out_of_range) {
const jint size = static_cast<std::vector< CTYPE >::size_type>(self->size());
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& value) throw (std::out_of_range) {
const jint size = static_cast<std::vector< CTYPE >::size_type>(self->size());
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] = value;
(*self)[index] = val;
return old_value;
}
else
@ -153,7 +151,7 @@ SWIGINTERN jint SWIG_VectorSize(size_t size) {
}
void doRemoveRange(jint fromIndex, jint toIndex) throw (std::out_of_range) {
const jint size = static_cast<std::vector< CTYPE >::size_type>(self->size());
jint size = static_cast<jint>(self->size());
if (0 <= fromIndex && fromIndex <= toIndex && toIndex <= size) {
self->erase(self->begin() + fromIndex, self->begin() + toIndex);
} else {
@ -173,7 +171,7 @@ SWIGINTERN jint SWIG_VectorSize(size_t size) {
namespace std {
template<class T> class vector {
SWIG_STD_VECTOR_MINIMUM_INTERNAL(T, const T&)
SWIG_STD_VECTOR_MINIMUM_INTERNAL(T, const value_type&)
};
// bool specialization
@ -185,4 +183,3 @@ namespace std {
%define specialize_std_vector(T)
#warning "specialize_std_vector - specialization for type T no longer needed"
%enddef

View file

@ -212,8 +212,16 @@ There are no char *OUTPUT typemaps, however you can apply the signed char * type
JCALL4(Set##JAVATYPE##ArrayRegion, jenv, $input, 0, 1, &jvalue);
}
%typemap(directorin,descriptor=JNIDESC) TYPE &OUTPUT, TYPE *OUTPUT %{
%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
@ -225,9 +233,11 @@ There are no char *OUTPUT typemaps, however you can apply the signed char * type
%typemap(directorargout, noblock=1) TYPE *OUTPUT
{
JNITYPE $1_jvalue;
JCALL4(Get##JAVATYPE##ArrayRegion, jenv, $input, 0, 1, &$1_jvalue);
*$result = ($*1_ltype)$1_jvalue;
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;
@ -273,9 +283,11 @@ OUTPUT_TYPEMAP(double, jdouble, double, Double, "[D", jdoubleArray);
%typemap(directorargout, noblock=1) bool *OUTPUT
{
jboolean $1_jvalue;
JCALL4(GetBooleanArrayRegion, jenv, $input, 0, 1, &$1_jvalue);
*$result = $1_jvalue ? true : false;
if ($result) {
jboolean $1_jvalue;
JCALL4(GetBooleanArrayRegion, jenv, $input, 0, 1, &$1_jvalue);
*$result = $1_jvalue ? true : false;
}
}
@ -388,14 +400,18 @@ There are no char *INOUT typemaps, however you can apply the signed char * typem
%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 %{
$input = JCALL1(New##JAVATYPE##Array, jenv, 1);
JNITYPE $1_jvalue = (JNITYPE)*$1;
JCALL4(Set##JAVATYPE##ArrayRegion, jenv, $input, 0, 1, &$1_jvalue);
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
@ -406,8 +422,11 @@ There are no char *INOUT typemaps, however you can apply the signed char * typem
%typemap(directorargout, noblock=1) TYPE *INOUT
{
JCALL4(Get##JAVATYPE##ArrayRegion, jenv, $input, 0, 1, &$1_jvalue);
*$result = ($*1_ltype)$1_jvalue;
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;
@ -459,8 +478,11 @@ INOUT_TYPEMAP(double, jdouble, double, Double, "[D", jdoubleArray);
%typemap(directorargout, noblock=1) bool *INOUT
{
JCALL4(GetBooleanArrayRegion, jenv, $input, 0, 1, &$1_jvalue);
*$result = $1_jvalue ? true : false;
if ($result) {
jboolean $1_jvalue;
JCALL4(GetBooleanArrayRegion, jenv, $input, 0, 1, &$1_jvalue);
*$result = $1_jvalue ? true : false;
}
}

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

@ -21,34 +21,39 @@
* fs = example.FiddleSticks;
* ----------------------------------------------------------------------------- */
%fragment("SWIG_JSCGetIntProperty", "header", fragment=SWIG_AsVal_frag(int)) {}
%fragment("SWIG_JSCGetIntProperty", "header", fragment=SWIG_AsVal_frag(int)) {}
%fragment("SWIG_JSCGetNumberProperty", "header", fragment=SWIG_AsVal_frag(double)) {}
%fragment("SWIG_JSCOutInt", "header", fragment=SWIG_From_frag(int)) {}
%fragment("SWIG_JSCOutNumber", "header", fragment=SWIG_From_frag(double)) {}
%typemap(in, fragment="SWIG_JSCGetIntProperty") int[], int[ANY]
(int length = 0, JSObjectRef array, JSValueRef jsvalue, int i = 0, int res = 0, $*1_ltype temp) {
%define JAVASCRIPT_ARRAYS_IN_DECL(NAME, CTYPE, ANY, ANYLENGTH)
%typemap(in, fragment=NAME) CTYPE[ANY] {
if (JSValueIsObject(context, $input))
{
int i;
// Convert into Array
array = JSValueToObject(context, $input, NULL);
JSObjectRef array = JSValueToObject(context, $input, NULL);
length = $1_dim0;
int length = ANYLENGTH;
$1 = ($*1_ltype *)malloc(sizeof($*1_ltype) * length);
// Get each element from array
for (i = 0; i < length; i++)
{
jsvalue = JSObjectGetPropertyAtIndex(context, array, i, NULL);
JSValueRef jsvalue = JSObjectGetPropertyAtIndex(context, array, i, NULL);
$*1_ltype temp;
// Get primitive value from JSObject
res = SWIG_AsVal(int)(jsvalue, &temp);
int res = SWIG_AsVal(CTYPE)(jsvalue, &temp);
if (!SWIG_IsOK(res))
{
SWIG_exception_fail(SWIG_ERROR, "Failed to convert $input to double");
}
arg$argnum[i] = temp;
}
}
else
{
@ -56,68 +61,34 @@
}
}
%typemap(freearg) int[], int[ANY] {
%typemap(freearg) CTYPE[ANY] {
free($1);
}
%typemap(out, fragment=SWIG_From_frag(int)) int[], int[ANY] (int length = 0, int i = 0)
{
length = $1_dim0;
%enddef
%define JAVASCRIPT_ARRAYS_OUT_DECL(NAME, CTYPE)
%typemap(out, fragment=NAME) CTYPE[ANY] {
int length = $1_dim0;
JSValueRef values[length];
int i;
for (i = 0; i < length; i++)
{
values[i] = SWIG_From(int)($1[i]);
values[i] = SWIG_From(CTYPE)($1[i]);
}
$result = JSObjectMakeArray(context, length, values, NULL);
}
%typemap(in, fragment="SWIG_JSCGetNumberProperty") double[], double[ANY]
(int length = 0, JSObjectRef array, JSValueRef jsvalue, int i = 0, int res = 0, $*1_ltype temp) {
if (JSValueIsObject(context, $input))
{
// Convert into Array
array = JSValueToObject(context, $input, NULL);
%enddef
length = $1_dim0;
JAVASCRIPT_ARRAYS_IN_DECL("SWIG_JSCGetIntProperty", int, , SWIGJSC_ArrayLength(context, array))
JAVASCRIPT_ARRAYS_IN_DECL("SWIG_JSCGetIntProperty", int, ANY, $1_dim0)
JAVASCRIPT_ARRAYS_IN_DECL("SWIG_JSCGetNumberProperty", double, , SWIGJSC_ArrayLength(context, array))
JAVASCRIPT_ARRAYS_IN_DECL("SWIG_JSCGetNumberProperty", double, ANY, $1_dim0)
$1 = ($*1_ltype *)malloc(sizeof($*1_ltype) * length);
JAVASCRIPT_ARRAYS_OUT_DECL("SWIG_JSCOutInt", int)
JAVASCRIPT_ARRAYS_OUT_DECL("SWIG_JSCOutNumber", double)
// Get each element from array
for (i = 0; i < length; i++)
{
jsvalue = JSObjectGetPropertyAtIndex(context, array, i, NULL);
// Get primitive value from JSObject
res = SWIG_AsVal(double)(jsvalue, &temp);
if (!SWIG_IsOK(res))
{
SWIG_exception_fail(SWIG_ERROR, "Failed to convert $input to double");
}
arg$argnum[i] = temp;
}
}
else
{
SWIG_exception_fail(SWIG_ERROR, "$input is not JSObjectRef");
}
}
%typemap(freearg) double[], double[ANY] {
free($1);
}
%typemap(out, fragment=SWIG_From_frag(double)) double[], double[ANY] (int length = 0, int i = 0)
{
length = $1_dim0;
JSValueRef values[length];
for (i = 0; i < length; i++)
{
values[i] = SWIG_From(double)($1[i]);
}
$result = JSObjectMakeArray(context, length, values, NULL);
}

View file

@ -12,15 +12,16 @@
#include <complex.h>
%}
#define complex _Complex
/* C complex constructor */
#define CCplxConst(r, i) ((r) + I*(i))
%swig_cplxflt_convn(float complex, CCplxConst, creal, cimag);
%swig_cplxdbl_convn(double complex, CCplxConst, creal, cimag);
%swig_cplxdbl_convn(complex, CCplxConst, creal, cimag);
%swig_cplxflt_convn(float _Complex, CCplxConst, creal, cimag);
%swig_cplxdbl_convn(double _Complex, CCplxConst, creal, cimag);
%swig_cplxdbl_convn(_Complex, CCplxConst, creal, cimag);
/* declaring the typemaps */
%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float complex);
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double complex);
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, complex);
%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float _Complex);
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double _Complex);
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, _Complex);

View file

@ -388,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

@ -127,7 +127,7 @@ SWIG_AsVal_dec(Type)(JSValueRef o, Type *val)
float re;
int res = SWIG_AddCast(SWIG_AsVal(float)(o, &re));
if (SWIG_IsOK(res)) {
if (val) *val = Constructor(re, 0.0);
if (val) *val = Constructor(re, 0.0f);
return res;
}
}

View file

@ -1,14 +1,59 @@
%insert(init) %{
SWIGRUNTIME void
SWIG_JSC_SetModule(swig_module_info *swig_module) {}
SWIG_JSC_SetModule(JSGlobalContextRef context, swig_module_info *swig_module) {
JSObjectRef globalObject;
JSStringRef moduleName;
JSClassDefinition classDef;
JSClassRef classRef;
JSObjectRef object;
if(context == 0){
return;
}
globalObject = JSContextGetGlobalObject(context);
moduleName = JSStringCreateWithUTF8CString("swig_module_info_data");
classDef = kJSClassDefinitionEmpty;
classRef = JSClassCreate(&classDef);
object = JSObjectMake(context, classRef, NULL);
JSObjectSetPrivate(object, (void*)swig_module);
JSObjectSetProperty(context, globalObject, moduleName, object, kJSPropertyAttributeNone, NULL);
JSClassRelease(classRef);
JSStringRelease(moduleName);
}
SWIGRUNTIME swig_module_info *
SWIG_JSC_GetModule(void) {
return 0;
SWIG_JSC_GetModule(JSGlobalContextRef context) {
JSObjectRef globalObject;
JSStringRef moduleName;
JSValueRef value;
JSObjectRef object;
if(context == 0){
return 0;
}
globalObject = JSContextGetGlobalObject(context);
moduleName = JSStringCreateWithUTF8CString("swig_module_info_data");
if(JSObjectHasProperty(context, globalObject, moduleName) == false) {
JSStringRelease(moduleName);
return 0;
}
value = JSObjectGetProperty(context, globalObject, moduleName, NULL);
object = JSValueToObject(context, value, NULL);
JSStringRelease(moduleName);
return (swig_module_info*)JSObjectGetPrivate(object);
}
#define SWIG_GetModule(clientdata) SWIG_JSC_GetModule()
#define SWIG_SetModule(clientdata, pointer) SWIG_JSC_SetModule(pointer)
#define SWIG_GetModule(clientdata) SWIG_JSC_GetModule(clientdata)
#define SWIG_SetModule(clientdata, pointer) SWIG_JSC_SetModule(clientdata, pointer)
#define SWIG_INIT_CLIENT_DATA_TYPE JSGlobalContextRef
%}
%insert(init) "swiginit.swg"
@ -26,7 +71,7 @@ extern "C" {
#endif
bool SWIGJSC_INIT (JSGlobalContextRef context, JSObjectRef *exports) {
SWIG_InitializeModule(0);
SWIG_InitializeModule(context);
%}
/* -----------------------------------------------------------------------------

View file

@ -117,27 +117,25 @@ SWIGRUNTIME int SWIG_JSC_ConvertInstancePtr(JSContextRef context, JSObjectRef ob
SwigPrivData *cdata;
cdata = (SwigPrivData *) JSObjectGetPrivate(objRef);
if(cdata == NULL) {
if (cdata == NULL) {
return SWIG_ERROR;
}
if(cdata->info != info) {
bool type_valid = false;
swig_cast_info *t = info->cast;
while(t != NULL) {
if(t->type == cdata->info) {
type_valid = true;
break;
}
t = t->next;
}
if(!type_valid) {
return SWIG_TypeError;
assert(ptr);
*ptr = NULL;
if (cdata->info == info) {
*ptr = cdata->swigCObject;
} else {
swig_cast_info *tc = SWIG_TypeCheckStruct(cdata->info, info);
if (tc) {
int newmemory = 0;
*ptr = SWIG_TypeCast(tc, cdata->swigCObject, &newmemory);
assert(!newmemory); /* newmemory handling not yet implemented */
} else {
return SWIG_ERROR;
}
}
*ptr = cdata->swigCObject;
if(flags & SWIG_POINTER_DISOWN) {
if (flags & SWIG_POINTER_DISOWN) {
cdata->swigCMemOwn = false;
}
@ -150,7 +148,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)) {
@ -317,6 +315,30 @@ unsigned int SWIGJSC_ArrayLength(JSContextRef context, JSObjectRef arr) {
}
}
SWIGRUNTIME
bool SWIGJSC_ValueIsArray(JSContextRef context, JSValueRef value) {
if (JSValueIsObject(context, value)) {
static JSStringRef ArrayString = NULL;
static JSStringRef isArrayString = NULL;
JSObjectRef array = NULL;
JSObjectRef isArray = NULL;
JSValueRef retval = NULL;
if (!ArrayString)
ArrayString = JSStringCreateWithUTF8CString("Array");
if (!isArrayString)
isArrayString = JSStringCreateWithUTF8CString("isArray");
array = (JSObjectRef)JSObjectGetProperty(context, JSContextGetGlobalObject(context), ArrayString, NULL);
isArray = (JSObjectRef)JSObjectGetProperty(context, array, isArrayString, NULL);
retval = JSObjectCallAsFunction(context, isArray, NULL, 1, &value, NULL);
if (JSValueIsBoolean(context, retval))
return JSValueToBoolean(context, retval);
}
return false;
}
SWIGRUNTIME
JSValueRef SWIGJSC_AppendOutput(JSContextRef context, JSValueRef value, JSValueRef obj) {
JSObjectRef arr;
@ -324,6 +346,8 @@ JSValueRef SWIGJSC_AppendOutput(JSContextRef context, JSValueRef value, JSValueR
if (JSValueIsUndefined(context, value)) {
arr = JSObjectMakeArray(context, 0, 0, 0);
} else if (!SWIGJSC_ValueIsArray(context, value)) {
arr = JSObjectMakeArray(context, 1, &value, 0);
} else {
arr = JSValueToObject(context, value, 0);
}

View file

@ -11,6 +11,7 @@
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <assert.h>
%}
%insert(runtime) "swigrun.swg"; /* SWIG API */

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

@ -21,105 +21,66 @@
* fs = example.FiddleSticks;
* ----------------------------------------------------------------------------- */
%fragment("SWIG_JSCGetIntProperty", "header", fragment=SWIG_AsVal_frag(int)) {}
%fragment("SWIG_JSCGetIntProperty", "header", fragment=SWIG_AsVal_frag(int)) {}
%fragment("SWIG_JSCGetNumberProperty", "header", fragment=SWIG_AsVal_frag(double)) {}
%fragment("SWIG_JSCOutInt", "header", fragment=SWIG_From_frag(int)) {}
%fragment("SWIG_JSCOutNumber", "header", fragment=SWIG_From_frag(double)) {}
%typemap(in, fragment="SWIG_JSCGetIntProperty") int[], int[ANY]
(int length = 0, v8::Local<v8::Array> array, v8::Local<v8::Value> jsvalue, int i = 0, int res = 0, $*1_ltype temp) {
if ($input->IsArray())
{
%define JAVASCRIPT_ARRAYS_IN_DECL(NAME, CTYPE, ANY, ANYLENGTH)
%typemap(in, fragment=NAME) CTYPE[ANY] {
if ($input->IsArray()) {
// Convert into Array
array = v8::Local<v8::Array>::Cast($input);
v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast($input);
length = $1_dim0;
int length = ANYLENGTH;
$1 = ($*1_ltype *)malloc(sizeof($*1_ltype) * length);
$1 = ($*1_ltype *)malloc(sizeof($*1_ltype) * length);
// Get each element from array
for (i = 0; i < length; i++)
{
jsvalue = array->Get(i);
for (int i = 0; i < length; i++) {
v8::Local<v8::Value> jsvalue = SWIGV8_ARRAY_GET(array, i);
$*1_ltype temp;
// Get primitive value from JSObject
res = SWIG_AsVal(int)(jsvalue, &temp);
if (!SWIG_IsOK(res))
{
int res = SWIG_AsVal(CTYPE)(jsvalue, &temp);
if (!SWIG_IsOK(res)) {
SWIG_exception_fail(SWIG_ERROR, "Failed to convert $input to double");
}
arg$argnum[i] = temp;
}
}
else
{
SWIG_exception_fail(SWIG_ERROR, "$input is not JSObjectRef");
} else {
SWIG_exception_fail(SWIG_ERROR, "$input is not an array");
}
}
%typemap(freearg) int[], int[ANY] {
free($1);
%typemap(freearg) CTYPE[ANY] {
free($1);
}
%typemap(out, fragment=SWIG_From_frag(int)) int[], int[ANY] (int length = 0, int i = 0)
{
length = $1_dim0;
v8::Local<v8::Array> array = v8::Array::New(length);
%enddef
for (i = 0; i < length; i++)
{
array->Set(i, SWIG_From(int)($1[i]));
%define JAVASCRIPT_ARRAYS_OUT_DECL(NAME, CTYPE)
%typemap(out, fragment=NAME) CTYPE[ANY] {
int length = $1_dim0;
v8::Local<v8::Array> array = SWIGV8_ARRAY_NEW(length);
for (int i = 0; i < length; i++) {
SWIGV8_ARRAY_SET(array, i, SWIG_From(CTYPE)($1[i]));
}
$result = array;
}
%typemap(in, fragment="SWIG_JSCGetNumberProperty") double[], double[ANY]
(int length = 0, v8::Local<v8::Array> array, v8::Local<v8::Value> jsvalue, int i = 0, int res = 0, $*1_ltype temp) {
if ($input->IsArray())
{
// Convert into Array
array = v8::Local<v8::Array>::Cast($input);
%enddef
length = $1_dim0;
JAVASCRIPT_ARRAYS_IN_DECL("SWIG_JSCGetIntProperty", int, , array->Length())
JAVASCRIPT_ARRAYS_IN_DECL("SWIG_JSCGetIntProperty", int, ANY, $1_dim0)
JAVASCRIPT_ARRAYS_IN_DECL("SWIG_JSCGetNumberProperty", double, , array->Length())
JAVASCRIPT_ARRAYS_IN_DECL("SWIG_JSCGetNumberProperty", double, ANY, $1_dim0)
$1 = ($*1_ltype *)malloc(sizeof($*1_ltype) * length);
JAVASCRIPT_ARRAYS_OUT_DECL("SWIG_JSCOutInt", int)
JAVASCRIPT_ARRAYS_OUT_DECL("SWIG_JSCOutNumber", double)
// Get each element from array
for (i = 0; i < length; i++)
{
jsvalue = array->Get(i);
// Get primitive value from JSObject
res = SWIG_AsVal(double)(jsvalue, &temp);
if (!SWIG_IsOK(res))
{
SWIG_exception_fail(SWIG_ERROR, "Failed to convert $input to double");
}
arg$argnum[i] = temp;
}
}
else
{
SWIG_exception_fail(SWIG_ERROR, "$input is not JSObjectRef");
}
}
%typemap(freearg) double[], double[ANY] {
free($1);
}
%typemap(out, fragment=SWIG_From_frag(double)) double[], double[ANY] (int length = 0, int i = 0)
{
length = $1_dim0;
v8::Local<v8::Array> array = v8::Array::New(length);
for (i = 0; i < length; i++)
{
array->Set(i, SWIG_From(double)($1[i]));
}
$result = array;
}

View file

@ -6,21 +6,22 @@
* ----------------------------------------------------------------------------- */
%include <javscriptcomplex.swg>
%include <javascriptcomplex.swg>
%{
#include <complex.h>
%}
#define complex _Complex
/* C complex constructor */
#define CCplxConst(r, i) ((r) + I*(i))
%swig_cplxflt_convn(float complex, CCplxConst, creal, cimag);
%swig_cplxdbl_convn(double complex, CCplxConst, creal, cimag);
%swig_cplxdbl_convn(complex, CCplxConst, creal, cimag);
%swig_cplxflt_convn(float _Complex, CCplxConst, creal, cimag);
%swig_cplxdbl_convn(double _Complex, CCplxConst, creal, cimag);
%swig_cplxdbl_convn(_Complex, CCplxConst, creal, cimag);
/* declaring the typemaps */
%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float complex);
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double complex);
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, complex);
%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float _Complex);
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double _Complex);
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, _Complex);

View file

@ -10,9 +10,10 @@
%fragment("js_ctor", "templates") %{
static SwigV8ReturnValue $jswrapper(const SwigV8Arguments &args) {
SWIGV8_HANDLESCOPE();
v8::Handle<v8::Object> self = args.Holder();
SWIGV8_OBJECT self = args.Holder();
$jslocals
if(self->InternalFieldCount() < 1) SWIG_exception_fail(SWIG_ERROR, "Illegal call of constructor $jswrapper.");
if(args.Length() != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
$jscode
@ -53,7 +54,7 @@ static SwigV8ReturnValue $jswrapper(const SwigV8Arguments &args) {
SWIGV8_HANDLESCOPE();
OverloadErrorHandler errorHandler;
v8::Handle<v8::Value> self;
SWIGV8_VALUE self;
// switch all cases by means of series of if-returns.
$jsdispatchcases
@ -77,9 +78,10 @@ fail:
%fragment("js_overloaded_ctor", "templates") %{
static SwigV8ReturnValue $jswrapper(const SwigV8Arguments &args, V8ErrorHandler &SWIGV8_ErrorHandler) {
SWIGV8_HANDLESCOPE();
v8::Handle<v8::Object> self = args.Holder();
SWIGV8_OBJECT self = args.Holder();
$jslocals
if(self->InternalFieldCount() < 1) SWIG_exception_fail(SWIG_ERROR, "Illegal call of constructor $jswrapper.");
if(args.Length() != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
$jscode
@ -133,10 +135,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) {
@ -147,7 +152,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();
@ -155,7 +162,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
}
@ -177,10 +184,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) {
@ -197,7 +207,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
}
@ -211,10 +221,14 @@ 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;
SWIGV8_VALUE jsresult;
$jslocals
$jscode
SWIGV8_RETURN_INFO(jsresult, info);
@ -233,8 +247,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
@ -256,7 +273,7 @@ fail:
static SwigV8ReturnValue $jswrapper(const SwigV8Arguments &args) {
SWIGV8_HANDLESCOPE();
v8::Handle<v8::Value> jsresult;
SWIGV8_VALUE jsresult;
$jslocals
if(args.Length() != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
@ -281,7 +298,7 @@ fail:
static SwigV8ReturnValue $jswrapper(const SwigV8Arguments &args) {
SWIGV8_HANDLESCOPE();
v8::Handle<v8::Value> jsresult;
SWIGV8_VALUE jsresult;
OverloadErrorHandler errorHandler;
$jscode
@ -305,7 +322,7 @@ static SwigV8ReturnValue $jswrapper(const SwigV8Arguments &args, V8ErrorHandler
{
SWIGV8_HANDLESCOPE();
v8::Handle<v8::Value> jsresult;
SWIGV8_VALUE jsresult;
$jslocals
$jscode
SWIGV8_RETURN(jsresult);
@ -359,7 +376,7 @@ fail:
%fragment("jsv8_define_class_template", "templates")
%{
/* Name: $jsmangledname, Type: $jsmangledtype, Dtor: $jsdtor */
v8::Handle<v8::FunctionTemplate> $jsmangledname_class = SWIGV8_CreateClassTemplate("$jsmangledname");
SWIGV8_FUNCTION_TEMPLATE $jsmangledname_class = SWIGV8_CreateClassTemplate("$jsmangledname");
SWIGV8_SET_CLASS_TEMPL($jsmangledname_clientData.class_templ, $jsmangledname_class);
$jsmangledname_clientData.dtor = $jsdtor;
if (SWIGTYPE_$jsmangledtype->clientdata == 0) {
@ -405,11 +422,18 @@ fail:
%fragment("jsv8_create_class_instance", "templates")
%{
/* Class: $jsname ($jsmangledname) */
v8::Handle<v8::FunctionTemplate> $jsmangledname_class_0 = SWIGV8_CreateClassTemplate("$jsname");
SWIGV8_FUNCTION_TEMPLATE $jsmangledname_class_0 = SWIGV8_CreateClassTemplate("$jsname");
$jsmangledname_class_0->SetCallHandler($jsctor);
$jsmangledname_class_0->Inherit($jsmangledname_class);
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903)
$jsmangledname_class_0->SetHiddenPrototype(true);
v8::Handle<v8::Object> $jsmangledname_obj = $jsmangledname_class_0->GetFunction();
#elif (SWIG_V8_VERSION < 0x0704)
$jsmangledname_class_0->SetHiddenPrototype(true);
v8::Local<v8::Object> $jsmangledname_obj = $jsmangledname_class_0->GetFunction();
#else
v8::Local<v8::Object> $jsmangledname_obj = $jsmangledname_class_0->GetFunction(context).ToLocalChecked();
#endif
%}
/* -----------------------------------------------------------------------------
@ -420,7 +444,12 @@ fail:
* ----------------------------------------------------------------------------- */
%fragment("jsv8_register_class", "templates")
%{
#if (V8_MAJOR_VERSION-0) < 5
$jsparent_obj->Set(SWIGV8_SYMBOL_NEW("$jsname"), $jsmangledname_obj);
#else
SWIGV8_MAYBE_CHECK($jsparent_obj->Set(context, SWIGV8_SYMBOL_NEW("$jsname"), $jsmangledname_obj));
#endif
%}
/* -----------------------------------------------------------------------------
@ -429,7 +458,7 @@ fail:
* ----------------------------------------------------------------------------- */
%fragment("jsv8_create_namespace", "templates")
%{
v8::Handle<v8::Object> $jsmangledname_obj = SWIGV8_OBJECT_NEW();
SWIGV8_OBJECT $jsmangledname_obj = SWIGV8_OBJECT_NEW();
%}
/* -----------------------------------------------------------------------------
@ -440,7 +469,11 @@ fail:
* ----------------------------------------------------------------------------- */
%fragment("jsv8_register_namespace", "templates")
%{
#if (V8_MAJOR_VERSION-0) < 5
$jsparent_obj->Set(SWIGV8_SYMBOL_NEW("$jsname"), $jsmangledname_obj);
#else
SWIGV8_MAYBE_CHECK($jsparent_obj->Set(context, SWIGV8_SYMBOL_NEW("$jsname"), $jsmangledname_obj));
#endif
%}
/* -----------------------------------------------------------------------------
@ -476,7 +509,7 @@ fail:
* ----------------------------------------------------------------------------- */
%fragment("jsv8_register_static_function", "templates")
%{
SWIGV8_AddStaticFunction($jsparent_obj, "$jsname", $jswrapper);
SWIGV8_AddStaticFunction($jsparent_obj, "$jsname", $jswrapper, context);
%}
/* -----------------------------------------------------------------------------
@ -490,5 +523,5 @@ fail:
* ----------------------------------------------------------------------------- */
%fragment("jsv8_register_static_variable", "templates")
%{
SWIGV8_AddStaticVariable($jsparent_obj, "$jsname", $jsgetter, $jssetter);
SWIGV8_AddStaticVariable($jsparent_obj, "$jsname", $jsgetter, $jssetter, context);
%}

View file

@ -12,15 +12,15 @@
%fragment(SWIG_From_frag(Type),"header",
fragment=SWIG_From_frag(double))
{
SWIGINTERNINLINE v8::Handle<v8::Value>
SWIGINTERNINLINE SWIGV8_VALUE
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(0);
vals->Set(0, SWIG_From(double)(Real(c)));
vals->Set(1, SWIG_From(double)(Imag(c)));
SWIGV8_ARRAY_SET(vals, 0, SWIG_From(double)(Real(c)));
SWIGV8_ARRAY_SET(vals, 1, SWIG_From(double)(Imag(c)));
SWIGV8_ESCAPE(vals);
}
}
@ -32,30 +32,30 @@ SWIG_From_dec(Type)(%ifcplusplus(const Type&, Type) c)
fragment=SWIG_AsVal_frag(double))
{
SWIGINTERN int
SWIG_AsVal_dec(Type) (v8::Handle<v8::Value> o, Type* val)
SWIG_AsVal_dec(Type) (SWIGV8_VALUE o, Type* val)
{
SWIGV8_HANDLESCOPE();
if (o->IsArray()) {
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(o);
SWIGV8_ARRAY array = SWIGV8_ARRAY::Cast(o);
if(array->Length() != 2) SWIG_Error(SWIG_TypeError, "Illegal argument for complex: must be array[2].");
if (array->Length() != 2) SWIG_Error(SWIG_TypeError, "Illegal argument for complex: must be array[2].");
double re, im;
int res;
res = SWIG_AsVal(double)(array->Get(0), &re);
if(!SWIG_IsOK(res)) {
res = SWIG_AsVal(double)(SWIGV8_ARRAY_GET(array, 0), &re);
if (!SWIG_IsOK(res)) {
return SWIG_TypeError;
}
res = SWIG_AsVal(double)(array->Get(1), &im);
if(!SWIG_IsOK(res)) {
res = SWIG_AsVal(double)(SWIGV8_ARRAY_GET(array, 1), &im);
if (!SWIG_IsOK(res)) {
return SWIG_TypeError;
}
if (val) *val = Constructor(re, im);
return SWIG_OK;
} else if(o->IsNumber()){
} else if (o->IsNumber()) {
double d;
int res = SWIG_AddCast(SWIG_AsVal(double)(o, &d));
if (SWIG_IsOK(res)) {
@ -74,24 +74,24 @@ SWIG_AsVal_dec(Type) (v8::Handle<v8::Value> o, Type* val)
%fragment(SWIG_AsVal_frag(Type),"header",
fragment=SWIG_AsVal_frag(float)) {
SWIGINTERN int
SWIG_AsVal_dec(Type) (v8::Handle<v8::Value> o, Type* val)
SWIG_AsVal_dec(Type) (SWIGV8_VALUE o, Type* val)
{
SWIGV8_HANDLESCOPE();
if (o->IsArray()) {
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(o);
SWIGV8_ARRAY array = SWIGV8_ARRAY::Cast(o);
if(array->Length() != 2) SWIG_Error(SWIG_TypeError, "Illegal argument for complex: must be array[2].");
if (array->Length() != 2) SWIG_Error(SWIG_TypeError, "Illegal argument for complex: must be array[2].");
double re, im;
int res;
res = SWIG_AsVal(double)(array->Get(0), &re);
if(!SWIG_IsOK(res)) {
res = SWIG_AsVal(double)(SWIGV8_ARRAY_GET(array, 0), &re);
if (!SWIG_IsOK(res)) {
return SWIG_TypeError;
}
res = SWIG_AsVal(double)(array->Get(1), &im);
if(!SWIG_IsOK(res)) {
res = SWIG_AsVal(double)(SWIGV8_ARRAY_GET(array, 1), &im);
if (!SWIG_IsOK(res)) {
return SWIG_TypeError;
}
@ -102,7 +102,7 @@ SWIG_AsVal_dec(Type) (v8::Handle<v8::Value> o, Type* val)
} else {
return SWIG_OverflowError;
}
} else if(o->IsNumber()){
} else if (o->IsNumber()) {
float re;
int res = SWIG_AddCast(SWIG_AsVal(float)(o, &re));
if (SWIG_IsOK(res)) {

View file

@ -6,29 +6,34 @@ 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
/**
* Creates a class template for a class with specified initialization function.
*/
SWIGRUNTIME v8::Handle<v8::FunctionTemplate> SWIGV8_CreateClassTemplate(const char* symbol) {
SWIGRUNTIME SWIGV8_FUNCTION_TEMPLATE SWIGV8_CreateClassTemplate(const char* symbol) {
SWIGV8_HANDLESCOPE_ESC();
v8::Local<v8::FunctionTemplate> class_templ = SWIGV8_FUNCTEMPLATE_NEW_VOID();
class_templ->SetClassName(SWIGV8_SYMBOL_NEW(symbol));
v8::Handle<v8::ObjectTemplate> inst_templ = class_templ->InstanceTemplate();
SWIGV8_OBJECT_TEMPLATE inst_templ = class_templ->InstanceTemplate();
inst_templ->SetInternalFieldCount(1);
v8::Handle<v8::ObjectTemplate> equals_templ = class_templ->PrototypeTemplate();
SWIGV8_OBJECT_TEMPLATE equals_templ = class_templ->PrototypeTemplate();
equals_templ->Set(SWIGV8_SYMBOL_NEW("equals"), SWIGV8_FUNCTEMPLATE_NEW(_SWIGV8_wrap_equals));
v8::Handle<v8::ObjectTemplate> cptr_templ = class_templ->PrototypeTemplate();
SWIGV8_OBJECT_TEMPLATE cptr_templ = class_templ->PrototypeTemplate();
cptr_templ->Set(SWIGV8_SYMBOL_NEW("getCPtr"), SWIGV8_FUNCTEMPLATE_NEW(_wrap_getCPtr));
SWIGV8_ESCAPE(class_templ);
@ -37,46 +42,69 @@ SWIGRUNTIME v8::Handle<v8::FunctionTemplate> SWIGV8_CreateClassTemplate(const ch
/**
* Registers a class method with given name for a given class template.
*/
SWIGRUNTIME void SWIGV8_AddMemberFunction(v8::Handle<v8::FunctionTemplate> class_templ, const char* symbol,
SWIGRUNTIME void SWIGV8_AddMemberFunction(SWIGV8_FUNCTION_TEMPLATE class_templ, const char* symbol,
SwigV8FunctionCallback _func) {
v8::Handle<v8::ObjectTemplate> proto_templ = class_templ->PrototypeTemplate();
SWIGV8_OBJECT_TEMPLATE proto_templ = class_templ->PrototypeTemplate();
proto_templ->Set(SWIGV8_SYMBOL_NEW(symbol), SWIGV8_FUNCTEMPLATE_NEW(_func));
}
/**
* Registers a class property with given name for a given class template.
*/
SWIGRUNTIME void SWIGV8_AddMemberVariable(v8::Handle<v8::FunctionTemplate> class_templ, const char* symbol,
SWIGRUNTIME void SWIGV8_AddMemberVariable(SWIGV8_FUNCTION_TEMPLATE class_templ, const char* symbol,
SwigV8AccessorGetterCallback getter, SwigV8AccessorSetterCallback setter) {
v8::Handle<v8::ObjectTemplate> proto_templ = class_templ->InstanceTemplate();
SWIGV8_OBJECT_TEMPLATE proto_templ = class_templ->InstanceTemplate();
proto_templ->SetAccessor(SWIGV8_SYMBOL_NEW(symbol), getter, setter);
}
/**
* Registers a class method with given name for a given object.
*/
SWIGRUNTIME void SWIGV8_AddStaticFunction(v8::Handle<v8::Object> obj, const char* symbol,
const SwigV8FunctionCallback& _func) {
SWIGRUNTIME void SWIGV8_AddStaticFunction(SWIGV8_OBJECT obj, const char* symbol,
const SwigV8FunctionCallback& _func, v8::Local<v8::Context> context) {
#if (V8_MAJOR_VERSION-0) < 5
obj->Set(SWIGV8_SYMBOL_NEW(symbol), SWIGV8_FUNCTEMPLATE_NEW(_func)->GetFunction());
#else
SWIGV8_MAYBE_CHECK(obj->Set(context, SWIGV8_SYMBOL_NEW(symbol), SWIGV8_FUNCTEMPLATE_NEW(_func)->GetFunction(context).ToLocalChecked()));
#endif
}
/**
* Registers a class method with given name for a given object.
*/
SWIGRUNTIME void SWIGV8_AddStaticVariable(v8::Handle<v8::Object> obj, const char* symbol,
SwigV8AccessorGetterCallback getter, SwigV8AccessorSetterCallback setter) {
SWIGRUNTIME void SWIGV8_AddStaticVariable(SWIGV8_OBJECT obj, const char* symbol,
SwigV8AccessorGetterCallback getter, SwigV8AccessorSetterCallback setter,
v8::Local<v8::Context> context) {
#if (V8_MAJOR_VERSION-0) < 5
obj->SetAccessor(SWIGV8_SYMBOL_NEW(symbol), getter, setter);
#else
SWIGV8_MAYBE_CHECK(obj->SetAccessor(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.");

View file

@ -1,21 +1,35 @@
%insert(header) %{
#include <assert.h>
%}
%insert(init) %{
#include <assert.h>
SWIGRUNTIME void
SWIG_V8_SetModule(void *, swig_module_info *swig_module) {
v8::Local<v8::Object> global_obj = SWIGV8_CURRENT_CONTEXT()->Global();
SWIG_V8_SetModule(v8::Local<v8::Context> context, swig_module_info *swig_module) {
v8::Local<v8::Object> global_obj = 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(context, privateKey, mod);
#endif
}
SWIGRUNTIME swig_module_info *
SWIG_V8_GetModule(void *) {
v8::Local<v8::Object> global_obj = SWIGV8_CURRENT_CONTEXT()->Global();
SWIG_V8_GetModule(v8::Local<v8::Context> context) {
v8::Local<v8::Object> global_obj = 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(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;
@ -38,6 +52,7 @@ SWIG_V8_GetModule(void *) {
#define SWIG_GetModule(clientdata) SWIG_V8_GetModule(clientdata)
#define SWIG_SetModule(clientdata, pointer) SWIG_V8_SetModule(clientdata, pointer)
#define SWIG_INIT_CLIENT_DATA_TYPE v8::Local<v8::Context>
%}
@ -50,20 +65,20 @@ SWIG_V8_GetModule(void *) {
%}
%insert(init) %{
#if !defined(NODE_MODULE_VERSION) || (NODE_MODULE_VERSION < 12)
// Note: 'extern "C"'' disables name mangling which makes it easier to load the symbol manually
// TODO: is it ok to do that?
extern "C"
#if (NODE_MODULE_VERSION < 0x000C)
void SWIGV8_INIT (v8::Handle<v8::Object> exports)
extern "C" void SWIGV8_INIT (SWIGV8_OBJECT exports_obj)
#elif (NODE_MODULE_VERSION < 64)
void SWIGV8_INIT (SWIGV8_OBJECT exports_obj, SWIGV8_VALUE /*module*/, void*)
#else
void SWIGV8_INIT (v8::Handle<v8::Object> exports, v8::Handle<v8::Object> /*module*/)
void SWIGV8_INIT (SWIGV8_OBJECT exports_obj, SWIGV8_VALUE /*module*/, v8::Local<v8::Context> context, void*)
#endif
{
SWIG_InitializeModule(static_cast<void *>(&exports));
#if !defined(NODE_MODULE_VERSION) || NODE_MODULE_VERSION < 64
v8::Local<v8::Context> context = SWIGV8_CURRENT_CONTEXT();
#endif
SWIGV8_HANDLESCOPE();
v8::Handle<v8::Object> exports_obj = exports;
SWIG_InitializeModule(context);
%}
@ -110,6 +125,10 @@ void SWIGV8_INIT (v8::Handle<v8::Object> exports, v8::Handle<v8::Object> /*modul
}
#if defined(BUILDING_NODE_EXTENSION)
#if (NODE_MODULE_VERSION < 64)
NODE_MODULE($jsname, $jsname_initialize)
#else
NODE_MODULE_CONTEXT_AWARE($jsname, $jsname_initialize)
#endif
#endif
%}

View file

@ -6,7 +6,7 @@
%fragment(SWIG_From_frag(bool),"header") {
SWIGINTERNINLINE
v8::Handle<v8::Value>
SWIGV8_VALUE
SWIG_From_dec(bool)(bool value)
{
return SWIGV8_BOOLEAN_NEW(value);
@ -16,13 +16,13 @@ SWIG_From_dec(bool)(bool value)
%fragment(SWIG_AsVal_frag(bool),"header",
fragment=SWIG_AsVal_frag(long)) {
SWIGINTERN
int SWIG_AsVal_dec(bool)(v8::Handle<v8::Value> obj, bool *val)
int SWIG_AsVal_dec(bool)(SWIGV8_VALUE obj, bool *val)
{
if(!obj->IsBoolean()) {
return SWIG_ERROR;
}
if (val) *val = obj->BooleanValue();
if (val) *val = SWIGV8_BOOLEAN_VALUE(obj);
return SWIG_OK;
}
}
@ -31,7 +31,7 @@ int SWIG_AsVal_dec(bool)(v8::Handle<v8::Value> obj, bool *val)
%fragment(SWIG_From_frag(int),"header") {
SWIGINTERNINLINE
v8::Handle<v8::Value> SWIG_From_dec(int)(int value)
SWIGV8_VALUE SWIG_From_dec(int)(int value)
{
return SWIGV8_INT32_NEW(value);
}
@ -39,12 +39,12 @@ v8::Handle<v8::Value> SWIG_From_dec(int)(int value)
%fragment(SWIG_AsVal_frag(int),"header") {
SWIGINTERN
int SWIG_AsVal_dec(int)(v8::Handle<v8::Value> valRef, int* val)
int SWIG_AsVal_dec(int)(SWIGV8_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;
}
@ -54,7 +54,7 @@ int SWIG_AsVal_dec(int)(v8::Handle<v8::Value> valRef, int* val)
%fragment(SWIG_From_frag(long),"header") {
SWIGINTERNINLINE
v8::Handle<v8::Value> SWIG_From_dec(long)(long value)
SWIGV8_VALUE SWIG_From_dec(long)(long value)
{
return SWIGV8_NUMBER_NEW(value);
}
@ -63,12 +63,12 @@ v8::Handle<v8::Value> SWIG_From_dec(long)(long value)
%fragment(SWIG_AsVal_frag(long),"header",
fragment="SWIG_CanCastAsInteger") {
SWIGINTERN
int SWIG_AsVal_dec(long)(v8::Handle<v8::Value> obj, long* val)
int SWIG_AsVal_dec(long)(SWIGV8_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;
}
@ -79,23 +79,22 @@ int SWIG_AsVal_dec(long)(v8::Handle<v8::Value> obj, long* val)
%fragment(SWIG_From_frag(unsigned long),"header",
fragment=SWIG_From_frag(long)) {
SWIGINTERNINLINE
v8::Handle<v8::Value> SWIG_From_dec(unsigned long)(unsigned long value)
SWIGV8_VALUE SWIG_From_dec(unsigned long)(unsigned long value)
{
return (value > LONG_MAX) ?
SWIGV8_INTEGER_NEW_UNS(value) : SWIGV8_INTEGER_NEW(%numeric_cast(value,long));
return SWIGV8_INTEGER_NEW_UNS(value);
}
}
%fragment(SWIG_AsVal_frag(unsigned long),"header",
fragment="SWIG_CanCastAsInteger") {
SWIGINTERN
int SWIG_AsVal_dec(unsigned long)(v8::Handle<v8::Value> obj, unsigned long *val)
int SWIG_AsVal_dec(unsigned long)(SWIGV8_VALUE obj, unsigned long *val)
{
if(!obj->IsNumber()) {
return SWIG_TypeError;
}
long longVal = (long) obj->NumberValue();
long longVal = (long) SWIGV8_NUMBER_VALUE(obj);
if(longVal < 0) {
return SWIG_OverflowError;
@ -115,7 +114,7 @@ int SWIG_AsVal_dec(unsigned long)(v8::Handle<v8::Value> obj, unsigned long *val)
fragment="SWIG_LongLongAvailable") {
%#ifdef SWIG_LONG_LONG_AVAILABLE
SWIGINTERNINLINE
v8::Handle<v8::Value> SWIG_From_dec(long long)(long long value)
SWIGV8_VALUE SWIG_From_dec(long long)(long long value)
{
return SWIGV8_NUMBER_NEW(value);
}
@ -128,12 +127,12 @@ v8::Handle<v8::Value> SWIG_From_dec(long long)(long long value)
fragment="SWIG_LongLongAvailable") {
%#ifdef SWIG_LONG_LONG_AVAILABLE
SWIGINTERN
int SWIG_AsVal_dec(long long)(v8::Handle<v8::Value> obj, long long* val)
int SWIG_AsVal_dec(long long)(SWIGV8_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;
}
@ -148,10 +147,9 @@ int SWIG_AsVal_dec(long long)(v8::Handle<v8::Value> obj, long long* val)
fragment="SWIG_LongLongAvailable") {
%#ifdef SWIG_LONG_LONG_AVAILABLE
SWIGINTERNINLINE
v8::Handle<v8::Value> SWIG_From_dec(unsigned long long)(unsigned long long value)
SWIGV8_VALUE SWIG_From_dec(unsigned long long)(unsigned long long value)
{
return (value > LONG_MAX) ?
SWIGV8_INTEGER_NEW_UNS(value) : SWIGV8_INTEGER_NEW(%numeric_cast(value,long));
return SWIGV8_INTEGER_NEW_UNS(value);
}
%#endif
}
@ -162,13 +160,13 @@ v8::Handle<v8::Value> SWIG_From_dec(unsigned long long)(unsigned long long value
fragment="SWIG_LongLongAvailable") {
%#ifdef SWIG_LONG_LONG_AVAILABLE
SWIGINTERN
int SWIG_AsVal_dec(unsigned long long)(v8::Handle<v8::Value> obj, unsigned long long *val)
int SWIG_AsVal_dec(unsigned long long)(SWIGV8_VALUE obj, unsigned long long *val)
{
if(!obj->IsNumber()) {
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;
@ -185,7 +183,7 @@ int SWIG_AsVal_dec(unsigned long long)(v8::Handle<v8::Value> obj, unsigned long
%fragment(SWIG_From_frag(double),"header") {
SWIGINTERN
v8::Handle<v8::Value> SWIG_From_dec(double) (double val)
SWIGV8_VALUE SWIG_From_dec(double) (double val)
{
return SWIGV8_NUMBER_NEW(val);
}
@ -193,14 +191,13 @@ v8::Handle<v8::Value> SWIG_From_dec(double) (double val)
%fragment(SWIG_AsVal_frag(double),"header") {
SWIGINTERN
int SWIG_AsVal_dec(double)(v8::Handle<v8::Value> obj, double *val)
int SWIG_AsVal_dec(double)(SWIGV8_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

@ -1,6 +1,7 @@
/* ---------------------------------------------------------------------------
* These typedefs and defines are used to deal with v8 API changes
*
* Useful table of versions: https://nodejs.org/en/download/releases/
* ---------------------------------------------------------------------------*/
// First v8 version that uses "SetWeak" and not "MakeWeak"
@ -9,8 +10,10 @@
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031803)
#define SWIGV8_STRING_NEW2(cstr, len) v8::String::New(cstr, len)
#else
#elif (SWIG_V8_VERSION < 0x0704)
#define SWIGV8_STRING_NEW2(cstr, len) v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), cstr, v8::String::kNormalString, len)
#else
#define SWIGV8_STRING_NEW2(cstr, len) (v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), cstr, v8::NewStringType::kNormal, len)).ToLocalChecked()
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903)
@ -51,12 +54,25 @@ typedef v8::PropertyCallbackInfo<v8::Value> SwigV8PropertyCallbackInfo;
#define SWIGV8_ADJUST_MEMORY(size) v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(size)
#define SWIGV8_CURRENT_CONTEXT() v8::Isolate::GetCurrent()->GetCurrentContext()
#define SWIGV8_THROW_EXCEPTION(err) v8::Isolate::GetCurrent()->ThrowException(err)
#define SWIGV8_STRING_NEW(str) v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), str)
#define SWIGV8_SYMBOL_NEW(sym) v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), sym)
#if (SWIG_V8_VERSION < 0x0704)
#define SWIGV8_STRING_NEW(str) v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), str, v8::String::kNormalString)
#define SWIGV8_SYMBOL_NEW(sym) v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), sym, v8::String::kNormalString)
#else
#define SWIGV8_STRING_NEW(str) (v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), str, v8::NewStringType::kNormal)).ToLocalChecked()
#define SWIGV8_SYMBOL_NEW(sym) (v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), sym, v8::NewStringType::kNormal)).ToLocalChecked()
#endif
#endif
#if (V8_MAJOR_VERSION-0) < 5
#define SWIGV8_MAYBE_CHECK(maybe) maybe
#elif (SWIG_V8_VERSION < 0x0704)
#define SWIGV8_MAYBE_CHECK(maybe) maybe.FromJust()
#else
#define SWIGV8_MAYBE_CHECK(maybe) maybe.Check()
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032318)
#define SWIGV8_ARRAY_NEW() v8::Array::New()
#define SWIGV8_ARRAY_NEW(size) v8::Array::New(size)
#define SWIGV8_BOOLEAN_NEW(bool) v8::Boolean::New(bool)
#define SWIGV8_EXTERNAL_NEW(val) v8::External::New(val)
#define SWIGV8_FUNCTEMPLATE_NEW(func) v8::FunctionTemplate::New(func)
@ -67,9 +83,16 @@ typedef v8::PropertyCallbackInfo<v8::Value> SwigV8PropertyCallbackInfo;
#define SWIGV8_NUMBER_NEW(num) v8::Number::New(num)
#define SWIGV8_OBJECT_NEW() v8::Object::New()
#define SWIGV8_UNDEFINED() v8::Undefined()
#define SWIGV8_ARRAY v8::Handle<v8::Array>
#define SWIGV8_FUNCTION_TEMPLATE v8::Handle<v8::FunctionTemplate>
#define SWIGV8_OBJECT v8::Handle<v8::Object>
#define SWIGV8_OBJECT_TEMPLATE v8::Handle<v8::ObjectTemplate>
#define SWIGV8_VALUE v8::Handle<v8::Value>
#define SWIGV8_NULL() v8::Null()
#define SWIGV8_ARRAY_GET(array, index) (array)->Get(index)
#define SWIGV8_ARRAY_SET(array, index, value) (array)->Set(index, value)
#else
#define SWIGV8_ARRAY_NEW() v8::Array::New(v8::Isolate::GetCurrent())
#define SWIGV8_ARRAY_NEW(size) v8::Array::New(v8::Isolate::GetCurrent(), size)
#define SWIGV8_BOOLEAN_NEW(bool) v8::Boolean::New(v8::Isolate::GetCurrent(), bool)
#define SWIGV8_EXTERNAL_NEW(val) v8::External::New(v8::Isolate::GetCurrent(), val)
#define SWIGV8_FUNCTEMPLATE_NEW(func) v8::FunctionTemplate::New(v8::Isolate::GetCurrent(), func)
@ -80,7 +103,14 @@ typedef v8::PropertyCallbackInfo<v8::Value> SwigV8PropertyCallbackInfo;
#define SWIGV8_NUMBER_NEW(num) v8::Number::New(v8::Isolate::GetCurrent(), num)
#define SWIGV8_OBJECT_NEW() v8::Object::New(v8::Isolate::GetCurrent())
#define SWIGV8_UNDEFINED() v8::Undefined(v8::Isolate::GetCurrent())
#define SWIGV8_ARRAY v8::Local<v8::Array>
#define SWIGV8_FUNCTION_TEMPLATE v8::Local<v8::FunctionTemplate>
#define SWIGV8_OBJECT v8::Local<v8::Object>
#define SWIGV8_OBJECT_TEMPLATE v8::Local<v8::ObjectTemplate>
#define SWIGV8_VALUE v8::Local<v8::Value>
#define SWIGV8_NULL() v8::Null(v8::Isolate::GetCurrent())
#define SWIGV8_ARRAY_GET(array, index) (array)->Get(SWIGV8_CURRENT_CONTEXT(), index).ToLocalChecked()
#define SWIGV8_ARRAY_SET(array, index, value) SWIGV8_MAYBE_CHECK((array)->Set(SWIGV8_CURRENT_CONTEXT(), index, value))
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
@ -91,6 +121,28 @@ typedef v8::PropertyCallbackInfo<v8::Value> SwigV8PropertyCallbackInfo;
#define SWIGV8_SET_CLASS_TEMPL(class_templ, class) class_templ.Reset(v8::Isolate::GetCurrent(), class);
#endif
#if (V8_MAJOR_VERSION-0) < 6 || (SWIG_V8_VERSION < 0x0608)
#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_WRITE_UTF8(handle, buffer, len) (handle)->WriteUtf8(v8::Isolate::GetCurrent(), buffer, len)
#define SWIGV8_UTF8_LENGTH(handle) (handle)->Utf8Length(v8::Isolate::GetCurrent())
#if (SWIG_V8_VERSION < 0x0704)
#define SWIGV8_BOOLEAN_VALUE(handle) (handle)->BooleanValue(SWIGV8_CURRENT_CONTEXT()).ToChecked()
#else
#define SWIGV8_BOOLEAN_VALUE(handle) (handle)->BooleanValue(v8::Isolate::GetCurrent())
#endif
#endif
/* ---------------------------------------------------------------------------
* Error handling
*
@ -109,11 +161,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
@ -137,7 +189,7 @@ public:
SWIGV8_THROW_EXCEPTION(err);
}
}
v8::Handle<v8::Value> err;
SWIGV8_VALUE err;
};
/* ---------------------------------------------------------------------------
@ -193,14 +245,16 @@ 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
};
SWIGRUNTIME v8::Persistent<v8::FunctionTemplate> SWIGV8_SWIGTYPE_Proxy_class_templ;
SWIGRUNTIME int SWIG_V8_ConvertInstancePtr(v8::Handle<v8::Object> objRef, void **ptr, swig_type_info *info, int flags) {
SWIGRUNTIME int SWIG_V8_ConvertInstancePtr(SWIGV8_OBJECT objRef, void **ptr, swig_type_info *info, int flags) {
SWIGV8_HANDLESCOPE();
if(objRef->InternalFieldCount() < 1) return SWIG_ERROR;
@ -224,8 +278,13 @@ SWIGRUNTIME int SWIG_V8_ConvertInstancePtr(v8::Handle<v8::Object> objRef, void *
if(!type_valid) {
return SWIG_TypeError;
}
int newmemory = 0;
*ptr = SWIG_TypeCast(tc, cdata->swigCObject, &newmemory);
assert(!newmemory); /* newmemory handling not yet implemented */
} else {
*ptr = cdata->swigCObject;
}
*ptr = cdata->swigCObject;
if(flags & SWIG_POINTER_DISOWN) {
cdata->swigCMemOwn = false;
}
@ -241,19 +300,22 @@ 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;
}
SWIGRUNTIME int SWIG_V8_GetInstancePtr(v8::Handle<v8::Value> valRef, void **ptr) {
SWIGRUNTIME int SWIG_V8_GetInstancePtr(SWIGV8_VALUE valRef, void **ptr) {
if(!valRef->IsObject()) {
return SWIG_TypeError;
}
v8::Handle<v8::Object> objRef = valRef->ToObject();
SWIGV8_OBJECT objRef = SWIGV8_OBJECT::Cast(valRef);
if(objRef->InternalFieldCount() < 1) return SWIG_ERROR;
@ -273,7 +335,7 @@ SWIGRUNTIME int SWIG_V8_GetInstancePtr(v8::Handle<v8::Value> valRef, void **ptr)
return SWIG_OK;
}
SWIGRUNTIME void SWIGV8_SetPrivateData(v8::Handle<v8::Object> obj, void *ptr, swig_type_info *info, int flags) {
SWIGRUNTIME void SWIGV8_SetPrivateData(SWIGV8_OBJECT obj, void *ptr, swig_type_info *info, int flags) {
SWIGV8_Proxy *cdata = new SWIGV8_Proxy();
cdata->swigCObject = ptr;
cdata->swigCMemOwn = (flags & SWIG_POINTER_OWN) ? 1 : 0;
@ -312,43 +374,50 @@ 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)
cdata->handle.MarkIndependent();
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100)
cdata->handle.MarkIndependent(v8::Isolate::GetCurrent());
#else
#elif (SWIG_V8_VERSION < 0x0704)
cdata->handle.MarkIndependent();
// Looks like future versions do not require that anymore:
// https://monorail-prod.appspot.com/p/chromium/issues/detail?id=923361#c11
#endif
}
SWIGRUNTIME int SWIG_V8_ConvertPtr(v8::Handle<v8::Value> valRef, void **ptr, swig_type_info *info, int flags) {
SWIGRUNTIME int SWIG_V8_ConvertPtr(SWIGV8_VALUE valRef, void **ptr, swig_type_info *info, int flags) {
SWIGV8_HANDLESCOPE();
/* 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();
SWIGV8_OBJECT objRef = SWIGV8_OBJECT::Cast(valRef);
return SWIG_V8_ConvertInstancePtr(objRef, ptr, info, flags);
}
SWIGRUNTIME v8::Handle<v8::Value> SWIG_V8_NewPointerObj(void *ptr, swig_type_info *info, int flags) {
SWIGRUNTIME SWIGV8_VALUE SWIG_V8_NewPointerObj(void *ptr, swig_type_info *info, int flags) {
SWIGV8_HANDLESCOPE_ESC();
v8::Handle<v8::FunctionTemplate> class_templ;
SWIGV8_FUNCTION_TEMPLATE class_templ;
if (ptr == NULL) {
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903)
@ -375,8 +444,12 @@ SWIGRUNTIME v8::Handle<v8::Value> SWIG_V8_NewPointerObj(void *ptr, swig_type_inf
}
#endif
// v8::Handle<v8::Object> result = class_templ->InstanceTemplate()->NewInstance();
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903)
v8::Local<v8::Object> result = class_templ->InstanceTemplate()->NewInstance();
#else
v8::Local<v8::Object> result = class_templ->InstanceTemplate()->NewInstance(SWIGV8_CURRENT_CONTEXT()).ToLocalChecked();
#endif
SWIGV8_SetPrivateData(result, ptr, info, flags);
SWIGV8_ESCAPE(result);
@ -396,7 +469,7 @@ SWIGRUNTIME v8::Handle<v8::Value> SWIG_V8_NewPointerObj(void *ptr, swig_type_inf
SWIGRUNTIME SwigV8ReturnValue _SWIGV8_wrap_equals(const SwigV8Arguments &args) {
SWIGV8_HANDLESCOPE();
v8::Handle<v8::Value> jsresult;
SWIGV8_VALUE jsresult;
void *arg1 = (void *) 0 ;
void *arg2 = (void *) 0 ;
bool result;
@ -426,7 +499,7 @@ fail:
SWIGRUNTIME SwigV8ReturnValue _wrap_getCPtr(const SwigV8Arguments &args) {
SWIGV8_HANDLESCOPE();
v8::Handle<v8::Value> jsresult;
SWIGV8_VALUE jsresult;
void *arg1 = (void *) 0 ;
long result;
int res1;
@ -465,23 +538,30 @@ public:
};
SWIGRUNTIMEINLINE
int SwigV8Packed_Check(v8::Handle<v8::Value> valRef) {
int SwigV8Packed_Check(SWIGV8_VALUE valRef) {
SWIGV8_HANDLESCOPE();
v8::Handle<v8::Object> objRef = valRef->ToObject();
SWIGV8_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
swig_type_info *SwigV8Packed_UnpackData(v8::Handle<v8::Value> valRef, void *ptr, size_t size) {
swig_type_info *SwigV8Packed_UnpackData(SWIGV8_VALUE valRef, void *ptr, size_t size) {
if (SwigV8Packed_Check(valRef)) {
SWIGV8_HANDLESCOPE();
SwigV8PackedData *sobj;
v8::Handle<v8::Object> objRef = valRef->ToObject();
SWIGV8_OBJECT objRef = SWIGV8_TO_OBJECT(valRef);
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031511)
v8::Handle<v8::Value> cdataRef = objRef->GetInternalField(0);
@ -498,7 +578,7 @@ swig_type_info *SwigV8Packed_UnpackData(v8::Handle<v8::Value> valRef, void *ptr,
}
SWIGRUNTIME
int SWIGV8_ConvertPacked(v8::Handle<v8::Value> valRef, void *ptr, size_t sz, swig_type_info *ty) {
int SWIGV8_ConvertPacked(SWIGV8_VALUE valRef, void *ptr, size_t sz, swig_type_info *ty) {
swig_type_info *to = SwigV8Packed_UnpackData(valRef, ptr, sz);
if (!to) return SWIG_ERROR;
if (ty) {
@ -519,10 +599,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,20 +620,25 @@ 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
}
SWIGRUNTIME
v8::Handle<v8::Value> SWIGV8_NewPackedObj(void *data, size_t size, swig_type_info *type) {
SWIGV8_VALUE SWIGV8_NewPackedObj(void *data, size_t size, swig_type_info *type) {
SWIGV8_HANDLESCOPE_ESC();
SwigV8PackedData *cdata = new SwigV8PackedData(data, size, type);
// 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,20 +661,25 @@ 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)
cdata->handle.MarkIndependent();
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100)
cdata->handle.MarkIndependent(v8::Isolate::GetCurrent());
#else
#elif (SWIG_V8_VERSION < 0x0704)
cdata->handle.MarkIndependent();
// Looks like future versions do not require that anymore:
// https://monorail-prod.appspot.com/p/chromium/issues/detail?id=923361#c11
#endif
SWIGV8_ESCAPE(obj);
}
#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIGV8_ConvertPacked(obj, ptr, sz, ty)
@ -600,22 +693,18 @@ v8::Handle<v8::Value> SWIGV8_NewPackedObj(void *data, size_t size, swig_type_inf
SWIGRUNTIME
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903)
v8::Handle<v8::Value> SWIGV8_AppendOutput(v8::Handle<v8::Value> result, v8::Handle<v8::Value> obj) {
#else
v8::Handle<v8::Value> SWIGV8_AppendOutput(v8::Local<v8::Value> result, v8::Handle<v8::Value> obj) {
#endif
SWIGV8_VALUE SWIGV8_AppendOutput(SWIGV8_VALUE result, SWIGV8_VALUE obj) {
SWIGV8_HANDLESCOPE_ESC();
if (result->IsUndefined()) {
result = SWIGV8_ARRAY_NEW();
result = SWIGV8_ARRAY_NEW(0);
} else if (!result->IsArray()) {
SWIGV8_ARRAY tmparr = SWIGV8_ARRAY_NEW(0);
SWIGV8_ARRAY_SET(tmparr, 0, result);
result = tmparr;
}
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903)
v8::Handle<v8::Array> arr = v8::Handle<v8::Array>::Cast(result);
#else
v8::Local<v8::Array> arr = v8::Local<v8::Array>::Cast(result);
#endif
arr->Set(arr->Length(), obj);
SWIGV8_ARRAY arr = SWIGV8_ARRAY::Cast(result);
SWIGV8_ARRAY_SET(arr, arr->Length(), obj);
SWIGV8_ESCAPE(arr);
}

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
@ -54,9 +56,15 @@
%insert(runtime) %{
#include <v8.h>
#if defined(V8_MAJOR_VERSION) && defined(V8_MINOR_VERSION)
#undef SWIG_V8_VERSION
#define SWIG_V8_VERSION (V8_MAJOR_VERSION * 256 + V8_MINOR_VERSION)
#endif
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <assert.h>
%}
%insert(runtime) "swigrun.swg"; /* SWIG API */

View file

@ -4,14 +4,18 @@
* ------------------------------------------------------------ */
%fragment("SWIG_AsCharPtrAndSize", "header", fragment="SWIG_pchar_descriptor") {
SWIGINTERN int
SWIG_AsCharPtrAndSize(v8::Handle<v8::Value> valRef, char** cptr, size_t* psize, int *alloc)
SWIG_AsCharPtrAndSize(SWIGV8_VALUE valRef, char** cptr, size_t* psize, int *alloc)
{
if(valRef->IsString()) {
v8::Handle<v8::String> js_str = valRef->ToString();
%#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903)
v8::Handle<v8::String> js_str = v8::Handle<v8::String>::Cast(valRef);
%#else
v8::Local<v8::String> js_str = v8::Local<v8::String>::Cast(valRef);
%#endif
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 +24,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();
SWIGV8_OBJECT obj = SWIGV8_OBJECT::Cast(valRef);
// try if the object is a wrapped char[]
swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
if (pchar_descriptor) {
@ -41,7 +45,7 @@ SWIG_AsCharPtrAndSize(v8::Handle<v8::Value> valRef, char** cptr, size_t* psize,
}
%fragment("SWIG_FromCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
SWIGINTERNINLINE v8::Handle<v8::Value>
SWIGINTERNINLINE SWIGV8_VALUE
SWIG_FromCharPtrAndSize(const char* carray, size_t size)
{
if (carray) {
@ -49,7 +53,11 @@ SWIG_FromCharPtrAndSize(const char* carray, size_t size)
// TODO: handle extra long strings
return SWIGV8_UNDEFINED();
} else {
%#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903)
v8::Handle<v8::String> js_str = SWIGV8_STRING_NEW2(carray, size);
%#else
v8::Local<v8::String> js_str = SWIGV8_STRING_NEW2(carray, size);
%#endif
return js_str;
}
} else {

View file

@ -25,7 +25,7 @@
/* Javascript types */
#define SWIG_Object v8::Handle<v8::Value>
#define SWIG_Object SWIGV8_VALUE
#define VOID_Object SWIGV8_UNDEFINED()
/* Overload of the output/constant/exception/dirout handling */

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

@ -18,7 +18,7 @@ you would use a real value instead.
int *INPUT
short *INPUT
long *INPUT
long long *INPUT
long long *INPUT
unsigned int *INPUT
unsigned short *INPUT
unsigned long *INPUT

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

@ -181,7 +181,7 @@ typedef struct swig_elua_entry {
/* Push the string STR on the Lua stack, like lua_pushstring, but
prefixed with the location of the innermost Lua call-point
(as formated by luaL_where). */
(as formatted by luaL_where). */
SWIGRUNTIME void
SWIG_Lua_pusherrstring (lua_State *L, const char *str)
{
@ -192,7 +192,7 @@ 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
location of the innermost Lua call-point (as formated by luaL_where). */
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 */
@ -341,7 +341,7 @@ typedef struct {
#define SWIG_isptrtype(L,I) (lua_isuserdata(L,I) || lua_isnil(L,I))
#ifdef __cplusplus
/* Special helper for member function pointers
/* Special helper for member function pointers
it gets the address, casts it, then dereferences it */
/*#define SWIG_mem_fn_as_voidptr(a) (*((char**)&(a))) */
#endif
@ -444,7 +444,7 @@ SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_ent
lua_pop(L,1); /*remove nil */
lua_newtable(L);
SWIG_Lua_elua_emulate_register(L,entry->value.value.table);
}
}
if(is_metatable) {
assert(lua_istable(L,-1));
lua_pushvalue(L,-1);
@ -453,11 +453,11 @@ SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_ent
break;
case LUA_TUSERDATA:
if(entry->value.value.userdata.member)
if(entry->value.value.userdata.member)
SWIG_NewMemberObj(L,entry->value.value.userdata.pvalue,
entry->value.value.userdata.lvalue,
*(entry->value.value.userdata.ptype));
else
else
SWIG_NewPointerObj(L,entry->value.value.userdata.pvalue,
*(entry->value.value.userdata.ptype),0);
break;
@ -502,7 +502,7 @@ SWIGINTERN int SWIG_Lua_emulate_elua_getmetatable(lua_State *L)
}
assert(lua_gettop(L) == 2);
return 1;
fail:
lua_error(L);
return 0;
@ -520,7 +520,7 @@ SWIGINTERN void SWIG_Lua_emulate_elua_swap_getmetatable(lua_State *L)
lua_pushcfunction(L, SWIG_Lua_emulate_elua_getmetatable);
lua_rawset(L,-3);
lua_pop(L,2);
}
/* END OF REMOVE */
@ -1039,17 +1039,11 @@ SWIGINTERN int SWIG_Lua_class_tostring(lua_State *L)
{
/* there should be 1 param passed in
(1) userdata (not the metatable) */
const char *className;
void* userData;
swig_lua_userdata* userData;
assert(lua_isuserdata(L,1)); /* just in case */
userData = lua_touserdata(L,1); /* get the userdata address for later */
lua_getmetatable(L,1); /* get the meta table */
assert(lua_istable(L,-1)); /* just in case */
userData = (swig_lua_userdata*)lua_touserdata(L,1); /* get the userdata address */
lua_getfield(L, -1, ".type");
className = lua_tostring(L, -1);
lua_pushfstring(L, "<%s userdata: %p>", className, userData);
lua_pushfstring(L, "<userdata of type '%s' at %p>", userData->type->str, userData->ptr);
return 1;
}
@ -1061,7 +1055,7 @@ SWIGINTERN int SWIG_Lua_class_disown(lua_State *L)
swig_lua_userdata *usr;
assert(lua_isuserdata(L,-1)); /* just in case */
usr=(swig_lua_userdata*)lua_touserdata(L,-1); /* get it */
usr->own = 0; /* clear our ownership */
return 0;
}
@ -1170,7 +1164,7 @@ SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L,const char *cname)
Each class structure has a list of pointers to the base class structures.
This function fills them.
It cannot be done at compile time, as this will not work with hireachies
spread over more than one swig file.
spread over more than one swig file.
Therefore it must be done at runtime, querying the SWIG type system.
*/
SWIGINTERN void SWIG_Lua_init_base_class(lua_State *L,swig_lua_class *clss)
@ -1404,11 +1398,11 @@ SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L)
lua_checkstack(L,5);
numargs = lua_gettop(L); /* number of arguments to pass to actual metamethod */
/* Get upvalues from closure */
lua_pushvalue(L, lua_upvalueindex(1)); /*Get function name*/
metamethod_name_idx = lua_gettop(L);
lua_pushvalue(L, lua_upvalueindex(2));
clss = (const swig_lua_class*)(lua_touserdata(L,-1));
lua_pop(L,1); /* remove lightuserdata with clss from stack */
@ -1440,7 +1434,7 @@ SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *
/* metamethod name - on the top of the stack */
assert(lua_isstring(L,-1));
key_index = lua_gettop(L);
/* Check whether method is already defined in metatable */
@ -1450,7 +1444,7 @@ SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *
lua_pop(L,1);
return -1;
}
lua_pop(L,1);
lua_pop(L,1);
/* Iterating over immediate bases */
for(i=0;clss->bases[i];i++)
@ -1460,13 +1454,13 @@ SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *
lua_pushvalue(L, key_index);
lua_rawget(L, -2);
if( !lua_isnil(L,-1) ) {
lua_pushvalue(L, key_index);
lua_pushvalue(L, key_index);
/* Add proxy function */
lua_pushvalue(L, key_index); /* first closure value is function name */
lua_pushlightuserdata(L, clss); /* second closure value is swig_lua_class structure */
lua_pushcclosure(L, SWIG_Lua_resolve_metamethod, 2);
lua_rawset(L, metatable_index);
success = 1;
}
@ -1477,7 +1471,7 @@ SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *
break;
}
return success;
return success;
}
SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class *clss)
@ -1765,7 +1759,17 @@ 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;
}
if (lua_islightuserdata(L,index))
{
*ptr=lua_touserdata(L,index);
return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
}
usr=(swig_lua_userdata*)lua_touserdata(L,index); /* get data */
if (usr)
{
@ -1811,7 +1815,7 @@ SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L,void *ptr,size_t size,swig_t
memcpy(raw->data,ptr,size); /* copy the data */
SWIG_Lua_AddMetatable(L,type); /* add metatable */
}
/* converts a packed userdata. user for member fn pointers only */
SWIGRUNTIME int SWIG_Lua_ConvertPacked(lua_State *L,int index,void *ptr,size_t size,swig_type_info *type)
{
@ -1910,7 +1914,7 @@ Unfortunately lua keeps changing its APIs, so we need a conditional compile
In lua 5.0.X it's lua_dostring()
In lua 5.1.X it's luaL_dostring()
*/
SWIGINTERN int
SWIGINTERN int
SWIG_Lua_dostring(lua_State *L, const char *str) {
int ok,top;
if (str==0 || str[0]==0) return 0; /* nothing to do */
@ -1925,7 +1929,7 @@ SWIG_Lua_dostring(lua_State *L, const char *str) {
}
lua_settop(L,top); /* restore the stack */
return ok;
}
}
#ifdef __cplusplus
}

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"

View file

@ -189,7 +189,7 @@ SWIGINTERN int SWIG_lua_isnilstring(lua_State *L, int idx) {
// Also needed for object ptrs by const ref
// eg A* const& ref_pointer(A* const& a);
// found in mixed_types.i
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE *const&($*ltype temp)
%typemap(in,checkfn="SWIG_isptrtype") SWIGTYPE *const&($*ltype temp)
%{temp=($*ltype)SWIG_MustGetPtr(L,$input,$*descriptor,0,$argnum,"$symname");
$1=($1_ltype)&temp;%}
@ -327,7 +327,7 @@ parameters match which function
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE & {
void *ptr;
if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $1_descriptor, 0)) {
if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $1_descriptor, SWIG_POINTER_NO_NULL)) {
$1 = 0;
} else {
$1 = 1;
@ -336,7 +336,7 @@ parameters match which function
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE && {
void *ptr;
if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $1_descriptor, 0)) {
if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $1_descriptor, SWIG_POINTER_NO_NULL)) {
$1 = 0;
} else {
$1 = 1;
@ -345,7 +345,7 @@ parameters match which function
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE {
void *ptr;
if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $&1_descriptor, 0)) {
if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $&1_descriptor, SWIG_POINTER_NO_NULL)) {
$1 = 0;
} else {
$1 = 1;
@ -367,7 +367,7 @@ parameters match which function
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *const&
{
void *ptr;
if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $*descriptor, 0)) {
if (SWIG_isptrtype(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $*descriptor, 0)) {
$1 = 0;
} else {
$1 = 1;

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

@ -7,21 +7,6 @@
%{
#include <utility>
%}
/*
A really cut down version of the pair class.
this is not useful on its own - it needs a %template definition with it
eg.
namespace std {
%template(IntPair) pair<int, int>;
%template(make_IntPair) make_pair<int, int>;
}
*/
namespace std {
template <class T, class U > struct pair {
@ -30,13 +15,12 @@ namespace std {
pair();
pair(T first, U second);
pair(const pair& p);
pair(const pair& other);
T first;
U second;
};
template <class T, class U >
pair<T,U> make_pair(const T&,const U&);
pair<T,U> make_pair(const T& first, const U& second);
}

View file

@ -109,7 +109,6 @@ as this is overloaded by the const char* version
public:
string();
string(const char*);
//string(const string&);
unsigned int size() const;
unsigned int length() const;
bool empty() const;
@ -119,7 +118,6 @@ as this is overloaded by the const char* version
// assign does not return a copy of this object
// (no point in a scripting language)
void assign(const char*);
//void assign(const string&);
// no support for all the other features
// it's probably better to do it in lua
};

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