summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Kalinin <vkalinin@opendesign.com>2013-01-11 21:46:40 +0400
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2013-01-11 22:18:35 +0000
commit245b8a0b344dce99e24c13a01da56fd9fafea9b6 (patch)
tree02a12522c44818114b71aacb563d26a315ee1da8
parent13d9e19cdbb9c3dc6d89fc0a44a97d66051d0068 (diff)
downloadswig-245b8a0b344dce99e24c13a01da56fd9fafea9b6.tar.gz
Documentation for csdirectorin 'pre', 'post' and 'terminator' support.
-rw-r--r--Doc/Manual/CSharp.html47
1 files changed, 46 insertions, 1 deletions
diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html
index a5394eb37..1281f7973 100644
--- a/Doc/Manual/CSharp.html
+++ b/Doc/Manual/CSharp.html
@@ -197,11 +197,56 @@ csattributes C# attributes for attaching to proxy classes/enums
The "null" attribute in the "out" typemap can be specified to provide a value for <tt>$null</tt> to expand into for wrapped functions that return non-void. Normally the default value of <tt>0</tt> is used.
For example this is needed if you change the return type to void:
</p>
-
<div class="code"><pre>
%typemap(ctype) Status "void"
%typemap(out, null="") Status { ... }
</pre></div>
+<p>
+The "pre" and "post" attributes in "csdirectorin" typemap act like the same attributes in "csin" typemap.
+ For example if we modify <a href="#CSharp_date_marshalling">Date marshalling example</a> like this:
+<div class="code"><pre>
+class CDate {
+...
+ void setYear(int);
+ void setMonth(int);
+ void setDay(int);
+};
+struct Action {
+virtual void someCallback(CDate& date);
+...
+};
+</pre></div>
+and declare %feature ("director") for the Action class, we would have to define additional
+marshaling rules for CDate. Director typemap may look like this:
+<div class="code"><pre>
+%typemap(csdirectorin,
+ pre="System.DateTime temp$iminput = new System.DateTime();",
+ post="CDate temp2$iminput = new CDate($iminput, false);\n"
+ "temp2$iminput.setYear(tempdate.Year);\n"
+ "temp2$iminput.setMonth(tempdate.Month);\n"
+ "temp2$iminput.setDay(tempdate.Day);"
+ ) CDate& date "out temp$iminput"
+</pre></div>
+The generated proxy class code will then contain the following wrapper for calling user-overloaded someCallback():
+<div class="code"><pre>
+...
+ private void SwigDirectorsomeCallback(IntPtr date) {
+ System.DateTime tempdate = new System.DateTime();
+ try {
+ someCallback(out tempdate);
+ }
+ finally {
+ // we create managed wrapper around existing C reference, just for convenience
+ CDate temp2date = new CDate(date, false);
+ temp2date.setYear(tempdate.Year);
+ temp2date.setMonth(tempdate.Month);
+ temp2date.setDay(tempdate.Day);
+ }
+ }
+...
+</pre></div>
+Pay special attention to the memory management issues, using these attributes.
+</p>
</li>