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