@@ -35,10 +35,31 @@ static RETURN_TYPE FUNCNAME ## _cmp(ARGS, bool (*cmp)(T, T)) {
35
35
36
36
%enddef
37
37
38
+ // >>> Create a native function pointer interface for the given comparator.
39
+ %define %flc_cmp_funptr(CTYPE, FTYPE)
40
+
41
+ // Define an abstract interface that gets inserted into the module
42
+ %fragment(" SWIG_cmp_funptr_" {CTYPE}, " fdecl" , noblock=1 )
43
+ { abstract interface
44
+ function SWIG_cmp_funptr_ ## CTYPE (left, right) bind (C) &
45
+ result (fresult)
46
+ use, intrinsic :: ISO_C_BINDING
47
+ FTYPE, intent (in), value :: left, right
48
+ logical (C_BOOL) :: fresult
49
+ end function
50
+ end interface}
51
+
52
+ %apply bool (*)(SWIGTYPE, SWIGTYPE) { bool (*)(CTYPE, CTYPE) };
53
+ %typemap(ftype, in={procedure (SWIG_cmp_funptr_ ## CTYPE)}, fragment=" SWIG_cmp_funptr_" {CTYPE}, noblock=1 ) bool (*)(CTYPE, CTYPE)
54
+ {procedure (SWIG_cmp_funptr_ ## CTYPE), pointer}
55
+
56
+ %enddef
57
+
38
58
/* *****************************
39
59
* Types
40
60
******************************/
41
61
62
+ // >>> Index integer type
42
63
%inline %{
43
64
typedef int index_int;
44
65
%}
@@ -49,6 +70,7 @@ typedef int index_int;
49
70
%typemap(ftype, in={integer (INDEX_INT), intent (in)}) index_int
50
71
%{integer (INDEX_INT)%}
51
72
73
+ // >>> Array types
52
74
%apply (SWIGTYPE *DATA, size_t SIZE) { (index_int *IDX, size_t IDXSIZE) };
53
75
54
76
%apply (const SWIGTYPE *DATA, size_t SIZE) {
@@ -59,6 +81,20 @@ typedef int index_int;
59
81
(const int64_t *DATA2, size_t DATASIZE2),
60
82
(const double *DATA2, size_t DATASIZE2) };
61
83
84
+
85
+ // >>> Function pointer types
86
+ %typemap(fin) bool (*)(SWIGTYPE, SWIGTYPE)
87
+ " $1 = c_funloc($input)"
88
+ %typemap(findecl, match=" fin" ) bool (*)(SWIGTYPE, SWIGTYPE) " "
89
+ %typemap(fout) bool (*)(CTYPE, CTYPE)
90
+ " call c_f_procpointer($1, $result)"
91
+ %typemap(foutdecl, match=" fout" ) bool (*)(SWIGTYPE, SWIGTYPE) " "
92
+
93
+ %flc_cmp_funptr(int32_t , integer(C_INT32_T))
94
+ %flc_cmp_funptr(int64_t , integer(C_INT64_T))
95
+ %flc_cmp_funptr(double , real(C_DOUBLE))
96
+ %flc_cmp_funptr(index_int, integer(INDEX_INT))
97
+
62
98
/* *****************************
63
99
* Sorting
64
100
******************************/
0 commit comments