Skip to content

Commit d74e0d8

Browse files
committed
Instantiate algorithms with c_ptr
1 parent be743af commit d74e0d8

File tree

4 files changed

+451
-39
lines changed

4 files changed

+451
-39
lines changed

include/flc.i

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,14 @@ using std::size_t;
7575
%apply (SWIGTYPE *DATA, size_t SIZE) {
7676
(int32_t *DATA, size_t DATASIZE),
7777
(int64_t *DATA, size_t DATASIZE),
78-
(double *DATA, size_t DATASIZE) };
78+
(double *DATA, size_t DATASIZE),
79+
(void **DATA, size_t DATASIZE)};
7980

8081
%apply (const SWIGTYPE *DATA, size_t SIZE) {
8182
(const int32_t *DATA, size_t DATASIZE),
8283
(const int64_t *DATA, size_t DATASIZE),
83-
(const double *DATA, size_t DATASIZE) };
84+
(const double *DATA, size_t DATASIZE),
85+
(const void **DATA, size_t DATASIZE)};
8486

8587
/* -------------------------------------------------------------------------
8688
* Version information

include/flc_algorithm.i

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,24 @@ static RETURN_TYPE FUNCNAME##_cmp(ARGS, bool (*cmp)(T, T)) {
3030
}
3131
}
3232

33+
// Instantiate numeric overloads
3334
%flc_template_numeric(FUNCNAME, FUNCNAME)
3435
%flc_template_numeric(FUNCNAME##_cmp, FUNCNAME)
3536

37+
// Instantiate comparators with void* arguments
38+
%template(FUNCNAME) FUNCNAME##_cmp<void*>;
39+
3640
%enddef
3741

3842
// >>> Create a native function pointer interface for the given comparator.
3943
%define %flc_cmp_funptr(CTYPE, FTYPE)
4044

45+
#define SWIG_cmp_funptr SWIG_cmp_funptr_## %mangle(CTYPE)
46+
4147
// Define an abstract interface that gets inserted into the module
4248
%fragment("SWIG_cmp_funptr_"{CTYPE}, "fdecl", noblock=1)
4349
{ abstract interface
44-
function SWIG_cmp_funptr_##CTYPE(left, right) bind(C) &
50+
function SWIG_cmp_funptr(left, right) bind(C) &
4551
result(fresult)
4652
use, intrinsic :: ISO_C_BINDING
4753
FTYPE, intent(in), value :: left, right
@@ -50,8 +56,10 @@ static RETURN_TYPE FUNCNAME##_cmp(ARGS, bool (*cmp)(T, T)) {
5056
end interface}
5157

5258
%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}
59+
%typemap(ftype, in={procedure(SWIG_cmp_funptr)}, fragment="SWIG_cmp_funptr_"{CTYPE}, noblock=1) bool (*)(CTYPE, CTYPE)
60+
{procedure(SWIG_cmp_funptr), pointer}
61+
62+
#undef SWIG_cmp_funptr
5563

5664
%enddef
5765

@@ -79,9 +87,11 @@ typedef int index_int;
7987
(const int32_t *DATA1, size_t DATASIZE1),
8088
(const int64_t *DATA1, size_t DATASIZE1),
8189
(const double *DATA1, size_t DATASIZE1),
90+
(const void **DATA1, size_t DATASIZE1),
8291
(const int32_t *DATA2, size_t DATASIZE2),
8392
(const int64_t *DATA2, size_t DATASIZE2),
84-
(const double *DATA2, size_t DATASIZE2) };
93+
(const double *DATA2, size_t DATASIZE2),
94+
(const void **DATA2, size_t DATASIZE2)};
8595

8696

8797
// Make function pointers available as generic types
@@ -96,6 +106,7 @@ typedef int index_int;
96106
%flc_cmp_funptr(int64_t, integer(C_INT64_T))
97107
%flc_cmp_funptr(double, real(C_DOUBLE))
98108
%flc_cmp_funptr(index_int, integer(INDEX_INT))
109+
%flc_cmp_funptr(void*, type(C_PTR))
99110

100111
/* -------------------------------------------------------------------------
101112
* Sorting routines
@@ -232,4 +243,4 @@ static void shuffle(std::SWIG_MERSENNE_TWISTER& g, T *DATA, size_t DATASIZE) {
232243
}
233244

234245
%flc_template_numeric(shuffle, shuffle)
235-
246+
%template(shuffle) shuffle<void*>;

0 commit comments

Comments
 (0)