11/* !
22 * \file flc_vector.i
33 *
4- * Copyright (c) 2019 Oak Ridge National Laboratory, UT-Battelle, LLC.
4+ * Copyright (c) 2019-2020 Oak Ridge National Laboratory, UT-Battelle, LLC.
55 * Distributed under an MIT open source license: see LICENSE for details.
66 */
77
88%module " flc_vector"
99%include " import_flc.i"
1010%flc_add_header
1111
12+ %include <complex .i>
1213%include <std_vector.i>
1314
1415/* -------------------------------------------------------------------------
1516 * Macro definitions
1617 * ------------------------------------------------------------------------- */
1718
18- %define %flc_std_vector_extend_pod(CTYPE)
19+ %define %flc_std_vector_extend_pod(CTYPE, IMTYPE )
1920%extend {
2021 %apply (const SWIGTYPE *DATA, ::size_t SIZE)
2122 { (const CTYPE* DATA, size_type SIZE) };
3132 }
3233
3334 // Get a mutable view to ourself
34- %fortran_array_pointer (CTYPE , vector<CTYPE>& view);
35+ %fortran_array_pointer (IMTYPE , vector<CTYPE>& view);
3536
3637 %typemap (out, noblock=1 ) vector<CTYPE>& view {
3738 $result.data = ($1 ->empty () ? NULL : &(*$1 ->begin ()));
@@ -63,7 +64,7 @@ namespace std {
6364
6465 %swig_std_vector(T, const T&)
6566 %swig_std_vector_extend_ref(T)
66- %flc_std_vector_extend_pod(T)
67+ %flc_std_vector_extend_pod(T, T )
6768 };
6869}
6970
@@ -72,6 +73,31 @@ namespace std {
7273
7374%enddef
7475
76+
77+ /* ------------------------------------------------------------------------- */
78+ /* ! \def %flc_template_std_vector_complex
79+ *
80+ * Inject member functions and typemaps for std::complex instantiations.
81+ *
82+ * This definition is considered part of the \em public API so that downstream
83+ * apps that generate FLC-based bindings can instantiate their own POD vectors.
84+ */
85+ %define %flc_template_std_vector_complex(NAME, T)
86+
87+ namespace std {
88+ template <> class vector <std::complex <T> > {
89+
90+ %swig_std_vector(std::complex <T>, const std::complex <T>&)
91+ %swig_std_vector_extend_ref(std::complex <T>)
92+ %flc_std_vector_extend_pod(std::complex <T>, SwigComplex_ ## T)
93+ };
94+ }
95+
96+ // Instantiate the template
97+ %template (NAME) std::vector<std::complex <T> >;
98+
99+ %enddef
100+
75101/* -------------------------------------------------------------------------
76102 * Numeric vectors
77103 * ------------------------------------------------------------------------- */
@@ -80,6 +106,8 @@ namespace std {
80106%flc_template_std_vector_pod(VectorInt8, int64_t )
81107%flc_template_std_vector_pod(VectorReal8, double )
82108
109+ %flc_template_std_vector_complex(VectorComplex8, double )
110+
83111/* -------------------------------------------------------------------------
84112 * String vectors
85113 * ------------------------------------------------------------------------- */
0 commit comments