Home | History | Annotate | Download | only in csharp
      1 /* -----------------------------------------------------------------------------
      2  * csharphead.swg
      3  *
      4  * Support code for exceptions if the SWIG_CSHARP_NO_EXCEPTION_HELPER is not defined
      5  * Support code for strings if the SWIG_CSHARP_NO_STRING_HELPER is not defined
      6  * ----------------------------------------------------------------------------- */
      7 
      8 %insert(runtime) %{
      9 #include <stdlib.h>
     10 #include <string.h>
     11 #include <stdio.h>
     12 %}
     13 
     14 #if !defined(SWIG_CSHARP_NO_EXCEPTION_HELPER)
     15 %insert(runtime) %{
     16 /* Support for throwing C# exceptions from C/C++. There are two types:
     17  * Exceptions that take a message and ArgumentExceptions that take a message and a parameter name. */
     18 typedef enum {
     19   SWIG_CSharpApplicationException,
     20   SWIG_CSharpArithmeticException,
     21   SWIG_CSharpDivideByZeroException,
     22   SWIG_CSharpIndexOutOfRangeException,
     23   SWIG_CSharpInvalidCastException,
     24   SWIG_CSharpInvalidOperationException,
     25   SWIG_CSharpIOException,
     26   SWIG_CSharpNullReferenceException,
     27   SWIG_CSharpOutOfMemoryException,
     28   SWIG_CSharpOverflowException,
     29   SWIG_CSharpSystemException
     30 } SWIG_CSharpExceptionCodes;
     31 
     32 typedef enum {
     33   SWIG_CSharpArgumentException,
     34   SWIG_CSharpArgumentNullException,
     35   SWIG_CSharpArgumentOutOfRangeException
     36 } SWIG_CSharpExceptionArgumentCodes;
     37 
     38 typedef void (SWIGSTDCALL* SWIG_CSharpExceptionCallback_t)(const char *);
     39 typedef void (SWIGSTDCALL* SWIG_CSharpExceptionArgumentCallback_t)(const char *, const char *);
     40 
     41 typedef struct {
     42   SWIG_CSharpExceptionCodes code;
     43   SWIG_CSharpExceptionCallback_t callback;
     44 } SWIG_CSharpException_t;
     45 
     46 typedef struct {
     47   SWIG_CSharpExceptionArgumentCodes code;
     48   SWIG_CSharpExceptionArgumentCallback_t callback;
     49 } SWIG_CSharpExceptionArgument_t;
     50 
     51 static SWIG_CSharpException_t SWIG_csharp_exceptions[] = {
     52   { SWIG_CSharpApplicationException, NULL },
     53   { SWIG_CSharpArithmeticException, NULL },
     54   { SWIG_CSharpDivideByZeroException, NULL },
     55   { SWIG_CSharpIndexOutOfRangeException, NULL },
     56   { SWIG_CSharpInvalidCastException, NULL },
     57   { SWIG_CSharpInvalidOperationException, NULL },
     58   { SWIG_CSharpIOException, NULL },
     59   { SWIG_CSharpNullReferenceException, NULL },
     60   { SWIG_CSharpOutOfMemoryException, NULL },
     61   { SWIG_CSharpOverflowException, NULL },
     62   { SWIG_CSharpSystemException, NULL }
     63 };
     64 
     65 static SWIG_CSharpExceptionArgument_t SWIG_csharp_exceptions_argument[] = {
     66   { SWIG_CSharpArgumentException, NULL },
     67   { SWIG_CSharpArgumentNullException, NULL },
     68   { SWIG_CSharpArgumentOutOfRangeException, NULL }
     69 };
     70 
     71 static void SWIGUNUSED SWIG_CSharpSetPendingException(SWIG_CSharpExceptionCodes code, const char *msg) {
     72   SWIG_CSharpExceptionCallback_t callback = SWIG_csharp_exceptions[SWIG_CSharpApplicationException].callback;
     73   if ((size_t)code < sizeof(SWIG_csharp_exceptions)/sizeof(SWIG_CSharpException_t)) {
     74     callback = SWIG_csharp_exceptions[code].callback;
     75   }
     76   callback(msg);
     77 }
     78 
     79 static void SWIGUNUSED SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpExceptionArgumentCodes code, const char *msg, const char *param_name) {
     80   SWIG_CSharpExceptionArgumentCallback_t callback = SWIG_csharp_exceptions_argument[SWIG_CSharpArgumentException].callback;
     81   if ((size_t)code < sizeof(SWIG_csharp_exceptions_argument)/sizeof(SWIG_CSharpExceptionArgument_t)) {
     82     callback = SWIG_csharp_exceptions_argument[code].callback;
     83   }
     84   callback(msg, param_name);
     85 }
     86 %}
     87 
     88 %insert(runtime) %{
     89 #ifdef __cplusplus
     90 extern "C"
     91 #endif
     92 SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionCallbacks_$module(
     93                                                 SWIG_CSharpExceptionCallback_t applicationCallback,
     94                                                 SWIG_CSharpExceptionCallback_t arithmeticCallback,
     95                                                 SWIG_CSharpExceptionCallback_t divideByZeroCallback,
     96                                                 SWIG_CSharpExceptionCallback_t indexOutOfRangeCallback,
     97                                                 SWIG_CSharpExceptionCallback_t invalidCastCallback,
     98                                                 SWIG_CSharpExceptionCallback_t invalidOperationCallback,
     99                                                 SWIG_CSharpExceptionCallback_t ioCallback,
    100                                                 SWIG_CSharpExceptionCallback_t nullReferenceCallback,
    101                                                 SWIG_CSharpExceptionCallback_t outOfMemoryCallback,
    102                                                 SWIG_CSharpExceptionCallback_t overflowCallback,
    103                                                 SWIG_CSharpExceptionCallback_t systemCallback) {
    104   SWIG_csharp_exceptions[SWIG_CSharpApplicationException].callback = applicationCallback;
    105   SWIG_csharp_exceptions[SWIG_CSharpArithmeticException].callback = arithmeticCallback;
    106   SWIG_csharp_exceptions[SWIG_CSharpDivideByZeroException].callback = divideByZeroCallback;
    107   SWIG_csharp_exceptions[SWIG_CSharpIndexOutOfRangeException].callback = indexOutOfRangeCallback;
    108   SWIG_csharp_exceptions[SWIG_CSharpInvalidCastException].callback = invalidCastCallback;
    109   SWIG_csharp_exceptions[SWIG_CSharpInvalidOperationException].callback = invalidOperationCallback;
    110   SWIG_csharp_exceptions[SWIG_CSharpIOException].callback = ioCallback;
    111   SWIG_csharp_exceptions[SWIG_CSharpNullReferenceException].callback = nullReferenceCallback;
    112   SWIG_csharp_exceptions[SWIG_CSharpOutOfMemoryException].callback = outOfMemoryCallback;
    113   SWIG_csharp_exceptions[SWIG_CSharpOverflowException].callback = overflowCallback;
    114   SWIG_csharp_exceptions[SWIG_CSharpSystemException].callback = systemCallback;
    115 }
    116 
    117 #ifdef __cplusplus
    118 extern "C"
    119 #endif
    120 SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_$module(
    121                                                 SWIG_CSharpExceptionArgumentCallback_t argumentCallback,
    122                                                 SWIG_CSharpExceptionArgumentCallback_t argumentNullCallback,
    123                                                 SWIG_CSharpExceptionArgumentCallback_t argumentOutOfRangeCallback) {
    124   SWIG_csharp_exceptions_argument[SWIG_CSharpArgumentException].callback = argumentCallback;
    125   SWIG_csharp_exceptions_argument[SWIG_CSharpArgumentNullException].callback = argumentNullCallback;
    126   SWIG_csharp_exceptions_argument[SWIG_CSharpArgumentOutOfRangeException].callback = argumentOutOfRangeCallback;
    127 }
    128 %}
    129 
    130 %pragma(csharp) imclasscode=%{
    131   protected class SWIGExceptionHelper {
    132 
    133     public delegate void ExceptionDelegate(string message);
    134     public delegate void ExceptionArgumentDelegate(string message, string paramName);
    135 
    136     static ExceptionDelegate applicationDelegate = new ExceptionDelegate(SetPendingApplicationException);
    137     static ExceptionDelegate arithmeticDelegate = new ExceptionDelegate(SetPendingArithmeticException);
    138     static ExceptionDelegate divideByZeroDelegate = new ExceptionDelegate(SetPendingDivideByZeroException);
    139     static ExceptionDelegate indexOutOfRangeDelegate = new ExceptionDelegate(SetPendingIndexOutOfRangeException);
    140     static ExceptionDelegate invalidCastDelegate = new ExceptionDelegate(SetPendingInvalidCastException);
    141     static ExceptionDelegate invalidOperationDelegate = new ExceptionDelegate(SetPendingInvalidOperationException);
    142     static ExceptionDelegate ioDelegate = new ExceptionDelegate(SetPendingIOException);
    143     static ExceptionDelegate nullReferenceDelegate = new ExceptionDelegate(SetPendingNullReferenceException);
    144     static ExceptionDelegate outOfMemoryDelegate = new ExceptionDelegate(SetPendingOutOfMemoryException);
    145     static ExceptionDelegate overflowDelegate = new ExceptionDelegate(SetPendingOverflowException);
    146     static ExceptionDelegate systemDelegate = new ExceptionDelegate(SetPendingSystemException);
    147 
    148     static ExceptionArgumentDelegate argumentDelegate = new ExceptionArgumentDelegate(SetPendingArgumentException);
    149     static ExceptionArgumentDelegate argumentNullDelegate = new ExceptionArgumentDelegate(SetPendingArgumentNullException);
    150     static ExceptionArgumentDelegate argumentOutOfRangeDelegate = new ExceptionArgumentDelegate(SetPendingArgumentOutOfRangeException);
    151 
    152     [DllImport("$dllimport", EntryPoint="SWIGRegisterExceptionCallbacks_$module")]
    153     public static extern void SWIGRegisterExceptionCallbacks_$module(
    154                                 ExceptionDelegate applicationDelegate,
    155                                 ExceptionDelegate arithmeticDelegate,
    156                                 ExceptionDelegate divideByZeroDelegate,
    157                                 ExceptionDelegate indexOutOfRangeDelegate,
    158                                 ExceptionDelegate invalidCastDelegate,
    159                                 ExceptionDelegate invalidOperationDelegate,
    160                                 ExceptionDelegate ioDelegate,
    161                                 ExceptionDelegate nullReferenceDelegate,
    162                                 ExceptionDelegate outOfMemoryDelegate,
    163                                 ExceptionDelegate overflowDelegate,
    164                                 ExceptionDelegate systemExceptionDelegate);
    165 
    166     [DllImport("$dllimport", EntryPoint="SWIGRegisterExceptionArgumentCallbacks_$module")]
    167     public static extern void SWIGRegisterExceptionCallbacksArgument_$module(
    168                                 ExceptionArgumentDelegate argumentDelegate,
    169                                 ExceptionArgumentDelegate argumentNullDelegate,
    170                                 ExceptionArgumentDelegate argumentOutOfRangeDelegate);
    171 
    172     static void SetPendingApplicationException(string message) {
    173       SWIGPendingException.Set(new System.ApplicationException(message, SWIGPendingException.Retrieve()));
    174     }
    175     static void SetPendingArithmeticException(string message) {
    176       SWIGPendingException.Set(new System.ArithmeticException(message, SWIGPendingException.Retrieve()));
    177     }
    178     static void SetPendingDivideByZeroException(string message) {
    179       SWIGPendingException.Set(new System.DivideByZeroException(message, SWIGPendingException.Retrieve()));
    180     }
    181     static void SetPendingIndexOutOfRangeException(string message) {
    182       SWIGPendingException.Set(new System.IndexOutOfRangeException(message, SWIGPendingException.Retrieve()));
    183     }
    184     static void SetPendingInvalidCastException(string message) {
    185       SWIGPendingException.Set(new System.InvalidCastException(message, SWIGPendingException.Retrieve()));
    186     }
    187     static void SetPendingInvalidOperationException(string message) {
    188       SWIGPendingException.Set(new System.InvalidOperationException(message, SWIGPendingException.Retrieve()));
    189     }
    190     static void SetPendingIOException(string message) {
    191       SWIGPendingException.Set(new System.IO.IOException(message, SWIGPendingException.Retrieve()));
    192     }
    193     static void SetPendingNullReferenceException(string message) {
    194       SWIGPendingException.Set(new System.NullReferenceException(message, SWIGPendingException.Retrieve()));
    195     }
    196     static void SetPendingOutOfMemoryException(string message) {
    197       SWIGPendingException.Set(new System.OutOfMemoryException(message, SWIGPendingException.Retrieve()));
    198     }
    199     static void SetPendingOverflowException(string message) {
    200       SWIGPendingException.Set(new System.OverflowException(message, SWIGPendingException.Retrieve()));
    201     }
    202     static void SetPendingSystemException(string message) {
    203       SWIGPendingException.Set(new System.SystemException(message, SWIGPendingException.Retrieve()));
    204     }
    205 
    206     static void SetPendingArgumentException(string message, string paramName) {
    207       SWIGPendingException.Set(new System.ArgumentException(message, paramName, SWIGPendingException.Retrieve()));
    208     }
    209     static void SetPendingArgumentNullException(string message, string paramName) {
    210       Exception e = SWIGPendingException.Retrieve();
    211       if (e != null) message = message + " Inner Exception: " + e.Message;
    212       SWIGPendingException.Set(new System.ArgumentNullException(paramName, message));
    213     }
    214     static void SetPendingArgumentOutOfRangeException(string message, string paramName) {
    215       Exception e = SWIGPendingException.Retrieve();
    216       if (e != null) message = message + " Inner Exception: " + e.Message;
    217       SWIGPendingException.Set(new System.ArgumentOutOfRangeException(paramName, message));
    218     }
    219 
    220     static SWIGExceptionHelper() {
    221       SWIGRegisterExceptionCallbacks_$module(
    222                                 applicationDelegate,
    223                                 arithmeticDelegate,
    224                                 divideByZeroDelegate,
    225                                 indexOutOfRangeDelegate,
    226                                 invalidCastDelegate,
    227                                 invalidOperationDelegate,
    228                                 ioDelegate,
    229                                 nullReferenceDelegate,
    230                                 outOfMemoryDelegate,
    231                                 overflowDelegate,
    232                                 systemDelegate);
    233 
    234       SWIGRegisterExceptionCallbacksArgument_$module(
    235                                 argumentDelegate,
    236                                 argumentNullDelegate,
    237                                 argumentOutOfRangeDelegate);
    238     }
    239   }
    240 
    241   protected static SWIGExceptionHelper swigExceptionHelper = new SWIGExceptionHelper();
    242 
    243   public class SWIGPendingException {
    244     [ThreadStatic]
    245     private static Exception pendingException = null;
    246     private static int numExceptionsPending = 0;
    247 
    248     public static bool Pending {
    249       get {
    250         bool pending = false;
    251         if (numExceptionsPending > 0)
    252           if (pendingException != null)
    253             pending = true;
    254         return pending;
    255       }
    256     }
    257 
    258     public static void Set(Exception e) {
    259       if (pendingException != null)
    260         throw new ApplicationException("FATAL: An earlier pending exception from unmanaged code was missed and thus not thrown (" + pendingException.ToString() + ")", e);
    261       pendingException = e;
    262       lock(typeof($imclassname)) {
    263         numExceptionsPending++;
    264       }
    265     }
    266 
    267     public static Exception Retrieve() {
    268       Exception e = null;
    269       if (numExceptionsPending > 0) {
    270         if (pendingException != null) {
    271           e = pendingException;
    272           pendingException = null;
    273           lock(typeof($imclassname)) {
    274             numExceptionsPending--;
    275           }
    276         }
    277       }
    278       return e;
    279     }
    280   }
    281 %}
    282 #endif // SWIG_CSHARP_NO_EXCEPTION_HELPER
    283 
    284 #if !defined(SWIG_CSHARP_NO_STRING_HELPER)
    285 %insert(runtime) %{
    286 /* Callback for returning strings to C# without leaking memory */
    287 typedef char * (SWIGSTDCALL* SWIG_CSharpStringHelperCallback)(const char *);
    288 static SWIG_CSharpStringHelperCallback SWIG_csharp_string_callback = NULL;
    289 %}
    290 
    291 %pragma(csharp) imclasscode=%{
    292   protected class SWIGStringHelper {
    293 
    294     public delegate string SWIGStringDelegate(string message);
    295     static SWIGStringDelegate stringDelegate = new SWIGStringDelegate(CreateString);
    296 
    297     [DllImport("$dllimport", EntryPoint="SWIGRegisterStringCallback_$module")]
    298     public static extern void SWIGRegisterStringCallback_$module(SWIGStringDelegate stringDelegate);
    299 
    300     static string CreateString(string cString) {
    301       return cString;
    302     }
    303 
    304     static SWIGStringHelper() {
    305       SWIGRegisterStringCallback_$module(stringDelegate);
    306     }
    307   }
    308 
    309   static protected SWIGStringHelper swigStringHelper = new SWIGStringHelper();
    310 %}
    311 
    312 %insert(runtime) %{
    313 #ifdef __cplusplus
    314 extern "C"
    315 #endif
    316 SWIGEXPORT void SWIGSTDCALL SWIGRegisterStringCallback_$module(SWIG_CSharpStringHelperCallback callback) {
    317   SWIG_csharp_string_callback = callback;
    318 }
    319 %}
    320 #endif // SWIG_CSHARP_NO_STRING_HELPER
    321 
    322 #if !defined(SWIG_CSHARP_NO_IMCLASS_STATIC_CONSTRUCTOR)
    323 // Ensure the class is not marked beforefieldinit
    324 %pragma(csharp) imclasscode=%{
    325   static $imclassname() {
    326   }
    327 %}
    328 #endif
    329 
    330 %insert(runtime) %{
    331 /* Contract support */
    332 
    333 #define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, msg, ""); return nullreturn; } else
    334 %}
    335