Merge trunk rev 13025 (swig-2.0.6) into gsoc2008-maciekd

Conflicts:
	Doc/Manual/chapters
	Examples/Makefile.in
	Examples/test-suite/dynamic_cast.i
	Lib/exception.i
	Makefile.in
	Source/Include/swigwarn.h
	Source/Modules/swigmain.cxx
	Source/Swig/swig.h
	Tools/config/config.guess
	Tools/config/config.sub
	configure.in

From: William S Fulton <wsf@fultondesigns.co.uk>

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@13036 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2012-05-07 16:59:38 +00:00
commit e0067ea998
2152 changed files with 99389 additions and 53536 deletions

View file

@ -16,6 +16,7 @@
float, double, long double, char *, void *,
enum SWIGTYPE "(cl::setq ACL_ffresult $body)";
%typemap(lout) void "$body";
#ifdef __cplusplus
%typemap(lout) SWIGTYPE[ANY], SWIGTYPE *,
SWIGTYPE &
%{ (cl:let* ((address $body)
@ -25,38 +26,83 @@
(cl:setq ACL_ffresult new-inst)) %}
%typemap(lout) SWIGTYPE "(cl::let* ((address $body)\n (new-inst (cl::make-instance '$lclass :foreign-address address)))\n (cl::unless (cl::zerop address)\n (excl:schedule-finalization new-inst #'$ldestructor))\n (cl::setq ACL_ffresult new-inst))";
#else
%typemap(lout) SWIGTYPE[ANY], SWIGTYPE *, SWIGTYPE &, SWIGTYPE
%{ (cl:let* ((address $body)
(new-inst (cl:make-instance '$lclass :foreign-address address)))
(cl:setq ACL_ffresult new-inst)) %}
#endif
%typemap(lisptype) bool "cl:boolean";
%typemap(lisptype) char "cl:character";
%typemap(lisptype) unsigned char "cl:integer";
%typemap(lisptype) signed char "cl:integer";
%typemap(lisptype) bool, const bool "cl:boolean";
%typemap(lisptype) char, const char "cl:character";
%typemap(lisptype) unsigned char, const unsigned char "cl:integer";
%typemap(lisptype) signed char, const signed char "cl:integer";
%typemap(ffitype) bool ":int";
%typemap(ffitype) char ":char";
%typemap(ffitype) unsigned char ":unsigned-char";
%typemap(ffitype) signed char ":char";
%typemap(ffitype) short, signed short ":short";
%typemap(ffitype) unsigned short ":unsigned-short";
%typemap(ffitype) int, signed int ":int";
%typemap(ffitype) unsigned int ":unsigned-int";
%typemap(ffitype) long, signed long ":long";
%typemap(ffitype) unsigned long ":unsigned-long";
%typemap(ffitype) float ":float";
%typemap(ffitype) double ":double";
%typemap(ffitype) char * "(* :char)";
%typemap(ffitype) bool, const bool ":int";
%typemap(ffitype) char, const char,
signed char, const signed char ":char";
%typemap(ffitype) unsigned char, const unsigned char ":unsigned-char";
%typemap(ffitype) short, const short,
signed short, const signed short ":short";
%typemap(ffitype) unsigned short, const unsigned short ":unsigned-short";
%typemap(ffitype) int, const int, signed int, const signed int ":int";
%typemap(ffitype) unsigned int, const unsigned int ":unsigned-int";
%typemap(ffitype) long, const long, signed long, const signed long ":long";
%typemap(ffitype) unsigned long, const unsigned long ":unsigned-long";
%typemap(ffitype) float, const float ":float";
%typemap(ffitype) double, const double ":double";
%typemap(ffitype) char *, const char *, signed char *,
const signed char *, signed char &,
const signed char & "(* :char)";
%typemap(ffitype) unsigned char *, const unsigned char *,
unsigned char &, const unsigned char & "(* :unsigned-char)";
%typemap(ffitype) short *, const short *, short &,
const short & "(* :short)";
%typemap(ffitype) unsigned short *, const unsigned short *,
unsigned short &, const unsigned short & "(* :unsigned-short)";
%typemap(ffitype) int *, const int *, int &, const int & "(* :int)";
%typemap(ffitype) unsigned int *, const unsigned int *,
unsigned int &, const unsigned int & "(* :unsigned-int)";
%typemap(ffitype) void * "(* :void)";
%typemap(ffitype) void ":void";
%typemap(ffitype) enum SWIGTYPE ":int";
%typemap(ffitype) SWIGTYPE & "(* :void)";
%typemap(ctype) bool "int";
/* const typemaps
idea: marshall all primitive c types to their respective lisp types
to maintain const corretness. For pointers/references, all bets
are off if you try to modify them.
idea: add a constant-p slot to the base foreign-pointer class. For
constant pointer/references check this value when setting (around method?)
and error if a setf operation is performed on the address of this object.
*/
/*
%exception %{
try {
$action
} catch (...) {
return $null;
}
%}
*/
// %typemap(throws) SWIGTYPE {
// (void)$1;
// SWIG_fail;
// }
%typemap(ctype) bool, const bool "int";
%typemap(ctype) char, unsigned char, signed char,
short, signed short, unsigned short,
int, signed int, unsigned int,
long, signed long, unsigned long,
float, double, long double, char *, void *, void,
enum SWIGTYPE, SWIGTYPE *,
SWIGTYPE[ANY], SWIGTYPE & "$1_ltype";
enum SWIGTYPE, SWIGTYPE *, SWIGTYPE[],
SWIGTYPE[ANY], SWIGTYPE &, const SWIGTYPE "$1_ltype";
%typemap(ctype) SWIGTYPE "$&1_type";
%typemap(in) bool "$1 = (bool)$input;";
@ -65,7 +111,7 @@
int, signed int, unsigned int,
long, signed long, unsigned long,
float, double, long double, char *, void *, void,
enum SWIGTYPE, SWIGTYPE *,
enum SWIGTYPE, SWIGTYPE *, SWIGTYPE[],
SWIGTYPE[ANY], SWIGTYPE & "$1 = $input;";
%typemap(in) SWIGTYPE "$1 = *$input;";
@ -122,7 +168,8 @@ SWIG_TYPECHECK_STRING_ARRAY 1140
long, signed long, unsigned long,
enum SWIGTYPE { $1 = 1; };
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &,
SWIGTYPE[ANY], SWIGTYPE { $1 = 1; };
SWIGTYPE[], SWIGTYPE[ANY],
SWIGTYPE { $1 = 1; };
/* This maps C/C++ types to Lisp classes for overload dispatch */
@ -147,7 +194,7 @@ SWIG_TYPECHECK_STRING_ARRAY 1140
enum SWIGTYPE, SWIGTYPE *,
SWIGTYPE[ANY], SWIGTYPE & "$result = $1;";
#ifdef __cplusplus
%typemap(out) SWIGTYPE "$result = new $1_type($1);";
%typemap(out) SWIGTYPE "$result = new $1_ltype($1);";
#else
%typemap(out) SWIGTYPE {
$result = ($&1_ltype) malloc(sizeof($1_type));
@ -163,22 +210,28 @@ SWIG_TYPECHECK_STRING_ARRAY 1140
%typemap(in) wchar_t "$1 = $input;";
%typemap(lin,numinputs=1) wchar_t "(cl::let (($out (cl:char-code $in)))\n $body)";
%typemap(lin,numinputs=1) wchar_t* "(excl:with-native-string ($out $in
%typemap(lin,numinputs=1) wchar_t * "(excl:with-native-string ($out $in
:external-format #+little-endian :fat-le #-little-endian :fat)\n
$body)"
%typemap(out) wchar_t "$result = $1;";
%typemap(lout) wchar_t "(cl::setq ACL_ffresult (cl::code-char $body))";
%typemap(lout) wchar_t* "(cl::setq ACL_ffresult (excl:native-to-string $body
%typemap(lout) wchar_t * "(cl::setq ACL_ffresult (excl:native-to-string $body
:external-format #+little-endian :fat-le #-little-endian :fat))";
%typemap(ffitype) wchar_t ":unsigned-short";
%typemap(lisptype) wchar_t "";
%typemap(ctype) wchar_t "wchar_t";
%typemap(lispclass) wchar_t "cl:character";
%typemap(lispclass) wchar_t* "cl:string";
%typemap(lispclass) wchar_t * "cl:string";
//////////////////////////////////////////////////////////////
/* Array reference typemaps */
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
/* name conversion for overloaded operators. */
#ifdef __cplusplus
%rename(__add__) *::operator+;
@ -243,12 +296,13 @@ $body)"
%rename(__funcall__) *::operator();
%rename(__aref__) *::operator[];
%rename(__bool__) *::operator bool();
%rename(__bool__) *::operator bool() const;
#endif
%insert("lisphead") %{
;; $Id$
(eval-when (compile load eval)
(eval-when (:compile-toplevel :load-toplevel :execute)
;; avoid compiling ef-templates at runtime
(excl:find-external-format :fat)
@ -296,15 +350,30 @@ $body)"
sym))))
(cl::defun full-name (id type arity class)
(cl::case type
(:getter (cl::format nil "~@[~A_~]~A" class id))
(:constructor (cl::format nil "new_~A~@[~A~]" id arity))
(:destructor (cl::format nil "delete_~A" id))
(:type (cl::format nil "ff_~A" id))
(:slot id)
(:ff-operator (cl::format nil "ffi_~A" id))
(otherwise (cl::format nil "~@[~A_~]~A~@[~A~]"
class id arity))))
; We need some kind of a hack here to handle template classes
; and other synonym types right. We need the original name.
(let*( (sym (read-symbol-from-string
(if (eq *swig-identifier-converter* 'identifier-convert-lispify)
(string-lispify id)
id)))
(sym-class (find-class sym nil))
(id (cond ( (not sym-class)
id )
( (and sym-class
(not (eq (class-name sym-class)
sym)))
(class-name sym-class) )
( t
id ))) )
(cl::case type
(:getter (cl::format nil "~@[~A_~]~A" class id))
(:constructor (cl::format nil "new_~A~@[~A~]" id arity))
(:destructor (cl::format nil "delete_~A" id))
(:type (cl::format nil "ff_~A" id))
(:slot id)
(:ff-operator (cl::format nil "ffi_~A" id))
(otherwise (cl::format nil "~@[~A_~]~A~@[~A~]"
class id arity)))))
(cl::defun identifier-convert-null (id &key type class arity)
(cl::if (cl::eq type :setter)
@ -312,6 +381,27 @@ $body)"
id :type :getter :class class :arity arity))
(read-symbol-from-string (full-name id type arity class))))
(cl::defun string-lispify (str)
(cl::let ( (cname (excl::replace-regexp str "_" "-"))
(lastcase :other)
newcase char res )
(cl::dotimes (n (cl::length cname))
(cl::setf char (cl::schar cname n))
(excl::if* (cl::alpha-char-p char)
then
(cl::setf newcase (cl::if (cl::upper-case-p char) :upper :lower))
(cl::when (cl::and (cl::eq lastcase :lower)
(cl::eq newcase :upper))
;; case change... add a dash
(cl::push #\- res)
(cl::setf newcase :other))
(cl::push (cl::char-downcase char) res)
(cl::setf lastcase newcase)
else
(cl::push char res)
(cl::setf lastcase :other)))
(cl::coerce (cl::nreverse res) 'string)))
(cl::defun identifier-convert-lispify (cname &key type class arity)
(cl::assert (cl::stringp cname))
(cl::when (cl::eq type :setter)
@ -321,31 +411,7 @@ $body)"
(cl::setq cname (full-name cname type arity class))
(cl::if (cl::eq type :constant)
(cl::setf cname (cl::format nil "*~A*" cname)))
(cl::setf cname (excl::replace-regexp cname "_" "-"))
(cl::let ((lastcase :other)
newcase char res)
(cl::dotimes (n (cl::length cname))
(cl::setf char (cl::schar cname n))
(excl::if* (cl::alpha-char-p char)
then
(cl::setf newcase (cl::if (cl::upper-case-p char) :upper :lower))
(cl::when (cl::or (cl::and (cl::eq lastcase :upper)
(cl::eq newcase :lower))
(cl::and (cl::eq lastcase :lower)
(cl::eq newcase :upper)))
;; case change... add a dash
(cl::push #\- res)
(cl::setf newcase :other))
(cl::push (cl::char-downcase char) res)
(cl::setf lastcase newcase)
else
(cl::push char res)
(cl::setf lastcase :other)))
(read-symbol-from-string (cl::coerce (cl::nreverse res) 'string))))
(read-symbol-from-string (string-lispify cname)))
(cl::defun id-convert-and-export (name &rest kwargs)
(cl::multiple-value-bind (symbol package)
@ -363,7 +429,7 @@ $body)"
(defswig2 swig-defconstant (string value)
(cl::let ((symbol (id-convert-and-export string :type :constant)))
`(cl::eval-when (compile load eval)
`(cl::eval-when (:compile-toplevel :load-toplevel :execute)
(cl::defconstant ,symbol ,value))))
(cl::defun maybe-reorder-args (funcname arglist)
@ -409,7 +475,7 @@ $body)"
)
(cl::when (swig-anyvarargs-p ffargs)
(cl::setq ffargs '()))
`(cl::eval-when (compile load eval)
`(cl::eval-when (:compile-toplevel :load-toplevel :execute)
(excl::compiler-let ((*record-xref-info* nil))
(ff:def-foreign-call (,mangle ,mangled-name) ,ffargs ,@kwargs))
(cl::macrolet ((swig-ff-call (&rest args)
@ -435,7 +501,7 @@ $body)"
ffargs
(cl::loop for (nil name nil . ffi) in ffargs
collect `(,name ,@ffi)))))
`(cl::eval-when (compile load eval)
`(cl::eval-when (:compile-toplevel :load-toplevel :execute)
(excl::compiler-let ((*record-xref-info* nil))
(ff:def-foreign-call (,mangle ,mangled-name) ,ffargs ,@kwargs))
(cl::macrolet ((swig-ff-call (&rest args)
@ -447,7 +513,7 @@ $body)"
(defswig1 swig-dispatcher ((name &key (type :operator) class arities))
(cl::let ((symbol (id-convert-and-export name
:type type :class class)))
`(cl::eval-when (compile load eval)
`(cl::eval-when (:compile-toplevel :load-toplevel :execute)
(cl::defun ,symbol (&rest args)
(cl::case (cl::length args)
,@(cl::loop for arity in arities
@ -460,14 +526,14 @@ $body)"
(defswig2 swig-def-foreign-stub (name)
(cl::let ((lsymbol (id-convert-and-export name :type :class))
(symbol (id-convert-and-export name :type :type)))
`(cl::eval-when (compile load eval)
`(cl::eval-when (:compile-toplevel :load-toplevel :execute)
(ff:def-foreign-type ,symbol (:class ))
(cl::defclass ,lsymbol (ff:foreign-pointer) ()))))
(defswig2 swig-def-foreign-class (name supers &rest rest)
(cl::let ((lsymbol (id-convert-and-export name :type :class))
(symbol (id-convert-and-export name :type :type)))
`(cl::eval-when (compile load eval)
`(cl::eval-when (:compile-toplevel :load-toplevel :execute)
(ff:def-foreign-type ,symbol ,@rest)
(cl::defclass ,lsymbol ,supers
((foreign-type :initform ',symbol :initarg :foreign-type
@ -475,11 +541,11 @@ $body)"
(defswig2 swig-def-foreign-type (name &rest rest)
(cl::let ((symbol (id-convert-and-export name :type :type)))
`(cl::eval-when (compile load eval)
`(cl::eval-when (:compile-toplevel :load-toplevel :execute)
(ff:def-foreign-type ,symbol ,@rest))))
(defswig2 swig-def-synonym-type (synonym of ff-synonym)
`(cl::eval-when (compile load eval)
`(cl::eval-when (:compile-toplevel :load-toplevel :execute)
(cl::setf (cl::find-class ',synonym) (cl::find-class ',of))
(ff:def-foreign-type ,ff-synonym (:struct ))))
@ -499,24 +565,24 @@ $body)"
(parent-strings (cl::mapcar #'package-name-for-namespace
parent-namespaces))
(string (package-name-for-namespace namespace)))
`(cl::eval-when (compile load eval)
`(cl::eval-when (:compile-toplevel :load-toplevel :execute)
(cl::defpackage ,string
(:use :swig :ff #+ignore '(:common-lisp :ff :excl)
,@parent-strings ,*swig-module-name*)
(:import-from :cl :* :nil :t)))))
(cl::defmacro swig-in-package (namespace)
`(cl::eval-when (compile load eval)
`(cl::eval-when (:compile-toplevel :load-toplevel :execute)
(cl::in-package ,(package-name-for-namespace namespace))))
(defswig2 swig-defvar (name mangled-name &key type (ftype :unsigned-natural))
(cl::let ((symbol (id-convert-and-export name :type type)))
`(cl::eval-when (compile load eval)
`(cl::eval-when (:compile-toplevel :load-toplevel :execute)
(ff:def-foreign-variable (,symbol ,mangled-name) :type ,ftype))))
) ;; eval-when
(cl::eval-when (compile eval)
(cl::eval-when (:compile-toplevel :execute)
(cl::flet ((starts-with-p (str prefix)
(cl::and (cl::>= (cl::length str) (cl::length prefix))
(cl::string= str prefix :end1 (cl::length prefix)))))
@ -527,7 +593,7 @@ $body)"
%}
typedef void *__SWIGACL_FwdReference;
%{
@ -539,6 +605,8 @@ $body)"
#define EXPORT EXTERN SWIGEXPORT
typedef void *__SWIGACL_FwdReference;
#include <string.h>
#include <stdlib.h>
%}

0
Lib/allegrocl/inout_typemaps.i Executable file → Normal file
View file

39
Lib/allegrocl/longlongs.i Executable file → Normal file
View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* longlongs.i
*
* Typemap addition for support of 'long long' type and 'unsigned long long
@ -10,27 +7,43 @@
* functions have been defined.
* ----------------------------------------------------------------------------- */
%typemap(in) long long, unsigned long long "$1 = $input;";
%typemap(out) long long, unsigned long long "$result = &$1;";
#ifdef Acl64Bit
%typemap(ctype) long long, unsigned long long "$1_ltype";
%typemap(out) long long, unsigned long long "$result = $1;";
%typemap(ffitype) long long ":nat";
%typemap(ffitype) unsigned long long ":unsigned-nat";
%typemap(lout) long long, unsigned long long " #+64bit (cl::setq ACL_ffresult $body)";
#else
%typemap(out) long long, unsigned long long "$result = &$1;";
%typemap(ffitype) long long "(:struct (l1 :long) (l2 :long))";
%typemap(ffitype) unsigned long long "(:struct (l1 :unsigned-long)
(l2 :unsigned-long))";
%typemap(ffitype) unsigned long long "(:struct (l1 :unsigned-long) (l2 :unsigned-long))";
%typemap(lout) long long
" (make-instance #.(swig-insert-id \"longlong\" () :type :class)
:foreign-address $body)";
" (cl::setq ACL_ffresult (make-instance '#.(swig-insert-id \"longlong\" () :type :class)
:foreign-address $body))";
%typemap(lout) unsigned long long
" (make-instance #.(swig-insert-id \"ulonglong\" () :type :class)
:foreign-address $body)";
" (cl:setq ACL_ffresult (make-instance '#.(swig-insert-id \"ulonglong\" () :type :class)
:foreign-address $body))";
#endif
%typemap(in) long long, unsigned long long "$1 = $input;";
%insert("lisphead") %{
#-64bit
(swig-def-foreign-class "longlong"
(ff:foreign-pointer)
(:struct (:struct (l1 :long) (l2 :long))))
(:struct (l1 :long) (l2 :long)))
#-64bit
(swig-def-foreign-class "ulonglong"
(ff:foreign-pointer)
(:struct (:struct (l1 :unsigned-long) (l2 :unsigned-long))))
(:struct (l1 :unsigned-long) (l2 :unsigned-long)))
%}

3
Lib/allegrocl/std_list.i Executable file → Normal file
View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* std_list.i
*
* SWIG typemaps for std::list types

9
Lib/allegrocl/std_string.i Executable file → Normal file
View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* std_string.i
*
* SWIG typemaps for std::string
@ -20,12 +17,6 @@
%{
#include <string>
// #include <vector>
// using std::vector;
using std::string;
%}
// %include <std_vector.i>

View file

@ -18,8 +18,9 @@
%include <chicken/chickenkw.swg>
%include <csharp/csharpkw.swg>
%include <d/dkw.swg>
%include <java/javakw.swg>
%include <php4/php4kw.swg>
%include <php/phpkw.swg>
%include <pike/pikekw.swg>
%include <python/pythonkw.swg>
%include <ocaml/ocamlkw.swg>

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* attribute.i
*
* SWIG library file for implementing attributes.

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* carrays.i
*
* SWIG library file containing macros that can be used to manipulate simple
@ -76,9 +73,8 @@ void NAME##_setitem(TYPE *ary, int index, TYPE value);
%{
typedef TYPE NAME;
%}
typedef struct NAME {
typedef struct {
/* Put language specific enhancements here */
} NAME;
%extend NAME {

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* cdata.i
*
* SWIG library file containing macros for manipulating raw C data as strings.
@ -29,6 +26,11 @@ typedef struct SWIGCDATA {
$result = C_string(&string_space, $1.len, $1.data);
}
%typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
#elif SWIGPHP
%typemap(out) SWIGCDATA {
ZVAL_STRINGL($result, $1.data, $1.len, 1);
}
%typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
#else
%echo "cdata.i module not supported."
#endif
@ -74,9 +76,6 @@ SWIGCDATA cdata_##NAME(TYPE *ptr, int nelements);
%cdata(void);
/* Memory move function */
/* Memory move function. Due to multi-argument typemaps this appears to be wrapped as
void memmove(void *data, const char *s); */
void memmove(void *data, const void *indata, int inlen);

View file

@ -130,6 +130,11 @@
%typemap(lispclass) double "cl:number";
%typemap(lispclass) char * "cl:string";
/* Array reference typemaps */
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
%{

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* chicken.swg
*
* CHICKEN configuration module.
@ -10,6 +7,7 @@
/* chicken.h has to appear first. */
%insert(runtime) %{
#include <assert.h>
#include <chicken.h>
%}
@ -540,7 +538,7 @@ $result = C_SCHEME_UNDEFINED;
* String & length
* ------------------------------------------------------------ */
%typemap(in) (char *STRING, int LENGTH) {
%typemap(in) (char *STRING, int LENGTH), (char *STRING, size_t LENGTH) {
if ($input == C_SCHEME_FALSE) {
swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Cannot use a null/#f string for a char*, int arguments");
}
@ -681,6 +679,16 @@ $result = C_SCHEME_UNDEFINED;
%apply unsigned long { size_t };
/* ------------------------------------------------------------
* Various
* ------------------------------------------------------------ */
/* Array reference typemaps */
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
/* ------------------------------------------------------------
* Overloaded operator support
* ------------------------------------------------------------ */

View file

@ -3,7 +3,7 @@
/* Warnings for certain CHICKEN keywords. From Section 7.1.1 of
Revised^5 Report on the Algorithmic Language Scheme */
#define CHICKENKW(x) %namewarn("314:" #x " is a R^5RS syntatic keyword") #x
#define CHICKENKW(x) %namewarn("314: '" #x "' is a R^5RS syntatic keyword") #x
CHICKENKW(else);
CHICKENKW(=>);

View file

@ -1,12 +1,9 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* chickenrun.swg
*
* ----------------------------------------------------------------------------- */
#include <chicken.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

View file

@ -21,7 +21,7 @@
;; which functions are used when.
;; Comments, bugs, suggestions: send either to chicken-users@nongnu.org or to
;; Author: John Lenz <lenz@cs.wisc.edu>, most code copied from TinyCLOS
;; Most code copied from TinyCLOS
(define <multi-generic> (make <entity-class>
'name "multi-generic"

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* std_string.i
*
* SWIG typemaps for std::string
@ -33,7 +30,7 @@ namespace std {
%typemap(typecheck) string = char *;
%typemap(typecheck) const string & = char *;
%typemap(in) string (char* tempptr) {
%typemap(in) string (char * tempptr) {
if ($input == C_SCHEME_FALSE) {
$1.resize(0);
} else {
@ -47,8 +44,7 @@ namespace std {
}
}
%typemap(in) const string& (std::string temp,
char* tempptr) {
%typemap(in) const string& (std::string temp, char *tempptr) {
if ($input == C_SCHEME_FALSE) {
temp.resize(0);

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* typemaps.i
*
* Pointer handling

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* clisp.swg
* ----------------------------------------------------------------------------- */

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* cmalloc.i
*
* SWIG library file containing macros that can be used to create objects using

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* constraints.i
*
* SWIG constraints library.

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* cpointer.i
*
* SWIG library file containing macros that can be used to manipulate simple
@ -58,14 +55,14 @@ NAME() {
return new TYPE();
}
~NAME() {
if (self) delete self;
if ($self) delete $self;
}
#else
NAME() {
return (TYPE *) calloc(1,sizeof(TYPE));
}
~NAME() {
if (self) free(self);
if ($self) free($self);
}
#endif
}
@ -73,13 +70,13 @@ NAME() {
%extend NAME {
void assign(TYPE value) {
*self = value;
*$self = value;
}
TYPE value() {
return *self;
return *$self;
}
TYPE * cast() {
return self;
return $self;
}
static NAME * frompointer(TYPE *t) {
return (NAME *) t;
@ -129,34 +126,34 @@ static TYPE *copy_##NAME(TYPE value) { %}
#ifdef __cplusplus
%{ return new TYPE(value); %}
#else
%{ TYPE *self = (TYPE *) calloc(1,sizeof(TYPE));
*self = value;
return self; %}
%{ TYPE *obj = (TYPE *) calloc(1,sizeof(TYPE));
*obj = value;
return obj; %}
#endif
%{}
static void delete_##NAME(TYPE *self) { %}
static void delete_##NAME(TYPE *obj) { %}
#ifdef __cplusplus
%{ if (self) delete self; %}
%{ if (obj) delete obj; %}
#else
%{ if (self) free(self); %}
%{ if (obj) free(obj); %}
#endif
%{}
static void NAME ##_assign(TYPE *self, TYPE value) {
*self = value;
static void NAME ##_assign(TYPE *obj, TYPE value) {
*obj = value;
}
static TYPE NAME ##_value(TYPE *self) {
return *self;
static TYPE NAME ##_value(TYPE *obj) {
return *obj;
}
%}
TYPE *new_##NAME();
TYPE *copy_##NAME(TYPE value);
void delete_##NAME(TYPE *self);
void NAME##_assign(TYPE *self, TYPE value);
TYPE NAME##_value(TYPE *self);
void delete_##NAME(TYPE *obj);
void NAME##_assign(TYPE *obj, TYPE value);
TYPE NAME##_value(TYPE *obj);
%enddef

137
Lib/csharp/arrays_csharp.i Normal file
View file

@ -0,0 +1,137 @@
/* -----------------------------------------------------------------------------
* arrays_csharp.i
*
* This file contains a two approaches to marshaling arrays. The first uses
* default p/invoke marshaling and the second uses pinning of the arrays.
*
* Default marshaling approach
* ----------------------------
* Array typemaps using default p/invoke marshaling. The data is copied to a separately
* allocated buffer when passing over the managed-native boundary.
*
* There are separate typemaps for in, out and inout arrays to enable avoiding
* unnecessary copying.
*
* Example usage:
*
* %include "arrays_csharp.i"
* %apply int INPUT[] { int* sourceArray }
* %apply int OUTPUT[] { int* targetArray }
* void myArrayCopy( int* sourceArray, int* targetArray, int nitems );
*
* %apply int INOUT[] { int* array1, int *array2 }
* void myArraySwap( int* array1, int* array2, int nitems );
*
* If handling large arrays you should consider using the pinning array typemaps
* described next.
*
* Pinning approach
* ----------------
* Array typemaps using pinning. These typemaps pin the managed array given
* as parameter and pass a pointer to it to the c/c++ side. This is very
* efficient as no copying is done (unlike in the default array marshaling),
* but it makes garbage collection more difficult. When considering using
* these typemaps, think carefully whether you have callbacks that may cause
* the control to re-enter the managed side from within the call (and produce
* garbage for the gc) or whether other threads may produce enough garbage to
* trigger gc while the call is being executed. In those cases it may be
* wiser to use the default marshaling typemaps.
*
* Please note that when using fixed arrays, you have to mark your corresponding
* module class method unsafe using
* %csmethodmodifiers "public unsafe"
* (the visibility of the method is up to you).
*
* Example usage:
*
* %include "arrays_csharp.i"
* %apply int FIXED[] { int* sourceArray, int *targetArray }
* %csmethodmodifiers myArrayCopy "public unsafe";
* void myArrayCopy( int *sourceArray, int* targetArray, int nitems );
*
* ----------------------------------------------------------------------------- */
%define CSHARP_ARRAYS( CTYPE, CSTYPE )
// input only arrays
%typemap(ctype) CTYPE INPUT[] "CTYPE*"
%typemap(cstype) CTYPE INPUT[] "CSTYPE[]"
%typemap(imtype, inattributes="[In, MarshalAs(UnmanagedType.LPArray)]") CTYPE INPUT[] "CSTYPE[]"
%typemap(csin) CTYPE INPUT[] "$csinput"
%typemap(in) CTYPE INPUT[] "$1 = $input;"
%typemap(freearg) CTYPE INPUT[] ""
%typemap(argout) CTYPE INPUT[] ""
// output only arrays
%typemap(ctype) CTYPE OUTPUT[] "CTYPE*"
%typemap(cstype) CTYPE OUTPUT[] "CSTYPE[]"
%typemap(imtype, inattributes="[Out, MarshalAs(UnmanagedType.LPArray)]") CTYPE OUTPUT[] "CSTYPE[]"
%typemap(csin) CTYPE OUTPUT[] "$csinput"
%typemap(in) CTYPE OUTPUT[] "$1 = $input;"
%typemap(freearg) CTYPE OUTPUT[] ""
%typemap(argout) CTYPE OUTPUT[] ""
// inout arrays
%typemap(ctype) CTYPE INOUT[] "CTYPE*"
%typemap(cstype) CTYPE INOUT[] "CSTYPE[]"
%typemap(imtype, inattributes="[In, Out, MarshalAs(UnmanagedType.LPArray)]") CTYPE INOUT[] "CSTYPE[]"
%typemap(csin) CTYPE INOUT[] "$csinput"
%typemap(in) CTYPE INOUT[] "$1 = $input;"
%typemap(freearg) CTYPE INOUT[] ""
%typemap(argout) CTYPE INOUT[] ""
%enddef // CSHARP_ARRAYS
CSHARP_ARRAYS(signed char, sbyte)
CSHARP_ARRAYS(unsigned char, byte)
CSHARP_ARRAYS(short, short)
CSHARP_ARRAYS(unsigned short, ushort)
CSHARP_ARRAYS(int, int)
CSHARP_ARRAYS(unsigned int, uint)
// FIXME - on Unix 64 bit, long is 8 bytes but is 4 bytes on Windows 64 bit.
// How can this be handled sensibly?
// See e.g. http://www.xml.com/ldd/chapter/book/ch10.html
CSHARP_ARRAYS(long, int)
CSHARP_ARRAYS(unsigned long, uint)
CSHARP_ARRAYS(long long, long)
CSHARP_ARRAYS(unsigned long long, ulong)
CSHARP_ARRAYS(float, float)
CSHARP_ARRAYS(double, double)
%define CSHARP_ARRAYS_FIXED( CTYPE, CSTYPE )
%typemap(ctype) CTYPE FIXED[] "CTYPE*"
%typemap(imtype) CTYPE FIXED[] "IntPtr"
%typemap(cstype) CTYPE FIXED[] "CSTYPE[]"
%typemap(csin,
pre= " fixed ( CSTYPE* swig_ptrTo_$csinput = $csinput ) {",
terminator=" }")
CTYPE FIXED[] "(IntPtr)swig_ptrTo_$csinput"
%typemap(in) CTYPE FIXED[] "$1 = $input;"
%typemap(freearg) CTYPE FIXED[] ""
%typemap(argout) CTYPE FIXED[] ""
%enddef // CSHARP_ARRAYS_FIXED
CSHARP_ARRAYS_FIXED(signed char, sbyte)
CSHARP_ARRAYS_FIXED(unsigned char, byte)
CSHARP_ARRAYS_FIXED(short, short)
CSHARP_ARRAYS_FIXED(unsigned short, ushort)
CSHARP_ARRAYS_FIXED(int, int)
CSHARP_ARRAYS_FIXED(unsigned int, uint)
CSHARP_ARRAYS_FIXED(long, int)
CSHARP_ARRAYS_FIXED(unsigned long, uint)
CSHARP_ARRAYS_FIXED(long long, long)
CSHARP_ARRAYS_FIXED(unsigned long long, ulong)
CSHARP_ARRAYS_FIXED(float, float)
CSHARP_ARRAYS_FIXED(double, double)

View file

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

View file

@ -1,7 +1,15 @@
// Users can provide their own SWIG_SHARED_PTR_TYPEMAPS macro before including this file to change the
// visibility of the constructor and getCPtr method if desired to public if using multiple modules.
#ifndef SWIG_SHARED_PTR_TYPEMAPS
#define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...) SWIG_SHARED_PTR_TYPEMAPS_IMPLEMENTATION(internal, internal, CONST, TYPE)
#endif
%include <shared_ptr.i>
%define SWIG_SHARED_PTR_TYPEMAPS(PROXYCLASS, CONST, TYPE...)
// Language specific macro implementing all the customisations for handling the smart pointer
%define SWIG_SHARED_PTR_TYPEMAPS_IMPLEMENTATION(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, CONST, TYPE...)
// %naturalvar is as documented for member variables
%naturalvar TYPE;
%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
@ -10,6 +18,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) %{
@ -33,7 +42,7 @@
// plain reference
%typemap(in, canthrow=1) CONST TYPE & %{
$1 = ($1_ltype)(((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input) ? ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input)->get() : 0);
if(!$1) {
if (!$1) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type reference is null", 0);
return $null;
} %}
@ -41,10 +50,10 @@
%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); %}
// plain pointer by reference
%typemap(in) CONST TYPE *& ($*1_ltype temp = 0)
%{ temp = (((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input) ? ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input)->get() : 0);
%typemap(in) TYPE *CONST& ($*1_ltype temp = 0)
%{ temp = (TYPE *)(((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input) ? ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input)->get() : 0);
$1 = &temp; %}
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE *&
%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST&
%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %}
// shared_ptr by value
@ -93,51 +102,51 @@
%typemap (cstype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "PROXYCLASS"
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "$typemap(cstype, TYPE)"
%typemap(csin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "PROXYCLASS.getCPtr($csinput)"
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "$typemap(cstype, TYPE).getCPtr($csinput)"
%typemap(csout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
IntPtr cPtr = $imcall;
PROXYCLASS ret = (cPtr == IntPtr.Zero) ? null : new PROXYCLASS(cPtr, true);$excode
$typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(csout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & {
IntPtr cPtr = $imcall;
PROXYCLASS ret = (cPtr == IntPtr.Zero) ? null : new PROXYCLASS(cPtr, true);$excode
$typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(csout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * {
IntPtr cPtr = $imcall;
PROXYCLASS ret = (cPtr == IntPtr.Zero) ? null : new PROXYCLASS(cPtr, true);$excode
$typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(csout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& {
IntPtr cPtr = $imcall;
PROXYCLASS ret = (cPtr == IntPtr.Zero) ? null : new PROXYCLASS(cPtr, true);$excode
$typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(csout, excode=SWIGEXCODE) CONST TYPE {
PROXYCLASS ret = new PROXYCLASS($imcall, true);$excode
$typemap(cstype, TYPE) ret = new $typemap(cstype, TYPE)($imcall, true);$excode
return ret;
}
%typemap(csout, excode=SWIGEXCODE) CONST TYPE & {
PROXYCLASS ret = new PROXYCLASS($imcall, true);$excode
$typemap(cstype, TYPE) ret = new $typemap(cstype, TYPE)($imcall, true);$excode
return ret;
}
%typemap(csout, excode=SWIGEXCODE) CONST TYPE * {
IntPtr cPtr = $imcall;
PROXYCLASS ret = (cPtr == IntPtr.Zero) ? null : new PROXYCLASS(cPtr, true);$excode
$typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(csout, excode=SWIGEXCODE) CONST TYPE *& {
%typemap(csout, excode=SWIGEXCODE) TYPE *CONST& {
IntPtr cPtr = $imcall;
PROXYCLASS ret = (cPtr == IntPtr.Zero) ? null : new PROXYCLASS(cPtr, true);$excode
$typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
return ret;
}
@ -156,13 +165,13 @@
%typemap(csvarout, excode=SWIGEXCODE2) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{
get {
IntPtr cPtr = $imcall;
PROXYCLASS ret = (cPtr == IntPtr.Zero) ? null : new PROXYCLASS(cPtr, true);$excode
$typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
return ret;
} %}
%typemap(csvarout, excode=SWIGEXCODE2) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{
get {
IntPtr cPtr = $imcall;
PROXYCLASS ret = (cPtr == IntPtr.Zero) ? null : new PROXYCLASS(cPtr, true);$excode
$typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
return ret;
} %}
@ -172,12 +181,12 @@
private HandleRef swigCPtr;
private bool swigCMemOwnBase;
internal $csclassname(IntPtr cPtr, bool cMemoryOwn) {
PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) {
swigCMemOwnBase = cMemoryOwn;
swigCPtr = new HandleRef(this, cPtr);
}
internal static HandleRef getCPtr($csclassname obj) {
CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
%}
@ -187,43 +196,43 @@
private HandleRef swigCPtr;
private bool swigCMemOwnDerived;
internal $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclassname_SWIGSharedPtrUpcast(cPtr), true) {
PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclazznameSWIGSmartPtrUpcast(cPtr), true) {
swigCMemOwnDerived = cMemoryOwn;
swigCPtr = new HandleRef(this, cPtr);
}
internal static HandleRef getCPtr($csclassname obj) {
CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
%}
%typemap(csdestruct, methodname="Dispose", methodmodifiers="public") TYPE {
lock(this) {
if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwnBase) {
swigCMemOwnBase = false;
$imcall;
if (swigCPtr.Handle != IntPtr.Zero) {
if (swigCMemOwnBase) {
swigCMemOwnBase = false;
$imcall;
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
GC.SuppressFinalize(this);
}
}
%typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") TYPE {
lock(this) {
if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwnDerived) {
swigCMemOwnDerived = false;
$imcall;
if (swigCPtr.Handle != IntPtr.Zero) {
if (swigCMemOwnDerived) {
swigCMemOwnDerived = false;
$imcall;
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
GC.SuppressFinalize(this);
base.Dispose();
}
}
%typemap(imtype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast "IntPtr"
%typemap(csin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast "PROXYCLASS.getCPtr($csinput).Handle"
%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
%enddef

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* csharp.swg
*
* C# typemaps
@ -300,19 +297,19 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
temp = ($*1_ltype)$input;
$result = &temp; %}
%typemap(directorin) const bool & "$input = $1_name;"
%typemap(directorin) const char & "$input = $1_name;"
%typemap(directorin) const signed char & "$input = $1_name;"
%typemap(directorin) const unsigned char & "$input = $1_name;"
%typemap(directorin) const short & "$input = $1_name;"
%typemap(directorin) const unsigned short & "$input = $1_name;"
%typemap(directorin) const int & "$input = $1_name;"
%typemap(directorin) const unsigned int & "$input = $1_name;"
%typemap(directorin) const long & "$input = $1_name;"
%typemap(directorin) const unsigned long & "$input = $1_name;"
%typemap(directorin) const long long & "$input = $1_name;"
%typemap(directorin) const float & "$input = $1_name;"
%typemap(directorin) const double & "$input = $1_name;"
%typemap(directorin) const bool & "$input = $1;"
%typemap(directorin) const char & "$input = $1;"
%typemap(directorin) const signed char & "$input = $1;"
%typemap(directorin) const unsigned char & "$input = $1;"
%typemap(directorin) const short & "$input = $1;"
%typemap(directorin) const unsigned short & "$input = $1;"
%typemap(directorin) const int & "$input = $1;"
%typemap(directorin) const unsigned int & "$input = $1;"
%typemap(directorin) const long & "$input = $1;"
%typemap(directorin) const unsigned long & "$input = $1;"
%typemap(directorin) const long long & "$input = $1;"
%typemap(directorin) const float & "$input = $1;"
%typemap(directorin) const double & "$input = $1;"
%typemap(csdirectorin) const char & ($*1_ltype temp),
const signed char & ($*1_ltype temp),
@ -396,7 +393,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
SWIG_UnpackData($input, (void *)&$1, sizeof($1));
%}
%typemap(in, canthrow=1) SWIGTYPE & %{ $1 = ($1_ltype)$input;
if(!$1) {
if (!$1) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type type is null", 0);
return $null;
} %}
@ -428,7 +425,8 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%typemap(directorin) SWIGTYPE &
%{ $input = ($1_ltype) &$1; %}
%typemap(csdirectorin) SWIGTYPE *, SWIGTYPE (CLASS::*), SWIGTYPE & "new $csclassname($iminput, false)"
%typemap(csdirectorin) SWIGTYPE *, SWIGTYPE (CLASS::*) "($iminput == IntPtr.Zero) ? null : new $csclassname($iminput, false)"
%typemap(csdirectorin) SWIGTYPE & "new $csclassname($iminput, false)"
%typemap(csdirectorout) SWIGTYPE *, SWIGTYPE (CLASS::*), SWIGTYPE & "$csclassname.getCPtr($cscall).Handle"
/* Default array handling */
@ -524,6 +522,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
SWIGTYPE,
SWIGTYPE *,
SWIGTYPE &,
SWIGTYPE *const&,
SWIGTYPE [],
SWIGTYPE (CLASS::*)
""
@ -784,23 +783,33 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
} %}
/* Pointer reference typemaps */
%typemap(ctype) SWIGTYPE *& "void *"
%typemap(imtype, out="IntPtr") SWIGTYPE *& "HandleRef"
%typemap(cstype) SWIGTYPE *& "$*csclassname"
%typemap(csin) SWIGTYPE *& "$*csclassname.getCPtr($csinput)"
%typemap(csout, excode=SWIGEXCODE) SWIGTYPE *& {
%typemap(ctype) SWIGTYPE *const& "void *"
%typemap(imtype, out="IntPtr") SWIGTYPE *const& "HandleRef"
%typemap(cstype) SWIGTYPE *const& "$*csclassname"
%typemap(csin) SWIGTYPE *const& "$*csclassname.getCPtr($csinput)"
%typemap(csout, excode=SWIGEXCODE) SWIGTYPE *const& {
IntPtr cPtr = $imcall;
$*csclassname ret = (cPtr == IntPtr.Zero) ? null : new $*csclassname(cPtr, $owner);$excode
return ret;
}
%typemap(in) SWIGTYPE *& ($*1_ltype temp = 0)
%typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0)
%{ temp = ($*1_ltype)$input;
$1 = &temp; %}
%typemap(out) SWIGTYPE *&
$1 = ($1_ltype)&temp; %}
%typemap(out) SWIGTYPE *const&
%{ $result = (void *)*$1; %}
/* Array reference typemaps */
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
/* Marshal C/C++ pointer to IntPtr */
%typemap(ctype) void *VOID_INT_PTR "void *"
%typemap(imtype) void *VOID_INT_PTR "IntPtr"
%typemap(cstype) void *VOID_INT_PTR "IntPtr"
%typemap(in) void *VOID_INT_PTR %{ $1 = ($1_ltype)$input; %}
%typemap(out) void *VOID_INT_PTR %{ $result = (void *)$1; %}
%typemap(csin) void *VOID_INT_PTR "$csinput"
%typemap(csout, excode=SWIGEXCODE) void *VOID_INT_PTR {
IntPtr ret = $imcall;$excode
return ret;
}
/* Typemaps used for the generation of proxy and type wrapper class code */
%typemap(csbase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
@ -811,66 +820,78 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%typemap(csinterfaces) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
%typemap(csinterfaces_derived) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
// csbody typemaps... these are in macros so that the visibility of the methods can be easily changed by users.
%define SWIG_CSBODY_PROXY(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE...)
// Proxy classes (base classes, ie, not derived classes)
%typemap(csbody) SWIGTYPE %{
%typemap(csbody) TYPE %{
private HandleRef swigCPtr;
protected bool swigCMemOwn;
internal $csclassname(IntPtr cPtr, bool cMemoryOwn) {
PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = new HandleRef(this, cPtr);
}
internal static HandleRef getCPtr($csclassname obj) {
CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
%}
// Derived proxy classes
%typemap(csbody_derived) SWIGTYPE %{
%typemap(csbody_derived) TYPE %{
private HandleRef swigCPtr;
internal $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclassnameUpcast(cPtr), cMemoryOwn) {
PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclazznameSWIGUpcast(cPtr), cMemoryOwn) {
swigCPtr = new HandleRef(this, cPtr);
}
internal static HandleRef getCPtr($csclassname obj) {
CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
%}
%enddef
%define SWIG_CSBODY_TYPEWRAPPER(PTRCTOR_VISIBILITY, DEFAULTCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE...)
// Typewrapper classes
%typemap(csbody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] %{
%typemap(csbody) TYPE *, TYPE &, TYPE [] %{
private HandleRef swigCPtr;
internal $csclassname(IntPtr cPtr, bool futureUse) {
PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool futureUse) {
swigCPtr = new HandleRef(this, cPtr);
}
protected $csclassname() {
DEFAULTCTOR_VISIBILITY $csclassname() {
swigCPtr = new HandleRef(null, IntPtr.Zero);
}
internal static HandleRef getCPtr($csclassname obj) {
CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
%}
%typemap(csbody) SWIGTYPE (CLASS::*) %{
%typemap(csbody) TYPE (CLASS::*) %{
private string swigCMemberPtr;
internal $csclassname(string cMemberPtr, bool futureUse) {
PTRCTOR_VISIBILITY $csclassname(string cMemberPtr, bool futureUse) {
swigCMemberPtr = cMemberPtr;
}
protected $csclassname() {
DEFAULTCTOR_VISIBILITY $csclassname() {
swigCMemberPtr = null;
}
internal static string getCMemberPtr($csclassname obj) {
CPTR_VISIBILITY static string getCMemberPtr($csclassname obj) {
return obj.swigCMemberPtr;
}
%}
%enddef
/* Set the default csbody typemaps to use internal visibility.
Use the macros to change to public if using multiple modules. */
SWIG_CSBODY_PROXY(internal, internal, SWIGTYPE)
SWIG_CSBODY_TYPEWRAPPER(internal, protected, internal, SWIGTYPE)
%typemap(csfinalize) SWIGTYPE %{
~$csclassname() {
@ -884,22 +905,26 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%typemap(csdestruct, methodname="Dispose", methodmodifiers="public") SWIGTYPE {
lock(this) {
if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
swigCMemOwn = false;
$imcall;
if (swigCPtr.Handle != IntPtr.Zero) {
if (swigCMemOwn) {
swigCMemOwn = false;
$imcall;
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
GC.SuppressFinalize(this);
}
}
%typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") SWIGTYPE {
lock(this) {
if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
swigCMemOwn = false;
$imcall;
if (swigCPtr.Handle != IntPtr.Zero) {
if (swigCMemOwn) {
swigCMemOwn = false;
$imcall;
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
GC.SuppressFinalize(this);
base.Dispose();
}
@ -938,12 +963,21 @@ using System.Runtime.InteropServices;
%apply unsigned long { size_t };
%apply const unsigned long & { const size_t & };
/* Array reference typemaps */
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
/* csharp keywords */
%include <csharpkw.swg>
// Default enum handling
%include <enums.swg>
// For vararg handling in macros, from swigmacros.swg
#define %arg(X...) X
/*
// Alternative char * typemaps.
%pragma(csharp) imclasscode=%{

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* csharphead.swg
*
* Support code for exceptions if the SWIG_CSHARP_NO_EXCEPTION_HELPER is not defined
@ -68,12 +65,12 @@ static SWIG_CSharpException_t SWIG_csharp_exceptions[] = {
static SWIG_CSharpExceptionArgument_t SWIG_csharp_exceptions_argument[] = {
{ SWIG_CSharpArgumentException, NULL },
{ SWIG_CSharpArgumentNullException, NULL },
{ SWIG_CSharpArgumentOutOfRangeException, NULL },
{ SWIG_CSharpArgumentOutOfRangeException, NULL }
};
static void SWIGUNUSED SWIG_CSharpSetPendingException(SWIG_CSharpExceptionCodes code, const char *msg) {
SWIG_CSharpExceptionCallback_t callback = SWIG_csharp_exceptions[SWIG_CSharpApplicationException].callback;
if (code >=0 && (size_t)code < sizeof(SWIG_csharp_exceptions)/sizeof(SWIG_CSharpException_t)) {
if ((size_t)code < sizeof(SWIG_csharp_exceptions)/sizeof(SWIG_CSharpException_t)) {
callback = SWIG_csharp_exceptions[code].callback;
}
callback(msg);
@ -81,7 +78,7 @@ static void SWIGUNUSED SWIG_CSharpSetPendingException(SWIG_CSharpExceptionCodes
static void SWIGUNUSED SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpExceptionArgumentCodes code, const char *msg, const char *param_name) {
SWIG_CSharpExceptionArgumentCallback_t callback = SWIG_csharp_exceptions_argument[SWIG_CSharpArgumentException].callback;
if (code >=0 && (size_t)code < sizeof(SWIG_csharp_exceptions_argument)/sizeof(SWIG_CSharpExceptionArgument_t)) {
if ((size_t)code < sizeof(SWIG_csharp_exceptions_argument)/sizeof(SWIG_CSharpExceptionArgument_t)) {
callback = SWIG_csharp_exceptions_argument[code].callback;
}
callback(msg, param_name);
@ -322,6 +319,14 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterStringCallback_$module(SWIG_CSharpString
%}
#endif // SWIG_CSHARP_NO_STRING_HELPER
#if !defined(SWIG_CSHARP_NO_IMCLASS_STATIC_CONSTRUCTOR)
// Ensure the class is not marked beforefieldinit
%pragma(csharp) imclasscode=%{
static $imclassname() {
}
%}
#endif
%insert(runtime) %{
/* Contract support */

View file

@ -2,7 +2,7 @@
#define CSHARP_CSHARPKW_SWG_
/* Warnings for C# keywords */
#define CSHARPKW(x) %namewarn("314:" #x " is a csharp keyword") #x
#define CSHARPKW(x) %keywordwarn("'" `x` "' is a C# keyword, renaming to '_" `x` "'",rename="_%s") `x`
/*
from

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* director.swg
*
* This file contains support for director classes so that C# proxy

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* enums.swg
*
* Include this file in order for C/C++ enums to be wrapped by proper C# enums.
@ -21,7 +18,7 @@
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE &
%{ static $*1_ltype temp = ($*1_ltype)$input;
$result = &temp; %}
%typemap(directorin) const enum SWIGTYPE & "$input = $1_name;"
%typemap(directorin) const enum SWIGTYPE & "$input = $1;"
%typemap(csdirectorin) const enum SWIGTYPE & "($*csclassname)$iminput"
%typemap(csdirectorout) const enum SWIGTYPE & "(int)$cscall"
@ -54,7 +51,7 @@
%typemap(out) enum SWIGTYPE %{ $result = $1; %}
%typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %}
%typemap(directorin) enum SWIGTYPE "$input = $1;"
%typemap(directorin) enum SWIGTYPE "$input = $1;"
%typemap(csdirectorin) enum SWIGTYPE "($csclassname)$iminput"
%typemap(csdirectorout) enum SWIGTYPE "(int)$cscall"

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* enumsimple.swg
*
* This file provides backwards compatible enum wrapping. SWIG versions 1.3.21
@ -23,7 +20,7 @@
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE &
%{ static $*1_ltype temp = ($*1_ltype)$input;
$result = &temp; %}
%typemap(directorin) const enum SWIGTYPE & "$input = $1_name;"
%typemap(directorin) const enum SWIGTYPE & "$input = $1;"
%typemap(csdirectorin) const enum SWIGTYPE & "$iminput"
%typemap(csdirectorout) const enum SWIGTYPE & "$cscall"
@ -56,7 +53,7 @@
%typemap(out) enum SWIGTYPE %{ $result = $1; %}
%typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %}
%typemap(directorin) enum SWIGTYPE "$input = $1;"
%typemap(directorin) enum SWIGTYPE "$input = $1;"
%typemap(csdirectorin) enum SWIGTYPE "$iminput"
%typemap(csdirectorout) enum SWIGTYPE "$cscall"

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* enumtypesafe.swg
*
* Include this file in order for C/C++ enums to be wrapped by the so called
@ -22,7 +19,7 @@
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE &
%{ static $*1_ltype temp = ($*1_ltype)$input;
$result = &temp; %}
%typemap(directorin) const enum SWIGTYPE & "$input = $1_name;"
%typemap(directorin) const enum SWIGTYPE & "$input = $1;"
%typemap(csdirectorin) const enum SWIGTYPE & "$*csclassname.swigToEnum($iminput)"
%typemap(csdirectorout) const enum SWIGTYPE & "$cscall.swigValue"
@ -55,7 +52,7 @@
%typemap(out) enum SWIGTYPE %{ $result = $1; %}
%typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %}
%typemap(directorin) enum SWIGTYPE "$input = $1;"
%typemap(directorin) enum SWIGTYPE "$input = $1;"
%typemap(csdirectorin) enum SWIGTYPE "$csclassname.swigToEnum($iminput)"
%typemap(csdirectorout) enum SWIGTYPE "$cscall.swigValue"

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* std_except.i
*
* Typemaps used by the STL wrappers that throw exceptions. These typemaps are

View file

@ -1,175 +1,311 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* std_map.i
*
* SWIG typemaps for std::map
* SWIG typemaps for std::map< K, T >
*
* The C# wrapper is made to look and feel like a C# System.Collections.Generic.IDictionary<>.
*
* Using this wrapper is fairly simple. For example, to create a map from integers to doubles use:
*
* %include <std_map.i>
* %template(MapIntDouble) std::map<int, double>
*
* Notes:
* 1) For .NET 1 compatibility, define SWIG_DOTNET_1 when compiling the C# code. In this case
* the C# wrapper has only basic functionality.
* 2) IEnumerable<> is implemented in the proxy class which is useful for using LINQ with
* C++ std::map wrappers.
*
* Warning: heavy macro usage in this file. Use swig -E to get a sane view on the real file contents!
* ----------------------------------------------------------------------------- */
%include <std_common.i>
// ------------------------------------------------------------------------
// std::map
// ------------------------------------------------------------------------
%{
#include <map>
#include <algorithm>
#include <stdexcept>
%}
// exported class
/* K is the C++ key type, T is the C++ value type */
%define SWIG_STD_MAP_INTERNAL(K, T)
namespace std {
%typemap(csinterfaces) std::map< K, T > "IDisposable \n#if !SWIG_DOTNET_1\n , System.Collections.Generic.IDictionary<$typemap(cstype, K), $typemap(cstype, T)>\n#endif\n";
%typemap(cscode) std::map<K, T > %{
template<class K, class T> class map {
// add typemaps here
public:
map();
map(const map<K,T> &);
unsigned int size() const;
bool empty() const;
void clear();
%extend {
T& get(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void set(const K& key, const T& x) {
(*self)[key] = x;
}
void del(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
else
throw std::out_of_range("key not found");
}
bool has_key(const K& key) {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
}
public $typemap(cstype, T) this[$typemap(cstype, K) key] {
get {
return getitem(key);
}
set {
setitem(key, value);
}
}
public bool TryGetValue($typemap(cstype, K) key, out $typemap(cstype, T) value) {
if (this.ContainsKey(key)) {
value = this[key];
return true;
}
value = default($typemap(cstype, T));
return false;
}
public int Count {
get {
return (int)size();
}
}
public bool IsReadOnly {
get {
return false;
}
}
#if !SWIG_DOTNET_1
public System.Collections.Generic.ICollection<$typemap(cstype, K)> Keys {
get {
System.Collections.Generic.ICollection<$typemap(cstype, K)> keys = new System.Collections.Generic.List<$typemap(cstype, K)>();
int size = this.Count;
if (size > 0) {
IntPtr iter = create_iterator_begin();
for (int i = 0; i < size; i++) {
keys.Add(get_next_key(iter));
}
};
destroy_iterator(iter);
}
return keys;
}
}
public System.Collections.Generic.ICollection<$typemap(cstype, T)> Values {
get {
System.Collections.Generic.ICollection<$typemap(cstype, T)> vals = new System.Collections.Generic.List<$typemap(cstype, T)>();
foreach (System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> pair in this) {
vals.Add(pair.Value);
}
return vals;
}
}
public void Add(System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> item) {
Add(item.Key, item.Value);
}
public bool Remove(System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> item) {
if (Contains(item)) {
return Remove(item.Key);
} else {
return false;
}
}
public bool Contains(System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> item) {
if (this[item.Key] == item.Value) {
return true;
} else {
return false;
}
}
public void CopyTo(System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>[] array) {
CopyTo(array, 0);
}
public void CopyTo(System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>[] array, int arrayIndex) {
if (array == null)
throw new ArgumentNullException("array");
if (arrayIndex < 0)
throw new ArgumentOutOfRangeException("arrayIndex", "Value is less than zero");
if (array.Rank > 1)
throw new ArgumentException("Multi dimensional array.", "array");
if (arrayIndex+this.Count > array.Length)
throw new ArgumentException("Number of elements to copy is too large.");
System.Collections.Generic.IList<$typemap(cstype, K)> keyList = new System.Collections.Generic.List<$typemap(cstype, K)>(this.Keys);
for (int i = 0; i < keyList.Count; i++) {
$typemap(cstype, K) currentKey = keyList[i];
array.SetValue(new System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>(currentKey, this[currentKey]), arrayIndex+i);
}
}
System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>>.GetEnumerator() {
return new $csclassnameEnumerator(this);
}
System.Collections.IEnumerator 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 : System.Collections.IEnumerator,
System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>>
{
private $csclassname collectionRef;
private System.Collections.Generic.IList<$typemap(cstype, K)> keyCollection;
private int currentIndex;
private object currentObject;
private int currentSize;
public $csclassnameEnumerator($csclassname collection) {
collectionRef = collection;
keyCollection = new System.Collections.Generic.List<$typemap(cstype, K)>(collection.Keys);
currentIndex = -1;
currentObject = null;
currentSize = collectionRef.Count;
}
// Type-safe iterator Current
public System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> Current {
get {
if (currentIndex == -1)
throw new InvalidOperationException("Enumeration not started.");
if (currentIndex > currentSize - 1)
throw new InvalidOperationException("Enumeration finished.");
if (currentObject == null)
throw new InvalidOperationException("Collection modified.");
return (System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>)currentObject;
}
}
// Type-unsafe IEnumerator.Current
object System.Collections.IEnumerator.Current {
get {
return Current;
}
}
public bool MoveNext() {
int size = collectionRef.Count;
bool moveOkay = (currentIndex+1 < size) && (size == currentSize);
if (moveOkay) {
currentIndex++;
$typemap(cstype, K) currentKey = keyCollection[currentIndex];
currentObject = new System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>(currentKey, collectionRef[currentKey]);
} else {
currentObject = null;
}
return moveOkay;
}
public void Reset() {
currentIndex = -1;
currentObject = null;
if (collectionRef.Count != currentSize) {
throw new InvalidOperationException("Collection modified.");
}
}
public void Dispose() {
currentIndex = -1;
currentObject = null;
}
}
#endif
%}
public:
map();
map(const map< K, T > &other);
typedef K key_type;
typedef T mapped_type;
typedef size_t size_type;
size_type size() const;
bool empty() const;
%rename(Clear) clear;
void clear();
%extend {
const mapped_type& getitem(const key_type& key) throw (std::out_of_range) {
std::map< K,T >::iterator iter = $self->find(key);
if (iter != $self->end())
return iter->second;
else
throw std::out_of_range("key not found");
}
void setitem(const key_type& key, const mapped_type& x) {
(*$self)[key] = x;
}
bool ContainsKey(const key_type& key) {
std::map< K, T >::iterator iter = $self->find(key);
return iter != $self->end();
}
void Add(const key_type& key, const mapped_type& val) throw (std::out_of_range) {
std::map< K, T >::iterator iter = $self->find(key);
if (iter != $self->end())
throw std::out_of_range("key already exists");
$self->insert(std::pair< K, T >(key, val));
}
bool Remove(const key_type& key) {
std::map< K, T >::iterator iter = $self->find(key);
if (iter != $self->end()) {
$self->erase(iter);
return true;
}
return false;
}
// create_iterator_begin(), get_next_key() and destroy_iterator work together to provide a collection of keys to C#
%apply void *VOID_INT_PTR { std::map< K, T >::iterator *create_iterator_begin }
%apply void *VOID_INT_PTR { std::map< K, T >::iterator *swigiterator }
std::map< K, T >::iterator *create_iterator_begin() {
return new std::map< K, T >::iterator($self->begin());
}
const key_type& get_next_key(std::map< K, T >::iterator *swigiterator) {
std::map< K, T >::iterator iter = *swigiterator;
(*swigiterator)++;
return (*iter).first;
}
void destroy_iterator(std::map< K, T >::iterator *swigiterator) {
delete swigiterator;
}
}
// specializations for built-ins
%enddef
%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
template<class T> class map<K,T> {
// add typemaps here
public:
map();
map(const map<K,T> &);
unsigned int size() const;
bool empty() const;
void clear();
%extend {
T& get(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void set(K key, const T& x) {
(*self)[key] = x;
}
void del(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
else
throw std::out_of_range("key not found");
}
bool has_key(K key) {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
}
}
};
%enddef
%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
template<class K> class map<K,T> {
// add typemaps here
public:
map();
map(const map<K,T> &);
unsigned int size() const;
bool empty() const;
void clear();
%extend {
T get(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void set(const K& key, T x) {
(*self)[key] = x;
}
void del(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
else
throw std::out_of_range("key not found");
}
bool has_key(const K& key) {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
}
}
};
%enddef
%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> {
// add typemaps here
public:
map();
map(const map<K,T> &);
unsigned int size() const;
bool empty() const;
void clear();
%extend {
T get(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void set(K key, T x) {
(*self)[key] = x;
}
void del(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
else
throw std::out_of_range("key not found");
}
bool has_key(K key) {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
}
}
};
%enddef
// add specializations here
%csmethodmodifiers std::map::size "private"
%csmethodmodifiers std::map::getitem "private"
%csmethodmodifiers std::map::setitem "private"
%csmethodmodifiers std::map::create_iterator_begin "private"
%csmethodmodifiers std::map::get_next_key "private"
%csmethodmodifiers std::map::destroy_iterator "private"
// Default implementation
namespace std {
template<class K, class T> class map {
SWIG_STD_MAP_INTERNAL(K, T)
};
}
// Legacy macros (deprecated)
%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
#warning "specialize_std_map_on_key ignored - macro is deprecated and no longer necessary"
%enddef
%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
#warning "specialize_std_map_on_value ignored - macro is deprecated and no longer necessary"
%enddef
%define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO)
#warning "specialize_std_map_on_both ignored - macro is deprecated and no longer necessary"
%enddef

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* std_pair.i
*
* SWIG typemaps for std::pair

View file

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

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* std_string.i
*
* Typemaps for std::string and const std::string&

255
Lib/csharp/std_vector.i Executable file → Normal file
View file

@ -1,20 +1,22 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* std_vector.i
*
* SWIG typemaps for std::vector
* SWIG typemaps for std::vector<T>
* C# implementation
* The C# wrapper is made to look and feel like a typesafe C# System.Collections.ArrayList
* All the methods in IList are defined, but we don't derive from IList as this is a typesafe collection.
* Warning: heavy macro usage in this file. Use swig -E to get a sane view on the real file contents!
* The C# wrapper is made to look and feel like a C# System.Collections.Generic.List<> collection.
* For .NET 1 compatibility, define SWIG_DOTNET_1 when compiling the C# code; then the C# wrapper is
* made to look and feel like a typesafe C# System.Collections.ArrayList.
*
* Very often the C# generated code will not compile as the C++ template type is not the same as the C#
* proxy type, so use the SWIG_STD_VECTOR_SPECIALIZE or SWIG_STD_VECTOR_SPECIALIZE_MINIMUM macro, eg
* Note that IEnumerable<> is implemented in the proxy class which is useful for using LINQ with
* C++ std::vector wrappers. The IList<> interface is also implemented to provide enhanced functionality
* whenever we are confident that the required C++ operator== is available. This is the case for when
* T is a primitive type or a pointer. If T does define an operator==, then use the SWIG_STD_VECTOR_ENHANCED
* macro to obtain this enhanced functionality, for example:
*
* SWIG_STD_VECTOR_SPECIALIZE_MINIMUM(Klass, SomeNamespace::Klass)
* 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.
@ -23,14 +25,13 @@
%include <std_common.i>
// MACRO for use within the std::vector class body
// CSTYPE and CTYPE respectively correspond to the types in the cstype and ctype typemaps
%define SWIG_STD_VECTOR_MINIMUM(CSTYPE, CTYPE...)
%typemap(csinterfaces) std::vector<CTYPE > "IDisposable, System.Collections.IEnumerable";
%typemap(cscode) std::vector<CTYPE > %{
%define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CSINTERFACE, CONST_REFERENCE, CTYPE...)
%typemap(csinterfaces) std::vector< CTYPE > "IDisposable, System.Collections.IEnumerable\n#if !SWIG_DOTNET_1\n , System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n#endif\n";
%typemap(cscode) std::vector< CTYPE > %{
public $csclassname(System.Collections.ICollection c) : this() {
if (c == null)
throw new ArgumentNullException("c");
foreach (CSTYPE element in c) {
foreach ($typemap(cstype, CTYPE) element in c) {
this.Add(element);
}
}
@ -47,7 +48,7 @@
}
}
public CSTYPE this[int index] {
public $typemap(cstype, CTYPE) this[int index] {
get {
return getitem(index);
}
@ -79,15 +80,30 @@
}
}
public void CopyTo(System.Array array) {
#if SWIG_DOTNET_1
public void CopyTo(System.Array array)
#else
public void CopyTo($typemap(cstype, CTYPE)[] array)
#endif
{
CopyTo(0, array, 0, this.Count);
}
public void CopyTo(System.Array array, int arrayIndex) {
#if SWIG_DOTNET_1
public void CopyTo(System.Array array, int arrayIndex)
#else
public void CopyTo($typemap(cstype, CTYPE)[] array, int arrayIndex)
#endif
{
CopyTo(0, array, arrayIndex, this.Count);
}
public void CopyTo(int index, System.Array array, int arrayIndex, int count) {
#if SWIG_DOTNET_1
public void CopyTo(int index, System.Array array, int arrayIndex, int count)
#else
public void CopyTo(int index, $typemap(cstype, CTYPE)[] array, int arrayIndex, int count)
#endif
{
if (array == null)
throw new ArgumentNullException("array");
if (index < 0)
@ -97,14 +113,19 @@
if (count < 0)
throw new ArgumentOutOfRangeException("count", "Value is less than zero");
if (array.Rank > 1)
throw new ArgumentException("Multi dimensional array.");
throw new ArgumentException("Multi dimensional array.", "array");
if (index+count > this.Count || arrayIndex+count > array.Length)
throw new ArgumentException("Number of elements to copy is too large.");
for (int i=0; i<count; i++)
array.SetValue(getitemcopy(index+i), arrayIndex+i);
}
// Type-safe version of IEnumerable.GetEnumerator
#if !SWIG_DOTNET_1
System.Collections.Generic.IEnumerator<$typemap(cstype, CTYPE)> System.Collections.Generic.IEnumerable<$typemap(cstype, CTYPE)>.GetEnumerator() {
return new $csclassnameEnumerator(this);
}
#endif
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
return new $csclassnameEnumerator(this);
}
@ -118,7 +139,11 @@
/// 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 : System.Collections.IEnumerator {
public sealed class $csclassnameEnumerator : System.Collections.IEnumerator
#if !SWIG_DOTNET_1
, System.Collections.Generic.IEnumerator<$typemap(cstype, CTYPE)>
#endif
{
private $csclassname collectionRef;
private int currentIndex;
private object currentObject;
@ -132,7 +157,7 @@
}
// Type-safe iterator Current
public CSTYPE Current {
public $typemap(cstype, CTYPE) Current {
get {
if (currentIndex == -1)
throw new InvalidOperationException("Enumeration not started.");
@ -140,7 +165,7 @@
throw new InvalidOperationException("Enumeration finished.");
if (currentObject == null)
throw new InvalidOperationException("Collection modified.");
return (CSTYPE)currentObject;
return ($typemap(cstype, CTYPE))currentObject;
}
}
@ -170,28 +195,36 @@
throw new InvalidOperationException("Collection modified.");
}
}
#if !SWIG_DOTNET_1
public void Dispose() {
currentIndex = -1;
currentObject = null;
}
#endif
}
%}
public:
typedef size_t size_type;
typedef CTYPE value_type;
typedef const value_type& const_reference;
typedef CONST_REFERENCE const_reference;
%rename(Clear) clear;
void clear();
%rename(Add) push_back;
void push_back(const value_type& x);
void push_back(CTYPE const& x);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);
%newobject GetRange(int index, int count);
%newobject Repeat(const value_type& value, 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;
std::vector< CTYPE >* pv = 0;
if (capacity >= 0) {
pv = new std::vector<CTYPE >();
pv = new std::vector< CTYPE >();
pv->reserve(capacity);
} else {
throw std::out_of_range("capacity");
@ -199,53 +232,53 @@
return pv;
}
CTYPE getitemcopy(int index) throw (std::out_of_range) {
if (index>=0 && index<(int)self->size())
return (*self)[index];
if (index>=0 && index<(int)$self->size())
return (*$self)[index];
else
throw std::out_of_range("index");
}
const_reference getitem(int index) throw (std::out_of_range) {
if (index>=0 && index<(int)self->size())
return (*self)[index];
if (index>=0 && index<(int)$self->size())
return (*$self)[index];
else
throw std::out_of_range("index");
}
void setitem(int index, const value_type& val) throw (std::out_of_range) {
if (index>=0 && index<(int)self->size())
(*self)[index] = val;
void setitem(int index, CTYPE const& val) throw (std::out_of_range) {
if (index>=0 && index<(int)$self->size())
(*$self)[index] = val;
else
throw std::out_of_range("index");
}
// Takes a deep copy of the elements unlike ArrayList.AddRange
void AddRange(const std::vector<CTYPE >& values) {
self->insert(self->end(), values.begin(), values.end());
void AddRange(const std::vector< CTYPE >& values) {
$self->insert($self->end(), values.begin(), values.end());
}
// Takes a deep copy of the elements unlike ArrayList.GetRange
std::vector<CTYPE > *GetRange(int index, int count) throw (std::out_of_range, std::invalid_argument) {
std::vector< CTYPE > *GetRange(int index, int count) throw (std::out_of_range, std::invalid_argument) {
if (index < 0)
throw std::out_of_range("index");
if (count < 0)
throw std::out_of_range("count");
if (index >= (int)self->size()+1 || index+count > (int)self->size())
if (index >= (int)$self->size()+1 || index+count > (int)$self->size())
throw std::invalid_argument("invalid range");
return new std::vector<CTYPE >(self->begin()+index, self->begin()+index+count);
return new std::vector< CTYPE >($self->begin()+index, $self->begin()+index+count);
}
void Insert(int index, const value_type& x) throw (std::out_of_range) {
if (index>=0 && index<(int)self->size()+1)
self->insert(self->begin()+index, x);
void Insert(int index, CTYPE const& x) throw (std::out_of_range) {
if (index>=0 && index<(int)$self->size()+1)
$self->insert($self->begin()+index, x);
else
throw std::out_of_range("index");
}
// Takes a deep copy of the elements unlike ArrayList.InsertRange
void InsertRange(int index, const std::vector<CTYPE >& values) throw (std::out_of_range) {
if (index>=0 && index<(int)self->size()+1)
self->insert(self->begin()+index, values.begin(), values.end());
void InsertRange(int index, const std::vector< CTYPE >& values) throw (std::out_of_range) {
if (index>=0 && index<(int)$self->size()+1)
$self->insert($self->begin()+index, values.begin(), values.end());
else
throw std::out_of_range("index");
}
void RemoveAt(int index) throw (std::out_of_range) {
if (index>=0 && index<(int)self->size())
self->erase(self->begin() + index);
if (index>=0 && index<(int)$self->size())
$self->erase($self->begin() + index);
else
throw std::out_of_range("index");
}
@ -254,87 +287,90 @@
throw std::out_of_range("index");
if (count < 0)
throw std::out_of_range("count");
if (index >= (int)self->size()+1 || index+count > (int)self->size())
if (index >= (int)$self->size()+1 || index+count > (int)$self->size())
throw std::invalid_argument("invalid range");
self->erase(self->begin()+index, self->begin()+index+count);
$self->erase($self->begin()+index, $self->begin()+index+count);
}
static std::vector<CTYPE > *Repeat(const value_type& value, int count) throw (std::out_of_range) {
static std::vector< CTYPE > *Repeat(CTYPE const& value, int count) throw (std::out_of_range) {
if (count < 0)
throw std::out_of_range("count");
return new std::vector<CTYPE >(count, value);
return new std::vector< CTYPE >(count, value);
}
void Reverse() {
std::reverse(self->begin(), self->end());
std::reverse($self->begin(), $self->end());
}
void Reverse(int index, int count) throw (std::out_of_range, std::invalid_argument) {
if (index < 0)
throw std::out_of_range("index");
if (count < 0)
throw std::out_of_range("count");
if (index >= (int)self->size()+1 || index+count > (int)self->size())
if (index >= (int)$self->size()+1 || index+count > (int)$self->size())
throw std::invalid_argument("invalid range");
std::reverse(self->begin()+index, self->begin()+index+count);
std::reverse($self->begin()+index, $self->begin()+index+count);
}
// Takes a deep copy of the elements unlike ArrayList.SetRange
void SetRange(int index, const std::vector<CTYPE >& values) throw (std::out_of_range) {
void SetRange(int index, const std::vector< CTYPE >& values) throw (std::out_of_range) {
if (index < 0)
throw std::out_of_range("index");
if (index+values.size() > self->size())
if (index+values.size() > $self->size())
throw std::out_of_range("index");
std::copy(values.begin(), values.end(), self->begin()+index);
std::copy(values.begin(), values.end(), $self->begin()+index);
}
}
%enddef
// Extra methods added to the collection class if operator== is defined for the class being wrapped
// CSTYPE and CTYPE respectively correspond to the types in the cstype and ctype typemaps
%define SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CSTYPE, CTYPE...)
// The class will then implement IList<>, which adds extra functionality
%define SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CTYPE...)
%extend {
bool Contains(const value_type& value) {
return std::find(self->begin(), self->end(), value) != self->end();
bool Contains(CTYPE const& value) {
return std::find($self->begin(), $self->end(), value) != $self->end();
}
int IndexOf(const value_type& value) {
int IndexOf(CTYPE const& value) {
int index = -1;
std::vector<CTYPE >::iterator it = std::find(self->begin(), self->end(), value);
if (it != self->end())
index = (int)(it - self->begin());
std::vector< CTYPE >::iterator it = std::find($self->begin(), $self->end(), value);
if (it != $self->end())
index = (int)(it - $self->begin());
return index;
}
int LastIndexOf(const value_type& value) {
int LastIndexOf(CTYPE const& value) {
int index = -1;
std::vector<CTYPE >::reverse_iterator rit = std::find(self->rbegin(), self->rend(), value);
if (rit != self->rend())
index = (int)(self->rend() - 1 - rit);
std::vector< CTYPE >::reverse_iterator rit = std::find($self->rbegin(), $self->rend(), value);
if (rit != $self->rend())
index = (int)($self->rend() - 1 - rit);
return index;
}
void Remove(const value_type& value) {
std::vector<CTYPE >::iterator it = std::find(self->begin(), self->end(), value);
if (it != self->end())
self->erase(it);
bool Remove(CTYPE const& value) {
std::vector< CTYPE >::iterator it = std::find($self->begin(), $self->end(), value);
if (it != $self->end()) {
$self->erase(it);
return true;
}
return false;
}
}
%enddef
// Macros for std::vector class specializations
// CSTYPE and CTYPE respectively correspond to the types in the cstype and ctype typemaps
%define SWIG_STD_VECTOR_SPECIALIZE(CSTYPE, CTYPE...)
// Macros for std::vector class specializations/enhancements
%define SWIG_STD_VECTOR_ENHANCED(CTYPE...)
namespace std {
template<> class vector<CTYPE > {
SWIG_STD_VECTOR_MINIMUM(CSTYPE, CTYPE)
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CSTYPE, CTYPE)
template<> class vector< CTYPE > {
SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, %arg(CTYPE const&), %arg(CTYPE))
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CTYPE)
};
}
%enddef
// Legacy macros
%define SWIG_STD_VECTOR_SPECIALIZE(CSTYPE, CTYPE...)
#warning SWIG_STD_VECTOR_SPECIALIZE macro deprecated, please see csharp/std_vector.i and switch to SWIG_STD_VECTOR_ENHANCED
SWIG_STD_VECTOR_ENHANCED(CTYPE)
%enddef
%define SWIG_STD_VECTOR_SPECIALIZE_MINIMUM(CSTYPE, CTYPE...)
namespace std {
template<> class vector<CTYPE > {
SWIG_STD_VECTOR_MINIMUM(CSTYPE, CTYPE)
};
}
#warning SWIG_STD_VECTOR_SPECIALIZE_MINIMUM macro deprecated, it is no longer required
%enddef
%{
#include <vector>
#include <algorithm>
@ -352,33 +388,34 @@ 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(T, T)
SWIG_STD_VECTOR_MINIMUM_INTERNAL(IEnumerable, T const&, T)
};
// specializations for pointers
template<class T> class vector<T*> {
SWIG_STD_VECTOR_MINIMUM(T, T*)
// specialization for pointers
template<class T> class vector<T *> {
SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, T *const&, T *)
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(T *)
};
template<class T> class vector<const T*> {
SWIG_STD_VECTOR_MINIMUM(T, const T*)
// bool is specialized in the C++ standard - const_reference in particular
template<> class vector<bool> {
SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, bool, bool)
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(bool)
};
}
// template specializations for std::vector
// these provide extra collections methods as operator== is defined
SWIG_STD_VECTOR_SPECIALIZE(bool, bool)
SWIG_STD_VECTOR_SPECIALIZE(char, char)
SWIG_STD_VECTOR_SPECIALIZE(sbyte, signed char)
SWIG_STD_VECTOR_SPECIALIZE(byte, unsigned char)
SWIG_STD_VECTOR_SPECIALIZE(short, short)
SWIG_STD_VECTOR_SPECIALIZE(ushort, unsigned short)
SWIG_STD_VECTOR_SPECIALIZE(int, int)
SWIG_STD_VECTOR_SPECIALIZE(uint, unsigned int)
SWIG_STD_VECTOR_SPECIALIZE(int, long)
SWIG_STD_VECTOR_SPECIALIZE(uint, unsigned long)
SWIG_STD_VECTOR_SPECIALIZE(long, long long)
SWIG_STD_VECTOR_SPECIALIZE(ulong, unsigned long long)
SWIG_STD_VECTOR_SPECIALIZE(float, float)
SWIG_STD_VECTOR_SPECIALIZE(double, double)
SWIG_STD_VECTOR_SPECIALIZE(string, std::string) // also requires a %include <std_string.i>
SWIG_STD_VECTOR_ENHANCED(char)
SWIG_STD_VECTOR_ENHANCED(signed char)
SWIG_STD_VECTOR_ENHANCED(unsigned char)
SWIG_STD_VECTOR_ENHANCED(short)
SWIG_STD_VECTOR_ENHANCED(unsigned short)
SWIG_STD_VECTOR_ENHANCED(int)
SWIG_STD_VECTOR_ENHANCED(unsigned int)
SWIG_STD_VECTOR_ENHANCED(long)
SWIG_STD_VECTOR_ENHANCED(unsigned long)
SWIG_STD_VECTOR_ENHANCED(long long)
SWIG_STD_VECTOR_ENHANCED(unsigned long long)
SWIG_STD_VECTOR_ENHANCED(float)
SWIG_STD_VECTOR_ENHANCED(double)
SWIG_STD_VECTOR_ENHANCED(std::string) // also requires a %include <std_string.i>

3
Lib/csharp/std_wstring.i Executable file → Normal file
View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* std_wstring.i
*
* Typemaps for std::wstring and const std::wstring&

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* stl.i
*
* Initial STL definition. extended as needed in each language

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* typemaps.i
*
* Pointer and reference handling typemap library
@ -54,29 +51,17 @@ or you can use the %apply directive :
In C# you could then use it like this:
double answer = modulename.fadd(10.0, 20.0);
*/
%define INPUT_TYPEMAP(TYPE, CTYPE, CSTYPE)
%typemap(ctype) TYPE *INPUT, TYPE &INPUT "CTYPE"
%typemap(imtype) TYPE *INPUT, TYPE &INPUT "CSTYPE"
%typemap(cstype) TYPE *INPUT, TYPE &INPUT "CSTYPE"
%typemap(ctype, out="void *") TYPE *INPUT, TYPE &INPUT "CTYPE"
%typemap(imtype, out="IntPtr") TYPE *INPUT, TYPE &INPUT "CSTYPE"
%typemap(cstype, out="$csclassname") TYPE *INPUT, TYPE &INPUT "CSTYPE"
%typemap(csin) TYPE *INPUT, TYPE &INPUT "$csinput"
%typemap(csdirectorin) TYPE *INPUT, TYPE &INPUT "$iminput"
%typemap(csdirectorout) TYPE *INPUT, TYPE &INPUT "$cscall"
%typemap(in) TYPE *INPUT, TYPE &INPUT
%{ $1 = ($1_ltype)&$input; %}
%typemap(directorout) TYPE *INPUT, TYPE &INPUT
%{ $result = ($1_ltype)&$input; %}
%typemap(directorin) TYPE &INPUT
%{ $input = (CTYPE *)$1; %}
%typemap(directorin) TYPE *INPUT
%{ $input = (CTYPE *)$1; %}
%typemap(typecheck) TYPE *INPUT = TYPE;
%typemap(typecheck) TYPE &INPUT = TYPE;
%enddef
@ -146,32 +131,17 @@ value returned in the second output parameter. In C# you would use it like this:
double dptr;
double fraction = modulename.modf(5, out dptr);
*/
%define OUTPUT_TYPEMAP(TYPE, CTYPE, CSTYPE, TYPECHECKPRECEDENCE)
%typemap(ctype) TYPE *OUTPUT, TYPE &OUTPUT "CTYPE *"
%typemap(imtype) TYPE *OUTPUT, TYPE &OUTPUT "out CSTYPE"
%typemap(cstype) TYPE *OUTPUT, TYPE &OUTPUT "out CSTYPE"
%typemap(ctype, out="void *") TYPE *OUTPUT, TYPE &OUTPUT "CTYPE *"
%typemap(imtype, out="IntPtr") TYPE *OUTPUT, TYPE &OUTPUT "out CSTYPE"
%typemap(cstype, out="$csclassname") TYPE *OUTPUT, TYPE &OUTPUT "out CSTYPE"
%typemap(csin) TYPE *OUTPUT, TYPE &OUTPUT "out $csinput"
%typemap(csdirectorin) TYPE *OUTPUT, TYPE &OUTPUT "$iminput"
%typemap(csdirectorout) TYPE *OUTPUT, TYPE &OUTPUT "$cscall"
%typemap(in) TYPE *OUTPUT, TYPE &OUTPUT
%{ $1 = ($1_ltype)$input; %}
%typemap(directorout,warning="Need to provide TYPE *OUTPUT directorout typemap") TYPE *OUTPUT, TYPE &OUTPUT {
}
%typemap(directorin) TYPE &OUTPUT
%{ $input = &$1; %}
%typemap(directorin,warning="Need to provide TYPE *OUTPUT directorin typemap, TYPE array length is unknown") TYPE *OUTPUT
{
}
%typecheck(SWIG_TYPECHECK_##TYPECHECKPRECEDENCE) TYPE *OUTPUT, TYPE &OUTPUT ""
%enddef
@ -192,6 +162,10 @@ OUTPUT_TYPEMAP(double, double, double, DOUBLE_PTR)
#undef OUTPUT_TYPEMAP
%typemap(in) bool *OUTPUT, bool &OUTPUT
%{ *$input = 0;
$1 = ($1_ltype)$input; %}
/*
INOUT typemaps
@ -249,26 +223,14 @@ of the function return value.
*/
%define INOUT_TYPEMAP(TYPE, CTYPE, CSTYPE, TYPECHECKPRECEDENCE)
%typemap(ctype) TYPE *INOUT, TYPE &INOUT "CTYPE *"
%typemap(imtype) TYPE *INOUT, TYPE &INOUT "ref CSTYPE"
%typemap(cstype) TYPE *INOUT, TYPE &INOUT "ref CSTYPE"
%typemap(ctype, out="void *") TYPE *INOUT, TYPE &INOUT "CTYPE *"
%typemap(imtype, out="IntPtr") TYPE *INOUT, TYPE &INOUT "ref CSTYPE"
%typemap(cstype, out="$csclassname") TYPE *INOUT, TYPE &INOUT "ref CSTYPE"
%typemap(csin) TYPE *INOUT, TYPE &INOUT "ref $csinput"
%typemap(csdirectorin) TYPE *INOUT, TYPE &INOUT "$iminput"
%typemap(csdirectorout) TYPE *INOUT, TYPE &INOUT "$cscall"
%typemap(in) TYPE *INOUT, TYPE &INOUT
%{ $1 = ($1_ltype)$input; %}
%typemap(directorout,warning="Need to provide TYPE *INOUT directorout typemap") TYPE *INOUT, TYPE &INOUT {
}
%typemap(directorin) TYPE &INOUT
%{ $input = &$1; %}
%typemap(directorin,warning="Need to provide TYPE *INOUT directorin typemap, TYPE array length is unknown") TYPE *INOUT, TYPE &INOUT
{
}
%typecheck(SWIG_TYPECHECK_##TYPECHECKPRECEDENCE) TYPE *INOUT, TYPE &INOUT ""
%enddef

207
Lib/csharp/wchar.i Executable file → Normal file
View file

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

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* cstring.i
* ----------------------------------------------------------------------------- */

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* cwstring.i
* ----------------------------------------------------------------------------- */

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

@ -0,0 +1,201 @@
%include <shared_ptr.i>
%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...)
%naturalvar TYPE;
%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
// destructor mods
%feature("unref") TYPE
//"if (debug_shared) { cout << \"deleting use_count: \" << (*smartarg1).use_count() << \" [\" << (boost::get_deleter<SWIG_null_deleter>(*smartarg1) ? std::string(\"CANNOT BE DETERMINED SAFELY\") : ((*smartarg1).get() ? (*smartarg1)->getValue() : std::string(\"NULL PTR\"))) << \"]\" << endl << flush; }\n"
"(void)arg1; delete smartarg1;"
// plain value
%typemap(in, canthrow=1) CONST TYPE ($&1_type argp = 0) %{
argp = ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input) ? ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input)->get() : 0;
if (!argp) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Attempt to dereference null $1_type");
return $null;
}
$1 = *argp; %}
%typemap(out) CONST TYPE
%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); %}
// plain pointer
%typemap(in, canthrow=1) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
smartarg = (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input;
$1 = (TYPE *)(smartarg ? smartarg->get() : 0); %}
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE * %{
$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0;
%}
// plain reference
%typemap(in, canthrow=1) CONST TYPE & %{
$1 = ($1_ltype)(((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input) ? ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input)->get() : 0);
if (!$1) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type reference is null");
return $null;
} %}
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE &
%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); %}
// plain pointer by reference
%typemap(in) TYPE *CONST& ($*1_ltype temp = 0)
%{ temp = (TYPE *)(((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input) ? ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input)->get() : 0);
$1 = &temp; %}
%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST&
%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %}
// shared_ptr by value
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >
%{ if ($input) $1 = *($&1_ltype)$input; %}
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >
%{ $result = $1 ? new $1_ltype($1) : 0; %}
// shared_ptr by reference
%typemap(in, canthrow=1) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & ($*1_ltype tempnull)
%{ $1 = $input ? ($1_ltype)$input : &tempnull; %}
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &
%{ $result = *$1 ? new $*1_ltype(*$1) : 0; %}
// shared_ptr by pointer
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * ($*1_ltype tempnull)
%{ $1 = $input ? ($1_ltype)$input : &tempnull; %}
%typemap(out, fragment="SWIG_null_deleter") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *
%{ $result = ($1 && *$1) ? new $*1_ltype(*($1_ltype)$1) : 0;
if ($owner) delete $1; %}
// shared_ptr by pointer reference
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempnull, $*1_ltype temp = 0)
%{ temp = $input ? *($1_ltype)&$input : &tempnull;
$1 = &temp; %}
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *&
%{ *($1_ltype)&$result = (*$1 && **$1) ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(**$1) : 0; %}
// various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug
%typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{
#error "typemaps for $1_type not available"
%}
%typemap(out) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{
#error "typemaps for $1_type not available"
%}
%typemap (ctype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "void *"
%typemap (imtype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "void*"
%typemap (dtype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "$typemap(dtype, TYPE)"
%typemap(din) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "$typemap(dtype, TYPE).swigGetCPtr($dinput)"
%typemap(dout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
void* cPtr = $imcall;
auto ret = (cPtr is null) ? null : new $typemap(dtype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(dout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & {
void* cPtr = $imcall;
auto ret = (cPtr is null) ? null : new $typemap(dtype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(dout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * {
void* cPtr = $imcall;
auto ret = (cPtr is null) ? null : new $typemap(dtype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(dout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& {
void* cPtr = $imcall;
auto ret = (cPtr is null) ? null : new $typemap(dtype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(dout, excode=SWIGEXCODE) CONST TYPE {
auto ret = new $typemap(dtype, TYPE)($imcall, true);$excode
return ret;
}
%typemap(dout, excode=SWIGEXCODE) CONST TYPE & {
auto ret = new $typemap(dtype, TYPE)($imcall, true);$excode
return ret;
}
%typemap(dout, excode=SWIGEXCODE) CONST TYPE * {
void* cPtr = $imcall;
auto ret = (cPtr is null) ? null : new $typemap(dtype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(dout, excode=SWIGEXCODE) TYPE *CONST& {
void* cPtr = $imcall;
auto ret = (cPtr is null) ? null : new $typemap(dtype, TYPE)(cPtr, true);$excode
return ret;
}
// For shared pointers, both the derived and the base class have to »own« their
// pointer; otherwise the reference count is not decreased properly on destruction.
%typemap(dbody) SWIGTYPE %{
private void* swigCPtr;
private bool swigCMemOwn;
public this(void* cObject, bool ownCObject) {
swigCPtr = cObject;
swigCMemOwn = ownCObject;
}
public static void* swigGetCPtr($dclassname obj) {
return (obj is null) ? null : obj.swigCPtr;
}
%}
%typemap(dbody_derived) SWIGTYPE %{
private void* swigCPtr;
private bool swigCMemOwn;
public this(void* cObject, bool ownCObject) {
super($imdmodule.$dclazznameSmartPtrUpcast(cObject), ownCObject);
swigCPtr = cObject;
swigCMemOwn = ownCObject;
}
public static void* swigGetCPtr($dclassname obj) {
return (obj is null) ? null : obj.swigCPtr;
}
%}
%typemap(ddispose, methodname="dispose", methodmodifiers="public") TYPE {
synchronized(this) {
if (swigCPtr !is null) {
if (swigCMemOwn) {
swigCMemOwn = false;
$imcall;
}
swigCPtr = null;
}
}
}
%typemap(ddispose_derived, methodname="dispose", methodmodifiers="public") TYPE {
synchronized(this) {
if (swigCPtr !is null) {
if (swigCMemOwn) {
swigCMemOwn = false;
$imcall;
}
swigCPtr = null;
super.dispose();
}
}
}
%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
%enddef

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

View file

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* stl.i
*
* Initial STL definition. extended as needed in each language

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

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

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

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

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* exception.i
*
* SWIG library file providing language independent exception handling
@ -229,6 +226,40 @@ struct SWIG_CException {
#endif // SWIGC
#ifdef SWIGD
%{
SWIGINTERN void SWIG_DThrowException(int code, const char *msg) {
SWIG_DExceptionCodes exception_code;
switch(code) {
case SWIG_IndexError:
exception_code = SWIG_DNoSuchElementException;
break;
case SWIG_IOError:
exception_code = SWIG_DIOException;
break;
case SWIG_ValueError:
exception_code = SWIG_DIllegalArgumentException;
break;
case SWIG_DivisionByZero:
case SWIG_MemoryError:
case SWIG_OverflowError:
case SWIG_RuntimeError:
case SWIG_TypeError:
case SWIG_SyntaxError:
case SWIG_SystemError:
case SWIG_UnknownError:
default:
exception_code = SWIG_DException;
break;
}
SWIG_DSetPendingException(exception_code, msg);
}
%}
#define SWIG_exception(code, msg)\
{ SWIG_DThrowException(code, msg); return $null; }
#endif // SWIGD
#ifdef __cplusplus
/*
You can use the SWIG_CATCH_STDEXCEPT macro with the %exception
@ -279,9 +310,15 @@ struct SWIG_CException {
/* rethrow the unknown exception */
#if defined(SWIGCSHARP) || defined(SWIGD)
%typemap(throws,noblock=1, canthrow=1) (...) {
SWIG_exception(SWIG_RuntimeError,"unknown exception");
}
#else
%typemap(throws,noblock=1) (...) {
SWIG_exception(SWIG_RuntimeError,"unknown exception");
}
#endif
#endif /* __cplusplus */

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* cni.swg
* ----------------------------------------------------------------------------- */

64
Lib/go/cdata.i Normal file
View file

@ -0,0 +1,64 @@
/* -----------------------------------------------------------------------------
* cdata.i
*
* SWIG library file containing macros for manipulating raw C data as strings.
* ----------------------------------------------------------------------------- */
%{
typedef struct SWIGCDATA {
char *data;
int len;
} SWIGCDATA;
%}
%typemap(gotype) SWIGCDATA %{ []byte %}
%typemap(out) SWIGCDATA %{
$result.data = (char*)_swig_goallocate($1.len);
memcpy($result.data, $1.data, $1.len);
$result.len = (int)$1.len;
%}
/* -----------------------------------------------------------------------------
* %cdata(TYPE [, NAME])
*
* Convert raw C data to a binary string.
* ----------------------------------------------------------------------------- */
%define %cdata(TYPE,NAME...)
%insert("header") {
#if #NAME == ""
static SWIGCDATA cdata_##TYPE(TYPE *ptr, int nelements) {
#else
static SWIGCDATA cdata_##NAME(TYPE *ptr, int nelements) {
#endif
SWIGCDATA d;
d.data = (char *) ptr;
#if #TYPE != "void"
d.len = nelements*sizeof(TYPE);
#else
d.len = nelements;
#endif
return d;
}
}
%typemap(default) int nelements "$1 = 1;"
#if #NAME == ""
SWIGCDATA cdata_##TYPE(TYPE *ptr, int nelements);
#else
SWIGCDATA cdata_##NAME(TYPE *ptr, int nelements);
#endif
%enddef
%typemap(default) int nelements;
%rename(cdata) ::cdata_void(void *ptr, int nelements);
%cdata(void);
/* Memory move function. Due to multi-argument typemaps this appears
to be wrapped as
void memmove(void *data, const char *s); */
void memmove(void *data, char *indata, int inlen);

7
Lib/go/exception.i Normal file
View file

@ -0,0 +1,7 @@
%typemap(throws,noblock=1) (...) {
SWIG_exception(SWIG_RuntimeError,"unknown exception");
}
%insert("runtime") %{
#define SWIG_exception(code, msg) _swig_gopanic(msg)
%}

529
Lib/go/go.swg Normal file
View file

@ -0,0 +1,529 @@
/* ------------------------------------------------------------
* go.swg
*
* Go configuration module.
* ------------------------------------------------------------ */
/* Basic types */
%typemap(gotype) bool, const bool & "bool"
%typemap(gotype) char, const char & "byte"
%typemap(gotype) signed char, const signed char & "int8"
%typemap(gotype) unsigned char, const unsigned char & "byte"
%typemap(gotype) short, const short & "int16"
%typemap(gotype) unsigned short, const unsigned short & "uint16"
%typemap(gotype) int, const int & "int"
%typemap(gotype) unsigned int, const unsigned int & "uint"
#if SWIGGO_LONG_TYPE_SIZE == 32
%typemap(gotype) long, const long & "int32"
%typemap(gotype) unsigned long, const unsigned long & "uint32"
#elif SWIGGO_LONG_TYPE_SIZE == 64
%typemap(gotype) long, const long & "int64"
%typemap(gotype) unsigned long, const unsigned long & "uint64"
#else
#error "SWIGGO_LONG_TYPE_SIZE not 32 or 64"
#endif
%typemap(gotype) long long, const long long & "int64"
%typemap(gotype) unsigned long long, const unsigned long long & "uint64"
%typemap(gotype) float, const float & "float32"
%typemap(gotype) double, const double & "float64"
%typemap(in) bool,
char,
signed char,
unsigned char,
short,
unsigned short,
int,
unsigned int,
long,
unsigned long,
long long,
unsigned long long,
float,
double
%{ $1 = ($1_ltype)$input; %}
%typemap(in) const bool &,
const char &,
const signed char &,
const unsigned char &,
const short &,
const unsigned short &,
const int &,
const unsigned int &,
const long &,
const unsigned long &,
const long long &,
const unsigned long long &,
const float &,
const double &
%{ $1 = ($1_ltype)&$input; %}
%typemap(out) bool,
char,
signed char,
unsigned char,
short,
unsigned short,
int,
unsigned int,
long,
unsigned long,
long long,
unsigned long long,
float,
double
%{ $result = $1; %}
%typemap(out) const bool &,
const char &,
const signed char &,
const unsigned char &,
const short &,
const unsigned short &,
const int &,
const unsigned int &,
const long &,
const unsigned long &,
const long long &,
const unsigned long long &,
const float &,
const double &
%{ $result = ($*1_ltype)*$1; %}
%typemap(out) void ""
%typemap(directorin) bool,
char,
signed char,
unsigned char,
short,
unsigned short,
int,
unsigned int,
long,
unsigned long,
long long,
unsigned long long,
float,
double
%{ $input = ($1_ltype)$1; %}
%typemap(directorin) const bool &,
const char &,
const signed char &,
const unsigned char &,
const short &,
const unsigned short &,
const int &,
const unsigned int &,
const long &,
const unsigned long &,
const long long &,
const unsigned long long &,
const float &,
const double &
%{ $input = ($*1_ltype)$1; %}
%typemap(directorout) bool,
char,
signed char,
unsigned char,
short,
unsigned short,
int,
unsigned int,
long,
unsigned long,
long long,
unsigned long long,
float,
double
%{ $result = ($1_ltype)$input; %}
%typemap(directorout) const bool &,
const char &,
const signed char &,
const unsigned char &,
const short &,
const unsigned short &,
const int &,
const unsigned int &,
const long &,
const unsigned long &,
const long long &,
const unsigned long long &,
const float &,
const double &
%{
$result = ($1_ltype)_swig_goallocate(sizeof($*1_ltype));
*$result = *($1_ltype)&$input;
%}
/* The size_t type. */
#if SWIGGO_LONG_TYPE_SIZE == 32
%typemap(gotype) size_t, const size_t & %{int%}
#else
%typemap(gotype) size_t, const size_t & %{int64%}
#endif
%typemap(in) size_t
%{ $1 = (size_t)$input; %}
%typemap(in) const size_t &
%{ $1 = ($1_ltype)&$input; %}
%typemap(out) size_t
%{ $result = $1; %}
%typemap(out) const size_t &
%{ $result = ($*1_ltype)*$1; %}
%typemap(directorin) size_t
%{ $input = (size_t)$1; %}
%typemap(directorin) const size_t &
%{ $input = ($*1_ltype)$1; %}
%typemap(directorout) size_t
%{ $result = ($1_ltype)$input; %}
%typemap(directorout) const size_t &
%{
$result = ($1_ltype)_swig_goallocate(sizeof($*1_ltype));
*$result = *($1_ltype)$input;
%}
/* Member pointers. */
%typemap(gotype) SWIGTYPE (CLASS::*)
%{$gotypename%}
%typemap(in) SWIGTYPE (CLASS::*)
%{ $1 = *($&1_ltype)$input; %}
%typemap(out) SWIGTYPE (CLASS::*)
%{
$result = _swig_goallocate(sizeof($1_ltype));
*($&1_ltype)$result = $1;
%}
%typemap(directorin) SWIGTYPE (CLASS::*)
%{ $input = *($&1_ltype)$1; %}
%typemap(directorout) SWIGTYPE (CLASS::*)
%{
$result = _swig_goallocate(sizeof($1_ltype));
*($&1_ltype)$result = $input;
%}
/* Pointers. */
/* We can't translate pointers using a typemap, so that is handled in
the C++ code. */
%typemap(gotype) SWIGTYPE *
%{$gotypename%}
%typemap(in) SWIGTYPE *
%{ $1 = *($&1_ltype)&$input; %}
%typemap(out) SWIGTYPE *
%{ *($&1_ltype)&$result = $1; %}
%typemap(directorin) SWIGTYPE *
%{ $input = ($1_ltype)$1; %}
%typemap(directorout) SWIGTYPE *
%{ $result = ($1_ltype)$input; %}
%apply SWIGTYPE * { SWIGTYPE *const }
/* Pointer references. */
%typemap(gotype) SWIGTYPE *const&
%{$gotypename%}
%typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0)
%{
temp = *($1_ltype)&$input;
$1 = ($1_ltype)&temp;
%}
%typemap(out) SWIGTYPE *const&
%{ *($1_ltype)&$result = *$1; %}
/* References. */
/* Converting a C++ reference to Go has to be handled in the C++
code. */
%typemap(gotype) SWIGTYPE &
%{$gotypename%}
%typemap(in) SWIGTYPE &
%{ $1 = *($&1_ltype)&$input; %}
%typemap(out) SWIGTYPE &
%{ *($&1_ltype)&$result = $1; %}
%typemap(directorin) SWIGTYPE &
%{ $input = ($1_ltype)&$1; %}
%typemap(directorout) SWIGTYPE &
%{ *($&1_ltype)&$result = $input; %}
/* C arrays turn into Go pointers. If we know the length we can use a
slice. */
%typemap(gotype) SWIGTYPE []
%{$gotypename%}
%typemap(in) SWIGTYPE []
%{ $1 = *($&1_ltype)&$input; %}
%typemap(out) SWIGTYPE []
%{ *($&1_ltype)&$result = $1; %}
%typemap(directorin) SWIGTYPE []
%{ $input = *($1_ltype)&$1; %}
%typemap(directorout) SWIGTYPE []
%{ *($&1_ltype)&$result = $input; %}
/* Strings. */
%typemap(gotype)
char *, char *&, char[ANY], char[],
signed char *, signed char *&, signed char[ANY], signed char[],
unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[]
"string"
/* Needed to avoid confusion with the way the go module handles
references. */
%typemap(gotype) char&, unsigned char& "*byte"
%typemap(gotype) signed char& "*int8"
%typemap(in)
char *, char[ANY], char[],
signed char *, signed char[ANY], signed char[],
unsigned char *, unsigned char[ANY], unsigned char[]
%{ $1 = ($1_ltype)$input.p; %}
%typemap(in) char *&, signed char *&, unsigned char *&
%{ $1 = ($1_ltype)$input.p; %}
%typemap(out)
char *, char *&, char[ANY], char[],
signed char *, signed char *&, signed char[ANY], signed char[],
unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[]
%{ $result = _swig_makegostring((char*)$1, $1 ? strlen((char*)$1) : 0); %}
%typemap(directorin)
char *, char *&, char[ANY], char[],
signed char *, signed char *&, signed char[ANY], signed char[],
unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[]
%{
$input = _swig_makegostring((char*)$1, $1 ? strlen((char*)$1) : 0);
%}
%typemap(directorout)
char *, char *&, char[ANY], char[],
signed char *, signed char *&, signed char[ANY], signed char[],
unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[]
%{ $result = ($1_ltype)$input.p; %}
/* String & length */
%typemap(gotype) (char *STRING, size_t LENGTH) "string"
%typemap(in) (char *STRING, size_t LENGTH)
%{
$1 = ($1_ltype)$input.p;
$2 = ($2_ltype)$input.n;
%}
%typemap(out) (char *STRING, size_t LENGTH)
%{ $result = _swig_makegostring((char*)$1, (size_t)$2); %}
%typemap(directorin) (char *STRING, size_t LENGTH)
%{ $input = _swig_makegostring((char*)$1, $2); %}
%typemap(directorout) (char *STRING, size_t LENGTH)
%{
$1 = ($1_ltype)$input.p;
$2 = ($2_ltype)$input.n;
%}
/* Enums. We can't do the right thing for enums in typemap(gotype) so
we deliberately don't define them. The right thing would be to
capitalize the name. This is instead done in go.cxx. */
%typemap(gotype) enum SWIGTYPE
%{$gotypename%}
%typemap(in) enum SWIGTYPE
%{ $1 = ($1_ltype)$input; %}
%typemap(out) enum SWIGTYPE
%{ $result = $1; %}
%typemap(directorin) enum SWIGTYPE
%{ $input = ($1_ltype)$1; %}
%typemap(directorout) enum SWIGTYPE
%{ $result = ($1_ltype)$input; %}
/* Arbitrary type. This is a type passed by value in the C/C++ code.
We convert it to a pointer for the Go code. Note that all basic
types are explicitly handled above. */
%typemap(gotype) SWIGTYPE
%{$gotypename%}
%typemap(in) SWIGTYPE ($&1_type argp)
%{
argp = ($&1_ltype)$input;
if (argp == NULL) {
_swig_gopanic("Attempt to dereference null $1_type");
}
$1 = ($1_ltype)*argp;
%}
%typemap(out) SWIGTYPE
#ifdef __cplusplus
%{ *($&1_ltype*)&$result = new $1_ltype($1); %}
#else
{
$&1_ltype $1ptr = ($&1_ltype)malloc(sizeof($1_ltype));
memmove($1ptr, &$1, sizeof($1_type));
*($&1_ltype*)&$result = $1ptr;
}
#endif
%typemap(directorin) SWIGTYPE
%{ $input = ($&1_ltype)&$1; %}
%typemap(directorout) SWIGTYPE
%{ $result = *($&1_ltype)$input; %}
/* Exception handling */
%typemap(throws) char *
%{ _swig_gopanic($1); %}
%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY]
%{
(void)$1;
_swig_gopanic("C++ $1_type exception thrown");
%}
/* Typecheck typemaps. The purpose of these is merely to issue a
warning for overloaded C++ functions * that cannot be overloaded in
Go as more than one C++ type maps to a single Go type. */
%typecheck(SWIG_TYPECHECK_BOOL) /* Go bool */
bool,
const bool &
""
%typecheck(SWIG_TYPECHECK_CHAR) /* Go byte */
char,
const char &,
unsigned char,
const unsigned char &
""
%typecheck(SWIG_TYPECHECK_INT8) /* Go int8 */
signed char,
const signed char &
""
%typecheck(SWIG_TYPECHECK_INT16) /* Go int16 */
short,
const short &
""
%typecheck(SWIG_TYPECHECK_INT16) /* Go uint16 */
unsigned short,
const unsigned short &
""
%typecheck(SWIG_TYPECHECK_INT32) /* Go int */
int,
const int &
""
%typecheck(SWIG_TYPECHECK_INT32) /* Go uint */
unsigned int,
const unsigned int &
""
#if SWIGGO_LONG_TYPE_SIZE == 32
%typecheck(SWIG_TYPECHECK_INT32) /* Go int32 */
long,
const long &
""
%typecheck(SWIG_TYPECHECK_INT32) /* Go uint32 */
unsigned long,
const unsigned long &
""
#endif
%typecheck(SWIG_TYPECHECK_INT64) /* Go int64 */
#if SWIGGO_LONG_TYPE_SIZE == 64
long,
const long &,
#endif
long long,
const long long &
""
%typecheck(SWIG_TYPECHECK_INT64) /* Go uint64 */
#if SWIGGO_LONG_TYPE_SIZE == 64
unsigned long,
const unsigned long &,
#endif
unsigned long long,
const unsigned long long &
""
%typecheck(SWIG_TYPECHECK_FLOAT) /* Go float32 */
float,
const float &
""
%typecheck(SWIG_TYPECHECK_DOUBLE) /* Go float64 */
double,
const double &
""
%typecheck(SWIG_TYPECHECK_STRING) /* Go string */
char *,
char *&,
char[ANY],
char [],
signed char *,
signed char *&,
signed char[ANY],
signed char [],
unsigned char *,
unsigned char *&,
unsigned char[ANY],
unsigned char []
""
%typecheck(SWIG_TYPECHECK_POINTER)
SWIGTYPE,
SWIGTYPE *,
SWIGTYPE &,
SWIGTYPE *const&,
SWIGTYPE [],
SWIGTYPE (CLASS::*)
""
/* Go keywords. */
%include <gokw.swg>
%include <goruntime.swg>

33
Lib/go/gokw.swg Normal file
View file

@ -0,0 +1,33 @@
/* Rename keywords. */
#define GOKW(x) %keywordwarn("'" `x` "' is a Go keyword, renaming to 'X"`x`"'",rename="X%s") `x`
#define GOBN(x) %builtinwarn("'" `x` "' conflicts with a built-in name in Go") "::"`x`
GOKW(break);
GOKW(case);
GOKW(chan);
GOKW(const);
GOKW(continue);
GOKW(default);
GOKW(defer);
GOKW(else);
GOKW(fallthrough);
GOKW(for);
GOKW(func);
GOKW(go);
GOKW(goto);
GOKW(if);
GOKW(import);
GOKW(interface);
GOKW(package);
GOKW(range);
GOKW(return);
GOKW(select);
GOKW(struct);
GOKW(switch);
GOKW(type);
GOKW(var);
GOBN(map);
#undef GOKW

138
Lib/go/goruntime.swg Normal file
View file

@ -0,0 +1,138 @@
/* ------------------------------------------------------------
* goruntime.swg
*
* Go runtime code for the various generated files.
* ------------------------------------------------------------ */
%insert(runtime) %{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct { char *p; int n; } _gostring_;
typedef struct { void* array; unsigned int len; unsigned int cap; } _goslice_;
%}
#ifndef SWIGGO_GCCGO
/* Boilerplate for C/C++ code when using 6g/8g. This code is compiled
with gcc. */
%insert(runtime) %{
#define swiggo_size_assert_eq(x, y, name) typedef char name[(x-y)*(x-y)*-2+1];
#define swiggo_size_assert(t, n) swiggo_size_assert_eq(sizeof(t), n, swiggo_sizeof_##t##_is_not_##n)
swiggo_size_assert(char, 1)
swiggo_size_assert(short, 2)
swiggo_size_assert(int, 4)
typedef long long swiggo_long_long;
swiggo_size_assert(swiggo_long_long, 8)
swiggo_size_assert(float, 4)
swiggo_size_assert(double, 8)
#ifdef __cplusplus
extern "C" {
#endif
extern void crosscall2(void (*fn)(void *, int), void *, int);
extern void _cgo_allocate(void *, int);
extern void _cgo_panic(void *, int);
#ifdef __cplusplus
}
#endif
static void *_swig_goallocate(size_t len) {
struct {
size_t len;
void *ret;
} a;
a.len = len;
crosscall2(_cgo_allocate, &a, (int) sizeof a);
return a.ret;
}
static void _swig_gopanic(const char *p) {
struct {
const char *p;
} a;
a.p = p;
crosscall2(_cgo_panic, &a, (int) sizeof a);
}
%}
/* Boilerplate for C code when using 6g/8g. This code is compiled
with 6c/8c. */
%insert(gc_header) %{
#include "runtime.h"
#include "cgocall.h"
#ifdef _64BIT
#define SWIG_PARM_SIZE 8
#else
#define SWIG_PARM_SIZE 4
#endif
%}
#else
/* Boilerplate for C/C++ code when using gccgo. */
%insert(runtime) %{
#define SWIGGO_GCCGO
#ifdef __cplusplus
extern "C" {
#endif
extern void *_cgo_allocate(size_t);
extern void _cgo_panic(const char *);
#ifdef __cplusplus
}
#endif
#define _swig_goallocate _cgo_allocate
#define _swig_gopanic _cgo_panic
%}
#endif
%insert(runtime) %{
static _gostring_ _swig_makegostring(const char *p, size_t l) {
_gostring_ ret;
ret.p = (char*)_swig_goallocate(l + 1);
memcpy(ret.p, p, l);
ret.n = l;
return ret;
}
#define SWIG_contract_assert(expr, msg) \
if (!(expr)) { _swig_gopanic(msg); } else
%}
#ifndef SWIGGO_GCCGO
%insert(go_header) %{
import _ "runtime/cgo"
%}
#else
%insert(go_header) %{
import "syscall"
type _ syscall.Sockaddr
%}
#endif
/* Function pointers are translated by the code in go.cxx into
_swig_fnptr. Member pointers are translated to _swig_memberptr. */
%insert(go_header) %{
type _swig_fnptr *byte
type _swig_memberptr *byte
%}

4
Lib/go/std_common.i Normal file
View file

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

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

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

29
Lib/go/std_except.i Normal file
View file

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

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

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

60
Lib/go/std_map.i Normal file
View file

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

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* std_pair.i
*
* SWIG typemaps for std::pair

55
Lib/go/std_string.i Normal file
View file

@ -0,0 +1,55 @@
/* -----------------------------------------------------------------------------
* std_string.i
*
* Typemaps for std::string and const std::string&
* These are mapped to a Go string and are passed around by value.
*
* To use non-const std::string references use the following %apply. Note
* that they are passed by value.
* %apply const std::string & {std::string &};
* ----------------------------------------------------------------------------- */
%{
#include <string>
%}
namespace std {
%naturalvar string;
class string;
%typemap(gotype) string, const string & "string"
%typemap(in) string
%{ $1.assign($input.p, $input.n); %}
%typemap(directorout) string
%{ $result.assign($input.p, $input.n); %}
%typemap(out) string
%{ $result = _swig_makegostring($1.data(), $1.length()); %}
%typemap(directorin) string
%{ $input = _swig_makegostring($1.data(), $1.length()); %}
%typemap(in) const string &
%{
std::string $1_str($input.p, $input.n);
$1 = &$1_str;
%}
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const string &
%{
static std::string $1_str;
$1_str.assign($input.p, $input.n);
$result = &$1_str;
%}
%typemap(out) const string &
%{ $result = _swig_makegostring((*$1).data(), (*$1).length()); %}
%typemap(directorin) const string &
%{ $input = _swig_makegostring($1.data(), $1.length()); %}
}

78
Lib/go/std_vector.i Normal file
View file

@ -0,0 +1,78 @@
/* -----------------------------------------------------------------------------
* std_vector.i
* ----------------------------------------------------------------------------- */
%{
#include <vector>
#include <stdexcept>
%}
namespace std {
template<class T> class vector {
public:
typedef size_t size_type;
typedef T value_type;
typedef const value_type& const_reference;
vector();
vector(size_type n);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);
%rename(isEmpty) empty;
bool empty() const;
void clear();
%rename(add) push_back;
void push_back(const value_type& x);
%extend {
const_reference get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, const value_type& val) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = val;
else
throw std::out_of_range("vector index out of range");
}
}
};
// bool specialization
template<> class vector<bool> {
public:
typedef size_t size_type;
typedef bool value_type;
typedef bool const_reference;
vector();
vector(size_type n);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);
%rename(isEmpty) empty;
bool empty() const;
void clear();
%rename(add) push_back;
void push_back(const value_type& x);
%extend {
const_reference get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, const value_type& val) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = val;
else
throw std::out_of_range("vector index out of range");
}
}
};
}

9
Lib/go/stl.i Normal file
View file

@ -0,0 +1,9 @@
/* -----------------------------------------------------------------------------
* stl.i
* ----------------------------------------------------------------------------- */
%include <std_common.i>
%include <std_string.i>
%include <std_vector.i>
%include <std_map.i>
%include <std_pair.i>

316
Lib/go/typemaps.i Normal file
View file

@ -0,0 +1,316 @@
/* -----------------------------------------------------------------------------
* typemaps.i
*
* Pointer and reference handling typemap library
*
* These mappings provide support for input/output arguments and common
* uses for C/C++ pointers and C++ references.
* ----------------------------------------------------------------------------- */
/*
INPUT typemaps
--------------
These typemaps remap a C pointer or C++ reference to be an "INPUT" value which is
passed by value instead of reference.
The following typemaps can be applied to turn a pointer or reference into a simple
input value. That is, instead of passing a pointer or reference to an object,
you would use a real value instead.
bool *INPUT, bool &INPUT
signed char *INPUT, signed char &INPUT
unsigned char *INPUT, unsigned char &INPUT
short *INPUT, short &INPUT
unsigned short *INPUT, unsigned short &INPUT
int *INPUT, int &INPUT
unsigned int *INPUT, unsigned int &INPUT
long *INPUT, long &INPUT
unsigned long *INPUT, unsigned long &INPUT
long long *INPUT, long long &INPUT
unsigned long long *INPUT, unsigned long long &INPUT
float *INPUT, float &INPUT
double *INPUT, double &INPUT
To use these, suppose you had a C function like this :
double fadd(double *a, double *b) {
return *a+*b;
}
You could wrap it with SWIG as follows :
%include <typemaps.i>
double fadd(double *INPUT, double *INPUT);
or you can use the %apply directive :
%include <typemaps.i>
%apply double *INPUT { double *a, double *b };
double fadd(double *a, double *b);
In Go you could then use it like this:
answer := modulename.Fadd(10.0, 20.0)
There are no char *INPUT typemaps, however you can apply the signed
char * typemaps instead:
%include <typemaps.i>
%apply signed char *INPUT {char *input};
void f(char *input);
*/
%define INPUT_TYPEMAP(TYPE, GOTYPE)
%typemap(gotype) TYPE *INPUT, TYPE &INPUT "GOTYPE"
%typemap(in) TYPE *INPUT
%{ $1 = ($1_ltype)&$input; %}
%typemap(in) TYPE &INPUT
%{ $1 = ($1_ltype)$input; %}
%typemap(out) TYPE *INPUT, TYPE &INPUT ""
%typemap(freearg) TYPE *INPUT, TYPE &INPUT ""
%typemap(argout) TYPE *INPUT, TYPE &INPUT ""
// %typemap(typecheck) TYPE *INPUT = TYPE;
// %typemap(typecheck) TYPE &INPUT = TYPE;
%enddef
INPUT_TYPEMAP(bool, bool);
INPUT_TYPEMAP(signed char, int8);
INPUT_TYPEMAP(char, byte);
INPUT_TYPEMAP(unsigned char, byte);
INPUT_TYPEMAP(short, int16);
INPUT_TYPEMAP(unsigned short, uint16);
INPUT_TYPEMAP(int, int);
INPUT_TYPEMAP(unsigned int, uint);
INPUT_TYPEMAP(long, int64);
INPUT_TYPEMAP(unsigned long, uint64);
INPUT_TYPEMAP(long long, int64);
INPUT_TYPEMAP(unsigned long long, uint64);
INPUT_TYPEMAP(float, float32);
INPUT_TYPEMAP(double, float64);
#undef INPUT_TYPEMAP
// OUTPUT typemaps. These typemaps are used for parameters that
// are output only. An array replaces the c pointer or reference parameter.
// The output value is returned in this array passed in.
/*
OUTPUT typemaps
---------------
The following typemaps can be applied to turn a pointer or reference
into an "output" value. When calling a function, no input value would
be given for a parameter, but an output value would be returned. This
works by a Go slice being passed as a parameter where a c pointer or
reference is required. As with any Go function, the array is passed
by reference so that any modifications to the array will be picked up
in the calling function. Note that the array passed in MUST have at
least one element, but as the c function does not require any input,
the value can be set to anything.
bool *OUTPUT, bool &OUTPUT
signed char *OUTPUT, signed char &OUTPUT
unsigned char *OUTPUT, unsigned char &OUTPUT
short *OUTPUT, short &OUTPUT
unsigned short *OUTPUT, unsigned short &OUTPUT
int *OUTPUT, int &OUTPUT
unsigned int *OUTPUT, unsigned int &OUTPUT
long *OUTPUT, long &OUTPUT
unsigned long *OUTPUT, unsigned long &OUTPUT
long long *OUTPUT, long long &OUTPUT
unsigned long long *OUTPUT, unsigned long long &OUTPUT
float *OUTPUT, float &OUTPUT
double *OUTPUT, double &OUTPUT
For example, suppose you were trying to wrap the modf() function in the
C math library which splits x into integral and fractional parts (and
returns the integer part in one of its parameters):
double modf(double x, double *ip);
You could wrap it with SWIG as follows :
%include <typemaps.i>
double modf(double x, double *OUTPUT);
or you can use the %apply directive :
%include <typemaps.i>
%apply double *OUTPUT { double *ip };
double modf(double x, double *ip);
The Go output of the function would be the function return value and the
value in the single element array. In Go you would use it like this:
ptr := []float64{0.0}
fraction := modulename.Modf(5.0,ptr)
There are no char *OUTPUT typemaps, however you can apply the signed
char * typemaps instead:
%include <typemaps.i>
%apply signed char *OUTPUT {char *output};
void f(char *output);
*/
%define OUTPUT_TYPEMAP(TYPE, GOTYPE)
%typemap(gotype) TYPE *OUTPUT, TYPE &OUTPUT %{[]GOTYPE%}
%typemap(in) TYPE *OUTPUT($*1_ltype temp)
{
if ($input.len == 0) {
_swig_gopanic("array must contain at least 1 element");
}
$1 = &temp;
}
%typemap(in) TYPE &OUTPUT($*1_ltype temp)
{
if ($input->len == 0) {
_swig_gopanic("array must contain at least 1 element");
}
$1 = &temp;
}
%typemap(out) TYPE *OUTPUT, TYPE &OUTPUT ""
%typemap(freearg) TYPE *OUTPUT, TYPE &OUTPUT ""
%typemap(argout) TYPE *OUTPUT
{
TYPE* a = (TYPE *) $input.array;
a[0] = temp$argnum;
}
%typemap(argout) TYPE &OUTPUT
{
TYPE* a = (TYPE *) $input->array;
a[0] = temp$argnum;
}
%enddef
OUTPUT_TYPEMAP(bool, bool);
OUTPUT_TYPEMAP(signed char, int8);
OUTPUT_TYPEMAP(char, byte);
OUTPUT_TYPEMAP(unsigned char, byte);
OUTPUT_TYPEMAP(short, int16);
OUTPUT_TYPEMAP(unsigned short, uint16);
OUTPUT_TYPEMAP(int, int);
OUTPUT_TYPEMAP(unsigned int, uint);
OUTPUT_TYPEMAP(long, int64);
OUTPUT_TYPEMAP(unsigned long, uint64);
OUTPUT_TYPEMAP(long long, int64);
OUTPUT_TYPEMAP(unsigned long long, uint64);
OUTPUT_TYPEMAP(float, float32);
OUTPUT_TYPEMAP(double, float64);
#undef OUTPUT_TYPEMAP
/*
INOUT typemaps
--------------
Mappings for a parameter that is both an input and an output parameter
The following typemaps can be applied to make a function parameter both
an input and output value. This combines the behavior of both the
"INPUT" and "OUTPUT" typemaps described earlier. Output values are
returned as an element in a Go slice.
bool *INOUT, bool &INOUT
signed char *INOUT, signed char &INOUT
unsigned char *INOUT, unsigned char &INOUT
short *INOUT, short &INOUT
unsigned short *INOUT, unsigned short &INOUT
int *INOUT, int &INOUT
unsigned int *INOUT, unsigned int &INOUT
long *INOUT, long &INOUT
unsigned long *INOUT, unsigned long &INOUT
long long *INOUT, long long &INOUT
unsigned long long *INOUT, unsigned long long &INOUT
float *INOUT, float &INOUT
double *INOUT, double &INOUT
For example, suppose you were trying to wrap the following function :
void neg(double *x) {
*x = -(*x);
}
You could wrap it with SWIG as follows :
%include <typemaps.i>
void neg(double *INOUT);
or you can use the %apply directive :
%include <typemaps.i>
%apply double *INOUT { double *x };
void neg(double *x);
This works similarly to C in that the mapping directly modifies the
input value - the input must be an array with a minimum of one element.
The element in the array is the input and the output is the element in
the array.
x := []float64{5.0}
Neg(x);
The implementation of the OUTPUT and INOUT typemaps is different to
other languages in that other languages will return the output value
as part of the function return value. This difference is due to Go
being a typed language.
There are no char *INOUT typemaps, however you can apply the signed
char * typemaps instead:
%include <typemaps.i>
%apply signed char *INOUT {char *inout};
void f(char *inout);
*/
%define INOUT_TYPEMAP(TYPE, GOTYPE)
%typemap(gotype) TYPE *INOUT, TYPE &INOUT %{[]GOTYPE%}
%typemap(in) TYPE *INOUT {
if ($input.len == 0) {
_swig_gopanic("array must contain at least 1 element");
}
$1 = ($1_ltype) $input.array;
}
%typemap(in) TYPE &INOUT {
if ($input->len == 0) {
_swig_gopanic("array must contain at least 1 element");
}
$1 = ($1_ltype) $input->array;
}
%typemap(out) TYPE *INOUT, TYPE &INOUT ""
%typemap(freearg) TYPE *INOUT, TYPE &INOUT ""
%typemap(argout) TYPE *INOUT, TYPE &INOUT ""
%enddef
INOUT_TYPEMAP(bool, bool);
INOUT_TYPEMAP(signed char, int8);
INOUT_TYPEMAP(char, byte);
INOUT_TYPEMAP(unsigned char, byte);
INOUT_TYPEMAP(short, int16);
INOUT_TYPEMAP(unsigned short, uint16);
INOUT_TYPEMAP(int, int);
INOUT_TYPEMAP(unsigned int, uint);
INOUT_TYPEMAP(long, int64);
INOUT_TYPEMAP(unsigned long, uint64);
INOUT_TYPEMAP(long long, int64);
INOUT_TYPEMAP(unsigned long long, uint64);
INOUT_TYPEMAP(float, float32);
INOUT_TYPEMAP(double, float64);
#undef INOUT_TYPEMAP

View file

@ -3,12 +3,6 @@
;;;*
;;;* This file contains generic SWIG GOOPS classes for generated
;;;* GOOPS file support
;;;*
;;;* Copyright (C) 2003 John Lenz (jelenz@wisc.edu)
;;;* Copyright (C) 2004 Matthias Koeppe (mkoeppe@mail.math.uni-magdeburg.de)
;;;*
;;;* This file may be freely redistributed without license or fee provided
;;;* this copyright message remains intact.
;;;************************************************************************
(define-module (Swig swigrun))

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* cplusplus.i
*
* SWIG typemaps for C++

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* guile.i
*
* SWIG Configuration File for Guile.

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* guile_gh.swg
*
* This SWIG interface file is processed if the Guile module is run

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* guile_gh_run.swg
*
* Guile GH runtime file

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* guile_scm.swg
*
* This SWIG interface file is processed if the Guile module is run

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* guile_scm_run.swg
* ----------------------------------------------------------------------------- */

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* guilemain.i
*
* The main functions for a user augmented guile

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* interpreter.i
*
* SWIG file for a simple Guile interpreter

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* list_vector.i
*
* Guile typemaps for converting between arrays and Scheme lists or vectors

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* pointer-in-out.i
*
* Guile typemaps for passing pointers indirectly

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* ports.i
*
* Guile typemaps for handling ports

View file

@ -1,7 +1,4 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* std_common.i
*
* SWIG typemaps for STL - common utilities

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