support for asymmetric type marshalling - added out attribute for ctype, imtype and cstype typemaps
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7172 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
9752bc2b97
commit
5b0b80a964
2 changed files with 50 additions and 6 deletions
|
|
@ -162,6 +162,40 @@ $jnicall -> $imcall
|
|||
</pre></div>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<p>
|
||||
The intermediary classname has <tt>PINVOKE</tt> appended after the module name instead of <tt>JNI</tt>, for example <tt>modulenamePINVOKE</tt>.
|
||||
</p>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<p>
|
||||
Support for asymmetric type marshalling. The 'ctype', 'imtype' and 'cstype' typemaps support an optional <tt>out</tt> attribute which is used for output types.
|
||||
If this typemap attribute is specified, then the type specified in the attribute is used for output types.
|
||||
the type specified in the typemap itself is used for the input type.
|
||||
If this typemap attribute is not specified, then the type used for both input and output is the type specified in the typemap.
|
||||
An example shows that <tt>char *</tt> could be marshalled in different ways,
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
%typemap(imtype, out="IntPtr") char * "string"
|
||||
char * function(char *);
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
The output type is thus IntPtr and the input type is string. The resulting intermediary C# code is:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
public static extern IntPtr function(string jarg1);
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
|
|
@ -171,10 +205,6 @@ The special variable will get translated into the value specified by the <tt>-dl
|
|||
if specified, otherwise it is equivalent to the <b>$module</b> special variable.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The intermediary classname has <tt>PINVOKE</tt> appended after the module name instead of <tt>JNI</tt>, for example <tt>modulenamePINVOKE</tt>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The directory <tt>Examples/csharp</tt> has a number of simple examples.
|
||||
Visual Studio .NET 2003 solution and project files are available for compiling with the Microsoft .NET C# compiler on Windows.
|
||||
|
|
|
|||
|
|
@ -482,6 +482,9 @@ class CSHARP : public Language {
|
|||
|
||||
/* Get return types */
|
||||
if ((tm = Swig_typemap_lookup_new("ctype",n,"",0))) {
|
||||
String *ctypeout = Getattr(n,"tmap:ctype:out"); // the type in the ctype typemap's out attribute overrides the type in the typemap
|
||||
if (ctypeout)
|
||||
tm = ctypeout;
|
||||
Printf(c_return_type,"%s", tm);
|
||||
} else {
|
||||
Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number,
|
||||
|
|
@ -489,6 +492,9 @@ class CSHARP : public Language {
|
|||
}
|
||||
|
||||
if ((tm = Swig_typemap_lookup_new("imtype",n,"",0))) {
|
||||
String *imtypeout = Getattr(n,"tmap:imtype:out"); // the type in the imtype typemap's out attribute overrides the type in the typemap
|
||||
if (imtypeout)
|
||||
tm = imtypeout;
|
||||
Printf(im_return_type,"%s", tm);
|
||||
} else {
|
||||
Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number,
|
||||
|
|
@ -1060,6 +1066,9 @@ class CSHARP : public Language {
|
|||
bool classname_substituted_flag = false;
|
||||
|
||||
if ((tm = Swig_typemap_lookup_new("cstype",n,"",0))) {
|
||||
String *cstypeout = Getattr(n,"tmap:cstype:out"); // the type in the cstype typemap's out attribute overrides the type in the typemap
|
||||
if (cstypeout)
|
||||
tm = cstypeout;
|
||||
classname_substituted_flag = substituteClassname(t, tm);
|
||||
Printf(return_type, "%s", tm);
|
||||
} else {
|
||||
|
|
@ -1513,6 +1522,9 @@ class CSHARP : public Language {
|
|||
if ((tm = Swig_typemap_lookup_new("cstype",n,"",0))) {
|
||||
// Note that in the case of polymorphic (covariant) return types, the method's return type is changed to be the base of the C++ return type
|
||||
SwigType *virtualtype = Getattr(n,"virtual:type");
|
||||
String *cstypeout = Getattr(n,"tmap:cstype:out"); // the type in the cstype typemap's out attribute overrides the type in the typemap
|
||||
if (cstypeout)
|
||||
tm = cstypeout;
|
||||
substituteClassname(virtualtype ? virtualtype : t, tm);
|
||||
Printf(return_type, "%s", tm);
|
||||
if (virtualtype)
|
||||
|
|
@ -1869,8 +1881,7 @@ class CSHARP : public Language {
|
|||
|
||||
String *getOverloadedName(Node *n) {
|
||||
|
||||
/* Although PInvoke functions are designed to handle overloaded functions,
|
||||
* a C# IntPtr is used for all classes in the SWIG intermediary class.
|
||||
/* A C# HandleRef is used for all classes in the SWIG intermediary class.
|
||||
* The intermediary class methods are thus mangled when overloaded to give
|
||||
* a unique name. */
|
||||
String *overloaded_name = NewStringf("%s", Getattr(n,"sym:name"));
|
||||
|
|
@ -1914,6 +1925,9 @@ class CSHARP : public Language {
|
|||
|
||||
/* Get return types */
|
||||
if ((tm = Swig_typemap_lookup_new("cstype",n,"",0))) {
|
||||
String *cstypeout = Getattr(n,"tmap:cstype:out"); // the type in the cstype typemap's out attribute overrides the type in the typemap
|
||||
if (cstypeout)
|
||||
tm = cstypeout;
|
||||
substituteClassname(t, tm);
|
||||
Printf(return_type, "%s", tm);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue