From 245b8a0b344dce99e24c13a01da56fd9fafea9b6 Mon Sep 17 00:00:00 2001 From: Vladimir Kalinin Date: Fri, 11 Jan 2013 21:46:40 +0400 Subject: Documentation for csdirectorin 'pre', 'post' and 'terminator' support. --- Doc/Manual/CSharp.html | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'Doc/Manual') 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 $null to expand into for wrapped functions that return non-void. Normally the default value of 0 is used. For example this is needed if you change the return type to void:

-
 %typemap(ctype) Status "void"
 %typemap(out, null="") Status { ... }
 
+

+The "pre" and "post" attributes in "csdirectorin" typemap act like the same attributes in "csin" typemap. + For example if we modify Date marshalling example like this: +

+class CDate {
+...
+  void setYear(int);
+  void setMonth(int);
+  void setDay(int);
+};
+struct Action {
+virtual void someCallback(CDate& date);
+...
+};
+
+and declare %feature ("director") for the Action class, we would have to define additional +marshaling rules for CDate. Director typemap may look like this: +
+%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"
+
+The generated proxy class code will then contain the following wrapper for calling user-overloaded someCallback(): +
+...
+  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);
+    }
+  }
+...
+
+Pay special attention to the memory management issues, using these attributes. +

-- cgit v1.2.3