Director support added

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9096 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2006-05-13 23:15:37 +00:00
commit c60b129351
7 changed files with 679 additions and 12 deletions

View file

@ -85,7 +85,7 @@
%typemap(cstype) SWIGTYPE & "$csclassname"
/* pointer to a class member */
%typemap(ctype) SWIGTYPE (CLASS::*) "int"
%typemap(ctype) SWIGTYPE (CLASS::*) "void *"
%typemap(imtype, out="IntPtr") SWIGTYPE (CLASS::*) "HandleRef"
%typemap(cstype) SWIGTYPE (CLASS::*) "$csclassname"
@ -95,6 +95,12 @@
%typemap(in) bool
%{ $1 = $input ? true : false; %}
%typemap(directorout) bool
%{ $1 = $input ? true : false; %}
%typemap(csdirectorin) bool "$iminput"
%typemap(csdirectorout) bool "$cscall"
%typemap(in) char,
signed char,
unsigned char,
@ -110,6 +116,66 @@
double
%{ $1 = ($1_ltype)$input; %}
%typemap(directorout) 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(directorin) bool "$input = $1;"
%typemap(directorin) char "$input = $1;"
%typemap(directorin) signed char "$input = $1;"
%typemap(directorin) unsigned char "$input = $1;"
%typemap(directorin) short "$input = $1;"
%typemap(directorin) unsigned short "$input = $1;"
%typemap(directorin) int "$input = $1;"
%typemap(directorin) unsigned int "$input = $1;"
%typemap(directorin) long "$input = $1;"
%typemap(directorin) unsigned long "$input = $1;"
%typemap(directorin) long long "$input = $1;"
%typemap(directorin) unsigned long long "$input = $1;"
%typemap(directorin) float "$input = $1;"
%typemap(directorin) double "$input = $1;"
%typemap(csdirectorin) char,
signed char,
unsigned char,
short,
unsigned short,
int,
unsigned int,
long,
unsigned long,
long long,
unsigned long long,
float,
double
"$iminput"
%typemap(csdirectorout) char,
signed char,
unsigned char,
short,
unsigned short,
int,
unsigned int,
long,
unsigned long,
long long,
unsigned long long,
float,
double
"$cscall"
%typemap(out) bool %{ $result = $1; %}
%typemap(out) char %{ $result = $1; %}
%typemap(out) signed char %{ $result = $1; %}
@ -126,16 +192,31 @@
%typemap(out) double %{ $result = $1; %}
/* char * - treat as String */
%typemap(in) char * %{ $1 = ($1_ltype)$input; %}
%typemap(in) char * %{ $1 = $input; %}
%typemap(out) char * %{ $result = SWIG_csharp_string_callback((const char *)$1); %}
%typemap(directorout) char * %{ $1 = $input; %}
%typemap(directorin) char * %{ $input = SWIG_csharp_string_callback($1); %}
%typemap(csdirectorin) char * "$iminput"
%typemap(csdirectorout) char * "$cscall"
%typemap(out, null="") void ""
%typemap(csdirectorin) void "$iminput"
%typemap(csdirectorout) void "$cscall"
%typemap(directorin) void ""
/* primitive types by const reference */
%typemap(in) const bool & ($*1_ltype temp)
%{ temp = $input ? true : false;
$1 = &temp; %}
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const bool &
%{ static $*1_ltype temp;
temp = $input ? true : false;
$1 = &temp; %}
%typemap(csdirectorin) const bool & "$iminput"
%typemap(csdirectorout) const bool & "$cscall"
%typemap(in) const char & ($*1_ltype temp),
const signed char & ($*1_ltype temp),
const unsigned char & ($*1_ltype temp),
@ -152,6 +233,65 @@
%{ temp = ($*1_ltype)$input;
$1 = &temp; %}
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) 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 float &,
const double &
%{ static $*1_ltype temp;
temp = ($*1_ltype)$input;
$1 = &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(csdirectorin) const char & ($*1_ltype temp),
const signed char & ($*1_ltype temp),
const unsigned char & ($*1_ltype temp),
const short & ($*1_ltype temp),
const unsigned short & ($*1_ltype temp),
const int & ($*1_ltype temp),
const unsigned int & ($*1_ltype temp),
const long & ($*1_ltype temp),
const unsigned long & ($*1_ltype temp),
const long long & ($*1_ltype temp),
const float & ($*1_ltype temp),
const double & ($*1_ltype temp)
"$iminput"
%typemap(csdirectorout) const char & ($*1_ltype temp),
const signed char & ($*1_ltype temp),
const unsigned char & ($*1_ltype temp),
const short & ($*1_ltype temp),
const unsigned short & ($*1_ltype temp),
const int & ($*1_ltype temp),
const unsigned int & ($*1_ltype temp),
const long & ($*1_ltype temp),
const unsigned long & ($*1_ltype temp),
const long long & ($*1_ltype temp),
const float & ($*1_ltype temp),
const double & ($*1_ltype temp)
"$cscall"
%typemap(out) const bool & %{ $result = *$1; %}
%typemap(out) const char & %{ $result = *$1; %}
%typemap(out) const signed char & %{ $result = *$1; %}
@ -175,6 +315,14 @@
return $null;
}
$1 = *argp; %}
%typemap(directorout) SWIGTYPE
%{ if (!$input) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Unexpected null return for type $1_type", 0);
return $null;
}
$1 = *($&1_ltype)$input; %}
%typemap(out) SWIGTYPE
#ifdef __cplusplus
%{ $result = new $1_ltype(($1_ltype &)$1); %}
@ -186,6 +334,11 @@
}
#endif
%typemap(directorin) SWIGTYPE
%{ $input = (void *)&$1; %}
%typemap(csdirectorin) SWIGTYPE "new $&csclassname($iminput, false)"
%typemap(csdirectorout) SWIGTYPE "$&csclassname.getCPtr($cscall).Handle"
/* Generic pointers and references */
%typemap(in) SWIGTYPE * %{ $1 = ($1_ltype)$input; %}
%typemap(in) SWIGTYPE (CLASS::*) %{ $1 = *($&1_ltype)&$input; %}
@ -195,8 +348,23 @@
return $null;
} %}
%typemap(out) SWIGTYPE *, SWIGTYPE & %{ $result = (void *)$1; %}
%typemap(out) SWIGTYPE (CLASS::*) %{ *($&1_ltype)&$result = $1; %}
%typemap(out) SWIGTYPE (CLASS::*) %{ $result = (void *)&$1; %}
%typemap(directorout) SWIGTYPE *, SWIGTYPE (CLASS::*)
%{ $1 = ($1_ltype)$input; %}
%typemap(directorin) SWIGTYPE *, SWIGTYPE (CLASS::*)
%{ $input = ($1_ltype) $1; %}
%typemap(directorout) SWIGTYPE &
%{ if (!$input) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Unexpected null return for type $1_type", 0);
return $null;
}
$1 = ($1_ltype)$input; %}
%typemap(directorin) SWIGTYPE &
%{ $input = ($1_ltype) &$1; %}
%typemap(csdirectorin) SWIGTYPE *, SWIGTYPE (CLASS::*), SWIGTYPE & "new $csclassname($iminput, false)"
%typemap(csdirectorout) SWIGTYPE *, SWIGTYPE (CLASS::*), SWIGTYPE & "$csclassname.getCPtr($cscall).Handle"
/* Default array handling */
%typemap(in) SWIGTYPE [] %{ $1 = ($1_ltype)$input; %}
@ -206,6 +374,12 @@
%typemap(in) char[ANY], char[] %{ $1 = $input; %}
%typemap(out) char[ANY], char[] %{ $result = SWIG_csharp_string_callback($1); %}
%typemap(directorout) char[ANY], char[] %{ $1 = $input; %}
%typemap(directorin) char[ANY], char[] %{ $input = SWIG_csharp_string_callback($1); %}
%typemap(csdirectorin) char[ANY], char[] "$iminput"
%typemap(csdirectorout) char[ANY], char[] "$cscall"
/* Typecheck typemaps - The purpose of these is merely to issue a warning for overloaded C++ functions
* that cannot be overloaded in C# as more than one C++ type maps to a single C# type */
@ -609,7 +783,7 @@
}
%}
%typemap(csconstruct, excode=SWIGEXCODE) SWIGTYPE %{: this($imcall, true) {$excode
%typemap(csconstruct, excode=SWIGEXCODE,directorconnect="\n SwigDirectorConnect();") SWIGTYPE %{: this($imcall, true) {$excode$directorconnect
}
%}
@ -632,6 +806,12 @@
base.Dispose();
}
%typemap(directordisconnect, methodname="swigDirectorDisconnect") SWIGTYPE %{
protected void $methodname() {
swigCMemOwn = false;
$imcall;
}
%}
/* C# specific directives */
#define %csconst(flag) %feature("cs:const","flag")

View file

@ -18,6 +18,13 @@
$1 = &temp; %}
%typemap(out) const enum SWIGTYPE & %{ $result = *$1; %}
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE &
%{ static $*1_ltype temp = ($*1_ltype)$input;
$1 = &temp; %}
%typemap(directorin) const enum SWIGTYPE & "$input = $1_name;"
%typemap(csdirectorin) const enum SWIGTYPE & "($*csclassname)$iminput"
%typemap(csdirectorout) const enum SWIGTYPE & "(int)$cscall"
%typecheck(SWIG_TYPECHECK_POINTER) const enum SWIGTYPE & ""
%typemap(throws, canthrow=1) const enum SWIGTYPE &
@ -46,6 +53,11 @@
%typemap(in) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}
%typemap(out) enum SWIGTYPE %{ $result = $1; %}
%typemap(directorout) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}
%typemap(directorin) enum SWIGTYPE "$input = $1;"
%typemap(csdirectorin) enum SWIGTYPE "($csclassname)$iminput"
%typemap(csdirectorout) enum SWIGTYPE "(int)$cscall"
%typecheck(SWIG_TYPECHECK_POINTER) enum SWIGTYPE ""
%typemap(throws, canthrow=1) enum SWIGTYPE

