Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

329 lines
16 KiB

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