swig.swg 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. /* -----------------------------------------------------------------------------
  2. * swig.swg
  3. *
  4. * Common macro definitions for various SWIG directives. This file is always
  5. * included at the top of each input file.
  6. * ----------------------------------------------------------------------------- */
  7. /* -----------------------------------------------------------------------------
  8. * User Directives
  9. * ----------------------------------------------------------------------------- */
  10. /* Deprecated SWIG-1.1 directives */
  11. #define %disabledoc %warn "104:%disabledoc is deprecated"
  12. #define %enabledoc %warn "105:%enabledoc is deprecated"
  13. #define %doconly %warn "106:%doconly is deprecated"
  14. #define %style %warn "107:%style is deprecated" /##/
  15. #define %localstyle %warn "108:%localstyle is deprecated" /##/
  16. #define %title %warn "109:%title is deprecated" /##/
  17. #define %section %warn "110:%section is deprecated" /##/
  18. #define %subsection %warn "111:%subsection is deprecated" /##/
  19. #define %subsubsection %warn "112:%subsubsection is deprecated" /##/
  20. #define %new %warn "117:%new is deprecated. Use %newobject"
  21. #define %text %insert("null")
  22. /* Code insertion directives such as %wrapper %{ ... %} */
  23. #define %begin %insert("begin")
  24. #define %runtime %insert("runtime")
  25. #define %header %insert("header")
  26. #define %wrapper %insert("wrapper")
  27. #define %init %insert("init")
  28. /* Class extension */
  29. #define %addmethods %warn "113:%addmethods is now %extend" %extend
  30. /* %ignore directive */
  31. #define %ignore %rename($ignore)
  32. #define %ignorewarn(x) %rename("$ignore:" x)
  33. /* Access control directives */
  34. #define %readonly %warn "114:%readonly is deprecated. Use %immutable; " %feature("immutable");
  35. #define %readwrite %warn "115:%readwrite is deprecated. Use %mutable; " %feature("immutable","");
  36. #define %immutable %feature("immutable")
  37. #define %noimmutable %feature("immutable","0")
  38. #define %clearimmutable %feature("immutable","")
  39. #define %mutable %clearimmutable
  40. /* Generation of default constructors/destructors (old form, don't use) */
  41. #define %nodefault %feature("nodefault","1")
  42. #define %default %feature("nodefault","0")
  43. #define %clearnodefault %feature("nodefault","")
  44. #define %makedefault %clearnodefault
  45. /* Disable the generation of implicit default constructor */
  46. #define %nodefaultctor %feature("nodefaultctor","1")
  47. #define %defaultctor %feature("nodefaultctor","0")
  48. #define %clearnodefaultctor %feature("nodefaultctor","")
  49. /* Disable the generation of implicit default destructor (dangerous) */
  50. #define %nodefaultdtor %feature("nodefaultdtor","1")
  51. #define %defaultdtor %feature("nodefaultdtor","0")
  52. #define %clearnodefaultdtor %feature("nodefaultdtor","")
  53. /* Enable the generation of copy constructor */
  54. #define %copyctor %feature("copyctor","1")
  55. #define %nocopyctor %feature("copyctor","0")
  56. #define %clearcopyctor %feature("copyctor","")
  57. /* Force the old nodefault behavior, ie disable both constructor and destructor */
  58. #define %oldnodefault %feature("oldnodefault","1")
  59. #define %nooldnodefault %feature("oldnodefault","0")
  60. #define %clearoldnodefault %feature("oldnodefault","")
  61. /* the %exception directive */
  62. #if defined(SWIGCSHARP) || defined(SWIGD)
  63. #define %exception %feature("except", canthrow=1)
  64. #else
  65. #define %exception %feature("except")
  66. #endif
  67. #define %noexception %feature("except","0")
  68. #define %clearexception %feature("except","")
  69. /* the %allowexception directive allows the %exception feature to
  70. be applied to set/get variable methods */
  71. #define %allowexception %feature("allowexcept")
  72. #define %noallowexception %feature("allowexcept","0")
  73. #define %clearallowexception %feature("allowexcept","")
  74. /* the %exceptionvar directive, as %exception but it is only applied
  75. to set/get variable methods. You don't need to use the
  76. %allowexception directive when using %exceptionvar.
  77. */
  78. #if defined(SWIGCSHARP) || defined(SWIGD)
  79. #define %exceptionvar %feature("exceptvar", canthrow=1)
  80. #else
  81. #define %exceptionvar %feature("exceptvar")
  82. #endif
  83. #define %noexceptionvar %feature("exceptvar","0")
  84. #define %clearexceptionvar %feature("exceptvar","")
  85. /* the %catches directive */
  86. #define %catches(tlist...) %feature("catches","("`tlist`")")
  87. #define %clearcatches %feature("catches","")
  88. /* the %exceptionclass directive */
  89. #define %exceptionclass %feature("exceptionclass")
  90. #define %noexceptionclass %feature("exceptionclass","0")
  91. #define %clearexceptionclass %feature("exceptionclass","")
  92. /* the %newobject directive */
  93. #define %newobject %feature("new")
  94. #define %nonewobject %feature("new","0")
  95. #define %clearnewobject %feature("new","")
  96. /* the %delobject directive */
  97. #define %delobject %feature("del")
  98. #define %nodelobject %feature("del","0")
  99. #define %cleardelobject %feature("del","")
  100. /* the %refobject/%unrefobject directives */
  101. #define %refobject %feature("ref")
  102. #define %norefobject %feature("ref","0")
  103. #define %clearrefobject %feature("ref","")
  104. #define %unrefobject %feature("unref")
  105. #define %nounrefobject %feature("unref","0")
  106. #define %clearunrefobject %feature("unref","")
  107. /* Directives for callback functions (experimental) */
  108. #define %callback(x) %feature("callback",`x`)
  109. #define %nocallback %feature("callback","0")
  110. #define %clearcallback %feature("callback","")
  111. /* the %nestedworkaround directive (deprecated) */
  112. #define %nestedworkaround %feature("nestedworkaround")
  113. #define %nonestedworkaround %feature("nestedworkaround","0")
  114. #define %clearnestedworkaround %feature("nestedworkaround","")
  115. /* the %flatnested directive */
  116. #define %flatnested %feature("flatnested")
  117. #define %noflatnested %feature("flatnested","0")
  118. #define %clearflatnested %feature("flatnested","")
  119. /* the %fastdispatch directive */
  120. #define %fastdispatch %feature("fastdispatch")
  121. #define %nofastdispatch %feature("fastdispatch","0")
  122. #define %clearfastdispatch %feature("fastdispatch","")
  123. /* directors directives */
  124. #define %director %feature("director")
  125. #define %nodirector %feature("director","0")
  126. #define %cleardirector %feature("director","")
  127. /* naturalvar directives */
  128. #define %naturalvar %feature("naturalvar")
  129. #define %nonaturalvar %feature("naturalvar","0")
  130. #define %clearnaturalvar %feature("naturalvar","")
  131. /* nspace directives */
  132. #define %nspace %feature("nspace")
  133. #define %nonspace %feature("nspace","0")
  134. #define %clearnspace %feature("nspace","")
  135. /* valuewrapper directives */
  136. #define %valuewrapper %feature("valuewrapper")
  137. #define %clearvaluewrapper %feature("valuewrapper","")
  138. #define %novaluewrapper %feature("novaluewrapper")
  139. #define %clearnovaluewrapper %feature("novaluewrapper","")
  140. /* Contract support - Experimental and undocumented */
  141. #define %contract %feature("contract")
  142. #define %nocontract %feature("contract","0")
  143. #define %clearcontract %feature("contract","")
  144. /* Macro for setting a dynamic cast function */
  145. %define DYNAMIC_CAST(mangle,func)
  146. %init %{
  147. mangle->dcast = (swig_dycast_func) func;
  148. %}
  149. %enddef
  150. /* aggregation support */
  151. /*
  152. This macro performs constant aggregation. Basically the idea of
  153. constant aggregation is that you can group a collection of constants
  154. together. For example, suppose you have some code like this:
  155. #define UP 1
  156. #define DOWN 2
  157. #define LEFT 3
  158. #define RIGHT 4
  159. Now, suppose you had a function like this:
  160. int move(int direction)
  161. In this case, you might want to restrict the direction argument to
  162. one of the supplied constant names. To do this, you could write some
  163. typemap code by hand. Alternatively, you can use the
  164. %aggregate_check macro defined here to create a simple check
  165. function for you. Here is an example:
  166. %aggregate_check(int, check_direction, UP, DOWN, LEFT, RIGHT);
  167. Now, using a typemap
  168. %typemap(check) int direction {
  169. if (!check_direction($1)) SWIG_exception(SWIG_ValueError,"Bad direction.");
  170. }
  171. or a contract (better)
  172. %contract move(int x) {
  173. require:
  174. check_direction(x);
  175. }
  176. */
  177. %define %aggregate_check(TYPE, NAME, FIRST, ...)
  178. %wrapper %{
  179. static int NAME(TYPE x) {
  180. static TYPE values[] = { FIRST, ##__VA_ARGS__ };
  181. static int size = sizeof(values);
  182. int i,j;
  183. for (i = 0, j = 0; i < size; i+=sizeof(TYPE),j++) {
  184. if (x == values[j]) return 1;
  185. }
  186. return 0;
  187. }
  188. %}
  189. %enddef
  190. /* -----------------------------------------------------------------------------
  191. * %rename predicates
  192. * ----------------------------------------------------------------------------- */
  193. /*
  194. Predicates to be used with %rename, for example:
  195. - to rename all the functions:
  196. %rename("%(utitle)s", %$isfunction) "";
  197. - to rename only the member methods:
  198. %rename("m_%(utitle)s", %$isfunction, %$ismember) "";
  199. - to rename only the global functions:
  200. %rename("m_%(utitle)s", %$isfunction, %$not %$ismember) "";
  201. or
  202. %rename("g_%(utitle)s", %$isfunction, %$isglobal) "";
  203. - to ignore the enumitems in a given class:
  204. %rename("$ignore", %$isenumitem, %$classname="MyClass") "";
  205. we use the prefix '%$' to avoid clashes with other swig
  206. macros/directives.
  207. */
  208. %define %$not "not" %enddef
  209. %define %$isenum "match"="enum" %enddef
  210. %define %$isenumitem "match"="enumitem" %enddef
  211. %define %$isaccess "match"="access" %enddef
  212. %define %$isclass "match"="class","notmatch$template$templatetype"="class" %enddef
  213. %define %$isextend "match"="extend" %enddef
  214. %define %$isconstructor "match"="constructor" %enddef
  215. %define %$isdestructor "match"="destructor" %enddef
  216. %define %$isnamespace "match"="namespace" %enddef
  217. %define %$istemplate "match"="template" %enddef
  218. %define %$isconstant "match"="constant" %enddef /* %constant definition */
  219. %define %$isunion "match$kind"="union" %enddef
  220. %define %$isfunction "match$kind"="function" %enddef
  221. %define %$isvariable "match$kind"="variable" %enddef
  222. %define %$isimmutable "match$feature:immutable"="1" %enddef
  223. %define %$hasconsttype "match$hasconsttype"="1" %enddef
  224. %define %$hasvalue "match$hasvalue"="1" %enddef
  225. %define %$isextension "match$isextension"="1" %enddef
  226. %define %$isstatic "match$storage"="static" %enddef
  227. %define %$isfriend "match$storage"="friend" %enddef
  228. %define %$istypedef "match$storage"="typedef" %enddef
  229. %define %$isvirtual "match$storage"="virtual" %enddef
  230. %define %$isexplicit "match$storage"="explicit" %enddef
  231. %define %$isextern "match$storage"="extern" %enddef
  232. %define %$ismember "match$ismember"="1" %enddef
  233. %define %$isglobal %$not %$ismember %enddef
  234. %define %$isextendmember "match$isextendmember"="1" %enddef
  235. %define %$innamespace "match$parentNode$nodeType"="namespace" %enddef
  236. %define %$ispublic "match$access"="public" %enddef
  237. %define %$isprotected "match$access"="protected" %enddef
  238. %define %$isprivate "match$access"="private" %enddef
  239. %define %$ismemberget "match$memberget"="1" %enddef
  240. %define %$ismemberset "match$memberset"="1" %enddef
  241. %define %$classname %$ismember,"match$parentNode$name" %enddef
  242. %define %$isnested "match$nested"="1" %enddef
  243. /* -----------------------------------------------------------------------------
  244. * Include all the warnings labels and macros
  245. * ----------------------------------------------------------------------------- */
  246. %include <swigwarnings.swg>
  247. /* -----------------------------------------------------------------------------
  248. * Overloading support
  249. * ----------------------------------------------------------------------------- */
  250. /*
  251. * Function/method overloading support. This is done through typemaps,
  252. * but also involves a precedence level.
  253. */
  254. /* Macro for overload resolution */
  255. %define %typecheck(_x...) %typemap(typecheck, precedence=_x) %enddef
  256. /* Macros for precedence levels */
  257. %define SWIG_TYPECHECK_POINTER 0 %enddef
  258. %define SWIG_TYPECHECK_ITERATOR 5 %enddef
  259. %define SWIG_TYPECHECK_VOIDPTR 10 %enddef
  260. %define SWIG_TYPECHECK_BOOL 15 %enddef
  261. %define SWIG_TYPECHECK_UINT8 20 %enddef
  262. %define SWIG_TYPECHECK_INT8 25 %enddef
  263. %define SWIG_TYPECHECK_UINT16 30 %enddef
  264. %define SWIG_TYPECHECK_INT16 35 %enddef
  265. %define SWIG_TYPECHECK_UINT32 40 %enddef
  266. %define SWIG_TYPECHECK_INT32 45 %enddef
  267. %define SWIG_TYPECHECK_SIZE 47 %enddef
  268. %define SWIG_TYPECHECK_PTRDIFF 48 %enddef
  269. %define SWIG_TYPECHECK_UINT64 50 %enddef
  270. %define SWIG_TYPECHECK_INT64 55 %enddef
  271. %define SWIG_TYPECHECK_UINT128 60 %enddef
  272. %define SWIG_TYPECHECK_INT128 65 %enddef
  273. %define SWIG_TYPECHECK_INTEGER 70 %enddef
  274. %define SWIG_TYPECHECK_FLOAT 80 %enddef
  275. %define SWIG_TYPECHECK_DOUBLE 90 %enddef
  276. %define SWIG_TYPECHECK_CPLXFLT 95 %enddef
  277. %define SWIG_TYPECHECK_CPLXDBL 100 %enddef
  278. %define SWIG_TYPECHECK_COMPLEX 105 %enddef
  279. %define SWIG_TYPECHECK_UNICHAR 110 %enddef
  280. %define SWIG_TYPECHECK_STDUNISTRING 115 %enddef
  281. %define SWIG_TYPECHECK_UNISTRING 120 %enddef
  282. %define SWIG_TYPECHECK_CHAR 130 %enddef
  283. %define SWIG_TYPECHECK_STDSTRING 135 %enddef
  284. %define SWIG_TYPECHECK_STRING 140 %enddef
  285. %define SWIG_TYPECHECK_PAIR 150 %enddef
  286. %define SWIG_TYPECHECK_STDARRAY 155 %enddef
  287. %define SWIG_TYPECHECK_VECTOR 160 %enddef
  288. %define SWIG_TYPECHECK_DEQUE 170 %enddef
  289. %define SWIG_TYPECHECK_LIST 180 %enddef
  290. %define SWIG_TYPECHECK_SET 190 %enddef
  291. %define SWIG_TYPECHECK_MULTISET 200 %enddef
  292. %define SWIG_TYPECHECK_MAP 210 %enddef
  293. %define SWIG_TYPECHECK_MULTIMAP 220 %enddef
  294. %define SWIG_TYPECHECK_STACK 230 %enddef
  295. %define SWIG_TYPECHECK_QUEUE 240 %enddef
  296. %define SWIG_TYPECHECK_BOOL_ARRAY 1015 %enddef
  297. %define SWIG_TYPECHECK_INT8_ARRAY 1025 %enddef
  298. %define SWIG_TYPECHECK_INT16_ARRAY 1035 %enddef
  299. %define SWIG_TYPECHECK_INT32_ARRAY 1045 %enddef
  300. %define SWIG_TYPECHECK_INT64_ARRAY 1055 %enddef
  301. %define SWIG_TYPECHECK_INT128_ARRAY 1065 %enddef
  302. %define SWIG_TYPECHECK_FLOAT_ARRAY 1080 %enddef
  303. %define SWIG_TYPECHECK_DOUBLE_ARRAY 1090 %enddef
  304. %define SWIG_TYPECHECK_CHAR_ARRAY 1130 %enddef
  305. %define SWIG_TYPECHECK_STRING_ARRAY 1140 %enddef
  306. %define SWIG_TYPECHECK_OBJECT_ARRAY 1150 %enddef
  307. %define SWIG_TYPECHECK_BOOL_PTR 2015 %enddef
  308. %define SWIG_TYPECHECK_UINT8_PTR 2020 %enddef
  309. %define SWIG_TYPECHECK_INT8_PTR 2025 %enddef
  310. %define SWIG_TYPECHECK_UINT16_PTR 2030 %enddef
  311. %define SWIG_TYPECHECK_INT16_PTR 2035 %enddef
  312. %define SWIG_TYPECHECK_UINT32_PTR 2040 %enddef
  313. %define SWIG_TYPECHECK_INT32_PTR 2045 %enddef
  314. %define SWIG_TYPECHECK_UINT64_PTR 2050 %enddef
  315. %define SWIG_TYPECHECK_INT64_PTR 2055 %enddef
  316. %define SWIG_TYPECHECK_FLOAT_PTR 2080 %enddef
  317. %define SWIG_TYPECHECK_DOUBLE_PTR 2090 %enddef
  318. %define SWIG_TYPECHECK_CHAR_PTR 2130 %enddef
  319. %define SWIG_TYPECHECK_SWIGOBJECT 5000 %enddef
  320. /* -----------------------------------------------------------------------------
  321. * Default handling of certain overloaded operators
  322. * ----------------------------------------------------------------------------- */
  323. #ifdef __cplusplus
  324. %ignoreoperator(NEW) operator new;
  325. %ignoreoperator(DELETE) operator delete;
  326. %ignoreoperator(NEWARR) operator new[];
  327. %ignoreoperator(DELARR) operator delete[];
  328. /* add C++ operator aliases */
  329. %rename("operator &&") operator and; // `and' `&&'
  330. %rename("operator ||") operator or; // `or' `||'
  331. %rename("operator !") operator not; // `not' `!'
  332. %rename("operator &=") operator and_eq; // `and_eq' `&='
  333. %rename("operator &") operator bitand; // `bitand' `&'
  334. %rename("operator |") operator bitor; // `bitor' `|'
  335. %rename("operator ~") operator compl; // `compl' `~'
  336. %rename("operator !=") operator not_eq; // `not_eq' `!='
  337. %rename("operator |=") operator or_eq; // `or_eq' `|='
  338. %rename("operator ^") operator xor; // `xor' `^'
  339. %rename("operator ^=") operator xor_eq; // `xor_eq' `^='
  340. /* Smart pointer handling */
  341. %rename(__deref__) *::operator->;
  342. %rename(__ref__) *::operator*();
  343. %rename(__ref__) *::operator*() const;
  344. /* Define std namespace */
  345. namespace std {
  346. /* Warn about std::initializer_list usage. The constructor/method where used should probably be ignored. See docs. */
  347. template<typename T> class initializer_list {};
  348. %typemap(in, warning=SWIGWARN_TYPEMAP_INITIALIZER_LIST_MSG) initializer_list<T> ""
  349. %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) initializer_list<T> ""
  350. }
  351. #endif
  352. /* -----------------------------------------------------------------------------
  353. * Default char * and C array typemaps
  354. * ----------------------------------------------------------------------------- */
  355. /* Set up the typemap for handling new return strings */
  356. #ifdef __cplusplus
  357. %typemap(newfree) char * "delete [] $1;";
  358. #else
  359. %typemap(newfree) char * "free($1);";
  360. #endif
  361. /* Default typemap for handling char * members */
  362. #ifdef __cplusplus
  363. %typemap(memberin) char * {
  364. delete [] $1;
  365. if ($input) {
  366. $1 = ($1_type) (new char[strlen((const char *)$input)+1]);
  367. strcpy((char *)$1, (const char *)$input);
  368. } else {
  369. $1 = 0;
  370. }
  371. }
  372. %typemap(memberin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * {
  373. if ($input) {
  374. $1 = ($1_type) (new char[strlen((const char *)$input)+1]);
  375. strcpy((char *)$1, (const char *)$input);
  376. } else {
  377. $1 = 0;
  378. }
  379. }
  380. %typemap(globalin) char * {
  381. delete [] $1;
  382. if ($input) {
  383. $1 = ($1_type) (new char[strlen((const char *)$input)+1]);
  384. strcpy((char *)$1, (const char *)$input);
  385. } else {
  386. $1 = 0;
  387. }
  388. }
  389. %typemap(globalin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * {
  390. if ($input) {
  391. $1 = ($1_type) (new char[strlen((const char *)$input)+1]);
  392. strcpy((char *)$1, (const char *)$input);
  393. } else {
  394. $1 = 0;
  395. }
  396. }
  397. #else
  398. %typemap(memberin) char * {
  399. free($1);
  400. if ($input) {
  401. $1 = ($1_type) malloc(strlen((const char *)$input)+1);
  402. strcpy((char *)$1, (const char *)$input);
  403. } else {
  404. $1 = 0;
  405. }
  406. }
  407. %typemap(memberin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * {
  408. if ($input) {
  409. $1 = ($1_type) malloc(strlen((const char *)$input)+1);
  410. strcpy((char *)$1, (const char *)$input);
  411. } else {
  412. $1 = 0;
  413. }
  414. }
  415. %typemap(globalin) char * {
  416. free($1);
  417. if ($input) {
  418. $1 = ($1_type) malloc(strlen((const char *)$input)+1);
  419. strcpy((char *)$1, (const char *)$input);
  420. } else {
  421. $1 = 0;
  422. }
  423. }
  424. %typemap(globalin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * {
  425. if ($input) {
  426. $1 = ($1_type) malloc(strlen((const char *)$input)+1);
  427. strcpy((char *)$1, (const char *)$input);
  428. } else {
  429. $1 = 0;
  430. }
  431. }
  432. #endif
  433. /* Character array handling */
  434. %typemap(memberin) char [ANY] {
  435. if($input) {
  436. strncpy((char*)$1, (const char *)$input, $1_dim0-1);
  437. $1[$1_dim0-1] = 0;
  438. } else {
  439. $1[0] = 0;
  440. }
  441. }
  442. %typemap(globalin) char [ANY] {
  443. if($input) {
  444. strncpy((char*)$1, (const char *)$input, $1_dim0-1);
  445. $1[$1_dim0-1] = 0;
  446. } else {
  447. $1[0] = 0;
  448. }
  449. }
  450. %typemap(memberin) char [] {
  451. if ($input) strcpy((char *)$1, (const char *)$input);
  452. else $1[0] = 0;
  453. }
  454. %typemap(globalin) char [] {
  455. if ($input) strcpy((char *)$1, (const char *)$input);
  456. else $1[0] = 0;
  457. }
  458. /* memberin/globalin typemap for arrays. */
  459. %typemap(memberin) SWIGTYPE [ANY] {
  460. size_t ii;
  461. $1_basetype *b = ($1_basetype *) $1;
  462. for (ii = 0; ii < (size_t)$1_size; ii++) b[ii] = *(($1_basetype *) $input + ii);
  463. }
  464. %typemap(globalin) SWIGTYPE [ANY] {
  465. size_t ii;
  466. $1_basetype *b = ($1_basetype *) $1;
  467. for (ii = 0; ii < (size_t)$1_size; ii++) b[ii] = *(($1_basetype *) $input + ii);
  468. }
  469. /* memberin/globalin typemap for double arrays. */
  470. %typemap(memberin) SWIGTYPE [ANY][ANY] {
  471. $basetype (*inp)[$1_dim1] = ($basetype (*)[$1_dim1])($input);
  472. $basetype (*dest)[$1_dim1] = ($basetype (*)[$1_dim1])($1);
  473. size_t ii = 0;
  474. for (; ii < $1_dim0; ++ii) {
  475. $basetype *ip = inp[ii];
  476. $basetype *dp = dest[ii];
  477. size_t jj = 0;
  478. for (; jj < $1_dim1; ++jj) dp[jj] = ip[jj];
  479. }
  480. }
  481. %typemap(globalin) SWIGTYPE [ANY][ANY] {
  482. $basetype (*inp)[$1_dim1] = ($basetype (*)[$1_dim1])($input);
  483. $basetype (*dest)[$1_dim1] = ($basetype (*)[$1_dim1])($1);
  484. size_t ii = 0;
  485. for (; ii < $1_dim0; ++ii) {
  486. $basetype *ip = inp[ii];
  487. $basetype *dp = dest[ii];
  488. size_t jj = 0;
  489. for (; jj < $1_dim1; ++jj) dp[jj] = ip[jj];
  490. }
  491. }
  492. /* -----------------------------------------------------------------------------
  493. * Runtime code
  494. * ----------------------------------------------------------------------------- */
  495. /* The SwigValueWrapper class */
  496. /*
  497. * This template wrapper is used to handle C++ objects that are passed or
  498. * returned by value. This is necessary to handle objects that define
  499. * no default-constructor (making it difficult for SWIG to properly declare
  500. * local variables).
  501. *
  502. * The wrapper is used as follows. First consider a function like this:
  503. *
  504. * Vector cross_product(Vector a, Vector b)
  505. *
  506. * Now, if Vector is defined as a C++ class with no default constructor,
  507. * code is generated as follows:
  508. *
  509. * Vector *wrap_cross_product(Vector *inarg1, Vector *inarg2) {
  510. * SwigValueWrapper<Vector> arg1;
  511. * SwigValueWrapper<Vector> arg2;
  512. * SwigValueWrapper<Vector> result;
  513. *
  514. * arg1 = *inarg1;
  515. * arg2 = *inarg2;
  516. * ...
  517. * result = cross_product(arg1,arg2);
  518. * ...
  519. * return new Vector(result);
  520. * }
  521. *
  522. * In the wrappers, the template SwigValueWrapper simply provides a thin
  523. * layer around a Vector *. However, it does this in a way that allows
  524. * the object to be bound after the variable declaration (which is not possible
  525. * with the bare object when it lacks a default constructor).
  526. *
  527. * An observant reader will notice that the code after the variable declarations
  528. * is *identical* to the code used for classes that do define default constructors.
  529. * Thus, this neat trick allows us to fix this special case without having to
  530. * make massive changes to typemaps and other parts of the SWIG code generator.
  531. *
  532. * Note: this code is not included when SWIG runs in C-mode, when classes
  533. * define default constructors, or when pointers and references are used.
  534. * SWIG tries to avoid doing this except in very special circumstances.
  535. *
  536. * Note: This solution suffers from making a large number of copies
  537. * of the underlying object. However, this is needed in the interest of
  538. * safety and in order to cover all of the possible ways in which a value
  539. * might be assigned. For example:
  540. *
  541. * arg1 = *inarg1; // Assignment from a pointer
  542. * arg1 = Vector(1,2,3); // Assignment from a value
  543. *
  544. * The class offers a strong guarantee of exception safety.
  545. * With regards to the implementation, the private SwigMovePointer nested class is
  546. * a simple smart pointer with move semantics, much like std::auto_ptr.
  547. *
  548. * This wrapping technique was suggested by William Fulton and is henceforth
  549. * known as the "Fulton Transform" :-).
  550. */
  551. #ifdef __cplusplus
  552. %insert("runtime") %{
  553. #ifdef __cplusplus
  554. /* SwigValueWrapper is described in swig.swg */
  555. template<typename T> class SwigValueWrapper {
  556. struct SwigMovePointer {
  557. T *ptr;
  558. SwigMovePointer(T *p) : ptr(p) { }
  559. ~SwigMovePointer() { delete ptr; }
  560. SwigMovePointer& operator=(SwigMovePointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; }
  561. } pointer;
  562. SwigValueWrapper& operator=(const SwigValueWrapper<T>& rhs);
  563. SwigValueWrapper(const SwigValueWrapper<T>& rhs);
  564. public:
  565. SwigValueWrapper() : pointer(0) { }
  566. SwigValueWrapper& operator=(const T& t) { SwigMovePointer tmp(new T(t)); pointer = tmp; return *this; }
  567. operator T&() const { return *pointer.ptr; }
  568. T *operator&() { return pointer.ptr; }
  569. };%}
  570. /*
  571. * SwigValueInit() is a generic initialisation solution as the following approach:
  572. *
  573. * T c_result = T();
  574. *
  575. * doesn't compile for all types for example:
  576. *
  577. * unsigned int c_result = unsigned int();
  578. */
  579. %insert("runtime") %{
  580. template <typename T> T SwigValueInit() {
  581. return T();
  582. }
  583. #endif
  584. %}
  585. #endif
  586. /* The swiglabels */
  587. %insert("runtime") "swiglabels.swg"