View file

@ -20,6 +20,13 @@
$1 = &temp; %}
%typemap(out) const enum SWIGTYPE & %{ $result = *$1; %}
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE &
%{ static $*1_ltype temp = ($*1_ltype)$input;
$1 = &temp; %}
%typemap(directorin) const enum SWIGTYPE & "$input = $1_name;"
%typemap(csdirectorin) const enum SWIGTYPE & "$iminput"
%typemap(csdirectorout) const enum SWIGTYPE & "$cscall"
%typecheck(SWIG_TYPECHECK_INT32) const enum SWIGTYPE & ""
%typemap(throws, canthrow=1) const enum SWIGTYPE &
@ -48,6 +55,11 @@
%typemap(in) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}
%typemap(out) enum SWIGTYPE %{ $result = $1; %}
%typemap(directorout) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}
%typemap(directorin) enum SWIGTYPE "$input = $1;"
%typemap(csdirectorin) enum SWIGTYPE "$iminput"
%typemap(csdirectorout) enum SWIGTYPE "$cscall"
%typecheck(SWIG_TYPECHECK_INT32) enum SWIGTYPE ""
%typemap(throws, canthrow=1) enum SWIGTYPE

View file

@ -19,6 +19,13 @@
$1 = &temp; %}
%typemap(out) const enum SWIGTYPE & %{ $result = *$1; %}
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE &
%{ static $*1_ltype temp = ($*1_ltype)$input;
$1 = &temp; %}
%typemap(directorin) const enum SWIGTYPE & "$input = $1_name;"
%typemap(csdirectorin) const enum SWIGTYPE & "$*csclassname.swigToEnum($iminput)"
%typemap(csdirectorout) const enum SWIGTYPE & "$cscall.swigValue"
%typecheck(SWIG_TYPECHECK_POINTER) const enum SWIGTYPE & ""
%typemap(throws, canthrow=1) const enum SWIGTYPE &
@ -47,6 +54,11 @@
%typemap(in) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}
%typemap(out) enum SWIGTYPE %{ $result = $1; %}
%typemap(directorout) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}
%typemap(directorin) enum SWIGTYPE "$input = $1;"
%typemap(csdirectorin) enum SWIGTYPE "$csclassname.swigToEnum($iminput)"
%typemap(csdirectorout) enum SWIGTYPE "$cscall.swigValue"
%typecheck(SWIG_TYPECHECK_POINTER) enum SWIGTYPE ""
%typemap(throws, canthrow=1) enum SWIGTYPE

