Loading [MathJax]/extensions/TeX/AMSsymbols.js
LAL 7.7.0.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
SWIGCommon.i
Go to the documentation of this file.
1//
2// Copyright (C) 2011--2014, 2022 Karl Wette
3//
4// This program is free software; you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation; either version 2 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with with program; see the file COPYING. If not, write to the
16// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17// MA 02110-1301 USA
18//
19
20///
21/// \defgroup SWIGCommon_i Interface SWIGCommon.i
22/// \ingroup lal_swig
23/// \brief Common SWIG interface code.
24/// \author Karl Wette
25///
26
27///
28/// # General SWIG directives
29///
30
31///
32/// Ensure that all LAL library bindings share type information.
33///
34%begin %{
35#define SWIG_TYPE_TABLE swiglal
36%}
37
38///
39/// Include SWIG headers.
40///
41%include <exception.i>
42%include <typemaps.i>
43
44///
45/// Turn on auto-documentation of functions.
46///
47%feature("autodoc", 1);
48
49///
50/// Enable keyword arguments for functions.
51///
52%feature("kwargs", 1);
53
54///
55/// Define macros for interpreting 64-bit integer constants.
56///
57#define INT64_C(c) c ## LL
58#define UINT64_C(c) c ## ULL
59
60///
61/// # Public macros
62///
63
64///
65/// Public macros (i.e. those used in headers) are contained inside the \b SWIGLAL() macro, so that
66/// they can be easily removed from the proprocessing interface. The \b SWIGLAL_CLEAR() macro is
67/// used to clear any effects of a public macro. Calls to \b SWIGLAL_CLEAR() are generated from the
68/// preprocessing interface.
69///
70#define SWIGLAL(...) %swiglal_public_##__VA_ARGS__
71#define SWIGLAL_CLEAR(...) %swiglal_public_clear_##__VA_ARGS__
72
73///
74/// # Utility macros
75///
76
77///
78/// The macro \b %swiglal_define2 defines a SWIG preprocessor symbol <tt>NAME1_NAME2</tt>.
79///
80%define %swiglal_define2(NAME1, NAME2)
81%define NAME1##_##NAME2 %enddef
82%enddef
83
84///
85/// The macro \b %swiglal_map() maps a one-argument <tt>MACRO(X)</tt> onto a list of arguments (which may
86/// be empty). Based on SWIG's <tt>%formacro()</tt>.
87///
88%define %_swiglal_map(MACRO, X, ...)
89#if #X != ""
90MACRO(X);
91%_swiglal_map(MACRO, __VA_ARGS__);
92#endif
93%enddef
94%define %swiglal_map(MACRO, ...)
95%_swiglal_map(MACRO, __VA_ARGS__, );
96%enddef
97
98///
99/// The macro \b %swiglal_map_a() maps a two-argument <tt>MACRO(A,X)</tt> onto a list of arguments (which
100/// may be empty), with a common first argument <tt>A</tt>.
101///
102%define %_swiglal_map_a(MACRO, A, X, ...)
103#if #X != ""
104MACRO(A, X);
105%_swiglal_map_a(MACRO, A, __VA_ARGS__);
106#endif
107%enddef
108%define %swiglal_map_a(MACRO, A, ...)
109%_swiglal_map_a(MACRO, A, __VA_ARGS__, );
110%enddef
111
112///
113/// The macro \b %swiglal_map_ab() maps a three-argument <tt>MACRO(A,B,X)</tt> onto a list of arguments
114/// (which may be empty), with common first arguments <tt>A</tt> and <tt>B</tt>.
115///
116%define %_swiglal_map_ab(MACRO, A, B, X, ...)
117#if #X != ""
118MACRO(A, B, X);
119%_swiglal_map_ab(MACRO, A, B, __VA_ARGS__);
120#endif
121%enddef
122%define %swiglal_map_ab(MACRO, A, B, ...)
123%_swiglal_map_ab(MACRO, A, B, __VA_ARGS__, );
124%enddef
125
126///
127/// The macro \b %swiglal_map_abc() maps a four-argument <tt>MACRO(A,B,C,X)</tt> onto a list of arguments
128/// (which may be empty), with common first arguments <tt>A,</tt> <tt>B,</tt> and <tt>C</tt>.
129///
130%define %_swiglal_map_abc(MACRO, A, B, C, X, ...)
131#if #X != ""
132MACRO(A, B, C, X);
133%_swiglal_map_abc(MACRO, A, B, C, __VA_ARGS__);
134#endif
135%enddef
136%define %swiglal_map_abc(MACRO, A, B, C, ...)
137%_swiglal_map_abc(MACRO, A, B, C, __VA_ARGS__, );
138%enddef
139
140///
141/// The macros \b %swiglal_apply() and \b %swiglal_clear() apply and clear SWIG typemaps.
142///
143%define %swiglal_apply(TYPEMAP, TYPE, NAME)
144%apply TYPEMAP { TYPE NAME };
145%enddef
146%define %swiglal_clear(TYPE, NAME)
147%clear TYPE NAME;
148%enddef
149
150///
151/// The macros \b %swiglal_feature and \b %swiglal_feature_nspace apply SWIG features.
152///
153%define %swiglal_feature(FEATURE, VALUE, NAME)
154%feature(FEATURE, VALUE) NAME;
155%enddef
156%define %swiglal_feature_nspace(FEATURE, VALUE, NSPACE, NAME)
157%feature(FEATURE, VALUE) NSPACE::NAME;
158%enddef
159
160///
161/// The macros \b %swiglal_warnfilter and \b %swiglal_warnfilter_nspace suppress SWIG warnings.
162///
163%define %swiglal_warnfilter(WARNING, NAME)
164%warnfilter(WARNING) NAME;
165%enddef
166%define %swiglal_warnfilter_nspace(WARNING, NSPACE, NAME)
167%warnfilter(WARNING) NSPACE::NAME;
168%enddef
169
170///
171/// The macro \b %swiglal_ignore_nspace ignores a symbol.
172///
173%define %swiglal_ignore_nspace(NSPACE, NAME)
174%ignore NSPACE::NAME;
175%enddef
176
177///
178/// These macros allocate and/or copy new instances and arrays. They are analogous to
179/// similarly-named SWIG macros but use XLALCalloc().
180///
181#define %swiglal_new_instance(TYPE...) %reinterpret_cast(XLALCalloc(1, sizeof(TYPE)), TYPE*)
182#define %swiglal_new_copy(VAL, TYPE...) %reinterpret_cast(memcpy(%swiglal_new_instance(TYPE), &(VAL), sizeof(TYPE)), TYPE*)
183#define %swiglal_new_array(SIZE, TYPE...) %reinterpret_cast(XLALCalloc(SIZE, sizeof(TYPE)), TYPE*)
184#define %swiglal_new_copy_array(PTR, SIZE, TYPE...) %reinterpret_cast(memcpy(%swiglal_new_array(SIZE, TYPE), PTR, sizeof(TYPE)*(SIZE)), TYPE*)
185
186///
187/// # General interface code
188///
189
190///
191/// Include C99/C++ headers.
192///
193%header %{
194#ifdef __cplusplus
195#include <cassert>
196#include <cstdlib>
197#include <cstdio>
198#include <cstring>
199#include <complex>
200#include <csignal>
201#else
202#include <assert.h>
203#include <stdlib.h>
204#include <stdio.h>
205#include <string.h>
206#include <stdbool.h>
207#include <complex.h>
208#include <signal.h>
209#endif
210#include <unistd.h>
211%}
212
213///
214/// Include SWIG configuration header generated from <tt>config.h</tt>, but don't generate wrappers for
215/// any of its symbols
216///
217%rename("$ignore", regexmatch$name="^SWIGLAL_") "";
218%include <swiglal_config.h>
219%header %{
220#include <swiglal_config.h>
221%}
222
223///
224/// Include GSL headers.
225///
226#ifdef SWIGLAL_HAVE_LIBGSL
227%header %{
228#include <gsl/gsl_errno.h>
229#include <gsl/gsl_math.h>
230#include <gsl/gsl_complex_math.h>
231#include <gsl/gsl_vector.h>
232#include <gsl/gsl_matrix.h>
233#include <gsl/gsl_rng.h>
234%}
235#endif
236
237///
238/// Add missing GSL constructor for single-precision complex numbers.
239///
240#ifdef SWIGLAL_HAVE_LIBGSL
241%header %{
242SWIGINTERNINLINE gsl_complex_float gsl_complex_float_rect(float x, float y) {
243 gsl_complex_float z;
244 GSL_SET_COMPLEX(&z, x, y);
245 return z;
246}
247%}
248#endif
249
250///
251/// Include LAL standard definitions header <tt>LALStddef.h</tt>: this contains macro definitions which
252/// are required for parsing LAL headers.
253///
254%include <lal/LALStddef.h>
255
256///
257/// Include LAL headers.
258///
259%header %{
260#include <lal/LALDatatypes.h>
261#include <lal/LALMalloc.h>
262#include <lal/LALString.h>
263#include <lal/XLALError.h>
264#include <lal/Date.h>
265%}
266
267///
268/// Version of SWIG used to generate wrapping code.
269///
270%constant int swig_version = SWIG_VERSION;
271
272///
273/// Standard output/error redirection
274/// - In some environments (e.g. IPython Jupyter notebooks) standard output/error within the scripting
275/// language are redirected in a non-trivial way. These redirections may not capture standard output/error
276/// from external C libraries such as LAL, which can result in e.g. error messages from LAL being printed
277/// to a terminal (if any) instead of the environment in which the scripting language is being used.
278/// - The \b lal.swig_redirect_standard_output_error() function turns on standard output/error redirection
279/// for all LAL libraries; see <tt>SWIGLALAlpha.i</tt> for its definition. The current redirection state
280/// is stored in the \c swig_lal_do_redirect_stdouterr variable.
281/// - It is possible for a SWIG wrapper function to call another SWIG wrapper function (e.g. through
282/// destructors), whereas standard output/error redirection should only happen once (within the outermost
283/// SWIG wrapper function). The \c swig_lal_has_stdouterr_been_redirected variable indicates whether
284/// redirection is already in place.
285/// - The \b SWIGLAL_REDIRECT_STDOUTERR and \b SWIGLAL_RESTORE_OUTPUT_STDOUTERR hooks are inserted by an
286/// \b %exception block (see below) and implement standard output/error redirection. These macros refer
287/// to a locally saved value of \c swig_lal_do_redirect_stdouterr in case its value is changed by
288/// \c $action (i.e. by a call to \b lal.swig_redirect_standard_output_error()). If the value of
289// \c swig_lal_has_stdouterr_been_redirected is true then redirection is already in place and these
290// macros do nothing.
291/// - The common function \b swiglal_redirect_stdouterr() redirects standard output & error to temporary
292/// files \c swiglal_tmp_stdout and \c swiglal_tmp_stderr respectively.
293/// - The common function \b swiglal_restore_stdouterr() restores the system standard output & error.
294/// - The scripting language-specific function \b swiglal_output_stdouterr() outputs the captured
295/// standard output & error through the scripting language API in a way that is robust to any
296/// redirections within the scripting language itself.
297///
298%header %{
301
302static int swiglal_save_stdout_fd, swiglal_save_stderr_fd;
303static FILE *swiglal_tmp_stdout, *swiglal_tmp_stderr;
304
305SWIGINTERN int swiglal_redirect_stdouterr(void);
306SWIGINTERN int swiglal_restore_stdouterr(void);
307SWIGINTERN int swiglal_output_stdouterr(void);
308
309#define SWIGLAL_REDIRECT_STDOUTERR \
310 { \
311 const int local_swig_lal_do_redirect_stdouterr = swig_lal_has_stdouterr_been_redirected ? 0 : swig_lal_do_redirect_stdouterr; \
312 if (local_swig_lal_do_redirect_stdouterr) { \
313 swig_lal_has_stdouterr_been_redirected = 1; \
314 if (!swiglal_redirect_stdouterr()) { \
315 SWIG_exception(SWIG_RuntimeError, "swiglal_redirect_stdouterr() failed"); \
316 } \
317 }
318#define SWIGLAL_RESTORE_OUTPUT_STDOUTERR \
319 if (local_swig_lal_do_redirect_stdouterr) { \
320 if (!swiglal_restore_stdouterr()) {\
321 SWIG_exception(SWIG_RuntimeError, "swiglal_restore_stdouterr() failed"); \
322 } \
323 if (!swiglal_output_stdouterr()) { \
324 SWIG_exception(SWIG_RuntimeError, "swiglal_output_stdouterr() failed"); \
325 } \
326 swig_lal_has_stdouterr_been_redirected = 0; \
327 } \
328 }
329
330SWIGINTERN int swiglal_redirect_stdouterr(void) {
331
332 // Flush standard output & error
333 fflush(stdout);
334 fsync(STDOUT_FILENO);
335 fflush(stderr);
336 fsync(STDERR_FILENO);
337
338 // Save the original standard output & error
339 swiglal_save_stdout_fd = dup(STDOUT_FILENO);
340 swiglal_save_stderr_fd = dup(STDERR_FILENO);
341 if (swiglal_save_stdout_fd < 0 || swiglal_save_stderr_fd < 0) {
342 const char msg[] = "redirect_stdouterr(): dup(STD{OUT|ERR}_FILENO) failed\n";
343 write(STDERR_FILENO, msg, sizeof(msg));
344 fsync(STDERR_FILENO);
345 return 0;
346 }
347
348 // Open new temporary files for standard output & error
349 swiglal_tmp_stdout = tmpfile();
350 swiglal_tmp_stderr = tmpfile();
351 if (swiglal_tmp_stdout == NULL || swiglal_tmp_stderr == NULL) {
352 const char msg[] = "redirect_stdouterr(): tmpfile() failed\n";
353 write(STDERR_FILENO, msg, sizeof(msg));
354 fsync(STDERR_FILENO);
355 close(swiglal_save_stdout_fd);
356 close(swiglal_save_stderr_fd);
357 if (swiglal_tmp_stdout != NULL) {
358 fclose(swiglal_tmp_stdout);
359 }
360 if (swiglal_tmp_stderr != NULL) {
361 fclose(swiglal_tmp_stderr);
362 }
363 return 0;
364 }
365
366 // Get file descriptors for temporary files
367 int swiglal_tmp_stdout_fd = fileno(swiglal_tmp_stdout);
368 int swiglal_tmp_stderr_fd = fileno(swiglal_tmp_stderr);
369 if (swiglal_tmp_stdout_fd < 0 || swiglal_tmp_stderr_fd < 0) {
370 const char msg[] = "redirect_stdouterr(): fileno(tmp_std{out|err}) failed\n";
371 write(STDERR_FILENO, msg, sizeof(msg));
372 fsync(STDERR_FILENO);
373 close(swiglal_save_stdout_fd);
374 close(swiglal_save_stderr_fd);
375 fclose(swiglal_tmp_stdout);
376 fclose(swiglal_tmp_stderr);
377 return 0;
378 }
379
380 // Redirect standard output & error to temporary files
381 if (dup2(swiglal_tmp_stdout_fd, STDOUT_FILENO) < 0) {
382 const char msg[] = "redirect_stdouterr(): dup2(swiglal_tmp_stdout_fd, STDOUT_FILENO) failed\n";
383 write(STDERR_FILENO, msg, sizeof(msg));
384 fsync(STDERR_FILENO);
385 close(swiglal_save_stdout_fd);
386 close(swiglal_save_stderr_fd);
387 fclose(swiglal_tmp_stdout);
388 fclose(swiglal_tmp_stderr);
389 return 0;
390 }
391 if (dup2(swiglal_tmp_stderr_fd, STDERR_FILENO) < 0) {
392 const char msg[] = "redirect_stdouterr(): dup2(swiglal_tmp_stderr_fd, STDERR_FILENO) failed\n";
393 write(STDERR_FILENO, msg, sizeof(msg));
394 fsync(STDERR_FILENO);
395 if (dup2(swiglal_save_stdout_fd, STDOUT_FILENO) < 0) {
396 const char msg[] = "redirect_stdouterr(): dup2(swiglal_save_stdout_fd, STDOUT_FILENO) failed\n";
397 write(STDERR_FILENO, msg, sizeof(msg));
398 fsync(STDERR_FILENO);
399 }
400 close(swiglal_save_stdout_fd);
401 close(swiglal_save_stderr_fd);
402 fclose(swiglal_tmp_stdout);
403 fclose(swiglal_tmp_stderr);
404 return 0;
405 }
406
407 return 1;
408
409}
410
411SWIGINTERN int swiglal_restore_stdouterr(void) {
412
413 // Flush standard output & error
414 fflush(stdout);
415 fsync(STDOUT_FILENO);
416 fflush(stderr);
417 fsync(STDERR_FILENO);
418
419 // Restore the original standard output & error
420 if (dup2(swiglal_save_stdout_fd, STDOUT_FILENO) < 0) {
421 const char msg[] = "redirect_stdouterr(): dup2(swiglal_save_stdout_fd, STDOUT_FILENO) failed\n";
422 write(swiglal_save_stderr_fd, msg, sizeof(msg));
423 fsync(swiglal_save_stderr_fd);
424 return 0;
425 }
426 if (dup2(swiglal_save_stderr_fd, STDERR_FILENO) < 0) {
427 const char msg[] = "redirect_stdouterr(): dup2(swiglal_save_stderr_fd, STDERR_FILENO) failed\n";
428 write(swiglal_save_stderr_fd, msg, sizeof(msg));
429 fsync(swiglal_save_stderr_fd);
430 return 0;
431 }
432
433 // Close the duplicated standard output & error file descriptors
434 close(swiglal_save_stdout_fd);
435 close(swiglal_save_stderr_fd);
436
437 return 1;
438
439}
440%}
441
442///
443/// Convert XLAL/LAL errors into native scripting-language exceptions:
444/// <dl>
445/// <dt>XLAL</dt><dd>Before performing any action, clear the XLAL error number. Check it after
446/// the action is performed; if it is non-zero, raise a native scripting-language exception with
447/// the appropriate XLAL error message.</dd>
448/// <dt>LAL</dt><dd>For any function which has a LALStatus* argument, create a blank LALStatus
449/// struct and pass its pointer to the LAL function. After the function is called, check the
450/// LALStatus statusCode; if it is non-zero, raise a generic XLAL error (to set the XLAL error
451/// number), then a native scripting-language exception. The <tt>swiglal_check_LALStatus</tt> (C)
452/// preprocessor symbol determines if the LAL error handling code is invoked; by default this
453/// symbol should be undefined, i.e. functions are XLAL functions by default.</dd>
454/// </dl>
455///
456/// The \b %exception block also inserts the \b SWIGLAL_REDIRECT_STDOUTERR and
457/// \b SWIGLAL_RESTORE_OUTPUT_STDOUTERR hooks for standard output/error redirection
458///
459%header %{
460static const LALStatus swiglal_empty_LALStatus = {0, NULL, NULL, NULL, NULL, 0, NULL, 0};
461#undef swiglal_check_LALStatus
462%}
463%typemap(in, noblock=1, numinputs=0) LALStatus* {
464 LALStatus lalstatus = swiglal_empty_LALStatus;
465 $1 = &lalstatus;
466%#define swiglal_check_LALStatus
467}
468%exception %{
470 SWIGLAL_REDIRECT_STDOUTERR
471 $action
472 SWIGLAL_RESTORE_OUTPUT_STDOUTERR
473#ifdef swiglal_check_LALStatus
474 if (lalstatus.statusCode) {
476 SWIG_exception(SWIG_RuntimeError, lalstatus.statusDescription);
477 }
478#else
479 if (xlalErrno) {
480 SWIG_exception(SWIG_RuntimeError, XLALErrorString(xlalErrno));
481 }
482#endif
483#undef swiglal_check_LALStatus
484%}
485
486///
487/// # General fragments
488///
489
490///
491/// Empty fragment, for fragment-generating macros.
492///
493%fragment("swiglal_empty_frag", "header") {}
494
495///
496/// Wrappers around SWIG's pointer to/from SWIG-wrapped scripting language object functions.
497/// \b swiglal_from_<i>SWIGTYPE</i>() simply returns a SWIG-wrapped object containing the input
498/// pointer. \b swiglal_from_<i>SWIGTYPE</i>() extracts a pointer from a SWIG-wrapped object, then
499/// struct-copies the pointer to the supplied output pointer.
500///
501%fragment("swiglal_from_SWIGTYPE", "header") {
502 SWIGINTERNINLINE SWIG_Object swiglal_from_SWIGTYPE(SWIG_Object self, bool copyobj, void *ptr, size_t len, bool isptr, swig_type_info *tinfo, int tflags) {
503 void *vptr = isptr ? *((void**)ptr) : ptr;
504 if (copyobj) {
505 vptr = memcpy(XLALCalloc(1, len), vptr, len);
506 tflags |= SWIG_POINTER_OWN;
507 } else if (vptr != NULL && swiglal_not_empty(self)) {
508 swiglal_store_parent(vptr, self);
509 tflags |= SWIG_POINTER_OWN;
510 }
511 return SWIG_NewPointerObj(vptr, tinfo, tflags);
512 }
513}
514%fragment("swiglal_as_SWIGTYPE", "header") {
515 SWIGINTERN int swiglal_as_SWIGTYPE(SWIG_Object self, SWIG_Object obj, void *ptr, size_t len, bool isptr, swig_type_info *tinfo, int tflags) {
516 void *vptr = NULL;
517 int res = SWIG_ConvertPtr(obj, &vptr, tinfo, tflags);
518 if (!SWIG_IsOK(res)) {
519 return res;
520 }
521 memcpy(ptr, isptr ? &vptr : vptr, len);
522 return res;
523 }
524}
525
526///
527/// # Extensions to structs
528///
529
530///
531/// Do not generate any default (copy) contructors or destructors.
532///
533%nodefaultctor;
534%nocopyctor;
535%nodefaultdtor;
536
537///
538/// Call the destructor <tt>DTORFUNC</tt>, but first call \b swiglal_release_parent() to check whether
539/// <tt>PTR</tt> own its own memory (and release any parents).
540///
541%define %swiglal_struct_call_dtor(DTORFUNC, PTR)
542if (swiglal_release_parent(PTR)) {
544 (void)DTORFUNC(PTR);
546}
547%enddef
548
549///
550/// Extend a <tt>struct TAGNAME</tt>.
551%define %swiglal_struct_extend(TAGNAME, OPAQUE, DTORFUNC)
552/// <ul><li>
553
554/// If this is an opaque struct, create an empty struct to represent the opaque struct, so that SWIG
555/// has something to attach the destructor to. No constructors are generated, since it is assumed
556/// that the struct will have a creator function. Otherwise, if this is not an opaque struct,
557/// generate basic constructor and (shallow) copy constructor, using XLALCalloc() to allocate memory.
558#if OPAQUE
559struct TAGNAME {
560};
561#else
562%extend TAGNAME {
563 TAGNAME() {
564 return %swiglal_new_instance(struct TAGNAME);
565 }
566 TAGNAME(const struct TAGNAME *src) {
567 return %swiglal_new_copy(*src, struct TAGNAME);
568 }
569}
570#endif
571
572/// </li><li>
573
574/// Create destructor, using either the destructor function <tt>DTORFUNC</tt>, or else XLALFree() if
575/// <tt>DTORFUNC</tt> is undefined, to destroy memory.
576#if #DTORFUNC == ""
577%extend TAGNAME {
578 ~TAGNAME() {
579 %swiglal_struct_call_dtor(XLALFree, $self);
580 }
581}
582#else
583%extend TAGNAME {
584 ~TAGNAME() {
585 %swiglal_struct_call_dtor(%arg(DTORFUNC), $self);
586 }
587}
588#endif
589
590/// </li><li>
591
592/// Add scripting-language-specific struct extensions.
593%swiglal_struct_extend_specific(TAGNAME, OPAQUE, DTORFUNC)
594
595/// </li></ul>
596%enddef
597
598///
599/// # Fragments and typemaps for arrays
600///
601
602///
603/// Map fixed-array types to special variables of their elements, e.g.
604/// <tt>$typemap(swiglal_fixarr_ltype, const int[][])</tt> returns <tt>int</tt>.
605///
606%typemap(swiglal_fixarr_ltype) SWIGTYPE "$ltype";
607%typemap(swiglal_fixarr_ltype) SWIGTYPE[ANY] "$typemap(swiglal_fixarr_ltype, $*type)";
608%typemap(swiglal_fixarr_ltype) SWIGTYPE[ANY][ANY] "$typemap(swiglal_fixarr_ltype, $*type)";
609
610%typemap(swiglal_fixarr_tinfo) SWIGTYPE "$&descriptor";
611%typemap(swiglal_fixarr_tinfo) SWIGTYPE * "$descriptor";
612%typemap(swiglal_fixarr_tinfo) SWIGTYPE *const "$descriptor";
613%typemap(swiglal_fixarr_tinfo) SWIGTYPE[ANY] "$typemap(swiglal_fixarr_tinfo, $*type)";
614%typemap(swiglal_fixarr_tinfo) SWIGTYPE[ANY][ANY] "$typemap(swiglal_fixarr_tinfo, $*type)";
615
616%typemap(swiglal_fixarr_isptr) SWIGTYPE "false";
617%typemap(swiglal_fixarr_isptr) SWIGTYPE * "true";
618%typemap(swiglal_fixarr_isptr) SWIGTYPE *const "true";
619%typemap(swiglal_fixarr_isptr) SWIGTYPE[ANY] "$typemap(swiglal_fixarr_isptr, $*type)";
620%typemap(swiglal_fixarr_isptr) SWIGTYPE[ANY][ANY] "$typemap(swiglal_fixarr_isptr, $*type)";
621
622///
623/// The conversion of C arrays to/from scripting-language arrays are performed by the following
624/// functions:
625/// <ul>
626/// <li>\b %swiglal_array_copyin...() copies a scripting-language array into a C array.</li>
627/// <li>\b %swiglal_array_copyout...() copies a C array into a scripting-language array.</li>
628/// <li>\b %swiglal_array_viewin...() tries to view a scripting-language array as a C array.</li>
629/// <li>\b %swiglal_array_viewout...() wraps a C array inside a scripting-language array, if this
630/// is supported by the target scripting language.</li>
631/// </ul>
632///
633/// These functions accept a subset of the following arguments:
634/// <ul>
635/// <li><tt>SWIG_Object obj</tt>: input scripting-language array.</li>
636/// <li><tt>SWIG_Object parent</tt>: SWIG-wrapped object containing parent struct.</li>
637/// <li><tt>void* ptr</tt>: pointer to C array.</li>
638/// <li><tt>int elemalloc</tt>: flag indicating whether C array elements must be freed.
639/// <li><tt>const size_t esize</tt>: size of one C array element, in bytes.</li>
640/// <li><tt>const size_t ndims</tt>: number of C array dimensions.</li>
641/// <li><tt>const size_t dims[]</tt>: length of each C array dimension.</li>
642/// <li><tt>const size_t strides[]</tt>: strides of C array dimension, in number of elements.</li>
643/// <li><tt>swig_type_info *tinfo</tt>: SWIG type info of the C array element datatype.</li>
644/// <li><tt>const int tflags</tt>: SWIG type conversion flags.</li>
645/// </ul>
646///
647/// Return values are:
648/// <ul>
649/// <li>\b %swiglal_array_copyin...(): SWIG error code as an <tt>int</tt>.</li>
650/// <li>\b %swiglal_array_copyout...(): output scripting-language array as a <tt>SWIG_Object</tt>.</li>
651/// <li>\b %swiglal_array_viewin...(): SWIG error code as an <tt>int</tt>.</li>
652/// <li>\b %swiglal_array_viewout...(): output scripting-language array view as a <tt>SWIG_Object</tt>.</li>
653/// </ul>
654///
655/// In addition, \b %swiglal_array_viewin...() should initialise <tt>dims</tt> regardless of whether
656/// a view is possible, as these values may need to be used by \b %swiglal_array_copyin...().
657///
658/// Finally, a common \b %swiglal_array_elemfree() function frees memory allocated for C array
659/// elements, if the flag <tt>elemalloc</tt> is set.
660///
661
662///
663/// Names of array conversion functions for array type <tt>ACFTYPE</tt>.
664///
665#define %swiglal_array_copyin_func(ACFTYPE) swiglal_array_copyin_##ACFTYPE
666#define %swiglal_array_copyout_func(ACFTYPE) swiglal_array_copyout_##ACFTYPE
667#define %swiglal_array_viewin_func(ACFTYPE) swiglal_array_viewin_##ACFTYPE
668#define %swiglal_array_viewout_func(ACFTYPE) swiglal_array_viewout_##ACFTYPE
669
670///
671/// Names of fragments containing the conversion functions for <tt>ACFTYPE</tt>.
672///
673#define %swiglal_array_copyin_frag(ACFTYPE) "swiglal_array_copyin_" %str(ACFTYPE)
674#define %swiglal_array_copyout_frag(ACFTYPE) "swiglal_array_copyout_" %str(ACFTYPE)
675#define %swiglal_array_viewin_frag(ACFTYPE) "swiglal_array_viewin_" %str(ACFTYPE)
676#define %swiglal_array_viewout_frag(ACFTYPE) "swiglal_array_viewout_" %str(ACFTYPE)
677
678///
679/// Common fragment to free memory allocated for C array elements.
680///
681%fragment("swiglal_array_elemfree", "header")
682{
683 SWIGINTERN void swiglal_array_elemfree(void* ptr,
684 int *pelemalloc,
685 const size_t esize,
686 const size_t ndims,
687 const size_t dims[])
688 {
689
690 // Return if C array elements should not be freed.
691 if (!(*pelemalloc)) {
692 return;
693 }
694
695 // Count the total number of C array elements.
696 size_t numel = 1;
697 for (size_t i = 0; i < ndims; ++i) {
698 numel *= dims[i];
699 }
700
701 // Iterate over all elements in the C array.
702 for (size_t i = 0; i < numel; ++i) {
703 void **elemptr = %reinterpret_cast(%reinterpret_cast(ptr, char*) + i*esize, void**);
704 XLALFree(*elemptr);
705 }
706
707 }
708}
709
710///
711/// The \b %swiglal_array_type() macro maps <tt>TYPE</tt>s of C arrays to an <tt>ACFTYPE</tt> of the
712/// appropriate array conversion functions, using a special typemap. The typemap also ensures that
713/// fragments containing the required conversion functions are included.
714///
715%define %_swiglal_array_type(ACFTYPE, TYPE)
716%fragment("swiglal_array_frags_" %str(ACFTYPE), "header",
717 fragment=%swiglal_array_copyin_frag(ACFTYPE),
718 fragment=%swiglal_array_copyout_frag(ACFTYPE),
719 fragment=%swiglal_array_viewin_frag(ACFTYPE),
720 fragment=%swiglal_array_viewout_frag(ACFTYPE),
721 fragment="swiglal_array_elemfree") {};
722%typemap(swiglal_array_typeid, fragment="swiglal_array_frags_" %str(ACFTYPE)) TYPE* %str(ACFTYPE);
723%typemap(swiglal_array_typeid, fragment="swiglal_array_frags_" %str(ACFTYPE)) const TYPE* %str(ACFTYPE);
724%typemap(swiglal_array_typeid, fragment="swiglal_array_frags_" %str(ACFTYPE)) TYPE[ANY] %str(ACFTYPE);
725%typemap(swiglal_array_typeid, fragment="swiglal_array_frags_" %str(ACFTYPE)) TYPE[ANY][ANY] %str(ACFTYPE);
726%typemap(swiglal_array_typeid, fragment="swiglal_array_frags_" %str(ACFTYPE)) const TYPE[ANY] %str(ACFTYPE);
727%typemap(swiglal_array_typeid, fragment="swiglal_array_frags_" %str(ACFTYPE)) const TYPE[ANY][ANY] %str(ACFTYPE);
728%enddef
729%define %swiglal_array_type(ACFTYPE, ...)
730%swiglal_map_a(%_swiglal_array_type, ACFTYPE, __VA_ARGS__);
731%enddef
732
733///
734/// Map C array <tt>TYPE</tt>s to array conversion function <tt>ACFTYPE</tt>s.
735///
736%swiglal_array_type(SWIGTYPE, SWIGTYPE);
737%swiglal_array_type(LALchar, char*);
738%swiglal_array_type(int8_t, char, signed char, int8_t);
739%swiglal_array_type(uint8_t, unsigned char, uint8_t);
740%swiglal_array_type(int16_t, short, int16_t);
741%swiglal_array_type(uint16_t, unsigned short, uint16_t);
742%swiglal_array_type(int32_t, int, int32_t, enum SWIGTYPE);
743%swiglal_array_type(uint32_t, unsigned int, uint32_t);
744%swiglal_array_type(int64_t, long long, int64_t);
745%swiglal_array_type(uint64_t, unsigned long long, uint64_t);
746%swiglal_array_type(float, float);
747%swiglal_array_type(double, double);
748%swiglal_array_type(gsl_complex_float, gsl_complex_float);
749%swiglal_array_type(gsl_complex, gsl_complex);
750%swiglal_array_type(COMPLEX8, COMPLEX8);
751%swiglal_array_type(COMPLEX16, COMPLEX16);
752
753///
754/// On modern systems, <tt>long</tt> could be either 32- or 64-bit...
755///
756%swiglal_array_type(int32or64_t, long);
757%swiglal_array_type(uint32or64_t, unsigned long);
758%define %swiglal_array_int32or64_frags(FRAG, FUNC, INT)
759%fragment(FRAG(INT##32or64_t), "header") {
760%#if LONG_MAX > INT_MAX
761%#define FUNC(INT##32or64_t) FUNC(INT##64_t)
762%#else
763%#define FUNC(INT##32or64_t) FUNC(INT##32_t)
764%#endif
765}
766%enddef
767%swiglal_array_int32or64_frags(%swiglal_array_copyin_frag, %swiglal_array_copyin_func, int);
768%swiglal_array_int32or64_frags(%swiglal_array_copyout_frag, %swiglal_array_copyout_func, int);
769%swiglal_array_int32or64_frags(%swiglal_array_viewin_frag, %swiglal_array_viewin_func, int);
770%swiglal_array_int32or64_frags(%swiglal_array_viewout_frag, %swiglal_array_viewout_func, int);
771%swiglal_array_int32or64_frags(%swiglal_array_copyin_frag, %swiglal_array_copyin_func, uint);
772%swiglal_array_int32or64_frags(%swiglal_array_copyout_frag, %swiglal_array_copyout_func, uint);
773%swiglal_array_int32or64_frags(%swiglal_array_viewin_frag, %swiglal_array_viewin_func, uint);
774%swiglal_array_int32or64_frags(%swiglal_array_viewout_frag, %swiglal_array_viewout_func, uint);
775
776///
777/// Call the appropriate conversion function for C <tt>TYPE</tt> arrays.
778///
779#define %swiglal_array_copyin(TYPE) %swiglal_array_copyin_func($typemap(swiglal_array_typeid, TYPE))
780#define %swiglal_array_copyout(TYPE) %swiglal_array_copyout_func($typemap(swiglal_array_typeid, TYPE))
781#define %swiglal_array_viewin(TYPE) %swiglal_array_viewin_func($typemap(swiglal_array_typeid, TYPE))
782#define %swiglal_array_viewout(TYPE) %swiglal_array_viewout_func($typemap(swiglal_array_typeid, TYPE))
783
784///
785/// ## Typemaps which convert to/from fixed-size arrays.
786///
787
788///
789/// Type checkers for overloaded functions:
790///
791%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE[ANY] {
792 $typemap(swiglal_fixarr_ltype, $1_type) temp_array[$1_dim0];
793 const size_t dims[1] = {$1_dim0};
794 const size_t strides[1] = {1};
795 /* swiglal_array_typeid input type: $1_type */
796 int res = %swiglal_array_copyin($1_type)(swiglal_no_self(), $input, %as_voidptr(&temp_array[0]), NULL,
797 sizeof(temp_array[0]), 1, dims, strides,
798 $typemap(swiglal_fixarr_isptr, $1_type), $typemap(swiglal_fixarr_tinfo, $1_type),
799 %convertptr_flags);
800 $1 = SWIG_CheckState(res);
801}
802%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE[ANY][ANY] {
803 $typemap(swiglal_fixarr_ltype, $1_type) temp_array[$1_dim0][$1_dim1];
804 const size_t dims[2] = {$1_dim0, $1_dim1};
805 const size_t strides[2] = {$1_dim1, 1};
806 /* swiglal_array_typeid input type: $1_type */
807 int res = %swiglal_array_copyin($1_type)(swiglal_no_self(), $input, %as_voidptr(&temp_array[0]), NULL,
808 sizeof(temp_array[0][0]), 2, dims, strides,
809 $typemap(swiglal_fixarr_isptr, $1_type), $typemap(swiglal_fixarr_tinfo, $1_type),
810 %convertptr_flags);
811 $1 = SWIG_CheckState(res);
812}
813
814///
815/// Input typemaps for functions and structs:
816///
817%typemap(in, noblock=1) SWIGTYPE[ANY] (size_t dims[1] = {0}, int elemalloc = 0), SWIGTYPE INOUT[ANY] (size_t dims[1] = {0}, int elemalloc = 0) {
818 $typemap(swiglal_fixarr_ltype, $1_type) temp_array$argnum[$1_dim0];
819 $1 = &temp_array$argnum[0];
820 {
821 dims[0] = $1_dim0;
822 const size_t strides[1] = {1};
823 /* swiglal_array_typeid input type: $1_type */
824 int res = %swiglal_array_copyin($1_type)(swiglal_no_self(), $input, %as_voidptr($1), &elemalloc,
825 sizeof($1[0]), 1, dims, strides,
826 $typemap(swiglal_fixarr_isptr, $1_type), $typemap(swiglal_fixarr_tinfo, $1_type),
827 $disown | %convertptr_flags);
828 if (!SWIG_IsOK(res)) {
829 %argument_fail(res, "$type", $symname, $argnum);
830 }
831 }
832}
833%typemap(freearg, match="in", noblock=1) SWIGTYPE[ANY], SWIGTYPE INOUT[ANY] {
834 swiglal_array_elemfree(arg$argnum, &elemalloc$argnum, sizeof($typemap(swiglal_fixarr_ltype, $1_type)), 1, dims$argnum);
835}
836%typemap(in, noblock=1) SWIGTYPE[ANY][ANY] (size_t dims[2] = {0, 0}, int elemalloc = 0), SWIGTYPE INOUT[ANY][ANY] (size_t dims[2] = {0, 0}, int elemalloc = 0) {
837 $typemap(swiglal_fixarr_ltype, $1_type) temp_array$argnum[$1_dim0][$1_dim1];
838 $1 = &temp_array$argnum[0];
839 {
840 dims[0] = $1_dim0; dims[1] = $1_dim1;
841 const size_t strides[2] = {$1_dim1, 1};
842 /* swiglal_array_typeid input type: $1_type */
843 int res = %swiglal_array_copyin($1_type)(swiglal_no_self(), $input, %as_voidptr($1), &elemalloc,
844 sizeof($1[0][0]), 2, dims, strides,
845 $typemap(swiglal_fixarr_isptr, $1_type), $typemap(swiglal_fixarr_tinfo, $1_type),
846 $disown | %convertptr_flags);
847 if (!SWIG_IsOK(res)) {
848 %argument_fail(res, "$type", $symname, $argnum);
849 }
850 }
851}
852%typemap(freearg, match="in", noblock=1) SWIGTYPE[ANY][ANY], SWIGTYPE INOUT[ANY][ANY] {
853 swiglal_array_elemfree(arg$argnum, &elemalloc$argnum, sizeof($typemap(swiglal_fixarr_ltype, $1_type)), 2, dims$argnum);
854}
855
856///
857/// Input typemaps for global variables:
858///
859%typemap(varin) SWIGTYPE[ANY] {
860 int elemalloc = 0;
861 const size_t dims[1] = {$1_dim0};
862 const size_t strides[1] = {1};
863 /* swiglal_array_typeid input type: $1_type */
864 int res = %swiglal_array_copyin($1_type)(swiglal_no_self(), $input, %as_voidptr($1), &elemalloc,
865 sizeof($1[0]), 1, dims, strides,
866 $typemap(swiglal_fixarr_isptr, $1_type), $typemap(swiglal_fixarr_tinfo, $1_type),
867 %convertptr_flags);
868 if (!SWIG_IsOK(res)) {
869 %variable_fail(res, "$type", $symname);
870 }
871}
872%typemap(varin) SWIGTYPE[ANY][ANY] {
873 int elemalloc = 0;
874 const size_t dims[2] = {$1_dim0, $1_dim1};
875 const size_t strides[2] = {$1_dim1, 1};
876 /* swiglal_array_typeid input type: $1_type */
877 int res = %swiglal_array_copyin($1_type)(swiglal_no_self(), $input, %as_voidptr($1), &elemalloc,
878 sizeof($1[0][0]), 2, dims, strides,
879 $typemap(swiglal_fixarr_isptr, $1_type), $typemap(swiglal_fixarr_tinfo, $1_type),
880 %convertptr_flags);
881 if (!SWIG_IsOK(res)) {
882 %variable_fail(res, "$type", $symname);
883 }
884}
885
886///
887/// Output typemaps for functions and structs:
888///
889%typemap(out) SWIGTYPE[ANY] {
890 const size_t dims[1] = {$1_dim0};
891 const size_t strides[1] = {1};
892 /* swiglal_array_typeid input type: $1_type */
893%#if $owner & SWIG_POINTER_OWN
894 %set_output(%swiglal_array_copyout($1_type)(swiglal_no_self(), %as_voidptr($1),
895 sizeof($1[0]), 1, dims, strides,
896 $typemap(swiglal_fixarr_isptr, $1_type), $typemap(swiglal_fixarr_tinfo, $1_type),
897 $owner | %newpointer_flags));
898%#else
899 %set_output(%swiglal_array_viewout($1_type)(swiglal_self(), %as_voidptr($1),
900 sizeof($1[0]), 1, dims, strides,
901 $typemap(swiglal_fixarr_isptr, $1_type), $typemap(swiglal_fixarr_tinfo, $1_type),
902 $owner | %newpointer_flags));
903%#endif
904}
905%typemap(out) SWIGTYPE[ANY][ANY] {
906 const size_t dims[2] = {$1_dim0, $1_dim1};
907 const size_t strides[2] = {$1_dim1, 1};
908 /* swiglal_array_typeid input type: $1_type */
909%#if $owner & SWIG_POINTER_OWN
910 %set_output(%swiglal_array_copyout($1_type)(swiglal_no_self(), %as_voidptr($1),
911 sizeof($1[0][0]), 2, dims, strides,
912 $typemap(swiglal_fixarr_isptr, $1_type), $typemap(swiglal_fixarr_tinfo, $1_type),
913 $owner | %newpointer_flags));
914%#else
915 %set_output(%swiglal_array_viewout($1_type)(swiglal_self(), %as_voidptr($1),
916 sizeof($1[0][0]), 2, dims, strides,
917 $typemap(swiglal_fixarr_isptr, $1_type), $typemap(swiglal_fixarr_tinfo, $1_type),
918 $owner | %newpointer_flags));
919%#endif
920}
921
922///
923/// Output typemaps for global variables:
924///
925%typemap(varout) SWIGTYPE[ANY] {
926 const size_t dims[1] = {$1_dim0};
927 const size_t strides[1] = {1};
928 /* swiglal_array_typeid input type: $1_type */
929 %set_output(%swiglal_array_viewout($1_type)(swiglal_no_self(), %as_voidptr($1),
930 sizeof($1[0]), 1, dims, strides,
931 $typemap(swiglal_fixarr_isptr, $1_type), $typemap(swiglal_fixarr_tinfo, $1_type),
932 %newpointer_flags));
933}
934%typemap(varout) SWIGTYPE[ANY][ANY] {
935 const size_t dims[2] = {$1_dim0, $1_dim1};
936 const size_t strides[2] = {$1_dim1, 1};
937 /* swiglal_array_typeid input type: $1_type */
938 %set_output(%swiglal_array_viewout($1_type)(swiglal_no_self(), %as_voidptr($1),
939 sizeof($1[0][0]), 2, dims, strides,
940 $typemap(swiglal_fixarr_isptr, $1_type), $typemap(swiglal_fixarr_tinfo, $1_type),
941 %newpointer_flags));
942}
943
944///
945/// Argument-output typemaps for functions:
946///
947%typemap(in, noblock=1, numinputs=0) SWIGTYPE OUTPUT[ANY] {
948 $typemap(swiglal_fixarr_ltype, $1_type) temp_array$argnum[$1_dim0];
949 $1 = &temp_array$argnum[0];
950}
951%typemap(argout) SWIGTYPE OUTPUT[ANY], SWIGTYPE INOUT[ANY] {
952 const size_t dims[1] = {$1_dim0};
953 const size_t strides[1] = {1};
954 /* swiglal_array_typeid input type: $1_type */
955 %append_output(%swiglal_array_copyout($1_type)(swiglal_no_self(), %as_voidptr($1),
956 sizeof($1[0]), 1, dims, strides,
957 $typemap(swiglal_fixarr_isptr, $1_type), $typemap(swiglal_fixarr_tinfo, $1_type),
958 SWIG_POINTER_OWN | %newpointer_flags));
959}
960%typemap(in, noblock=1, numinputs=0) SWIGTYPE OUTPUT[ANY][ANY] {
961 $typemap(swiglal_fixarr_ltype, $1_type) temp_array$argnum[$1_dim0][$1_dim1];
962 $1 = &temp_array$argnum[0];
963}
964%typemap(argout) SWIGTYPE OUTPUT[ANY][ANY], SWIGTYPE INOUT[ANY][ANY] {
965 const size_t dims[2] = {$1_dim0, $1_dim1};
966 const size_t strides[2] = {$1_dim1, 1};
967 /* swiglal_array_typeid input type: $1_type */
968 %append_output(%swiglal_array_copyout($1_type)(swiglal_no_self(), %as_voidptr($1),
969 sizeof($1[0][0]), 2, dims, strides,
970 $typemap(swiglal_fixarr_isptr, $1_type), $typemap(swiglal_fixarr_tinfo, $1_type),
971 SWIG_POINTER_OWN | %newpointer_flags));
972}
973
974///
975/// Public macros to make fixed <i>n</i>D arrays:
976/// <ul>
977/// <li>output-only arguments: <b>SWIGLAL(OUTPUT_ARRAY_<i>n</i>D(TYPE, ...))</b></li>
978%define %swiglal_public_OUTPUT_ARRAY_1D(TYPE, ...)
979%swiglal_map_ab(%swiglal_apply, SWIGTYPE OUTPUT[ANY], TYPE, __VA_ARGS__);
980%enddef
981%define %swiglal_public_clear_OUTPUT_ARRAY_1D(TYPE, ...)
982%swiglal_map_a(%swiglal_clear, TYPE, __VA_ARGS__);
983%enddef
984%define %swiglal_public_OUTPUT_ARRAY_2D(TYPE, ...)
985%swiglal_map_ab(%swiglal_apply, SWIGTYPE OUTPUT[ANY][ANY], TYPE, __VA_ARGS__);
986%enddef
987%define %swiglal_public_clear_OUTPUT_ARRAY_2D(TYPE, ...)
988%swiglal_map_a(%swiglal_clear, TYPE, __VA_ARGS__);
989%enddef
990/// <li>input-output arguments: <b>SWIGLAL(INOUT_ARRAY_<i>n</i>D(TYPE, ...))</b></li>
991%define %swiglal_public_INOUT_ARRAY_1D(TYPE, ...)
992%swiglal_map_ab(%swiglal_apply, SWIGTYPE INOUT[ANY], TYPE, __VA_ARGS__);
993%enddef
994%define %swiglal_public_clear_INOUT_ARRAY_1D(TYPE, ...)
995%swiglal_map_a(%swiglal_clear, TYPE, __VA_ARGS__);
996%enddef
997%define %swiglal_public_INOUT_ARRAY_2D(TYPE, ...)
998%swiglal_map_ab(%swiglal_apply, SWIGTYPE INOUT[ANY][ANY], TYPE, __VA_ARGS__);
999%enddef
1000%define %swiglal_public_clear_INOUT_ARRAY_2D(TYPE, ...)
1001%swiglal_map_a(%swiglal_clear, TYPE, __VA_ARGS__);
1002%enddef
1003/// </ul>
1004
1005///
1006/// ## Typemaps which convert to/from dynamically-sized arrays.
1007///
1008
1009///
1010/// Get the correct descriptor for a dynamic array element. Always return a pointer description,
1011/// even for non-pointer types, and determine whether array is an array of pointers or of data
1012/// blocks.
1013///
1014%typemap(swiglal_dynarr_tinfo) SWIGTYPE "$&descriptor";
1015%typemap(swiglal_dynarr_tinfo) SWIGTYPE* "$descriptor";
1016
1017%typemap(swiglal_dynarr_isptr) SWIGTYPE "false";
1018%typemap(swiglal_dynarr_isptr) SWIGTYPE* "true";
1019
1020///
1021/// Create immutable members for accessing the array's dimensions. <tt>NI</tt> is the name of the
1022/// dimension member, and <tt>SIZET</tt> is its type.
1023///
1024%define %swiglal_array_dynamic_size(SIZET, NI)
1025%feature("action") NI {
1026 result = %static_cast(arg1->NI, SIZET);
1027}
1028%extend {
1029 const SIZET NI;
1030}
1031%feature("action", "") NI;
1032%enddef
1033
1034///
1035/// Check that array strides are non-zero, otherwise fail.
1036///
1037%define %swiglal_array_dynamic_check_strides(NAME, DATA, I)
1038if (strides[I-1] == 0) {
1039 SWIG_exception_fail(SWIG_IndexError, "Stride of dimension "#I" of "#NAME"."#DATA" is zero");
1040}
1041%enddef
1042
1043///
1044/// The \b %swiglal_array_dynamic_<i>n</i>D() macros create typemaps which convert <i>n</i>D
1045/// dynamically-allocated arrays in structs <tt>NAME</tt>. The macros must be added inside the definition
1046/// of the struct, before the struct members comprising the array are defined. The <tt>DATA</tt> and \c
1047/// N{I,J} members give the array data and dimensions, <tt>TYPE</tt> and <tt>SIZET</tt> give their respective
1048/// types. The <tt>S{I,J}</tt> give the strides of the array, in number of elements. If the sizes or
1049/// strides are members of the struct, <tt>arg1-></tt> should be used to access the struct itself.
1050///
1051/// <ul><li>
1052/// 1-D arrays:
1053%define %swiglal_array_dynamic_1D(NAME, TYPE, SIZET, DATA, NI, SI)
1054/// <ul><li>
1055
1056/// Typemaps which convert to/from the dynamically-allocated array.
1057%typemap(in, noblock=1) TYPE* DATA (size_t dims[1] = {0}, int elemalloc = 0) {
1058 if (arg1) {
1059 dims[0] = %static_cast(NI, size_t);
1060 const size_t strides[1] = {%static_cast(SI, size_t)};
1061 %swiglal_array_dynamic_check_strides(NAME, DATA, 1);
1062 $1 = %reinterpret_cast(arg1->DATA, TYPE*);
1063 /* swiglal_array_typeid input type: $1_type */
1064 int res = %swiglal_array_copyin($1_type)(swiglal_self(), $input, %as_voidptr($1), &elemalloc,
1065 sizeof(TYPE), 1, dims, strides,
1066 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
1067 $disown | %convertptr_flags);
1068 if (!SWIG_IsOK(res)) {
1069 %argument_fail(res, "$type", $symname, $argnum);
1070 }
1071 }
1072}
1073%typemap(freearg, noblock=1) TYPE* DATA {
1074 swiglal_array_elemfree(%as_voidptr(arg1->DATA), &elemalloc$argnum, sizeof(TYPE), 1, dims$argnum);
1075}
1076%typemap(out, noblock=1) TYPE* DATA {
1077 if (arg1) {
1078 const size_t dims[1] = {%static_cast(NI, size_t)};
1079 const size_t strides[1] = {%static_cast(SI, size_t)};
1080 %swiglal_array_dynamic_check_strides(NAME, DATA, 1);
1081 $1 = %reinterpret_cast(arg1->DATA, TYPE*);
1082 /* swiglal_array_typeid input type: $1_type */
1083 %set_output(%swiglal_array_viewout($1_type)(swiglal_self(), %as_voidptr($1),
1084 sizeof(TYPE), 1, dims, strides,
1085 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
1086 $owner | %newpointer_flags));
1087 }
1088}
1089
1090/// </li><li>
1091
1092/// Clear unneeded typemaps and features.
1093%typemap(memberin, noblock=1) TYPE* DATA "";
1094%typemap(argout, noblock=1) TYPE* DATA "";
1095%typemap(freearg, noblock=1) TYPE* DATA "";
1096%feature("action") DATA "";
1097%feature("except") DATA "";
1098
1099/// </li><li>
1100
1101/// Create the array's data member.
1102%extend {
1103 TYPE *DATA;
1104}
1105
1106/// </li><li>
1107
1108/// Restore modified typemaps and features.
1109%feature("action", "") DATA;
1110%feature("except", "") DATA;
1111%clear TYPE* DATA;
1112
1113/// </li></ul>
1114%enddef
1115
1116/// </li><li>
1117/// a 1-D array of pointers to 1-D arrays; <tt>NI</tt> refer to the array of pointers, <tt>NJ/SJ</tt> refer to
1118/// the arrays pointed to:
1119%define %swiglal_array_dynamic_1d_ptr_1d(NAME, TYPE, SIZET, DATA, NI, NJ, SJ)
1120/// <ul><li>
1121
1122/// Typemaps which convert from the dynamically-allocated array, indexed by <tt>arg2</tt>
1123%typemap(out, noblock=1) TYPE* DATA {
1124 if (arg1) {
1125 const size_t dims[1] = {%static_cast(NJ, size_t)};
1126 const size_t strides[1] = {%static_cast(SJ, size_t)};
1127 %swiglal_array_dynamic_check_strides(NAME, DATA, 1);
1128 if (((uint64_t)arg2) >= ((uint64_t)NI)) {
1129 SWIG_exception_fail(SWIG_IndexError, "Index to "#NAME"."#DATA" is outside of range [0,"#NI"]");
1130 }
1131 $1 = %reinterpret_cast(arg1->DATA, TYPE*)[arg2];
1132 /* swiglal_array_typeid input type: $1_type */
1133 %set_output(%swiglal_array_viewout($1_type)(swiglal_self(), %as_voidptr($1),
1134 sizeof(TYPE), 1, dims, strides,
1135 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
1136 $owner | %newpointer_flags));
1137 }
1138}
1139
1140/// </li><li>
1141
1142/// Clear unneeded typemaps and features.
1143%typemap(memberin, noblock=1) TYPE* DATA "";
1144%typemap(argout, noblock=1) TYPE* DATA "";
1145%typemap(freearg, noblock=1) TYPE* DATA "";
1146%feature("action") DATA "";
1147%feature("except") DATA "";
1148
1149/// </li><li>
1150
1151/// Create the array's indexed data member.
1152%extend {
1153 TYPE *DATA(const SIZET index);
1154}
1155
1156/// </li><li>
1157
1158/// Restore modified typemaps and features.
1159%feature("action", "") DATA;
1160%feature("except", "") DATA;
1161%clear TYPE* DATA;
1162
1163/// </li></ul>
1164%enddef
1165
1166/// </li><li>
1167/// 2-D arrays:
1168%define %swiglal_array_dynamic_2D(NAME, TYPE, SIZET, DATA, NI, NJ, SI, SJ)
1169/// <ul><li>
1170
1171/// Typemaps which convert to/from the dynamically-allocated array.
1172%typemap(in, noblock=1) TYPE* DATA (size_t dims[2] = {0, 0}, int elemalloc = 0) {
1173 if (arg1) {
1174 dims[0] = %static_cast(NI, size_t); dims[1] = %static_cast(NJ, size_t);
1175 const size_t strides[2] = {%static_cast(SI, size_t), %static_cast(SJ, size_t)};
1176 %swiglal_array_dynamic_check_strides(NAME, DATA, 1);
1177 %swiglal_array_dynamic_check_strides(NAME, DATA, 2);
1178 $1 = %reinterpret_cast(arg1->DATA, TYPE*);
1179 /* swiglal_array_typeid input type: $1_type */
1180 int res = %swiglal_array_copyin($1_type)(swiglal_self(), $input, %as_voidptr($1), &elemalloc,
1181 sizeof(TYPE), 2, dims, strides,
1182 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
1183 $disown | %convertptr_flags);
1184 if (!SWIG_IsOK(res)) {
1185 %argument_fail(res, "$type", $symname, $argnum);
1186 }
1187 }
1188}
1189%typemap(freearg, noblock=1) TYPE* DATA {
1190 swiglal_array_elemfree(%as_voidptr(arg1->DATA), &elemalloc$argnum, sizeof(TYPE), 2, dims$argnum);
1191}
1192%typemap(out, noblock=1) TYPE* DATA {
1193 if (arg1) {
1194 const size_t dims[2] = {%static_cast(NI, size_t), %static_cast(NJ, size_t)};
1195 const size_t strides[2] = {%static_cast(SI, size_t), %static_cast(SJ, size_t)};
1196 %swiglal_array_dynamic_check_strides(NAME, DATA, 1);
1197 %swiglal_array_dynamic_check_strides(NAME, DATA, 2);
1198 $1 = %reinterpret_cast(arg1->DATA, TYPE*);
1199 /* swiglal_array_typeid input type: $1_type */
1200 %set_output(%swiglal_array_viewout($1_type)(swiglal_self(), %as_voidptr($1),
1201 sizeof(TYPE), 2, dims, strides,
1202 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
1203 $owner | %newpointer_flags));
1204 }
1205}
1206
1207/// </li><li>
1208
1209/// Clear unneeded typemaps and features.
1210%typemap(memberin, noblock=1) TYPE* DATA "";
1211%typemap(argout, noblock=1) TYPE* DATA "";
1212%typemap(freearg, noblock=1) TYPE* DATA "";
1213%feature("action") DATA "";
1214%feature("except") DATA "";
1215
1216/// </li><li>
1217
1218/// Create the array's data member.
1219%extend {
1220 TYPE *DATA;
1221}
1222
1223/// </li><li>
1224
1225/// Restore modified typemaps and features.
1226%feature("action", "") DATA;
1227%feature("except", "") DATA;
1228%clear TYPE* DATA;
1229
1230/// </li></ul>
1231%enddef
1232
1233/// </li></ul>
1234///
1235
1236///
1237/// The \b %swiglal_array_struct_<i>n</i>D() macros create typemaps which attempt to view a
1238/// C array <tt>struct NAME</tt> as a scripting-language array. If the input is not already a
1239/// SWIG-wrapped object wrapping a <tt>struct NAME</tt>, an input view is attempted using \b
1240/// %swiglal_array_viewin...().
1241///
1242/// The main concern with passing scripting-language memory to C code is that it might try to
1243/// re-allocate or free the memory, which would certainly lead to undefined behaviour. Therefore, by
1244/// default a view is attempted only for pointers to <tt>const NAME*</tt>, since it is reasonable to
1245/// assume the called C code will not try to re-allocate or free constant memory. When it is known
1246/// that the called C function will not try to re-allocate or free a particular argument, the
1247/// <b>SWIGLAL(VIEWIN_ARRAYS(NAME, ...))</b> macro can be used to apply the typemap to pointers to
1248/// (non-<tt>const</tt>) <tt>NAME*</tt>. Alternatively, the <b>SWIGLAL(COPYINOUT_ARRAYS(NAME, ...))</b>
1249/// macro treats <tt>NAME*</tt> as an input-output argument, and makes an internal copy of it if necessary.
1250///
1251/// <ul><li>
1252/// 1-D arrays:
1253%define %swiglal_array_struct_1D(NAME, TYPE, SIZET, DATA, NI)
1254/// <ul><li>
1255
1256/// Typemap which attempts to view pointers to <tt>const NAME*</tt>.
1257%typemap(in, noblock=1) const NAME* (void *argp = 0, int res = 0, NAME temp_struct, void *temp_data = 0, size_t dims[1] = {0}, int elemalloc = 0) %{
1258 res = SWIG_ConvertPtr($input, &argp, $descriptor, 0 /*$disown*/ | %convertptr_flags);
1259 if (!SWIG_IsOK(res)) {
1260 typedef struct { SIZET NI; TYPE* DATA; } sizchk_t;
1261 if (!($disown) && sizeof(sizchk_t) == sizeof(NAME)) {
1262 temp_struct.DATA = NULL;
1263 /* swiglal_array_typeid input type: TYPE* */
1264 res = %swiglal_array_viewin(TYPE*)(swiglal_no_self(), $input, %as_voidptrptr(&temp_struct.DATA),
1265 sizeof(TYPE), 1, dims,
1266 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
1267 $disown | %convertptr_flags);
1268 if (!SWIG_IsOK(res)) {
1269 temp_data = temp_struct.DATA = %swiglal_new_array(dims[0], TYPE);
1270 size_t strides[1] = {1};
1271 res = %swiglal_array_copyin(TYPE*)(swiglal_no_self(), $input, %as_voidptr(temp_struct.DATA), &elemalloc,
1272 sizeof(TYPE), 1, dims, strides,
1273 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
1274 $disown | %convertptr_flags);
1275 if (!SWIG_IsOK(res)) {
1276 %argument_fail(res, "$type", $symname, $argnum);
1277 } else {
1278 temp_struct.NI = %static_cast(dims[0], SIZET);
1279 argp = &temp_struct;
1280 }
1281 } else {
1282 temp_struct.NI = %static_cast(dims[0], SIZET);
1283 argp = &temp_struct;
1284 }
1285 } else {
1286 %argument_fail(res, "$type", $symname, $argnum);
1287 }
1288 }
1289 $1 = %reinterpret_cast(argp, $ltype);
1290%}
1291%typemap(freearg, match="in", noblock=1) const NAME* %{
1292 if (temp_data$argnum) {
1293 swiglal_array_elemfree(%as_voidptr(temp_data$argnum), &elemalloc$argnum, sizeof(TYPE), 1, dims$argnum);
1294 XLALFree(temp_data$argnum);
1295 }
1296%}
1297
1298/// </li><li>
1299
1300/// Typemap which attempts to view pointers to non-<tt>const</tt> <tt>NAME*</tt>.
1301%typemap(in, noblock=1) NAME* SWIGLAL_VIEWIN_ARRAY (void *argp = 0, int res = 0, NAME temp_struct) %{
1302 res = SWIG_ConvertPtr($input, &argp, $descriptor, 0 /*$disown*/ | %convertptr_flags);
1303 if (!SWIG_IsOK(res)) {
1304 typedef struct { SIZET NI; TYPE* DATA; } sizchk_t;
1305 if (!($disown) && sizeof(sizchk_t) == sizeof(NAME)) {
1306 size_t dims[1] = {0};
1307 temp_struct.DATA = NULL;
1308 /* swiglal_array_typeid input type: TYPE* */
1309 res = %swiglal_array_viewin(TYPE*)(swiglal_no_self(), $input, %as_voidptrptr(&temp_struct.DATA),
1310 sizeof(TYPE), 1, dims,
1311 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
1312 $disown | %convertptr_flags);
1313 if (!SWIG_IsOK(res)) {
1314 %argument_fail(res, "$type", $symname, $argnum);
1315 } else {
1316 temp_struct.NI = %static_cast(dims[0], SIZET);
1317 argp = &temp_struct;
1318 }
1319 } else {
1320 %argument_fail(res, "$type", $symname, $argnum);
1321 }
1322 }
1323 $1 = %reinterpret_cast(argp, $ltype);
1324%}
1325
1326/// </li><li>
1327
1328/// Typemap which treats pointers to non-<tt>const</tt> <tt>NAME*</tt> as input-output arguments.
1329/// The type of the output argument should always match that of the input argument, so:
1330/// - If the input argument is a SWIG-wrapped <tt>NAME*</tt>, just unwrap it and return a reference.
1331/// - If the input argument is a native scripting-language array, make an internal copy of it,
1332/// use the copy, and return a native scripting-language array copy of the internal copy.
1333%typemap(in, noblock=1) NAME* SWIGLAL_COPYINOUT_ARRAY (void *argp = 0, int res = 0, NAME temp_struct, SWIG_Object input_ref, void *temp_data = 0, size_t dims[1] = {0}, int elemalloc = 0) %{
1334 res = SWIG_ConvertPtr($input, &argp, $descriptor, 0 /*$disown*/ | %convertptr_flags);
1335 if (!SWIG_IsOK(res)) {
1336 typedef struct { SIZET NI; TYPE* DATA; } sizchk_t;
1337 if (!($disown) && sizeof(sizchk_t) == sizeof(NAME)) {
1338 /* swiglal_array_typeid input type: TYPE* */
1339 res = %swiglal_array_viewin(TYPE*)(swiglal_no_self(), $input, %as_voidptrptr(&temp_data),
1340 sizeof(TYPE), 1, dims,
1341 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
1342 $disown | %convertptr_flags);
1343 if (dims[0] > 0) {
1344 temp_data = temp_struct.DATA = %swiglal_new_array(dims[0], TYPE);
1345 size_t strides[1] = {1};
1346 res = %swiglal_array_copyin(TYPE*)(swiglal_no_self(), $input, %as_voidptr(temp_data), &elemalloc,
1347 sizeof(TYPE), 1, dims, strides,
1348 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
1349 $disown | %convertptr_flags);
1350 if (!SWIG_IsOK(res)) {
1351 %argument_fail(res, "$type", $symname, $argnum);
1352 } else {
1353 temp_struct.NI = %static_cast(dims[0], SIZET);
1354 argp = &temp_struct;
1355 }
1356 } else {
1357 %argument_fail(res, "$type", $symname, $argnum);
1358 }
1359 } else {
1360 %argument_fail(res, "$type", $symname, $argnum);
1361 }
1362 } else {
1363 input_ref = $input;
1364 }
1365 $1 = %reinterpret_cast(argp, $ltype);
1366%}
1367%typemap(argout, match="in", noblock=1) NAME* SWIGLAL_COPYINOUT_ARRAY %{
1368 if (temp_data$argnum) {
1369 const size_t dims[1] = {%static_cast(temp_struct$argnum.NI, size_t)};
1370 const size_t strides[1] = {1};
1371 /* swiglal_array_typeid input type: TYPE* */
1372 %append_output(%swiglal_array_copyout(TYPE*)(swiglal_no_self(), %as_voidptr(temp_data$argnum),
1373 sizeof(TYPE), 1, dims, strides,
1374 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
1375 SWIG_POINTER_OWN | %newpointer_flags));
1376 } else {
1377 %append_output(swiglal_get_reference(input_ref$argnum));
1378 }
1379%}
1380%typemap(freearg, match="in", noblock=1) NAME* SWIGLAL_COPYINOUT_ARRAY %{
1381 if (temp_data$argnum) {
1382 swiglal_array_elemfree(%as_voidptr(temp_data$argnum), &elemalloc$argnum, sizeof(TYPE), 1, dims$argnum);
1383 XLALFree(temp_data$argnum);
1384 }
1385%}
1386
1387/// </li></ul>
1388%enddef
1389
1390/// </li><li>
1391/// 2-D arrays:
1392%define %swiglal_array_struct_2D(NAME, TYPE, SIZET, DATA, NI, NJ)
1393/// <ul><li>
1394
1395/// Typemap which attempts to view pointers to <tt>const NAME*</tt>.
1396%typemap(in, noblock=1) const NAME* (void *argp = 0, int res = 0, NAME temp_struct, void *temp_data = 0, size_t dims[2] = {0, 0}, int elemalloc = 0) %{
1397 res = SWIG_ConvertPtr($input, &argp, $descriptor, 0 /*$disown*/ | %convertptr_flags);
1398 if (!SWIG_IsOK(res)) {
1399 typedef struct { SIZET NI; SIZET NJ; TYPE* DATA; } sizchk_t;
1400 if (!($disown) && sizeof(sizchk_t) == sizeof(NAME)) {
1401 temp_struct.DATA = NULL;
1402 /* swiglal_array_typeid input type: TYPE* */
1403 res = %swiglal_array_viewin(TYPE*)(swiglal_no_self(), $input, %as_voidptrptr(&temp_struct.DATA),
1404 sizeof(TYPE), 2, dims,
1405 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
1406 $disown | %convertptr_flags);
1407 if (!SWIG_IsOK(res)) {
1408 temp_data = temp_struct.DATA = %swiglal_new_array(dims[0] * dims[1], TYPE);
1409 size_t strides[2] = {dims[1], 1};
1410 res = %swiglal_array_copyin(TYPE*)(swiglal_no_self(), $input, %as_voidptr(temp_struct.DATA), &elemalloc,
1411 sizeof(TYPE), 2, dims, strides,
1412 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
1413 $disown | %convertptr_flags);
1414 if (!SWIG_IsOK(res)) {
1415 %argument_fail(res, "$type", $symname, $argnum);
1416 } else {
1417 temp_struct.NI = %static_cast(dims[0], SIZET);
1418 temp_struct.NJ = %static_cast(dims[1], SIZET);
1419 argp = &temp_struct;
1420 }
1421 } else {
1422 temp_struct.NI = %static_cast(dims[0], SIZET);
1423 temp_struct.NJ = %static_cast(dims[1], SIZET);
1424 argp = &temp_struct;
1425 }
1426 } else {
1427 %argument_fail(res, "$type", $symname, $argnum);
1428 }
1429 }
1430 $1 = %reinterpret_cast(argp, $ltype);
1431%}
1432%typemap(freearg, match="in", noblock=1) const NAME* %{
1433 if (temp_data$argnum) {
1434 swiglal_array_elemfree(%as_voidptr(temp_data$argnum), &elemalloc$argnum, sizeof(TYPE), 2, dims$argnum);
1435 XLALFree(temp_data$argnum);
1436 }
1437%}
1438
1439/// </li><li>
1440
1441/// Typemap which attempts to view pointers to non-<tt>const</tt> <tt>NAME*</tt>.
1442%typemap(in, noblock=1) NAME* SWIGLAL_VIEWIN_ARRAY (void *argp = 0, int res = 0, NAME temp_struct) %{
1443 res = SWIG_ConvertPtr($input, &argp, $descriptor, 0 /*$disown*/ | %convertptr_flags);
1444 if (!SWIG_IsOK(res)) {
1445 typedef struct { SIZET NI; SIZET NJ; TYPE* DATA; } sizchk_t;
1446 if (!($disown) && sizeof(sizchk_t) == sizeof(NAME)) {
1447 size_t dims[2] = {0, 0};
1448 temp_struct.DATA = NULL;
1449 /* swiglal_array_typeid input type: TYPE* */
1450 res = %swiglal_array_viewin(TYPE*)(swiglal_no_self(), $input, %as_voidptrptr(&temp_struct.DATA),
1451 sizeof(TYPE), 2, dims,
1452 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
1453 $disown | %convertptr_flags);
1454 if (!SWIG_IsOK(res)) {
1455 %argument_fail(res, "$type", $symname, $argnum);
1456 } else {
1457 temp_struct.NI = %static_cast(dims[0], SIZET);
1458 temp_struct.NJ = %static_cast(dims[1], SIZET);
1459 argp = &temp_struct;
1460 }
1461 } else {
1462 %argument_fail(res, "$type", $symname, $argnum);
1463 }
1464 }
1465 $1 = %reinterpret_cast(argp, $ltype);
1466%}
1467
1468/// </li><li>
1469
1470/// Typemap which treats pointers to non-<tt>const</tt> <tt>NAME*</tt> as input-output arguments.
1471/// The type of the output argument should always match that of the input argument, so:
1472/// - If the input argument is a SWIG-wrapped <tt>NAME*</tt>, just unwrap it and return a reference.
1473/// - If the input argument is a native scripting-language array, make an internal copy of it,
1474/// use the copy, and return a native scripting-language array copy of the internal copy.
1475%typemap(in, noblock=1) NAME* SWIGLAL_COPYINOUT_ARRAY (void *argp = 0, int res = 0, NAME temp_struct, SWIG_Object input_ref, void *temp_data = 0, size_t dims[2] = {0, 0}, int elemalloc = 0) %{
1476 res = SWIG_ConvertPtr($input, &argp, $descriptor, 0 /*$disown*/ | %convertptr_flags);
1477 if (!SWIG_IsOK(res)) {
1478 typedef struct { SIZET NI; SIZET NJ; TYPE* DATA; } sizchk_t;
1479 if (!($disown) && sizeof(sizchk_t) == sizeof(NAME)) {
1480 /* swiglal_array_typeid input type: TYPE* */
1481 res = %swiglal_array_viewin(TYPE*)(swiglal_no_self(), $input, %as_voidptrptr(&temp_data),
1482 sizeof(TYPE), 2, dims,
1483 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
1484 $disown | %convertptr_flags);
1485 if (dims[0] * dims[1] > 0) {
1486 temp_data = temp_struct.DATA = %swiglal_new_array(dims[0] * dims[1], TYPE);
1487 size_t strides[2] = {dims[1], 1};
1488 res = %swiglal_array_copyin(TYPE*)(swiglal_no_self(), $input, %as_voidptr(temp_data), &elemalloc,
1489 sizeof(TYPE), 2, dims, strides,
1490 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
1491 $disown | %convertptr_flags);
1492 if (!SWIG_IsOK(res)) {
1493 %argument_fail(res, "$type", $symname, $argnum);
1494 } else {
1495 temp_struct.NI = %static_cast(dims[0], SIZET);
1496 temp_struct.NJ = %static_cast(dims[1], SIZET);
1497 argp = &temp_struct;
1498 }
1499 } else {
1500 %argument_fail(res, "$type", $symname, $argnum);
1501 }
1502 } else {
1503 %argument_fail(res, "$type", $symname, $argnum);
1504 }
1505 } else {
1506 input_ref = $input;
1507 }
1508 $1 = %reinterpret_cast(argp, $ltype);
1509%}
1510%typemap(argout, match="in", noblock=1) NAME* SWIGLAL_COPYINOUT_ARRAY %{
1511 if (temp_data$argnum) {
1512 const size_t dims[2] = {%static_cast(temp_struct$argnum.NI, size_t), %static_cast(temp_struct$argnum.NJ, size_t)};
1513 const size_t strides[2] = {dims[1], 1};
1514 /* swiglal_array_typeid input type: TYPE* */
1515 %append_output(%swiglal_array_copyout(TYPE*)(swiglal_no_self(), %as_voidptr(temp_data$argnum),
1516 sizeof(TYPE), 2, dims, strides,
1517 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
1518 SWIG_POINTER_OWN | %newpointer_flags));
1519 } else {
1520 %append_output(swiglal_get_reference(input_ref$argnum));
1521 }
1522%}
1523%typemap(freearg, match="in", noblock=1) NAME* SWIGLAL_COPYINOUT_ARRAY %{
1524 if (temp_data$argnum) {
1525 swiglal_array_elemfree(%as_voidptr(temp_data$argnum), &elemalloc$argnum, sizeof(TYPE), 2, dims$argnum);
1526 XLALFree(temp_data$argnum);
1527 }
1528%}
1529
1530/// </li></ul>
1531%enddef
1532
1533/// </li></ul>
1534///
1535
1536///
1537/// The <b>SWIGLAL(VIEWIN_ARRAYS(NAME, ...))</b> macro can be used to apply the above input view
1538/// typemaps to pointers to (non-<tt>const</tt>) <tt>NAME*</tt>.
1539///
1540%define %swiglal_public_VIEWIN_ARRAYS(NAME, ...)
1541%swiglal_map_ab(%swiglal_apply, NAME* SWIGLAL_VIEWIN_ARRAY, NAME*, __VA_ARGS__);
1542%enddef
1543%define %swiglal_public_clear_VIEWIN_ARRAYS(NAME, ...)
1544%swiglal_map_a(%swiglal_clear, NAME*, __VA_ARGS__);
1545%enddef
1546
1547///
1548/// The <b>SWIGLAL(COPYINOUT_ARRAYS(NAME, ...))</b> treats <tt>NAME*</tt> as an input-output argument.
1549/// The type of the output argument should always match that of the input argument, i.e. either
1550/// a SWIG-wrapped <tt>NAME*</tt> struct, or a native scripting language array.
1551///
1552%define %swiglal_public_COPYINOUT_ARRAYS(NAME, ...)
1553%swiglal_map_ab(%swiglal_apply, NAME* SWIGLAL_COPYINOUT_ARRAY, NAME*, __VA_ARGS__);
1554%enddef
1555%define %swiglal_public_clear_COPYINOUT_ARRAYS(NAME, ...)
1556%swiglal_map_a(%swiglal_clear, NAME*, __VA_ARGS__);
1557%enddef
1558
1559///
1560/// The <b>SWIGLAL(ARRAY_<i>n</i>D...(NAME, ...))</b> macros should be called from within the
1561/// definitions of LAL structs NAME containing dynamically-allocated arrays.
1562/// <ul><li>
1563/// 1-D arrays, e.g <tt>SIZET NI; TYPE* DATA;</tt>:
1564%define %swiglal_public_ARRAY_1D(NAME, TYPE, DATA, SIZET, NI)
1565%swiglal_array_dynamic_size(SIZET, NI);
1566%swiglal_array_dynamic_1D(NAME, TYPE, SIZET, DATA, arg1->NI, 1);
1567%ignore DATA;
1568%ignore NI;
1569%enddef
1570#define %swiglal_public_clear_ARRAY_1D(NAME, TYPE, DATA, SIZET, NI)
1571/// </li><li>
1572/// 1-D array structs, e.g <tt>typedef struct { SIZET NI; TYPE* DATA; } NAME;</tt>:
1573%define %swiglal_public_ARRAY_STRUCT_1D(NAME, TYPE, DATA, SIZET, NI)
1574%swiglal_public_ARRAY_1D(NAME, TYPE, DATA, SIZET, NI)
1575%swiglal_array_struct_1D(NAME, TYPE, SIZET, DATA, NI);
1576%enddef
1577#define %swiglal_public_clear_ARRAY_STRUCT_1D(NAME, TYPE, DATA, SIZET, NI)
1578/// </li><li>
1579/// a 1-D array of pointers to 1-D arrays, e.g. <tt>SIZET NI; SIZET NJ; ATYPE* DATA[(NI
1580/// members)];</tt>
1581%define %swiglal_public_ARRAY_1D_PTR_1D(NAME, TYPE, DATA, SIZET, NI, NJ)
1582%swiglal_array_dynamic_size(SIZET, NI);
1583%swiglal_array_dynamic_size(SIZET, NJ);
1584%swiglal_array_dynamic_1d_ptr_1d(NAME, TYPE, SIZET, DATA, arg1->NI, arg1->NJ, 1);
1585%ignore DATA;
1586%ignore NJ;
1587%enddef
1588#define %swiglal_public_clear_ARRAY_1D_PTR_1D(NAME, TYPE, DATA, SIZET, NI, NJ)
1589/// </li><li>
1590/// 2-D arrays, e.g <tt>SIZET NI, NJ; TYPE* DATA;</tt>:
1591%define %swiglal_public_ARRAY_2D(NAME, TYPE, DATA, SIZET, NI, NJ)
1592%swiglal_array_dynamic_size(SIZET, NI);
1593%swiglal_array_dynamic_size(SIZET, NJ);
1594%swiglal_array_dynamic_2D(NAME, TYPE, SIZET, DATA, arg1->NI, arg1->NJ, arg1->NJ, 1);
1595%ignore DATA;
1596%ignore NI;
1597%ignore NJ;
1598%enddef
1599#define %swiglal_public_clear_ARRAY_2D(NAME, TYPE, DATA, SIZET, NI, NJ)
1600/// </li><li>
1601/// 2-D array structs, e.g <tt>typedef { SIZET NI, NJ; TYPE* DATA; } NAME</tt>:
1602%define %swiglal_public_ARRAY_STRUCT_2D(NAME, TYPE, DATA, SIZET, NI, NJ)
1603%swiglal_public_ARRAY_2D(NAME, TYPE, DATA, SIZET, NI, NJ)
1604%swiglal_array_struct_2D(NAME, TYPE, SIZET, DATA, NI, NJ);
1605%enddef
1606#define %swiglal_public_clear_ARRAY_2D(NAME, TYPE, DATA, SIZET, NI, NJ)
1607/// </li><li>
1608/// 2-D arrays of fixed-length arrays, e.g <tt>typedef ETYPE[NJ] ATYPE; SIZET NI; ATYPE* DATA;</tt>:
1609%define %swiglal_public_ARRAY_2D_FIXED(NAME, ETYPE, ATYPE, DATA, SIZET, NI)
1610%swiglal_array_dynamic_size(SIZET, NI);
1611%swiglal_array_dynamic_2D(NAME, ETYPE, SIZET, DATA, arg1->NI, (sizeof(ATYPE)/sizeof(ETYPE)), (sizeof(ATYPE)/sizeof(ETYPE)), 1);
1612%ignore DATA;
1613%ignore NI;
1614%enddef
1615#define %swiglal_public_clear_ARRAY_2D_FIXED(NAME, ETYPE, ATYPE, DATA, SIZET, NI)
1616/// </li></ul>
1617///
1618
1619///
1620/// If multiple arrays in the same struct use the same length parameter, the
1621/// <b>SWIGLAL(ARRAY_MULTIPLE_LENGTHS(TAGNAME, ...))</b> macro is required
1622/// before the struct definition to suppress warnings.
1623///
1624%define %swiglal_public_ARRAY_MULTIPLE_LENGTHS(TAGNAME, ...)
1625%swiglal_map_ab(%swiglal_warnfilter_nspace, SWIGWARN_PARSE_REDEFINED, TAGNAME, __VA_ARGS__);
1626%enddef
1627#define %swiglal_public_clear_ARRAY_MULTIPLE_LENGTHS(TAGNAME, ...)
1628
1629///
1630/// # Include scripting-language-specific interface headers
1631///
1632#if defined(SWIGOCTAVE)
1633%include <lal/SWIGOctave.i>
1634#elif defined(SWIGPYTHON)
1635%include <lal/SWIGPython.i>
1636#else
1637#error Unrecognised scripting language
1638#endif
1639
1640///
1641/// # General typemaps
1642///
1643
1644///
1645/// Typemap for functions which return <tt>int</tt>. If these functions also return other output arguments
1646/// (via <tt>argout</tt> typemaps), the <tt>int</tt> return value is ignored. This is because <tt>int</tt> is very
1647/// commonly used to return an XLAL error code, which will be converted into a native
1648/// scripting-language exception, and so the error code itself is not needed directly. To avoid
1649/// having to unpack the error code when collecting the other output arguments, therefore, it is
1650/// ignored in the wrappings. Functions which fit this criteria but do return a useful <tt>int</tt> can
1651/// use <b>SWIGLAL(RETURN_VALUE(int, ...))</b> to disable this behaviour.
1652///
1653/// For functions, the <tt>newfree</tt> typemap is applied, which calls the scripting-language-specific macro
1654/// \b swiglal_maybe_return_int(). For structs, the <tt>newfree</tt> typemap is never applied.
1655///
1656%typemap(newfree, noblock=1) int SWIGLAL_MAYBE_RETURN_INT {
1657 swiglal_maybe_return_int();
1658}
1659
1660///
1661/// Typemaps for empty arguments. These typemaps are useful when no input from the scripting
1662/// language is required, and an empty struct needs to be supplied to the C function. The
1663/// <b>SWIGLAL(EMPTY_ARGUMENT(TYPE, ...))</b> macro applies the typemap which supplies a static
1664/// struct, while the <b>SWIGLAL(NEW_EMPTY_ARGUMENT(TYPE, ...))</b> macro applies the typemap which
1665/// supplies a dynamically-allocated struct. These typemaps may cause there to be no SWIG-wrapped
1666/// object for the first argument; if so, <tt>swiglal_no_1starg</tt> is defined for the duration of the
1667/// wrapping function.
1668///
1669%define %swiglal_public_EMPTY_ARGUMENT(TYPE, ...)
1670%swiglal_map_ab(%swiglal_apply, SWIGTYPE* SWIGLAL_EMPTY_ARGUMENT, TYPE, __VA_ARGS__);
1671%enddef
1672%define %swiglal_public_clear_EMPTY_ARGUMENT(TYPE, ...)
1673%swiglal_map_a(%swiglal_clear, TYPE, __VA_ARGS__);
1674%enddef
1675%typemap(in, noblock=1, numinputs=0) SWIGTYPE* SWIGLAL_EMPTY_ARGUMENT ($*ltype emptyarg) {
1676 memset(&emptyarg, 0, sizeof($*type));
1677 $1 = &emptyarg;
1678%#if $argnum == 1
1679%#define swiglal_no_1starg
1680%#endif
1681}
1682%typemap(freearg, noblock=1) SWIGTYPE* SWIGLAL_EMPTY_ARGUMENT {
1683%#undef swiglal_no_1starg
1684}
1685%define %swiglal_public_NEW_EMPTY_ARGUMENT(TYPE, ...)
1686%swiglal_map_ab(%swiglal_apply, SWIGTYPE* SWIGLAL_NEW_EMPTY_ARGUMENT, TYPE, __VA_ARGS__);
1687%enddef
1688%define %swiglal_public_clear_NEW_EMPTY_ARGUMENT(TYPE, ...)
1689%swiglal_map_a(%swiglal_clear, TYPE, __VA_ARGS__);
1690%enddef
1691%typemap(in, noblock=1, numinputs=0) SWIGTYPE* SWIGLAL_NEW_EMPTY_ARGUMENT {
1692 $1 = %swiglal_new_instance($*type);
1693%#if $argnum == 1
1694%#define swiglal_no_1starg
1695%#endif
1696}
1697%typemap(freearg, noblock=1) SWIGTYPE* SWIGLAL_NEW_EMPTY_ARGUMENT {
1698%#undef swiglal_no_1starg
1699}
1700
1701///
1702/// SWIG conversion functions for C99 integer types. These are mapped to the corresponding basic C
1703/// types, conversion functions for which are supplied by SWIG.
1704///
1705%define %swiglal_numeric_typedef(CHECKCODE, BASETYPE, TYPE)
1706%numeric_type_from(TYPE, BASETYPE);
1707%numeric_type_asval(TYPE, BASETYPE, "swiglal_empty_frag", false);
1708%typemaps_primitive(%checkcode(CHECKCODE), TYPE);
1709%enddef
1710%swiglal_numeric_typedef(INT8, signed char, int8_t);
1711%swiglal_numeric_typedef(UINT8, unsigned char, uint8_t);
1712%swiglal_numeric_typedef(INT16, short, int16_t);
1713%swiglal_numeric_typedef(UINT16, unsigned short, uint16_t);
1714%swiglal_numeric_typedef(INT32, int, int32_t);
1715%swiglal_numeric_typedef(UINT32, unsigned int, uint32_t);
1716%swiglal_numeric_typedef(INT64, long long, int64_t);
1717%swiglal_numeric_typedef(UINT64, unsigned long long, uint64_t);
1718
1719///
1720/// Fragments and typemaps for the LAL ::BOOLEAN type. The fragments re-use existing
1721/// scriping-language conversion functions for the C/C++ boolean type. Appropriate
1722/// typemaps are then generated by <tt>%typemaps_asvalfromn()</tt>.
1723///
1724%fragment(SWIG_From_frag(BOOLEAN), "header", fragment=SWIG_From_frag(bool)) {
1725 SWIGINTERNINLINE SWIG_Object SWIG_From_dec(BOOLEAN)(BOOLEAN value) {
1726 return SWIG_From(bool)(value ? true : false);
1727 }
1728}
1729%fragment(SWIG_AsVal_frag(BOOLEAN), "header", fragment=SWIG_AsVal_frag(bool)) {
1730 SWIGINTERN int SWIG_AsVal_dec(BOOLEAN)(SWIG_Object obj, BOOLEAN *val) {
1731 bool v;
1732 int res = SWIG_AsVal(bool)(obj, val ? &v : 0);
1733 if (!SWIG_IsOK(res)) {
1734 return SWIG_TypeError;
1735 }
1736 if (val) {
1737 *val = v ? 1 : 0;
1738 }
1739 return res;
1740 }
1741}
1742%typemaps_primitive(%checkcode(BOOL), BOOLEAN);
1743
1744///
1745/// Fragments and typemaps for LAL strings, which should be (de)allocated using XLALMalloc() and
1746/// XLALFree(). The fragments re-use existing scriping-language conversion functions for ordinary
1747/// <tt>char*</tt> strings. Appropriate typemaps are then generated by <tt>%typemaps_string_alloc()</tt>, with
1748/// custom memory allocators.
1749///
1750%fragment("SWIG_FromLALcharPtrAndSize", "header", fragment="SWIG_FromCharPtrAndSize") {
1751 SWIGINTERNINLINE SWIG_Object SWIG_FromLALcharPtrAndSize(const char *str, size_t size) {
1752 return SWIG_FromCharPtrAndSize(str, size);
1753 }
1754}
1755%fragment("SWIG_AsLALcharPtrAndSize", "header", fragment="SWIG_AsCharPtrAndSize") {
1756 SWIGINTERN int SWIG_AsLALcharPtrAndSize(SWIG_Object obj, char **pstr, size_t *psize, int *alloc) {
1757 char *slstr = 0;
1758 size_t slsize = 0;
1759 int slalloc = 0;
1760 /* Allow empty 'obj' to correspond to NULL string pointer */
1761 if (swiglal_null_ptr(obj)) {
1762 if (pstr) {
1763 *pstr = NULL;
1764 }
1765 return SWIG_OK;
1766 }
1767 /* Get pointer to scripting-language string 'slstr' and size 'slsize'. */
1768 /* The 'slalloc' argument indicates whether a new string was allocated. */
1769 int res = SWIG_AsCharPtrAndSize(obj, &slstr, &slsize, &slalloc);
1770 if (!SWIG_IsOK(res)) {
1771 return SWIG_TypeError;
1772 }
1773 /* Return the string, if needed. */
1774 if (pstr) {
1775 /* Free the LAL string if it is already allocated. */
1776 if (*pstr) {
1777 XLALFree(*pstr);
1778 }
1779 if (alloc) {
1780 /* Copy the scripting-language string into a LAL-managed memory string. */
1781 *pstr = %swiglal_new_copy_array(slstr, slsize, char);
1782 *alloc = SWIG_NEWOBJ;
1783 }
1784 else {
1785 return SWIG_TypeError;
1786 }
1787 }
1788 /* Return the size (length+1) of the string, if needed. */
1789 if (psize) {
1790 *psize = slsize;
1791 }
1792 /* Free the scripting-language string, if it was allocated. */
1793 if (slalloc == SWIG_NEWOBJ) {
1794 %delete_array(slstr);
1795 }
1796 return res;
1797 }
1798}
1799#if SWIG_VERSION >= 0x040100
1800%typemaps_string_alloc(%checkcode(STRING), %checkcode(char),
1801 SWIGWARN_TYPEMAP_CHARLEAK_MSG, char, LALchar,
1802 SWIG_AsLALcharPtrAndSize, SWIG_FromLALcharPtrAndSize,
1803 strlen, SWIG_strnlen, %swiglal_new_copy_array, XLALFree,
1804 "<limits.h>", CHAR_MIN, CHAR_MAX);
1805#else
1806%typemaps_string_alloc(%checkcode(STRING), %checkcode(char), char, LALchar,
1807 SWIG_AsLALcharPtrAndSize, SWIG_FromLALcharPtrAndSize,
1808 strlen, SWIG_strnlen, %swiglal_new_copy_array, XLALFree,
1809 "<limits.h>", CHAR_MIN, CHAR_MAX);
1810#endif
1811
1812///
1813/// Typemaps for string pointers. By default, treat arguments of type <tt>char**</tt> as output-only
1814/// arguments, which do not require a scripting-language input argument, and return their results in
1815/// the output argument list. Also supply an <tt>INOUT</tt> typemap for input-output arguments, which
1816/// allows a scripting-language input string to be supplied. The <tt>INOUT</tt> typemaps can be applied as
1817/// needed using the <b>SWIGLAL(INOUT_STRINGS(...))</b> macro.
1818///
1819%typemap(in, noblock=1, numinputs=0) char ** (char *str = NULL, int alloc = 0) {
1820 $1 = %reinterpret_cast(&str, $ltype);
1821 alloc = 0;
1822}
1823%typemap(in, noblock=1, fragment="SWIG_AsLALcharPtrAndSize") char ** INOUT (char *str = NULL, int alloc = 0, int res = 0) {
1824 res = SWIG_AsLALcharPtr($input, &str, &alloc);
1825 if (!SWIG_IsOK(res)) {
1826 %argument_fail(res, "$type", $symname, $argnum);
1827 }
1828 $1 = %reinterpret_cast(&str, $ltype);
1829}
1830%typemap(argout, noblock=1) char ** {
1831 %append_output(SWIG_FromLALcharPtr(str$argnum));
1832}
1833%typemap(freearg, match="in") char ** {
1834 if (SWIG_IsNewObj(alloc$argnum)) {
1835 XLALFree(str$argnum);
1836 }
1837}
1838%define %swiglal_public_INOUT_STRINGS(...)
1839%swiglal_map_ab(%swiglal_apply, char ** INOUT, char **, __VA_ARGS__);
1840%enddef
1841%define %swiglal_public_clear_INOUT_STRINGS(...)
1842%swiglal_map_a(%swiglal_clear, char **, __VA_ARGS__);
1843%enddef
1844
1845///
1846/// Do not try to free <tt>const char*</tt> return arguments.
1847///
1848%typemap(newfree, noblock=1) const char* "";
1849
1850///
1851/// Input typemap for pointer-to-<tt>const</tt> <tt>SWIGTYPE</tt>s. This typemap is identical to the
1852/// standard <tt>SWIGTYPE</tt> pointer typemap, except <tt>$disown</tt> is commented out. This prevents
1853/// SWIG transferring ownership of SWIG-wrapped objects when assigning to pointer-to-<tt>const</tt>
1854/// members of structs. In this case, it is assumed that the struct does not want to take ownership
1855/// of the pointer, since it cannot free it (since it is a pointer-to-<tt>const</tt>).
1856///
1857%typemap(in, noblock=1) const SWIGTYPE * (void *argp = 0, int res = 0) {
1858 res = SWIG_ConvertPtr($input, &argp, $descriptor, 0 /*$disown*/ | %convertptr_flags);
1859 if (!SWIG_IsOK(res)) {
1860 %argument_fail(res, "$type", $symname, $argnum);
1861 }
1862 $1 = %reinterpret_cast(argp, $ltype);
1863}
1864%typemap(freearg) const SWIGTYPE * "";
1865
1866///
1867/// Struct member assignment typemap for pointer-to-<tt>const</tt> <tt>SWIGTYPE</tt>s. This typemap
1868/// overrides the standard SWIG-generated assigment code which casts away <tt>const</tt> on the left-hand,
1869/// thereby generating compiler errors.
1870///
1871%typemap(memberin, noblock=1) const SWIGTYPE * {
1872 if (arg1) *($type*)&(arg1)->$name = ($type)arg2;
1873}
1874
1875///
1876/// Typemaps for output <tt>SWIGTYPE</tt>s. This typemaps will match either the SWIG-wrapped return
1877/// argument from functions (which will have the <tt>SWIG_POINTER_OWN</tt> bit set in <tt>$owner</tt>) or
1878/// return a member of a struct through a <tt>get</tt> functions (in which case <tt>SWIG_POINTER_OWN</tt> will
1879/// not be set). They require the following macros:
1880///
1881/// The macro \b %swiglal_store_parent() is called to store a reference to the struct containing the
1882/// member being accessed, in order to prevent it from being destroyed as long as the SWIG-wrapped
1883/// member object is in scope. The return object is then always created with <tt>SWIG_POINTER_OWN</tt>, so
1884/// that its destructor will always be called.
1885///
1886%define %swiglal_store_parent(PTR, OWNER, SELF)
1887%#if !(OWNER & SWIG_POINTER_OWN)
1888 if (%as_voidptr(PTR) != NULL) {
1889 swiglal_store_parent(%as_voidptr(PTR), SELF);
1890 }
1891%#endif
1892%enddef
1893///
1894/// The macro \b %swiglal_set_output() sets the output of the wrapping function. If the (pointer)
1895/// return type of the function is the same as its first argument, then
1896/// <tt>swiglal_return_1starg_\#\#<i>NAME</i></tt> is defined. Unless <tt>swiglal_no_1starg</tt> is
1897/// defined (in which case the first argument is being handled by e.g. the <tt>EMPTY_ARGUMENT</tt>
1898/// typemap), the macro compares the pointer of the return value (<tt>result</tt>) to that of the first
1899/// argument (<tt>arg1</tt>). If they're equal, the SWIG-wrapped function will return a \e reference to
1900/// the SWIG object wrapping the first argument, i.e. the same object with its reference count
1901/// incremented. That way, if the return value is assigned to a different scripting-language
1902/// variable than the first argument, the underlying C struct will not be destroyed until both
1903/// scripting-language variables are cleared. If the pointers are not equal, or one pointer is \c
1904/// NULL, the macro return a SWIG object wrapping the new C struct.
1905///
1906%define %swiglal_set_output(NAME, OBJ)
1907%#if defined(swiglal_return_1starg_##NAME) && !defined(swiglal_no_1starg)
1908 if (result != NULL && result == arg1) {
1909 %set_output(swiglal_get_reference(swiglal_1starg()));
1910 } else {
1911 %set_output(OBJ);
1912 }
1913%#else
1914 %set_output(OBJ);
1915%#endif
1916%enddef
1917%typemap(out, noblock=1) SWIGTYPE *, SWIGTYPE &, SWIGTYPE[] {
1918 %swiglal_store_parent($1, $owner, swiglal_self());
1919 %swiglal_set_output($1_name, SWIG_NewPointerObj(%as_voidptr($1), $descriptor, ($owner | %newpointer_flags) | SWIG_POINTER_OWN));
1920}
1921%typemap(out, noblock=1) const SWIGTYPE *, const SWIGTYPE &, const SWIGTYPE[] {
1922 %set_output(SWIG_NewPointerObj(%as_voidptr($1), $descriptor, ($owner | %newpointer_flags) & ~SWIG_POINTER_OWN));
1923}
1924%typemap(out, noblock=1) SWIGTYPE *const& {
1925 %swiglal_store_parent(*$1, $owner, swiglal_self());
1926 %swiglal_set_output($1_name, SWIG_NewPointerObj(%as_voidptr(*$1), $*descriptor, ($owner | %newpointer_flags) | SWIG_POINTER_OWN));
1927}
1928%typemap(out, noblock=1) const SWIGTYPE *const& {
1929 %set_output(SWIG_NewPointerObj(%as_voidptr(*$1), $*descriptor, ($owner | %newpointer_flags) & ~SWIG_POINTER_OWN));
1930}
1931%typemap(out, noblock=1) SWIGTYPE (void* copy = NULL) {
1932 copy = %swiglal_new_copy($1, $ltype);
1933 %swiglal_store_parent(copy, SWIG_POINTER_OWN, swiglal_self());
1934 %set_output(SWIG_NewPointerObj(copy, $&descriptor, (%newpointer_flags) | SWIG_POINTER_OWN));
1935}
1936%typemap(varout, noblock=1) SWIGTYPE *, SWIGTYPE [] {
1937 %set_varoutput(SWIG_NewPointerObj(%as_voidptr($1), $descriptor, (%newpointer_flags) & ~SWIG_POINTER_OWN));
1938}
1939%typemap(varout, noblock=1) SWIGTYPE & {
1940 %set_varoutput(SWIG_NewPointerObj(%as_voidptr(&$1), $descriptor, (%newpointer_flags) & ~SWIG_POINTER_OWN));
1941}
1942%typemap(varout, noblock=1) SWIGTYPE {
1943 %set_varoutput(SWIG_NewPointerObj(%as_voidptr(&$1), $&descriptor, (%newpointer_flags) & ~SWIG_POINTER_OWN));
1944}
1945
1946///
1947/// Typemaps for pointers to primitive scalars. These are treated as output-only arguments by
1948/// default, by globally applying the SWIG <tt>OUTPUT</tt> typemaps.
1949///
1950%apply bool* OUTPUT { bool* };
1951%apply BOOLEAN* OUTPUT { BOOLEAN* };
1952%apply int* OUTPUT { enum SWIGTYPE* };
1953%apply short* OUTPUT { short* };
1954%apply unsigned short* OUTPUT { unsigned short* };
1955%apply int* OUTPUT { int* };
1956%apply unsigned int* OUTPUT { unsigned int* };
1957%apply long* OUTPUT { long* };
1958%apply unsigned long* OUTPUT { unsigned long* };
1959%apply long long* OUTPUT { long long* };
1960%apply unsigned long long* OUTPUT { unsigned long long* };
1961%apply float* OUTPUT { float* };
1962%apply double* OUTPUT { double* };
1963%apply int8_t* OUTPUT { int8_t* };
1964%apply uint8_t* OUTPUT { uint8_t* };
1965%apply int16_t* OUTPUT { int16_t* };
1966%apply uint16_t* OUTPUT { uint16_t* };
1967%apply int32_t* OUTPUT { int32_t* };
1968%apply uint32_t* OUTPUT { uint32_t* };
1969%apply int64_t* OUTPUT { int64_t* };
1970%apply uint64_t* OUTPUT { uint64_t* };
1971%apply gsl_complex_float* OUTPUT { gsl_complex_float* };
1972%apply gsl_complex* OUTPUT { gsl_complex* };
1973%apply COMPLEX8* OUTPUT { COMPLEX8* };
1974%apply COMPLEX16* OUTPUT { COMPLEX16* };
1975///
1976/// The INOUT typemaps can be applied instead using the macro <b>SWIGLAL(INOUT_SCALARS(TYPE,
1977/// ...))</b>.
1978///
1979%define %swiglal_public_INOUT_SCALARS(TYPE, ...)
1980%swiglal_map_ab(%swiglal_apply, TYPE INOUT, TYPE, __VA_ARGS__);
1981%enddef
1982%define %swiglal_public_clear_INOUT_SCALARS(TYPE, ...)
1983%swiglal_map_a(%swiglal_clear, TYPE, __VA_ARGS__);
1984%enddef
1985///
1986/// The INPUT typemaps can be applied instead using the macro <b>SWIGLAL(INPUT_SCALARS(TYPE,
1987/// ...))</b>.
1988///
1989%typemap(argout, noblock=1) SWIGTYPE* SWIGLAL_INPUT_SCALAR "";
1990%define %swiglal_public_INPUT_SCALARS(TYPE, ...)
1991%swiglal_map_ab(%swiglal_apply, TYPE INPUT, TYPE, __VA_ARGS__);
1992%swiglal_map_ab(%swiglal_apply, SWIGTYPE* SWIGLAL_INPUT_SCALAR, TYPE, __VA_ARGS__);
1993%enddef
1994%define %swiglal_public_clear_INPUT_SCALARS(TYPE, ...)
1995%swiglal_map_a(%swiglal_clear, TYPE, __VA_ARGS__);
1996%enddef
1997
1998///
1999/// Typemaps for double pointers. By default, treat arguments of type <tt>TYPE**</tt> as output-only
2000/// arguments, which do not require a scripting-language input argument, and return their results in
2001/// the output argument list. Also supply an <tt>INOUT</tt> typemap for input-output arguments, which
2002/// allows a scripting-language input argument to be supplied. The INOUT typemaps can be applied as
2003/// needed using the <b>SWIGLAL(INOUT_STRUCTS(TYPE, ...))</b> macro.
2004///
2005/// The typemaps apply the following convention for <tt>NULL</tt> pointers. For an argument <tt>arg</tt> of type
2006/// <tt>TYPE**</tt>, where <b>SWIGLAL(INOUT_STRUCTS(TYPE, arg))</b> has been applied:
2007/// <ul>
2008/// <li>if <tt>arg</tt> is passed a scripting language <tt>empty</tt> value (e.g. <tt>[]</tt> in Octave, or
2009/// <tt>None</tt> in Python), this is interpreted as a <tt>NULL</tt> pointer of type <tt>TYPE**</tt>, e.g.
2010/// <tt>TYPE** arg = NULL;</tt>.</li>
2011/// <li>if <tt>arg</tt> is passed the integer value <tt>0</tt>, this is interpreted as a valid pointer of
2012/// type TYPE** to a NULL pointer of type TYPE*, e.g. <tt>TYPE* ptr = NULL; TYPE** arg =
2013/// \&ptr;</tt>.</li>
2014/// </ul>
2015///
2016%typemap(in, noblock=1, numinputs=0) SWIGTYPE ** (void *argp = NULL) {
2017 $1 = %reinterpret_cast(&argp, $ltype);
2018}
2019%typemap(in, noblock=1, fragment=SWIG_AsVal_frag(int)) SWIGTYPE ** INOUT (SWIG_Object inobj, void *inarg = NULL, void *inoutarg = NULL, int res = 0) {
2020 inobj = $input;
2021 res = SWIG_ConvertPtr(inobj, &inarg, $*descriptor, ($disown | %convertptr_flags) & ~SWIG_POINTER_DISOWN);
2022 if (!SWIG_IsOK(res)) {
2023 int val = 0;
2024 res = SWIG_AsVal(int)(inobj, &val);
2025 if (!SWIG_IsOK(res) || val != 0) {
2026 %argument_fail(res, "$type", $symname, $argnum);
2027 } else {
2028 inoutarg = inarg = NULL;
2029 $1 = %reinterpret_cast(&inoutarg, $ltype);
2030 }
2031 } else {
2032 inoutarg = inarg;
2033 if (inoutarg == NULL) {
2034 $1 = NULL;
2035 } else {
2036 $1 = %reinterpret_cast(&inoutarg, $ltype);
2037 }
2038 }
2039}
2040%typemap(argout, noblock=1) SWIGTYPE ** {
2041 %append_output(SWIG_NewPointerObj($1 != NULL ? %as_voidptr(*$1) : NULL, $*descriptor, %newpointer_flags | SWIG_POINTER_OWN));
2042}
2043%typemap(argout, noblock=1) SWIGTYPE ** INOUT {
2044 if ($1 != NULL && *$1 != NULL && *$1 == inarg$argnum) {
2045 %append_output(swiglal_get_reference(inobj$argnum));
2046 } else {
2047 %append_output(SWIG_NewPointerObj($1 != NULL ? %as_voidptr(*$1) : NULL, $*descriptor, %newpointer_flags | SWIG_POINTER_OWN));
2048 }
2049}
2050%typemap(freearg) SWIGTYPE ** "";
2051%define %swiglal_public_INOUT_STRUCTS(TYPE, ...)
2052%swiglal_map_ab(%swiglal_apply, SWIGTYPE ** INOUT, TYPE, __VA_ARGS__);
2053%enddef
2054%define %swiglal_public_clear_INOUT_STRUCTS(TYPE, ...)
2055%swiglal_map_a(%swiglal_clear, TYPE, __VA_ARGS__);
2056%enddef
2057
2058///
2059/// Make the wrapping of <tt>printf()</tt>-style LAL functions a little safer, as suggested in the
2060/// SWIG 2.0 documentation (section 13.5). These functions should now be safely able to print any
2061/// string, so long as the format string is named <tt>format</tt> or <tt>fmt</tt>.
2062///
2063%typemap(in, fragment="SWIG_AsLALcharPtrAndSize") (const char *SWIGLAL_PRINTF_FORMAT, ...)
2064(char fmt[] = "%s", char *str = 0, int alloc = 0)
2065{
2066 $1 = fmt;
2067 int res = SWIG_AsLALcharPtr($input, &str, &alloc);
2068 if (!SWIG_IsOK(res)) {
2069 %argument_fail(res, "$type", $symname, $argnum);
2070 }
2071 $2 = (void *) str;
2072}
2073%typemap(freearg, match="in") (const char *format, ...) {
2074 if (SWIG_IsNewObj(alloc$argnum)) {
2075 XLALFree(str$argnum);
2076 }
2077}
2078%apply (const char *SWIGLAL_PRINTF_FORMAT, ...) {
2079 (const char *format, ...), (const char *fmt, ...)
2080};
2081
2082///
2083/// Specialised input typemap for C file pointers. Generally it is not possible to convert
2084/// scripting-language file objects into <tt>FILE*</tt>, since the scripting language may not provide
2085/// access to the <tt>FILE*</tt>, or even be using <tt>FILE*</tt> internally for I/O. The <tt>FILE*</tt> will
2086/// therefore have to be supplied from another SWIG-wrapped C function. For convenience, however,
2087/// we allow the user to pass integers 0, 1, or 2 in place of a <tt>FILE*</tt>, as an instruction to use
2088/// standard input, output, or error respectively.
2089///
2090%typemap(in, noblock=1, fragment=SWIG_AsVal_frag(int)) FILE* (void *argp = 0, int res = 0) {
2091 res = SWIG_ConvertPtr($input, &argp, $descriptor, $disown | %convertptr_flags);
2092 if (!SWIG_IsOK(res)) {
2093 int val = 0;
2094 res = SWIG_AsVal(int)($input, &val);
2095 if (!SWIG_IsOK(res)) {
2096 %argument_fail(res, "$type", $symname, $argnum);
2097 } else {
2098 switch (val) {
2099 case 0:
2100 $1 = stdin;
2101 break;
2102 case 1:
2103 $1 = stdout;
2104 break;
2105 case 2:
2106 $1 = stderr;
2107 break;
2108 default:
2109 %argument_fail(SWIG_ValueError, "$type", $symname, $argnum);
2110 }
2111 }
2112 } else {
2113 $1 = %reinterpret_cast(argp, $ltype);
2114 }
2115}
2116%typemap(freearg) FILE* "";
2117
2118///
2119/// Specialised input typemaps for a given <tt>struct TAGNAME</tt>. If conversion from a
2120/// SWIG-wrapped scripting language object <tt>INPUT</tt> fails, call the function defined in <tt>FRAGMENT</tt>,
2121/// <b>swiglal_specialised_<i>TAGNAME</i>(INPUT, OUTPUT)</b>, to try to convert <tt>INPUT</tt> from some
2122/// other value, and if successful store it in <tt>struct TAGNAME OUTPUT</tt>. Otherwise, raise a
2123/// SWIG error. Separate typemaps are needed for <tt>struct TAGNAME</tt> and pointers to <tt>struct
2124/// TAGNAME</tt>. Typecheck typemaps are used by overloaded functions, e.g. constructors.
2125/// The <tt>%swiglal_specialised_typemaps()</tt> macro handles flat structs, while the
2126/// <tt>%swiglal_specialised_ptr_typemaps()</tt> macro handles structs allocated with dynamic memory.
2127///
2128%define %swiglal_specialised_typemaps(TAGNAME, FRAGMENT)
2129%typemap(in, noblock=1, fragment=FRAGMENT)
2130 struct TAGNAME (void *argp = 0, int res = 0),
2131 const struct TAGNAME (void *argp = 0, int res = 0)
2132{
2133 res = SWIG_ConvertPtr($input, &argp, $&descriptor, $disown | %convertptr_flags);
2134 if (!SWIG_IsOK(res)) {
2135 res = swiglal_specialised_##TAGNAME($input, &$1);
2136 if (!SWIG_IsOK(res)) {
2137 %argument_fail(res, "$type", $symname, $argnum);
2138 }
2139 } else {
2140 if (!argp) {
2141 %argument_nullref("$type", $symname, $argnum);
2142 } else {
2143 $&ltype temp_ptr = %reinterpret_cast(argp, $&ltype);
2144 $1 = *temp_ptr;
2145 if (SWIG_IsNewObj(res)) {
2146 %delete(temp_ptr);
2147 }
2148 }
2149 }
2150}
2151%typemap(freearg) struct TAGNAME, const struct TAGNAME "";
2152%typemap(in, noblock=1, fragment=FRAGMENT)
2153 struct TAGNAME* (struct TAGNAME temp_struct, void *argp = 0, int res = 0),
2154 const struct TAGNAME* (struct TAGNAME temp_struct, void *argp = 0, int res = 0)
2155{
2156 res = SWIG_ConvertPtr($input, &argp, $descriptor, $disown | %convertptr_flags);
2157 if (!SWIG_IsOK(res)) {
2158 res = swiglal_specialised_##TAGNAME($input, &temp_struct);
2159 if (!SWIG_IsOK(res)) {
2160 %argument_fail(res, "$type", $symname, $argnum);
2161 } else {
2162 $1 = %reinterpret_cast(&temp_struct, $ltype);
2163 }
2164 } else {
2165 $1 = %reinterpret_cast(argp, $ltype);
2166 }
2167}
2168%typemap(freearg) struct TAGNAME*, const struct TAGNAME* "";
2169%typemap(typecheck, fragment=FRAGMENT, precedence=SWIG_TYPECHECK_SWIGOBJECT) struct TAGNAME, const struct TAGNAME {
2170 void *argp = 0;
2171 int res = SWIG_ConvertPtr($input, &argp, $&descriptor, 0);
2172 $1 = SWIG_CheckState(res);
2173 if (!$1) {
2174 struct TAGNAME temp_struct;
2175 res = swiglal_specialised_##TAGNAME($input, &temp_struct);
2176 $1 = SWIG_CheckState(res);
2177 }
2178}
2179%typemap(typecheck, fragment=FRAGMENT, precedence=SWIG_TYPECHECK_SWIGOBJECT) struct TAGNAME*, const struct TAGNAME* {
2180 void *argp = 0;
2181 int res = SWIG_ConvertPtr($input, &argp, $descriptor, 0);
2182 $1 = SWIG_CheckState(res);
2183 if (!$1) {
2184 struct TAGNAME temp_struct;
2185 res = swiglal_specialised_##TAGNAME($input, &temp_struct);
2186 $1 = SWIG_CheckState(res);
2187 }
2188}
2189%enddef
2190%define %swiglal_specialised_ptr_typemaps(TAGNAME, FRAGMENT)
2191%typemap(in, noblock=1, fragment=FRAGMENT)
2192 struct TAGNAME* (struct TAGNAME* temp_ptr = 0, void *argp = 0, int res = 0),
2193 const struct TAGNAME* (struct TAGNAME* temp_ptr = 0, void *argp = 0, int res = 0)
2194{
2195 res = SWIG_ConvertPtr($input, &argp, $descriptor, $disown | %convertptr_flags);
2196 if (!SWIG_IsOK(res)) {
2197 res = swiglal_specialised_ptr_##TAGNAME($input, &temp_ptr);
2198 if (!SWIG_IsOK(res)) {
2199 %argument_fail(res, "$type", $symname, $argnum);
2200 } else {
2201 $1 = %reinterpret_cast(temp_ptr, $ltype);
2202 }
2203 } else {
2204 $1 = %reinterpret_cast(argp, $ltype);
2205 }
2206}
2207%typemap(freearg) struct TAGNAME*, const struct TAGNAME* {
2208 if (temp_ptr$argnum) {
2209 swiglal_specialised_ptr_##TAGNAME##_destroy(temp_ptr$argnum);
2210 }
2211}
2212%typemap(typecheck, fragment=FRAGMENT, precedence=SWIG_TYPECHECK_SWIGOBJECT) struct TAGNAME*, const struct TAGNAME* {
2213 void *argp = 0;
2214 int res = SWIG_ConvertPtr($input, &argp, $descriptor, 0);
2215 $1 = SWIG_CheckState(res);
2216 if (!$1) {
2217 struct TAGNAME* temp_ptr;
2218 res = swiglal_specialised_##TAGNAME($input, &temp_ptr);
2219 $1 = SWIG_CheckState(res);
2220 swiglal_specialised_ptr_##TAGNAME##_destroy(temp_ptr);
2221 }
2222}
2223%enddef
2224
2225///
2226/// # General macros
2227///
2228
2229///
2230/// The <b>SWIGLAL(RETURN_VOID(TYPE,...))</b> public macro can be used to ensure that the return
2231/// value of a function is always ignored.
2232///
2233%define %swiglal_public_RETURN_VOID(TYPE, ...)
2234%swiglal_map_ab(%swiglal_apply, SWIGTYPE SWIGLAL_RETURN_VOID, TYPE, __VA_ARGS__);
2235%enddef
2236%define %swiglal_public_clear_RETURN_VOID(TYPE, ...)
2237%swiglal_map_a(%swiglal_clear, TYPE, __VA_ARGS__);
2238%enddef
2239%typemap(out, noblock=1) SWIGTYPE SWIGLAL_RETURN_VOID {
2240 %set_output(VOID_Object);
2241}
2242
2243///
2244/// The <b>SWIGLAL(RETURN_VALUE(TYPE,...))</b> public macro can be used to ensure that the return
2245/// value of a function is not ignored, if the return value has previously been ignored in the
2246/// generated wrappings.
2247///
2248%define %swiglal_public_RETURN_VALUE(TYPE, ...)
2249%swiglal_map_a(%swiglal_clear, TYPE, __VA_ARGS__);
2250%enddef
2251#define %swiglal_public_clear_RETURN_VALUE(TYPE, ...)
2252
2253///
2254/// The <b>SWIGLAL(DISABLE_EXCEPTIONS(...))</b> public macro is useful for functions which
2255/// manipulate XLAL error codes, which thus require XLAL exception handling to be disabled.
2256///
2257%define %swiglal_public_DISABLE_EXCEPTIONS(...)
2258%swiglal_map_ab(%swiglal_feature, "except", "$action", __VA_ARGS__);
2259%enddef
2260#define %swiglal_public_clear_DISABLE_EXCEPTIONS(...)
2261
2262///
2263/// The <b>SWIGLAL(FUNCTION_POINTER(...))</b> macro can be used to create a function pointer
2264/// constant, for functions which need to be used as callback functions.
2265///
2266%define %swiglal_public_FUNCTION_POINTER(...)
2267%swiglal_map_ab(%swiglal_feature, "callback", "%sPtr", __VA_ARGS__);
2268%enddef
2269#define %swiglal_public_clear_FUNCTION_POINTER(...)
2270
2271///
2272/// The <b>SWIGLAL(VARIABLE_ARGUMENT_LIST(...))</b> macro supports functions which require a
2273/// variable-length list of arguments of type <tt>TYPE</tt>, i.e. a list of strings. It generates SWIG
2274/// \e compact default arguments, i.e. only one wrapping function where all missing arguments are
2275/// assigned \e ENDVALUE, generates 11 additional optional arguments of type \e TYPE, and creates a
2276/// contract ensuring that the last argument is always <tt>ENDVALUE</tt>, so that the argument list is
2277/// terminated by <tt>ENDVALUE</tt>.
2278///
2279%define %swiglal_public_VARIABLE_ARGUMENT_LIST(FUNCTION, TYPE, ENDVALUE)
2280%feature("kwargs", 0) FUNCTION;
2281%feature("compactdefaultargs") FUNCTION;
2282%varargs(11, TYPE arg = ENDVALUE) FUNCTION;
2283%contract FUNCTION {
2284require:
2285 arg11 == ENDVALUE;
2286}
2287%enddef
2288#define %swiglal_public_clear_VARIABLE_ARGUMENT_LIST(FUNCTION, TYPE, ENDVALUE)
2289
2290///
2291/// The <b>SWIGLAL(RETURN_OWNED_BY_1ST_ARG(...))</b> macro is used when a function returns an object
2292/// whose memory is owned by the object supplied as the first argument to the function. Typically
2293/// this occurs when the function is returning some property of its first argument. The macro
2294/// applies a typemap which calles <tt>swiglal_store_parent()</tt> to store a reference to the first
2295/// argument as the <tt>parent</tt> of the return argument, so that the parent will not be destroyed as
2296/// long as the return value is in scope.
2297///
2298%define %swiglal_public_RETURN_OWNED_BY_1ST_ARG(TYPE, ...)
2299%swiglal_map_ab(%swiglal_apply, SWIGTYPE* SWIGLAL_RETURN_OWNED_BY_1ST_ARG, TYPE, __VA_ARGS__);
2300%enddef
2301%define %swiglal_public_clear_RETURN_OWNED_BY_1ST_ARG(TYPE, ...)
2302%swiglal_map_a(%swiglal_clear, TYPE, __VA_ARGS__);
2303%enddef
2304%typemap(out, noblock=1) SWIGTYPE* SWIGLAL_RETURN_OWNED_BY_1ST_ARG {
2305%#ifndef swiglal_no_1starg
2306 %swiglal_store_parent($1, 0, swiglal_1starg());
2307%#endif
2308 %set_output(SWIG_NewPointerObj(%as_voidptr($1), $descriptor, ($owner | %newpointer_flags) | SWIG_POINTER_OWN));
2309}
2310
2311///
2312/// The <b>SWIGLAL(OUTPUT_OWNED_BY_1ST_ARG(...))</b> macro is used when an output-only argument of a
2313/// function is an object whose memory is owned by the object supplied as the first argument to the
2314/// function. Typically this occurs when the function is returning some property of its first
2315/// argument. The macro applies a typemap which calles <tt>swiglal_store_parent()</tt> to store a
2316/// reference to the first argument as the <tt>parent</tt> of the output-only argument, so that the parent
2317/// will not be destroyed as long as the output value is in scope.
2318///
2319%define %swiglal_public_OUTPUT_OWNED_BY_1ST_ARG(TYPE, ...)
2320%swiglal_map_ab(%swiglal_apply, SWIGTYPE** SWIGLAL_OUTPUT_OWNED_BY_1ST_ARG, TYPE, __VA_ARGS__);
2321%enddef
2322%define %swiglal_public_clear_OUTPUT_OWNED_BY_1ST_ARG(TYPE, ...)
2323%swiglal_map_a(%swiglal_clear, TYPE, __VA_ARGS__);
2324%enddef
2325%typemap(argout, noblock=1) SWIGTYPE** SWIGLAL_OUTPUT_OWNED_BY_1ST_ARG {
2326%#ifndef swiglal_no_1starg
2327 %swiglal_store_parent(*$1, 0, swiglal_1starg());
2328%#endif
2329 %append_output(SWIG_NewPointerObj($1 != NULL ? %as_voidptr(*$1) : NULL, $*descriptor, %newpointer_flags | SWIG_POINTER_OWN));
2330}
2331
2332///
2333/// The <b>SWIGLAL(OWNS_THIS_ARG(...))</b> macro indicates that a function will acquire
2334/// ownership of a particular argument, e.g. by storing that argument in some container, and that
2335/// therefore the SWIG object wrapping that argument should no longer own its memory.
2336///
2337%typemap(swiglal_owns_this_arg_is_char) SWIGTYPE "0";
2338%typemap(swiglal_owns_this_arg_is_char) char * "1";
2339%typemap(swiglal_owns_this_arg_is_char) const char * "1";
2340%typemap(in, noblock=1) SWIGTYPE SWIGLAL_OWNS_THIS_ARG (int res = 0) {
2341%#if $typemap(swiglal_owns_this_arg_is_char, $1_type)
2342 {
2343 char *str = NULL;
2344 int alloc = 0;
2345 res = SWIG_AsLALcharPtr($input, &str, &alloc);
2346 if (!SWIG_IsOK(res)) {
2347 %argument_fail(res,"$type",$symname, $argnum);
2348 }
2349 $1 = %reinterpret_cast(str, $1_ltype);
2350 }
2351%#else
2352 res = SWIG_ConvertPtr($input, %as_voidptrptr(&$1), $descriptor, SWIG_POINTER_DISOWN | %convertptr_flags);
2353 if (!SWIG_IsOK(res)) {
2354 %argument_fail(res,"$type", $symname, $argnum);
2355 }
2356%#endif
2357}
2358%define %swiglal_public_OWNS_THIS_ARG(TYPE, ...)
2359%swiglal_map_ab(%swiglal_apply, SWIGTYPE SWIGLAL_OWNS_THIS_ARG, TYPE, __VA_ARGS__);
2360%enddef
2361%define %swiglal_public_clear_OWNS_THIS_ARG(TYPE, ...)
2362%swiglal_map_a(%swiglal_clear, TYPE, __VA_ARGS__);
2363%enddef
2364
2365///
2366/// The <b>SWIGLAL(NO_OWN_ON_ASSIGNMENT(...))</b> macro prevents structs for taking ownership of
2367/// any values assigned to the listed struct members, which is the (hard-coded) SWIG default.
2368///
2369%typemap(in, noblock=1) SWIGTYPE * SWIGLAL_NO_OWN_ON_ASSIGNMENT (void *argp = 0, int res = 0) {
2370 res = SWIG_ConvertPtr($input, &argp, $descriptor, 0 /*$disown*/ | %convertptr_flags);
2371 if (!SWIG_IsOK(res)) {
2372 %argument_fail(res, "$type", $symname, $argnum);
2373 }
2374 $1 = %reinterpret_cast(argp, $ltype);
2375}
2376%define %swiglal_public_NO_OWN_ON_ASSIGNMENT(...)
2377%swiglal_map_ab(%swiglal_apply, SWIGTYPE * SWIGLAL_NO_OWN_ON_ASSIGNMENT, SWIGTYPE *, __VA_ARGS__);
2378%enddef
2379%define %swiglal_public_clear_NO_OWN_ON_ASSIGNMENT(TYPE, ...)
2380%swiglal_map_a(%swiglal_clear, SWIGTYPE *, __VA_ARGS__);
2381%enddef
2382
2383///
2384/// The <b>SWIGLAL(EXTERNAL_STRUCT(...))</b> macro can be used to support structs which are not
2385/// declared in LALSuite. It treats the struct as opaque, and attaches a destructor function to it.
2386///
2387%define %swiglal_public_EXTERNAL_STRUCT(NAME, DTORFUNC)
2388typedef struct {} NAME;
2389%ignore DTORFUNC;
2390%extend NAME {
2391 ~NAME() {
2392 (void)DTORFUNC($self);
2393 }
2394}
2395%enddef
2396#define %swiglal_public_clear_EXTERNAL_STRUCT(NAME, DTORFUNC)
2397
2398///
2399/// The <b>SWIGLAL(CAST_STRUCT_TO(...))</b> macro adds to the containing struct methods which cast
2400/// it to each of the given list of types. For example:
2401/// \code
2402/// typedef struct tagBase { ... } Base;
2403/// typedef struct tagDerived {
2404/// SWIGLAL(CAST_STRUCT_TO(Base));
2405/// ...
2406/// } Derived;
2407/// \endcode
2408/// adds a method <i>Base* cast2Base()</i> method to Derived. Obviously this should be a valid cast
2409/// for the given types! The SWIG-wrapped object returned by the <i>cast2...()</i> methods will
2410/// remain in scope as long as the struct that was cast from, by using a typemap similar to that of
2411/// the SWIGLAL(RETURN_OWNED_BY_1ST_ARG(...)) macro.
2412///
2413%typemap(out, noblock=1) SWIGTYPE* SWIGLAL_RETURNS_SELF {
2414%#ifndef swiglal_no_1starg
2415 %swiglal_store_parent($1, 0, swiglal_self());
2416%#endif
2417 %set_output(SWIG_NewPointerObj(%as_voidptr($1), $descriptor, ($owner | %newpointer_flags) | SWIG_POINTER_OWN));
2418}
2419%define %swiglal_cast_struct(TOTYPE)
2420%extend {
2421 %apply SWIGTYPE* SWIGLAL_RETURNS_SELF { TOTYPE* cast2##TOTYPE() };
2422 TOTYPE* cast2##TOTYPE() {
2423 return (TOTYPE*) $self;
2424 }
2425}
2426%enddef
2427%define %swiglal_public_CAST_STRUCT_TO(...)
2428%swiglal_map(%swiglal_cast_struct, __VA_ARGS__);
2429%enddef
2430#define %swiglal_public_clear_CAST_STRUCT_TO(...)
2431
2432///
2433/// The <b>SWIGLAL(IMMUTABLE_MEMBERS(TAGNAME, ...))</b> macro can be used to make the listed members
2434/// of the struct TAGNAME immutable.
2435///
2436%define %swiglal_public_IMMUTABLE_MEMBERS(TAGNAME, ...)
2437%swiglal_map_abc(%swiglal_feature_nspace, "immutable", "1", TAGNAME, __VA_ARGS__);
2438%enddef
2439#define %swiglal_public_clear_IMMUTABLE_MEMBERS(...)
2440
2441///
2442/// The <b>SWIGLAL(IGNORE_MEMBERS(TAGNAME, ...))</b> macro can be used to ignore the listed members
2443/// of the struct TAGNAME.
2444///
2445%define %swiglal_public_IGNORE_MEMBERS(TAGNAME, ...)
2446%swiglal_map_a(%swiglal_ignore_nspace, TAGNAME, __VA_ARGS__);
2447%enddef
2448#define %swiglal_public_clear_IGNORE_MEMBERS(...)
2449
2450// Local Variables:
2451// mode: c
2452// End:
#define TYPE
#define ATYPE
#define _(msgid)
Definition: LALgetopt.c:39
#define FUNC
Definition: PrintVector.c:15
#define STRING(a)
Definition: PrintVector.c:12
#define BASETYPE
#define DATA
unsigned char BOOLEAN
Boolean logical type, see Headers LAL(Atomic)Datatypes.h for more details.
uint64_t UINT8
Eight-byte unsigned integer; on some platforms this is equivalent to unsigned long int instead.
double complex COMPLEX16
Double-precision floating-point complex number (16 bytes total)
int64_t INT8
Eight-byte signed integer; on some platforms this is equivalent to long int instead.
float complex COMPLEX8
Single-precision floating-point complex number (8 bytes total)
#define XLALCalloc(m, n)
Definition: LALMalloc.h:45
#define XLALFree(p)
Definition: LALMalloc.h:47
int swig_lal_has_stdouterr_been_redirected
int swig_lal_do_redirect_stdouterr
The swig_lal_do_redirect_stdouterr variable turns on standard output/error redirection for all LAL li...
const char * XLALErrorString(int code)
Returns the error message associated with an error number.
Definition: XLALError.c:409
#define xlalErrno
Modifiable lvalue containing the XLAL error number.
Definition: XLALError.h:571
int XLALSetErrno(int errnum)
Sets the XLAL error number to errnum, returns the new value.
Definition: XLALError.c:327
int XLALClearErrno(void)
Clears the XLAL error number, returns the old value.
Definition: XLALError.c:363
@ XLAL_EFAILED
Generic failure.
Definition: XLALError.h:418
Definition: __init__.py:1
LAL status structure, see The LALStatus structure for more details.
Definition: LALDatatypes.h:947