summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2004-10-27 20:53:05 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2004-10-27 20:53:05 +0000
commit684aa69c65d296efcd0e38db7d636ab8cc01a822 (patch)
tree71f9ddebf21352dbf46b287dffa4a26a0e240a54
parent2b477d8899cd5548637304db14ec66310952b5df (diff)
downloadswig-684aa69c65d296efcd0e38db7d636ab8cc01a822.tar.gz
C# INOUT, INPUT, OUTPUT typemaps
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6533 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r--Lib/csharp/typemaps.i316
-rw-r--r--Lib/swig.swg15
2 files changed, 266 insertions, 65 deletions
diff --git a/Lib/csharp/typemaps.i b/Lib/csharp/typemaps.i
index f40d9d8aa..d211d6431 100644
--- a/Lib/csharp/typemaps.i
+++ b/Lib/csharp/typemaps.i
@@ -1,66 +1,254 @@
+//
+// SWIG Typemap library
+// C# implementation
+//
-/* These typemaps will eventually probably maybe make their way into named typemaps
- * OUTPUT * and OUTPUT & as they currently break functions that return a pointer or
- * reference. */
-
-%typemap(ctype) bool *, bool & "bool *"
-%typemap(ctype) char & "char *"
-%typemap(ctype) signed char *, signed char & "signed char *"
-%typemap(ctype) unsigned char *, unsigned char & "unsigned char *"
-%typemap(ctype) short *, short & "short *"
-%typemap(ctype) unsigned short *, unsigned short & "unsigned short *"
-%typemap(ctype) int *, int & "int *"
-%typemap(ctype) unsigned int *, unsigned int & "unsigned int *"
-%typemap(ctype) long *, long & "long *"
-%typemap(ctype) unsigned long *, unsigned long & "unsigned long *"
-%typemap(ctype) long long *, long long & "long long *"
-%typemap(ctype) unsigned long long *, unsigned long long & "unsigned long long *"
-%typemap(ctype) float *, float & "float *"
-%typemap(ctype) double *, double & "double *"
-
-%typemap(imtype) bool *, bool & "ref bool"
-%typemap(imtype) char & "ref char"
-%typemap(imtype) signed char *, signed char & "ref sbyte"
-%typemap(imtype) unsigned char *, unsigned char & "ref byte"
-%typemap(imtype) short *, short & "ref short"
-%typemap(imtype) unsigned short *, unsigned short & "ref ushort"
-%typemap(imtype) int *, int & "ref int"
-%typemap(imtype) unsigned int *, unsigned int & "ref uint"
-%typemap(imtype) long *, long & "ref int"
-%typemap(imtype) unsigned long *, unsigned long & "ref uint"
-%typemap(imtype) long long *, long long & "ref long"
-%typemap(imtype) unsigned long long *, unsigned long long & "ref ulong"
-%typemap(imtype) float *, float & "ref float"
-%typemap(imtype) double *, double & "ref double"
-
-%typemap(cstype) bool *, bool & "ref bool"
-%typemap(cstype) char & "ref char"
-%typemap(cstype) signed char *, signed char & "ref sbyte"
-%typemap(cstype) unsigned char *, unsigned char & "ref byte"
-%typemap(cstype) short *, short & "ref short"
-%typemap(cstype) unsigned short *, unsigned short & "ref ushort"
-%typemap(cstype) int *, int & "ref int"
-%typemap(cstype) unsigned int *, unsigned int & "ref uint"
-%typemap(cstype) long *, long & "ref int"
-%typemap(cstype) unsigned long *, unsigned long & "ref uint"
-%typemap(cstype) long long *, long long & "ref long"
-%typemap(cstype) unsigned long long *, unsigned long long & "ref ulong"
-%typemap(cstype) float *, float & "ref float"
-%typemap(cstype) double *, double & "ref double"
-
-%typemap(csin) bool *, bool &,
- char &,
- signed char *, signed char &,
- unsigned char *, unsigned char &,
- short *, short &,
- unsigned short *, unsigned short &,
- int *, int &,
- unsigned int *, unsigned int &,
- long *, long &,
- unsigned long *, unsigned long &,
- long long *, long long &,
- unsigned long long *, unsigned long long &,
- float *, float &,
- double *, double &
- "ref $csinput"
+// ------------------------------------------------------------------------
+// Pointer and reference handling
+//
+// 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
+are mapped to a C# 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 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(csin) TYPE *INPUT, TYPE &INPUT "$csinput"
+
+%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)
+INPUT_TYPEMAP(signed char, signed char, sbyte)
+INPUT_TYPEMAP(unsigned char, unsigned char, byte)
+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, int)
+INPUT_TYPEMAP(unsigned long, unsigned long, uint)
+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)
+
+#undef INPUT_TYPEMAP
+
+/*
+OUTPUT typemaps
+---------------
+
+These typemaps are used for pointer/reference parameters that are output only and
+are mapped to a C# 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 C#, 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 C# output of the function would be the function return value and the
+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(csin) TYPE *OUTPUT, TYPE &OUTPUT "out $csinput"
+
+%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)
+OUTPUT_TYPEMAP(signed char, signed char, sbyte, INT8_PTR)
+OUTPUT_TYPEMAP(unsigned char, unsigned char, byte, 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, int, INT32_PTR)
+OUTPUT_TYPEMAP(unsigned long, unsigned long, uint, 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)
+
+#undef OUTPUT_TYPEMAP
+
+
+/*
+INOUT typemaps
+--------------
+
+These typemaps are for pointer/reference parameters that are both input and
+output and are mapped to a C# 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 C#, 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 C# output of the function would be the new value returned by the
+reference parameter. In C# you would use it like this:
+
+
+ double x = 5.0;
+ neg(ref 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, 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(csin) TYPE *INOUT, TYPE &INOUT "ref $csinput"
+
+%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, sbyte, INT8_PTR)
+INOUT_TYPEMAP(unsigned char, unsigned char, byte, 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, int, INT32_PTR)
+INOUT_TYPEMAP(unsigned long, unsigned long, uint, 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)
+
+#undef INOUT_TYPEMAP
diff --git a/Lib/swig.swg b/Lib/swig.swg
index 34b6b8d6d..57a7e4929 100644
--- a/Lib/swig.swg
+++ b/Lib/swig.swg
@@ -269,7 +269,20 @@ namespace std {
%define SWIG_TYPECHECK_DOUBLE_ARRAY 1090 %enddef
%define SWIG_TYPECHECK_CHAR_ARRAY 1130 %enddef
%define SWIG_TYPECHECK_STRING_ARRAY 1140 %enddef
-%define SWIG_TYPECHECK_OBJECT_ARRAY 1150 %enddef
+%define SWIG_TYPECHECK_OBJECT_ARRAY 1150 %enddef
+
+%define SWIG_TYPECHECK_BOOL_PTR 2015 %enddef
+%define SWIG_TYPECHECK_UINT8_PTR 2020 %enddef
+%define SWIG_TYPECHECK_INT8_PTR 2025 %enddef
+%define SWIG_TYPECHECK_UINT16_PTR 2030 %enddef
+%define SWIG_TYPECHECK_INT16_PTR 2035 %enddef
+%define SWIG_TYPECHECK_UINT32_PTR 2040 %enddef
+%define SWIG_TYPECHECK_INT32_PTR 2045 %enddef
+%define SWIG_TYPECHECK_UINT64_PTR 2050 %enddef
+%define SWIG_TYPECHECK_INT64_PTR 2055 %enddef
+%define SWIG_TYPECHECK_FLOAT_PTR 2080 %enddef
+%define SWIG_TYPECHECK_DOUBLE_PTR 2090 %enddef
+%define SWIG_TYPECHECK_CHAR_PTR 2130 %enddef
/*
* This template wrapper is used to handle C++ objects that are passed or