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.

971 lines
34 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. * csharp.swg
  6. *
  7. * C# typemaps
  8. * ----------------------------------------------------------------------------- */
  9. %include <csharphead.swg>
  10. /* The ctype, imtype and cstype typemaps work together and so there should be one of each.
  11. * The ctype typemap contains the PInvoke type used in the PInvoke (C/C++) code.
  12. * The imtype typemap contains the C# type used in the intermediary class.
  13. * The cstype typemap contains the C# type used in the C# proxy classes, type wrapper classes and module class. */
  14. /* Fragments */
  15. %fragment("SWIG_PackData", "header") {
  16. /* Pack binary data into a string */
  17. SWIGINTERN char * SWIG_PackData(char *c, void *ptr, size_t sz) {
  18. static const char hex[17] = "0123456789abcdef";
  19. register const unsigned char *u = (unsigned char *) ptr;
  20. register const unsigned char *eu = u + sz;
  21. for (; u != eu; ++u) {
  22. register unsigned char uu = *u;
  23. *(c++) = hex[(uu & 0xf0) >> 4];
  24. *(c++) = hex[uu & 0xf];
  25. }
  26. return c;
  27. }
  28. }
  29. %fragment("SWIG_UnPackData", "header") {
  30. /* Unpack binary data from a string */
  31. SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
  32. register unsigned char *u = (unsigned char *) ptr;
  33. register const unsigned char *eu = u + sz;
  34. for (; u != eu; ++u) {
  35. register char d = *(c++);
  36. register unsigned char uu;
  37. if ((d >= '0') && (d <= '9'))
  38. uu = ((d - '0') << 4);
  39. else if ((d >= 'a') && (d <= 'f'))
  40. uu = ((d - ('a'-10)) << 4);
  41. else
  42. return (char *) 0;
  43. d = *(c++);
  44. if ((d >= '0') && (d <= '9'))
  45. uu |= (d - '0');
  46. else if ((d >= 'a') && (d <= 'f'))
  47. uu |= (d - ('a'-10));
  48. else
  49. return (char *) 0;
  50. *u = uu;
  51. }
  52. return c;
  53. }
  54. }
  55. /* Primitive types */
  56. %typemap(ctype) bool, const bool & "unsigned int"
  57. %typemap(ctype) char, const char & "char"
  58. %typemap(ctype) signed char, const signed char & "signed char"
  59. %typemap(ctype) unsigned char, const unsigned char & "unsigned char"
  60. %typemap(ctype) short, const short & "short"
  61. %typemap(ctype) unsigned short, const unsigned short & "unsigned short"
  62. %typemap(ctype) int, const int & "int"
  63. %typemap(ctype) unsigned int, const unsigned int & "unsigned int"
  64. %typemap(ctype) long, const long & "long"
  65. %typemap(ctype) unsigned long, const unsigned long & "unsigned long"
  66. %typemap(ctype) long long, const long long & "long long"
  67. %typemap(ctype) unsigned long long, const unsigned long long & "unsigned long long"
  68. %typemap(ctype) float, const float & "float"
  69. %typemap(ctype) double, const double & "double"
  70. %typemap(ctype) void "void"
  71. %typemap(imtype) bool, const bool & "bool"
  72. %typemap(imtype) char, const char & "char"
  73. %typemap(imtype) signed char, const signed char & "sbyte"
  74. %typemap(imtype) unsigned char, const unsigned char & "byte"
  75. %typemap(imtype) short, const short & "short"
  76. %typemap(imtype) unsigned short, const unsigned short & "ushort"
  77. %typemap(imtype) int, const int & "int"
  78. %typemap(imtype) unsigned int, const unsigned int & "uint"
  79. %typemap(imtype) long, const long & "int"
  80. %typemap(imtype) unsigned long, const unsigned long & "uint"
  81. %typemap(imtype) long long, const long long & "long"
  82. %typemap(imtype) unsigned long long, const unsigned long long & "ulong"
  83. %typemap(imtype) float, const float & "float"
  84. %typemap(imtype) double, const double & "double"
  85. %typemap(imtype) void "void"
  86. %typemap(cstype) bool, const bool & "bool"
  87. %typemap(cstype) char, const char & "char"
  88. %typemap(cstype) signed char, const signed char & "sbyte"
  89. %typemap(cstype) unsigned char, const unsigned char & "byte"
  90. %typemap(cstype) short, const short & "short"
  91. %typemap(cstype) unsigned short, const unsigned short & "ushort"
  92. %typemap(cstype) int, const int & "int"
  93. %typemap(cstype) unsigned int, const unsigned int & "uint"
  94. %typemap(cstype) long, const long & "int"
  95. %typemap(cstype) unsigned long, const unsigned long & "uint"
  96. %typemap(cstype) long long, const long long & "long"
  97. %typemap(cstype) unsigned long long, const unsigned long long & "ulong"
  98. %typemap(cstype) float, const float & "float"
  99. %typemap(cstype) double, const double & "double"
  100. %typemap(cstype) void "void"
  101. %typemap(ctype) char *, char[ANY], char[] "char *"
  102. %typemap(imtype) char *, char[ANY], char[] "string"
  103. %typemap(cstype) char *, char[ANY], char[] "string"
  104. /* Non primitive types */
  105. %typemap(ctype) SWIGTYPE "void *"
  106. %typemap(imtype, out="IntPtr") SWIGTYPE "HandleRef"
  107. %typemap(cstype) SWIGTYPE "$&csclassname"
  108. %typemap(ctype) SWIGTYPE [] "void *"
  109. %typemap(imtype, out="IntPtr") SWIGTYPE [] "HandleRef"
  110. %typemap(cstype) SWIGTYPE [] "$csclassname"
  111. %typemap(ctype) SWIGTYPE * "void *"
  112. %typemap(imtype, out="IntPtr") SWIGTYPE * "HandleRef"
  113. %typemap(cstype) SWIGTYPE * "$csclassname"
  114. %typemap(ctype) SWIGTYPE & "void *"
  115. %typemap(imtype, out="IntPtr") SWIGTYPE & "HandleRef"
  116. %typemap(cstype) SWIGTYPE & "$csclassname"
  117. /* pointer to a class member */
  118. %typemap(ctype) SWIGTYPE (CLASS::*) "char *"
  119. %typemap(imtype) SWIGTYPE (CLASS::*) "string"
  120. %typemap(cstype) SWIGTYPE (CLASS::*) "$csclassname"
  121. /* The following are the in and out typemaps. These are the PInvoke code generating typemaps for converting from C# to C and visa versa. */
  122. /* primitive types */
  123. %typemap(in) bool
  124. %{ $1 = $input ? true : false; %}
  125. %typemap(directorout) bool
  126. %{ $result = $input ? true : false; %}
  127. %typemap(csdirectorin) bool "$iminput"
  128. %typemap(csdirectorout) bool "$cscall"
  129. %typemap(in) char,
  130. signed char,
  131. unsigned char,
  132. short,
  133. unsigned short,
  134. int,
  135. unsigned int,
  136. long,
  137. unsigned long,
  138. long long,
  139. unsigned long long,
  140. float,
  141. double
  142. %{ $1 = ($1_ltype)$input; %}
  143. %typemap(directorout) char,
  144. signed char,
  145. unsigned char,
  146. short,
  147. unsigned short,
  148. int,
  149. unsigned int,
  150. long,
  151. unsigned long,
  152. long long,
  153. unsigned long long,
  154. float,
  155. double
  156. %{ $result = ($1_ltype)$input; %}
  157. %typemap(directorin) bool "$input = $1;"
  158. %typemap(directorin) char "$input = $1;"
  159. %typemap(directorin) signed char "$input = $1;"
  160. %typemap(directorin) unsigned char "$input = $1;"
  161. %typemap(directorin) short "$input = $1;"
  162. %typemap(directorin) unsigned short "$input = $1;"
  163. %typemap(directorin) int "$input = $1;"
  164. %typemap(directorin) unsigned int "$input = $1;"
  165. %typemap(directorin) long "$input = $1;"
  166. %typemap(directorin) unsigned long "$input = $1;"
  167. %typemap(directorin) long long "$input = $1;"
  168. %typemap(directorin) unsigned long long "$input = $1;"
  169. %typemap(directorin) float "$input = $1;"
  170. %typemap(directorin) double "$input = $1;"
  171. %typemap(csdirectorin) char,
  172. signed char,
  173. unsigned char,
  174. short,
  175. unsigned short,
  176. int,
  177. unsigned int,
  178. long,
  179. unsigned long,
  180. long long,
  181. unsigned long long,
  182. float,
  183. double
  184. "$iminput"
  185. %typemap(csdirectorout) char,
  186. signed char,
  187. unsigned char,
  188. short,
  189. unsigned short,
  190. int,
  191. unsigned int,
  192. long,
  193. unsigned long,
  194. long long,
  195. unsigned long long,
  196. float,
  197. double
  198. "$cscall"
  199. %typemap(out) bool %{ $result = $1; %}
  200. %typemap(out) char %{ $result = $1; %}
  201. %typemap(out) signed char %{ $result = $1; %}
  202. %typemap(out) unsigned char %{ $result = $1; %}
  203. %typemap(out) short %{ $result = $1; %}
  204. %typemap(out) unsigned short %{ $result = $1; %}
  205. %typemap(out) int %{ $result = $1; %}
  206. %typemap(out) unsigned int %{ $result = $1; %}
  207. %typemap(out) long %{ $result = $1; %}
  208. %typemap(out) unsigned long %{ $result = (unsigned long)$1; %}
  209. %typemap(out) long long %{ $result = $1; %}
  210. %typemap(out) unsigned long long %{ $result = $1; %}
  211. %typemap(out) float %{ $result = $1; %}
  212. %typemap(out) double %{ $result = $1; %}
  213. /* char * - treat as String */
  214. %typemap(in) char * %{ $1 = ($1_ltype)$input; %}
  215. %typemap(out) char * %{ $result = SWIG_csharp_string_callback((const char *)$1); %}
  216. %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) char * %{ $result = ($1_ltype)$input; %}
  217. %typemap(directorin) char * %{ $input = SWIG_csharp_string_callback((const char *)$1); %}
  218. %typemap(csdirectorin) char * "$iminput"
  219. %typemap(csdirectorout) char * "$cscall"
  220. %typemap(out, null="") void ""
  221. %typemap(csdirectorin) void "$iminput"
  222. %typemap(csdirectorout) void "$cscall"
  223. %typemap(directorin) void ""
  224. /* primitive types by const reference */
  225. %typemap(in) const bool & ($*1_ltype temp)
  226. %{ temp = $input ? true : false;
  227. $1 = &temp; %}
  228. %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const bool &
  229. %{ static $*1_ltype temp;
  230. temp = $input ? true : false;
  231. $result = &temp; %}
  232. %typemap(csdirectorin) const bool & "$iminput"
  233. %typemap(csdirectorout) const bool & "$cscall"
  234. %typemap(in) const char & ($*1_ltype temp),
  235. const signed char & ($*1_ltype temp),
  236. const unsigned char & ($*1_ltype temp),
  237. const short & ($*1_ltype temp),
  238. const unsigned short & ($*1_ltype temp),
  239. const int & ($*1_ltype temp),
  240. const unsigned int & ($*1_ltype temp),
  241. const long & ($*1_ltype temp),
  242. const unsigned long & ($*1_ltype temp),
  243. const long long & ($*1_ltype temp),
  244. const unsigned long long & ($*1_ltype temp),
  245. const float & ($*1_ltype temp),
  246. const double & ($*1_ltype temp)
  247. %{ temp = ($*1_ltype)$input;
  248. $1 = &temp; %}
  249. %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const char &,
  250. const signed char &,
  251. const unsigned char &,
  252. const short &,
  253. const unsigned short &,
  254. const int &,
  255. const unsigned int &,
  256. const long &,
  257. const unsigned long &,
  258. const long long &,
  259. const float &,
  260. const double &
  261. %{ static $*1_ltype temp;
  262. temp = ($*1_ltype)$input;
  263. $result = &temp; %}
  264. %typemap(directorin) const bool & "$input = $1_name;"
  265. %typemap(directorin) const char & "$input = $1_name;"
  266. %typemap(directorin) const signed char & "$input = $1_name;"
  267. %typemap(directorin) const unsigned char & "$input = $1_name;"
  268. %typemap(directorin) const short & "$input = $1_name;"
  269. %typemap(directorin) const unsigned short & "$input = $1_name;"
  270. %typemap(directorin) const int & "$input = $1_name;"
  271. %typemap(directorin) const unsigned int & "$input = $1_name;"
  272. %typemap(directorin) const long & "$input = $1_name;"
  273. %typemap(directorin) const unsigned long & "$input = $1_name;"
  274. %typemap(directorin) const long long & "$input = $1_name;"
  275. %typemap(directorin) const float & "$input = $1_name;"
  276. %typemap(directorin) const double & "$input = $1_name;"
  277. %typemap(csdirectorin) const char & ($*1_ltype temp),
  278. const signed char & ($*1_ltype temp),
  279. const unsigned char & ($*1_ltype temp),
  280. const short & ($*1_ltype temp),
  281. const unsigned short & ($*1_ltype temp),
  282. const int & ($*1_ltype temp),
  283. const unsigned int & ($*1_ltype temp),
  284. const long & ($*1_ltype temp),
  285. const unsigned long & ($*1_ltype temp),
  286. const long long & ($*1_ltype temp),
  287. const float & ($*1_ltype temp),
  288. const double & ($*1_ltype temp)
  289. "$iminput"
  290. %typemap(csdirectorout) const char & ($*1_ltype temp),
  291. const signed char & ($*1_ltype temp),
  292. const unsigned char & ($*1_ltype temp),
  293. const short & ($*1_ltype temp),
  294. const unsigned short & ($*1_ltype temp),
  295. const int & ($*1_ltype temp),
  296. const unsigned int & ($*1_ltype temp),
  297. const long & ($*1_ltype temp),
  298. const unsigned long & ($*1_ltype temp),
  299. const long long & ($*1_ltype temp),
  300. const float & ($*1_ltype temp),
  301. const double & ($*1_ltype temp)
  302. "$cscall"
  303. %typemap(out) const bool & %{ $result = *$1; %}
  304. %typemap(out) const char & %{ $result = *$1; %}
  305. %typemap(out) const signed char & %{ $result = *$1; %}
  306. %typemap(out) const unsigned char & %{ $result = *$1; %}
  307. %typemap(out) const short & %{ $result = *$1; %}
  308. %typemap(out) const unsigned short & %{ $result = *$1; %}
  309. %typemap(out) const int & %{ $result = *$1; %}
  310. %typemap(out) const unsigned int & %{ $result = *$1; %}
  311. %typemap(out) const long & %{ $result = *$1; %}
  312. %typemap(out) const unsigned long & %{ $result = (unsigned long)*$1; %}
  313. %typemap(out) const long long & %{ $result = *$1; %}
  314. %typemap(out) const unsigned long long & %{ $result = *$1; %}
  315. %typemap(out) const float & %{ $result = *$1; %}
  316. %typemap(out) const double & %{ $result = *$1; %}
  317. /* Default handling. Object passed by value. Convert to a pointer */
  318. %typemap(in, canthrow=1) SWIGTYPE ($&1_type argp)
  319. %{ argp = ($&1_ltype)$input;
  320. if (!argp) {
  321. SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null $1_type", 0);
  322. return $null;
  323. }
  324. $1 = *argp; %}
  325. %typemap(directorout) SWIGTYPE
  326. %{ if (!$input) {
  327. SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Unexpected null return for type $1_type", 0);
  328. return $null;
  329. }
  330. $result = *($&1_ltype)$input; %}
  331. %typemap(out) SWIGTYPE
  332. #ifdef __cplusplus
  333. %{ $result = new $1_ltype(($1_ltype &)$1); %}
  334. #else
  335. {
  336. $&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype));
  337. memmove($1ptr, &$1, sizeof($1_type));
  338. $result = $1ptr;
  339. }
  340. #endif
  341. %typemap(directorin) SWIGTYPE
  342. %{ $input = (void *)&$1; %}
  343. %typemap(csdirectorin) SWIGTYPE "new $&csclassname($iminput, false)"
  344. %typemap(csdirectorout) SWIGTYPE "$&csclassname.getCPtr($cscall).Handle"
  345. /* Generic pointers and references */
  346. %typemap(in) SWIGTYPE * %{ $1 = ($1_ltype)$input; %}
  347. %typemap(in, fragment="SWIG_UnPackData") SWIGTYPE (CLASS::*) %{
  348. SWIG_UnpackData($input, (void *)&$1, sizeof($1));
  349. %}
  350. %typemap(in, canthrow=1) SWIGTYPE & %{ $1 = ($1_ltype)$input;
  351. if(!$1) {
  352. SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type type is null", 0);
  353. return $null;
  354. } %}
  355. %typemap(out) SWIGTYPE * %{ $result = (void *)$1; %}
  356. %typemap(out, fragment="SWIG_PackData") SWIGTYPE (CLASS::*) %{
  357. char buf[128];
  358. char *data = SWIG_PackData(buf, (void *)&$1, sizeof($1));
  359. *data = '\0';
  360. $result = SWIG_csharp_string_callback(buf);
  361. %}
  362. %typemap(out) SWIGTYPE & %{ $result = (void *)$1; %}
  363. %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE *
  364. %{ $result = ($1_ltype)$input; %}
  365. %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE (CLASS::*)
  366. %{ $result = ($1_ltype)$input; %}
  367. %typemap(directorin) SWIGTYPE *
  368. %{ $input = (void *) $1; %}
  369. %typemap(directorin) SWIGTYPE (CLASS::*)
  370. %{ $input = (void *) $1; %}
  371. %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE &
  372. %{ if (!$input) {
  373. SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Unexpected null return for type $1_type", 0);
  374. return $null;
  375. }
  376. $result = ($1_ltype)$input; %}
  377. %typemap(directorin) SWIGTYPE &
  378. %{ $input = ($1_ltype) &$1; %}
  379. %typemap(csdirectorin) SWIGTYPE *, SWIGTYPE (CLASS::*), SWIGTYPE & "new $csclassname($iminput, false)"
  380. %typemap(csdirectorout) SWIGTYPE *, SWIGTYPE (CLASS::*), SWIGTYPE & "$csclassname.getCPtr($cscall).Handle"
  381. /* Default array handling */
  382. %typemap(in) SWIGTYPE [] %{ $1 = ($1_ltype)$input; %}
  383. %typemap(out) SWIGTYPE [] %{ $result = $1; %}
  384. /* char arrays - treat as String */
  385. %typemap(in) char[ANY], char[] %{ $1 = ($1_ltype)$input; %}
  386. %typemap(out) char[ANY], char[] %{ $result = SWIG_csharp_string_callback((const char *)$1); %}
  387. %typemap(directorout) char[ANY], char[] %{ $result = ($1_ltype)$input; %}
  388. %typemap(directorin) char[ANY], char[] %{ $input = SWIG_csharp_string_callback((const char *)$1); %}
  389. %typemap(csdirectorin) char[ANY], char[] "$iminput"
  390. %typemap(csdirectorout) char[ANY], char[] "$cscall"
  391. /* Typecheck typemaps - The purpose of these is merely to issue a warning for overloaded C++ functions
  392. * that cannot be overloaded in C# as more than one C++ type maps to a single C# type */
  393. %typecheck(SWIG_TYPECHECK_BOOL)
  394. bool,
  395. const bool &
  396. ""
  397. %typecheck(SWIG_TYPECHECK_CHAR)
  398. char,
  399. const char &
  400. ""
  401. %typecheck(SWIG_TYPECHECK_INT8)
  402. signed char,
  403. const signed char &
  404. ""
  405. %typecheck(SWIG_TYPECHECK_UINT8)
  406. unsigned char,
  407. const unsigned char &
  408. ""
  409. %typecheck(SWIG_TYPECHECK_INT16)
  410. short,
  411. const short &
  412. ""
  413. %typecheck(SWIG_TYPECHECK_UINT16)
  414. unsigned short,
  415. const unsigned short &
  416. ""
  417. %typecheck(SWIG_TYPECHECK_INT32)
  418. int,
  419. long,
  420. const int &,
  421. const long &
  422. ""
  423. %typecheck(SWIG_TYPECHECK_UINT32)
  424. unsigned int,
  425. unsigned long,
  426. const unsigned int &,
  427. const unsigned long &
  428. ""
  429. %typecheck(SWIG_TYPECHECK_INT64)
  430. long long,
  431. const long long &
  432. ""
  433. %typecheck(SWIG_TYPECHECK_UINT64)
  434. unsigned long long,
  435. const unsigned long long &
  436. ""
  437. %typecheck(SWIG_TYPECHECK_FLOAT)
  438. float,
  439. const float &
  440. ""
  441. %typecheck(SWIG_TYPECHECK_DOUBLE)
  442. double,
  443. const double &
  444. ""
  445. %typecheck(SWIG_TYPECHECK_STRING)
  446. char *,
  447. char[ANY],
  448. char[]
  449. ""
  450. %typecheck(SWIG_TYPECHECK_POINTER)
  451. SWIGTYPE,
  452. SWIGTYPE *,
  453. SWIGTYPE &,
  454. SWIGTYPE [],
  455. SWIGTYPE (CLASS::*)
  456. ""
  457. /* Exception handling */
  458. %typemap(throws, canthrow=1) int,
  459. long,
  460. short,
  461. unsigned int,
  462. unsigned long,
  463. unsigned short
  464. %{ char error_msg[256];
  465. sprintf(error_msg, "C++ $1_type exception thrown, value: %d", $1);
  466. SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, error_msg);
  467. return $null; %}
  468. %typemap(throws, canthrow=1) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [ANY]
  469. %{ (void)$1;
  470. SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, "C++ $1_type exception thrown");
  471. return $null; %}
  472. %typemap(throws, canthrow=1) char *
  473. %{ SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, $1);
  474. return $null; %}
  475. /* Typemaps for code generation in proxy classes and C# type wrapper classes */
  476. /* The csin typemap is used for converting function parameter types from the type
  477. * used in the proxy, module or type wrapper class to the type used in the PInvoke class. */
  478. %typemap(csin) bool, const bool &,
  479. char, const char &,
  480. signed char, const signed char &,
  481. unsigned char, const unsigned char &,
  482. short, const short &,
  483. unsigned short, const unsigned short &,
  484. int, const int &,
  485. unsigned int, const unsigned int &,
  486. long, const long &,
  487. unsigned long, const unsigned long &,
  488. long long, const long long &,
  489. unsigned long long, const unsigned long long &,
  490. float, const float &,
  491. double, const double &
  492. "$csinput"
  493. %typemap(csin) char *, char[ANY], char[] "$csinput"
  494. %typemap(csin) SWIGTYPE "$&csclassname.getCPtr($csinput)"
  495. %typemap(csin) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] "$csclassname.getCPtr($csinput)"
  496. %typemap(csin) SWIGTYPE (CLASS::*) "$csclassname.getCMemberPtr($csinput)"
  497. /* The csout typemap is used for converting function return types from the return type
  498. * used in the PInvoke class to the type returned by the proxy, module or type wrapper class.
  499. * The $excode special variable is replaced by the excode typemap attribute code if the
  500. * method can throw any exceptions from unmanaged code, otherwise replaced by nothing. */
  501. // Macro used by the $excode special variable
  502. %define SWIGEXCODE "\n if ($imclassname.SWIGPendingException.Pending) throw $imclassname.SWIGPendingException.Retrieve();" %enddef
  503. %define SWIGEXCODE2 "\n if ($imclassname.SWIGPendingException.Pending) throw $imclassname.SWIGPendingException.Retrieve();" %enddef
  504. %typemap(csout, excode=SWIGEXCODE) bool, const bool & {
  505. bool ret = $imcall;$excode
  506. return ret;
  507. }
  508. %typemap(csout, excode=SWIGEXCODE) char, const char & {
  509. char ret = $imcall;$excode
  510. return ret;
  511. }
  512. %typemap(csout, excode=SWIGEXCODE) signed char, const signed char & {
  513. sbyte ret = $imcall;$excode
  514. return ret;
  515. }
  516. %typemap(csout, excode=SWIGEXCODE) unsigned char, const unsigned char & {
  517. byte ret = $imcall;$excode
  518. return ret;
  519. }
  520. %typemap(csout, excode=SWIGEXCODE) short, const short & {
  521. short ret = $imcall;$excode
  522. return ret;
  523. }
  524. %typemap(csout, excode=SWIGEXCODE) unsigned short, const unsigned short & {
  525. ushort ret = $imcall;$excode
  526. return ret;
  527. }
  528. %typemap(csout, excode=SWIGEXCODE) int, const int & {
  529. int ret = $imcall;$excode
  530. return ret;
  531. }
  532. %typemap(csout, excode=SWIGEXCODE) unsigned int, const unsigned int & {
  533. uint ret = $imcall;$excode
  534. return ret;
  535. }
  536. %typemap(csout, excode=SWIGEXCODE) long, const long & {
  537. int ret = $imcall;$excode
  538. return ret;
  539. }
  540. %typemap(csout, excode=SWIGEXCODE) unsigned long, const unsigned long & {
  541. uint ret = $imcall;$excode
  542. return ret;
  543. }
  544. %typemap(csout, excode=SWIGEXCODE) long long, const long long & {
  545. long ret = $imcall;$excode
  546. return ret;
  547. }
  548. %typemap(csout, excode=SWIGEXCODE) unsigned long long, const unsigned long long & {
  549. ulong ret = $imcall;$excode
  550. return ret;
  551. }
  552. %typemap(csout, excode=SWIGEXCODE) float, const float & {
  553. float ret = $imcall;$excode
  554. return ret;
  555. }
  556. %typemap(csout, excode=SWIGEXCODE) double, const double & {
  557. double ret = $imcall;$excode
  558. return ret;
  559. }
  560. %typemap(csout, excode=SWIGEXCODE) char *, char[ANY], char[] {
  561. string ret = $imcall;$excode
  562. return ret;
  563. }
  564. %typemap(csout, excode=SWIGEXCODE) void {
  565. $imcall;$excode
  566. }
  567. %typemap(csout, excode=SWIGEXCODE) SWIGTYPE {
  568. $&csclassname ret = new $&csclassname($imcall, true);$excode
  569. return ret;
  570. }
  571. %typemap(csout, excode=SWIGEXCODE) SWIGTYPE & {
  572. $csclassname ret = new $csclassname($imcall, $owner);$excode
  573. return ret;
  574. }
  575. %typemap(csout, excode=SWIGEXCODE) SWIGTYPE *, SWIGTYPE [] {
  576. IntPtr cPtr = $imcall;
  577. $csclassname ret = (cPtr == IntPtr.Zero) ? null : new $csclassname(cPtr, $owner);$excode
  578. return ret;
  579. }
  580. %typemap(csout, excode=SWIGEXCODE) SWIGTYPE (CLASS::*) {
  581. string cMemberPtr = $imcall;
  582. $csclassname ret = (cMemberPtr == null) ? null : new $csclassname(cMemberPtr, $owner);$excode
  583. return ret;
  584. }
  585. /* Properties */
  586. %typemap(csvarin, excode=SWIGEXCODE2) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) %{
  587. set {
  588. $imcall;$excode
  589. } %}
  590. %typemap(csvarin, excode=SWIGEXCODE2) char *, char[ANY], char[] %{
  591. set {
  592. $imcall;$excode
  593. } %}
  594. %typemap(csvarout, excode=SWIGEXCODE2) bool, const bool & %{
  595. get {
  596. bool ret = $imcall;$excode
  597. return ret;
  598. } %}
  599. %typemap(csvarout, excode=SWIGEXCODE2) char, const char & %{
  600. get {
  601. char ret = $imcall;$excode
  602. return ret;
  603. } %}
  604. %typemap(csvarout, excode=SWIGEXCODE2) signed char, const signed char & %{
  605. get {
  606. sbyte ret = $imcall;$excode
  607. return ret;
  608. } %}
  609. %typemap(csvarout, excode=SWIGEXCODE2) unsigned char, const unsigned char & %{
  610. get {
  611. byte ret = $imcall;$excode
  612. return ret;
  613. } %}
  614. %typemap(csvarout, excode=SWIGEXCODE2) short, const short & %{
  615. get {
  616. short ret = $imcall;$excode
  617. return ret;
  618. } %}
  619. %typemap(csvarout, excode=SWIGEXCODE2) unsigned short, const unsigned short & %{
  620. get {
  621. ushort ret = $imcall;$excode
  622. return ret;
  623. } %}
  624. %typemap(csvarout, excode=SWIGEXCODE2) int, const int & %{
  625. get {
  626. int ret = $imcall;$excode
  627. return ret;
  628. } %}
  629. %typemap(csvarout, excode=SWIGEXCODE2) unsigned int, const unsigned int & %{
  630. get {
  631. uint ret = $imcall;$excode
  632. return ret;
  633. } %}
  634. %typemap(csvarout, excode=SWIGEXCODE2) long, const long & %{
  635. get {
  636. int ret = $imcall;$excode
  637. return ret;
  638. } %}
  639. %typemap(csvarout, excode=SWIGEXCODE2) unsigned long, const unsigned long & %{
  640. get {
  641. uint ret = $imcall;$excode
  642. return ret;
  643. } %}
  644. %typemap(csvarout, excode=SWIGEXCODE2) long long, const long long & %{
  645. get {
  646. long ret = $imcall;$excode
  647. return ret;
  648. } %}
  649. %typemap(csvarout, excode=SWIGEXCODE2) unsigned long long, const unsigned long long & %{
  650. get {
  651. ulong ret = $imcall;$excode
  652. return ret;
  653. } %}
  654. %typemap(csvarout, excode=SWIGEXCODE2) float, const float & %{
  655. get {
  656. float ret = $imcall;$excode
  657. return ret;
  658. } %}
  659. %typemap(csvarout, excode=SWIGEXCODE2) double, const double & %{
  660. get {
  661. double ret = $imcall;$excode
  662. return ret;
  663. } %}
  664. %typemap(csvarout, excode=SWIGEXCODE2) char *, char[ANY], char[] %{
  665. get {
  666. string ret = $imcall;$excode
  667. return ret;
  668. } %}
  669. %typemap(csvarout, excode=SWIGEXCODE2) void %{
  670. get {
  671. $imcall;$excode
  672. } %}
  673. %typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE %{
  674. get {
  675. $&csclassname ret = new $&csclassname($imcall, true);$excode
  676. return ret;
  677. } %}
  678. %typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE & %{
  679. get {
  680. $csclassname ret = new $csclassname($imcall, $owner);$excode
  681. return ret;
  682. } %}
  683. %typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE *, SWIGTYPE [] %{
  684. get {
  685. IntPtr cPtr = $imcall;
  686. $csclassname ret = (cPtr == IntPtr.Zero) ? null : new $csclassname(cPtr, $owner);$excode
  687. return ret;
  688. } %}
  689. %typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE (CLASS::*) %{
  690. get {
  691. string cMemberPtr = $imcall;
  692. $csclassname ret = (cMemberPtr == null) ? null : new $csclassname(cMemberPtr, $owner);$excode
  693. return ret;
  694. } %}
  695. /* Pointer reference typemaps */
  696. %typemap(ctype) SWIGTYPE *& "void *"
  697. %typemap(imtype, out="IntPtr") SWIGTYPE *& "HandleRef"
  698. %typemap(cstype) SWIGTYPE *& "$*csclassname"
  699. %typemap(csin) SWIGTYPE *& "$*csclassname.getCPtr($csinput)"
  700. %typemap(csout, excode=SWIGEXCODE) SWIGTYPE *& {
  701. IntPtr cPtr = $imcall;
  702. $*csclassname ret = (cPtr == IntPtr.Zero) ? null : new $*csclassname(cPtr, $owner);$excode
  703. return ret;
  704. }
  705. %typemap(in) SWIGTYPE *& ($*1_ltype temp = 0)
  706. %{ temp = ($*1_ltype)$input;
  707. $1 = &temp; %}
  708. %typemap(out) SWIGTYPE *&
  709. %{ $result = (void *)*$1; %}
  710. /* Array reference typemaps */
  711. %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
  712. /* Typemaps used for the generation of proxy and type wrapper class code */
  713. %typemap(csbase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
  714. %typemap(csclassmodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "public class"
  715. %typemap(cscode) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
  716. %typemap(csimports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "\nusing System;\nusing System.Runtime.InteropServices;\n"
  717. %typemap(csinterfaces) SWIGTYPE "IDisposable"
  718. %typemap(csinterfaces) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
  719. %typemap(csinterfaces_derived) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
  720. // Proxy classes (base classes, ie, not derived classes)
  721. %typemap(csbody) SWIGTYPE %{
  722. private HandleRef swigCPtr;
  723. protected bool swigCMemOwn;
  724. internal $csclassname(IntPtr cPtr, bool cMemoryOwn) {
  725. swigCMemOwn = cMemoryOwn;
  726. swigCPtr = new HandleRef(this, cPtr);
  727. }
  728. internal static HandleRef getCPtr($csclassname obj) {
  729. return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
  730. }
  731. %}
  732. // Derived proxy classes
  733. %typemap(csbody_derived) SWIGTYPE %{
  734. private HandleRef swigCPtr;
  735. internal $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclassnameUpcast(cPtr), cMemoryOwn) {
  736. swigCPtr = new HandleRef(this, cPtr);
  737. }
  738. internal static HandleRef getCPtr($csclassname obj) {
  739. return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
  740. }
  741. %}
  742. // Typewrapper classes
  743. %typemap(csbody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] %{
  744. private HandleRef swigCPtr;
  745. internal $csclassname(IntPtr cPtr, bool futureUse) {
  746. swigCPtr = new HandleRef(this, cPtr);
  747. }
  748. protected $csclassname() {
  749. swigCPtr = new HandleRef(null, IntPtr.Zero);
  750. }
  751. internal static HandleRef getCPtr($csclassname obj) {
  752. return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
  753. }
  754. %}
  755. %typemap(csbody) SWIGTYPE (CLASS::*) %{
  756. private string swigCMemberPtr;
  757. internal $csclassname(string cMemberPtr, bool futureUse) {
  758. swigCMemberPtr = cMemberPtr;
  759. }
  760. protected $csclassname() {
  761. swigCMemberPtr = null;
  762. }
  763. internal static string getCMemberPtr($csclassname obj) {
  764. return obj.swigCMemberPtr;
  765. }
  766. %}
  767. %typemap(csfinalize) SWIGTYPE %{
  768. ~$csclassname() {
  769. Dispose();
  770. }
  771. %}
  772. %typemap(csconstruct, excode=SWIGEXCODE,directorconnect="\n SwigDirectorConnect();") SWIGTYPE %{: this($imcall, true) {$excode$directorconnect
  773. }
  774. %}
  775. %typemap(csdestruct, methodname="Dispose", methodmodifiers="public") SWIGTYPE {
  776. lock(this) {
  777. if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
  778. swigCMemOwn = false;
  779. $imcall;
  780. }
  781. swigCPtr = new HandleRef(null, IntPtr.Zero);
  782. GC.SuppressFinalize(this);
  783. }
  784. }
  785. %typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") SWIGTYPE {
  786. lock(this) {
  787. if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
  788. swigCMemOwn = false;
  789. $imcall;
  790. }
  791. swigCPtr = new HandleRef(null, IntPtr.Zero);
  792. GC.SuppressFinalize(this);
  793. base.Dispose();
  794. }
  795. }
  796. %typemap(directordisconnect, methodname="swigDirectorDisconnect") SWIGTYPE %{
  797. protected void $methodname() {
  798. swigCMemOwn = false;
  799. $imcall;
  800. }
  801. %}
  802. /* C# specific directives */
  803. #define %csconst(flag) %feature("cs:const","flag")
  804. #define %csconstvalue(value) %feature("cs:constvalue",value)
  805. #define %csenum(wrapapproach) %feature("cs:enum","wrapapproach")
  806. #define %csmethodmodifiers %feature("cs:methodmodifiers")
  807. #define %csnothrowexception %feature("except")
  808. #define %csattributes %feature("cs:attributes")
  809. %pragma(csharp) imclassclassmodifiers="class"
  810. %pragma(csharp) moduleclassmodifiers="public class"
  811. %pragma(csharp) moduleimports=%{
  812. using System;
  813. using System.Runtime.InteropServices;
  814. %}
  815. %pragma(csharp) imclassimports=%{
  816. using System;
  817. using System.Runtime.InteropServices;
  818. %}
  819. /* Some ANSI C typemaps */
  820. %apply unsigned long { size_t };
  821. %apply const unsigned long & { const size_t & };
  822. /* csharp keywords */
  823. %include <csharpkw.swg>
  824. // Default enum handling
  825. %include <enums.swg>
  826. /*
  827. // Alternative char * typemaps.
  828. %pragma(csharp) imclasscode=%{
  829. public class SWIGStringMarshal : IDisposable {
  830. public readonly HandleRef swigCPtr;
  831. public SWIGStringMarshal(string str) {
  832. swigCPtr = new HandleRef(this, System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(str));
  833. }
  834. public virtual void Dispose() {
  835. System.Runtime.InteropServices.Marshal.FreeHGlobal(swigCPtr.Handle);
  836. GC.SuppressFinalize(this);
  837. }
  838. }
  839. %}
  840. %typemap(imtype, out="IntPtr") char *, char[ANY], char[] "HandleRef"
  841. %typemap(out) char *, char[ANY], char[] %{ $result = $1; %}
  842. %typemap(csin) char *, char[ANY], char[] "new $imclassname.SWIGStringMarshal($csinput).swigCPtr"
  843. %typemap(csout, excode=SWIGEXCODE) char *, char[ANY], char[] {
  844. string ret = System.Runtime.InteropServices.Marshal.PtrToStringAnsi($imcall);$excode
  845. return ret;
  846. }
  847. %typemap(csvarin, excode=SWIGEXCODE2) char *, char[ANY], char[] %{
  848. set {
  849. $imcall;$excode
  850. } %}
  851. %typemap(csvarout, excode=SWIGEXCODE2) char *, char[ANY], char[] %{
  852. get {
  853. string ret = System.Runtime.InteropServices.Marshal.PtrToStringAnsi($imcall);$excode
  854. return ret;
  855. } %}
  856. */