View file

@ -6,7 +6,7 @@
*
* Typemaps for std::string and const std::string&
* These are mapped to a C# 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 &};
@ -26,6 +26,8 @@ class string;
%typemap(ctype) string "char *"
%typemap(imtype) string "string"
%typemap(cstype) string "string"
%typemap(csdirectorin) string "$iminput"
%typemap(csdirectorout) string "$cscall"
%typemap(in, canthrow=1) string
%{ if (!$input) {
@ -35,6 +37,15 @@ class string;
$1 = std::string($input); %}
%typemap(out) string %{ $result = SWIG_csharp_string_callback($1.c_str()); %}
%typemap(directorout, canthrow=1) string
%{ if (!$input) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
return $null;
}
$1 = std::string($input); %}
%typemap(directorin) string %{ $input = SWIG_csharp_string_callback($1.c_str()); %}
%typemap(csin) string "$csinput"
%typemap(csout, excode=SWIGEXCODE) string {
string ret = $imcall;$excode
@ -61,6 +72,8 @@ class string;
%typemap(ctype) const string & "char *"
%typemap(imtype) const string & "string"
%typemap(cstype) const string & "string"
%typemap(csdirectorin) const string & "$iminput"
%typemap(csdirectorout) const string & "$cscall"
%typemap(in, canthrow=1) const string &
%{ if (!$input) {
@ -77,6 +90,17 @@ class string;
return ret;
}
%typemap(directorout, canthrow=1, warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const string &
%{ if (!$input) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
return $null;
}
/* possible thread/reentrant code problem */
static std::string $1_str($input);
$1 = &$1_str; %}
%typemap(directorin) const string & %{ $input = SWIG_csharp_string_callback($1->c_str()); %}
%typemap(csvarin, excode=SWIGEXCODE2) const string & %{
set {
$imcall;$excode

View file

@ -15,7 +15,7 @@ INPUT typemaps
--------------
These typemaps are used for pointer/reference parameters that are input only
are mapped to a C# input parameter.
and 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,
@ -62,10 +62,21 @@ In C# you could then use it like this:
%typemap(imtype) TYPE *INPUT, TYPE &INPUT "CSTYPE"
%typemap(cstype) 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
%{ $1 = ($1_ltype)&$input; %}
%typemap(directorin) TYPE &INPUT
%{ $input = (CTYPE *)$1; %}
%typemap(directorin) TYPE *INPUT
%{ $input = (CTYPE *)$1; %}
%typemap(typecheck) TYPE *INPUT = TYPE;
%typemap(typecheck) TYPE &INPUT = TYPE;
%enddef
@ -143,10 +154,24 @@ value returned in the second output parameter. In C# you would use it like this:
%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(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
@ -228,10 +253,23 @@ of the function return value.
%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(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