PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-27/SWIG/Lib/csharp/csharphead.swg

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