|
| 1 | +%include "typemaps.i" |
| 2 | +%include "cstring.i" |
| 3 | + |
| 4 | +/* epanet simple python wrapper */ |
| 5 | +%module (package="epanet") output |
| 6 | +%{ |
| 7 | +#define SHARED_EXPORTS_BUILT_AS_STATIC |
| 8 | +#include <epanet_output.h> |
| 9 | +%} |
| 10 | +%include <epanet_output_enums.h> |
| 11 | + |
| 12 | +/* strip the pseudo-scope from function declarations */ |
| 13 | +%rename("%(strip:[ENR_])s") ""; |
| 14 | + |
| 15 | +%typemap(in,numinputs=0) ENR_Handle* p_handle_out (ENR_Handle temp) { |
| 16 | + $1 = &temp; |
| 17 | +} |
| 18 | + |
| 19 | +%typemap(argout) ENR_Handle* p_handle_out { |
| 20 | + %append_output(SWIG_NewPointerObj(SWIG_as_voidptr(retval$argnum), $1_descriptor, 0)); |
| 21 | +} |
| 22 | + |
| 23 | +/* TYPEMAP FOR IGNORING INT ERROR CODE RETURN VALUE */ |
| 24 | +%typemap(out) int { |
| 25 | + $result = Py_None; |
| 26 | + Py_INCREF($result); |
| 27 | +} |
| 28 | + |
| 29 | + |
| 30 | +/* TYPEMAPS FOR MEMORY MANAGEMENT OF FLOAT ARRAYS */ |
| 31 | +%typemap(in, numinputs=0)float** float_out (float* temp), int* int_dim (int temp){ |
| 32 | + $1 = &temp; |
| 33 | +} |
| 34 | +%typemap(argout) (float** float_out, int* int_dim) { |
| 35 | + if (*$1) { |
| 36 | + PyObject *o = PyList_New(*$2); |
| 37 | + int i; |
| 38 | + float* temp = *$1; |
| 39 | + for(i=0; i<*$2; i++) { |
| 40 | + PyList_SetItem(o, i, PyFloat_FromDouble((double)temp[i])); |
| 41 | + } |
| 42 | + $result = SWIG_Python_AppendOutput($result, o); |
| 43 | + free(*$1); |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +/* TYPEMAPS FOR MEMORY MANAGEMENT OF INT ARRAYS */ |
| 48 | +%typemap(in, numinputs=0)int** int_out (long* temp), int* int_dim (int temp){ |
| 49 | + $1 = &temp; |
| 50 | +} |
| 51 | +%typemap(argout) (int** int_out, int* int_dim) { |
| 52 | + if (*$1) { |
| 53 | + PyObject *o = PyList_New(*$2); |
| 54 | + int i; |
| 55 | + long* temp = *$1; |
| 56 | + for(i=0; i<*$2; i++) { |
| 57 | + PyList_SetItem(o, i, PyInt_FromLong(temp[i])); |
| 58 | + } |
| 59 | + $result = SWIG_Python_AppendOutput($result, o); |
| 60 | + free(*$1); |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +/* TYPEMAP FOR MEMORY MANAGEMENT AND ENCODING OF STRINGS */ |
| 65 | +%typemap(in, numinputs=0)char** string_out (char* temp), int* slen (int temp){ |
| 66 | + $1 = &temp; |
| 67 | +} |
| 68 | +%typemap(argout)(char** string_out, int* slen) { |
| 69 | + if (*$1) { |
| 70 | + PyObject* o; |
| 71 | + o = PyUnicode_FromStringAndSize(*$1, *$2); |
| 72 | + |
| 73 | + $result = SWIG_Python_AppendOutput($result, o); |
| 74 | + free(*$1); |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +%apply int *OUTPUT { |
| 79 | + int *int_out |
| 80 | +}; |
| 81 | + |
| 82 | +/* INSERTS CUSTOM EXCEPTION HANDLING IN WRAPPER */ |
| 83 | +%exception |
| 84 | +{ |
| 85 | + $action |
| 86 | + if ( result > 0) { |
| 87 | + PyErr_SetString(PyExc_Exception, "ERROR"); |
| 88 | + SWIG_fail; |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +%feature("autodoc", "2"); |
| 93 | +#define SHARED_EXPORTS_BUILT_AS_STATIC |
| 94 | +%include <epanet_output.h> |
| 95 | + |
| 96 | +%exception; |
0 commit comments