scilab:implement li_typemaps test (library typemaps.i test)
This commit is contained in:
parent
ccab675c57
commit
c47456a9bb
2 changed files with 150 additions and 193 deletions
112
Examples/test-suite/scilab/li_typemaps_runme.sci
Normal file
112
Examples/test-suite/scilab/li_typemaps_runme.sci
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
exec("swigtest.start", -1);
|
||||
|
||||
|
||||
// double
|
||||
if (in_double(22.22) <> 22.22) then swigtesterror(); end
|
||||
if (inr_double(22.22) <> 22.22) then swigtesterror(); end
|
||||
if (out_double(22.22) <> 22.22) then swigtesterror(); end
|
||||
if (outr_double(22.22) <> 22.22) then swigtesterror(); end
|
||||
if (inout_double(22.22) <> 22.22) then swigtesterror(); end
|
||||
if (inoutr_double(22.22) <> 22.22) then swigtesterror(); end
|
||||
|
||||
// signed char
|
||||
if (in_schar(22) <> 22) then swigtesterror(); end
|
||||
if (inr_schar(22) <> 22) then swigtesterror(); end
|
||||
if (out_schar(22) <> 22) then swigtesterror(); end
|
||||
if (outr_schar(22) <> 22) then swigtesterror(); end
|
||||
if (inoutr_schar(22) <> 22) then swigtesterror(); end
|
||||
|
||||
// unsigned char
|
||||
if (in_uchar(uint8(22)) <> uint8(22)) then swigtesterror(); end
|
||||
if (inr_uchar(uint8(22)) <> uint8(22)) then swigtesterror(); end
|
||||
if (out_uchar(uint8(22)) <> uint8(22)) then swigtesterror(); end
|
||||
if (outr_uchar(uint8(22)) <> uint8(22)) then swigtesterror(); end
|
||||
if (inoutr_uchar(uint8(22)) <> uint8(22)) then swigtesterror(); end
|
||||
|
||||
// short
|
||||
if (in_short(22) <> 22) then swigtesterror(); end
|
||||
if (inr_short(22) <> 22) then swigtesterror(); end
|
||||
if (out_short(22) <> 22) then swigtesterror(); end
|
||||
if (outr_short(22) <> 22) then swigtesterror(); end
|
||||
if (inout_short(22) <> 22) then swigtesterror(); end
|
||||
if (inoutr_short(22) <> 22) then swigtesterror(); end
|
||||
|
||||
// unsigned short
|
||||
if (in_ushort(uint16(22)) <> uint16(22)) then swigtesterror(); end
|
||||
if (inr_ushort(uint16(22)) <> uint16(22)) then swigtesterror(); end
|
||||
if (out_ushort(uint16(22)) <> uint16(22)) then swigtesterror(); end
|
||||
if (outr_ushort(uint16(22)) <> uint16(22)) then swigtesterror(); end
|
||||
if (inout_ushort(uint16(22)) <> uint16(22)) then swigtesterror(); end
|
||||
if (inoutr_ushort(uint16(22)) <> uint16(22)) then swigtesterror(); end
|
||||
|
||||
// int
|
||||
if (in_int(22) <> 22) then swigtesterror(); end
|
||||
if (inr_int(22) <> 22) then swigtesterror(); end
|
||||
if (out_int(22) <> 22) then swigtesterror(); end
|
||||
if (outr_int(22) <> 22) then swigtesterror(); end
|
||||
if (inout_int(22) <> 22) then swigtesterror(); end
|
||||
if (inoutr_int(22) <> 22) then swigtesterror(); end
|
||||
|
||||
// unsigned int
|
||||
if (in_uint(uint32(22)) <> uint32(22)) then swigtesterror(); end
|
||||
if (inr_uint(uint32(22)) <> uint32(22)) then swigtesterror(); end
|
||||
if (out_uint(uint32(22)) <> uint32(22)) then swigtesterror(); end
|
||||
if (outr_uint(uint32(22)) <> uint32(22)) then swigtesterror(); end
|
||||
if (inout_uint(uint32(22)) <> uint32(22)) then swigtesterror(); end
|
||||
if (inoutr_uint(uint32(22)) <> uint32(22)) then swigtesterror(); end
|
||||
|
||||
// long
|
||||
if (in_long(22) <> 22) then swigtesterror(); end
|
||||
if (inr_long(22) <> 22) then swigtesterror(); end
|
||||
if (out_long(22) <> 22) then swigtesterror(); end
|
||||
if (outr_long(22) <> 22) then swigtesterror(); end
|
||||
if (inout_long(22) <> 22) then swigtesterror(); end
|
||||
if (inoutr_long(22) <> 22) then swigtesterror(); end
|
||||
|
||||
// unsigned long
|
||||
if (in_ulong(uint32(22)) <> uint32(22)) then swigtesterror(); end
|
||||
if (inr_ulong(uint32(22)) <> uint32(22)) then swigtesterror(); end
|
||||
if (out_ulong(uint32(22)) <> uint32(22)) then swigtesterror(); end
|
||||
if (outr_ulong(uint32(22)) <> uint32(22)) then swigtesterror(); end
|
||||
if (inout_ulong(uint32(22)) <> uint32(22)) then swigtesterror(); end
|
||||
if (inoutr_ulong(uint32(22)) <> uint32(22)) then swigtesterror(); end
|
||||
|
||||
// bool
|
||||
if (in_bool(%t) <> %t) then swigtesterror(); end
|
||||
if (inr_bool(%f) <> %f) then swigtesterror(); end
|
||||
if (out_bool(%t) <> %t) then swigtesterror(); end
|
||||
if (outr_bool(%f) <> %f) then swigtesterror(); end
|
||||
if (inout_bool(%t) <> %t) then swigtesterror(); end
|
||||
if (inoutr_bool(%f) <> %f) then swigtesterror(); end
|
||||
|
||||
// float
|
||||
//if (in_float(22.22) <> 22.22) then swigtesterror(); end
|
||||
//if (inr_float(22.22) <> 22.22) then swigtesterror(); end
|
||||
//if (out_float(22.22) <> 22.22) then swigtesterror(); end
|
||||
//if (outr_float(22.22) <> 22.22) then swigtesterror(); end
|
||||
//if (inout_float(22.22) <> 22.22) then swigtesterror(); end
|
||||
//if (inoutr_float(22.22) <> 22.22) then swigtesterror(); end
|
||||
|
||||
// long long
|
||||
//if (in_longlong(22) <> 22) then swigtesterror(); end
|
||||
//if (inr_longlong(22) <> 22) then swigtesterror(); end
|
||||
//if (out_longlong(22) <> 22) then swigtesterror(); end
|
||||
//if (outr_longlong(22) <> 22) then swigtesterror(); end
|
||||
//if (inout_longlong(22) <> 22) then swigtesterror(); end
|
||||
//if (inoutr_longlong(22) <> 22) then swigtesterror(); end
|
||||
|
||||
// unsigned long long
|
||||
//if (in_ulonglong(uint64(22)) <> 22) then swigtesterror(); end
|
||||
//if (inr_ulonglong(uint64(22)) <> 22) then swigtesterror(); end
|
||||
//if (out_ulonglong(uint64(22)) <> 22) then swigtesterror(); end
|
||||
//if (outr_ulonglong(uint64(22)) <> 22) then swigtesterror(); end
|
||||
//if (inout_ulonglong(uint64(22)) <> 22) then swigtesterror(); end
|
||||
//if (inoutr_ulonglong(uint64(22)) <> 22) then swigtesterror(); end
|
||||
|
||||
// the others
|
||||
//a,b = inoutr_int2(1, 2);
|
||||
//if (a<>1 || b<>2) then swigtesterror(); end
|
||||
//f,i = out_foo(10)
|
||||
//if (f.a <> 10 || i <> 20) then swigtesterror(); end
|
||||
|
||||
exec("swigtest.quit", -1);
|
||||
|
|
@ -1,217 +1,62 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* typemaps.i
|
||||
*
|
||||
* The SWIG typemap library provides a language independent mechanism for
|
||||
* supporting output arguments, input values, and other C function
|
||||
* calling mechanisms. The primary use of the library is to provide a
|
||||
* better interface to certain C function--especially those involving
|
||||
* pointers.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
// INPUT typemaps.
|
||||
// These remap a C pointer to be an "INPUT" value which is passed by value
|
||||
// instead of reference.
|
||||
|
||||
|
||||
/*
|
||||
The following methods can be applied to turn a pointer into a simple
|
||||
"input" value. That is, instead of passing a pointer to an object,
|
||||
you would use a real value instead.
|
||||
|
||||
int *INPUT
|
||||
short *INPUT
|
||||
long *INPUT
|
||||
long long *INPUT
|
||||
unsigned int *INPUT
|
||||
unsigned short *INPUT
|
||||
unsigned long *INPUT
|
||||
unsigned long long *INPUT
|
||||
unsigned char *INPUT
|
||||
bool *INPUT
|
||||
float *INPUT
|
||||
double *INPUT
|
||||
|
||||
To use these, suppose you had a C function like this :
|
||||
|
||||
double fadd(double *a, double *b) {
|
||||
return *a+*b;
|
||||
}
|
||||
|
||||
You could wrap it with SWIG as follows :
|
||||
|
||||
%include typemaps.i
|
||||
double fadd(double *INPUT, double *INPUT);
|
||||
|
||||
or you can use the %apply directive :
|
||||
|
||||
%include typemaps.i
|
||||
%apply double *INPUT { double *a, double *b };
|
||||
double fadd(double *a, double *b);
|
||||
|
||||
*/
|
||||
|
||||
%typemap(in, noblock=1, fragment=SWIG_AsVal_frag(int)) int *INPUT(int temp), int &INPUT(int temp) {
|
||||
if (SWIG_AsVal_dec(int)($input, &temp) != SWIG_OK) {
|
||||
SWIG_fail;
|
||||
// INPUT typemaps
|
||||
%define %scilab_input_typemap(Type)
|
||||
%typemap(in, noblock=1, fragment=SWIG_AsVal_frag(Type)) Type *INPUT(Type temp), Type &INPUT(Type temp) {
|
||||
int ecode$argnum = SWIG_AsVal_dec(Type)($input, &temp);
|
||||
if (!SWIG_IsOK(ecode$argnum)) {
|
||||
%argument_fail(ecode$argnum, "$type", $symname, $argnum);
|
||||
}
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(freearg, noblock=1) int *INPUT, int &INPUT {
|
||||
%typemap(freearg, noblock=1) Type *INPUT, Type &INPUT {
|
||||
}
|
||||
|
||||
//short *INPUT
|
||||
//long *INPUT
|
||||
//long long *INPUT
|
||||
//unsigned int *INPUT
|
||||
//unsigned short *INPUT
|
||||
//unsigned long *INPUT
|
||||
//unsigned long long *INPUT
|
||||
//unsigned char *INPUT
|
||||
//bool *INPUT
|
||||
//float *INPUT
|
||||
|
||||
%typemap(in, noblock=1, fragment=SWIG_AsVal_frag(double)) double *INPUT(double temp), double &INPUT(double temp) {
|
||||
if (SWIG_AsVal_dec(double)($input, &temp) != SWIG_OK) {
|
||||
SWIG_fail;
|
||||
}
|
||||
$1 = &temp;
|
||||
%typemap(typecheck) Type *INPUT, Type &INPUT {
|
||||
}
|
||||
%enddef
|
||||
|
||||
%typemap(freearg, noblock=1) double *INPUT, double &INPUT {
|
||||
// OUTPUT typemaps
|
||||
%define %scilab_output_typemap(Type)
|
||||
%typemap(argout, noblock=1, fragment=SWIG_From_frag(Type)) Type *OUTPUT, Type &OUTPUT {
|
||||
%set_output(SWIG_From_dec(Type)(*$1));
|
||||
}
|
||||
%enddef
|
||||
|
||||
// OUTPUT typemaps. These typemaps are used for parameters that
|
||||
// are output only. The output value is appended to the result as
|
||||
// a list element.
|
||||
// INOUT typemaps
|
||||
%define %scilab_inout_typemap(Type)
|
||||
%typemap(in) Type *INOUT = Type *INPUT;
|
||||
%typemap(in) Type &INOUT = Type &INPUT;
|
||||
%typemap(argout) Type *INOUT = Type *OUTPUT;
|
||||
%typemap(argout) Type &INOUT = Type &OUTPUT;
|
||||
%enddef
|
||||
|
||||
/*
|
||||
The following methods can be applied to turn a pointer into an "output"
|
||||
value. When calling a function, no input value would be given for
|
||||
a parameter, but an output value would be returned. In the case of
|
||||
multiple output values, functions will return a Scilab array.
|
||||
|
||||
int *OUTPUT
|
||||
short *OUTPUT
|
||||
long *OUTPUT
|
||||
long long *OUTPUT
|
||||
unsigned int *OUTPUT
|
||||
unsigned short *OUTPUT
|
||||
unsigned long *OUTPUT
|
||||
unsigned long long *OUTPUT
|
||||
unsigned char *OUTPUT
|
||||
bool *OUTPUT
|
||||
float *OUTPUT
|
||||
double *OUTPUT
|
||||
%define %scilab_inout_typemaps(Type)
|
||||
%scilab_input_typemap(%arg(Type))
|
||||
%scilab_output_typemap(%arg(Type))
|
||||
%scilab_inout_typemap(%arg(Type))
|
||||
%enddef
|
||||
|
||||
For example, suppose you were trying to wrap the modf() function in the
|
||||
C math library which splits x into integral and fractional parts (and
|
||||
returns the integer part in one of its parameters).:
|
||||
%scilab_inout_typemaps(double);
|
||||
%scilab_inout_typemaps(signed char);
|
||||
%scilab_inout_typemaps(unsigned char);
|
||||
%scilab_inout_typemaps(short);
|
||||
%scilab_inout_typemaps(unsigned short);
|
||||
%scilab_inout_typemaps(int);
|
||||
%scilab_inout_typemaps(unsigned int);
|
||||
%scilab_inout_typemaps(long);
|
||||
%scilab_inout_typemaps(unsigned long);
|
||||
%scilab_inout_typemaps(bool);
|
||||
%scilab_inout_typemaps(float);
|
||||
|
||||
double modf(double x, double *ip);
|
||||
//%apply_ctypes(%scilab_inout_typemaps);
|
||||
|
||||
You could wrap it with SWIG as follows :
|
||||
|
||||
%include typemaps.i
|
||||
double modf(double x, double *OUTPUT);
|
||||
|
||||
or you can use the %apply directive :
|
||||
|
||||
%include typemaps.i
|
||||
%apply double *OUTPUT { double *ip };
|
||||
double modf(double x, double *ip);
|
||||
|
||||
The Scilab output of the function would be an array containing both
|
||||
output values.
|
||||
|
||||
*/
|
||||
|
||||
%typemap(argout, noblock=1, fragment=SWIG_From_frag(int)) int *OUTPUT, int &OUTPUT {
|
||||
%set_output(SWIG_From_dec(int)(*$1));
|
||||
}
|
||||
//short *OUTPUT
|
||||
//long *OUTPUT
|
||||
//long long *OUTPUT
|
||||
//unsigned int *OUTPUT
|
||||
//unsigned short *OUTPUT
|
||||
//unsigned long *OUTPUT
|
||||
//unsigned long long *OUTPUT
|
||||
//unsigned char *OUTPUT
|
||||
//bool *OUTPUT
|
||||
//float *OUTPUT
|
||||
//double *OUTPUT
|
||||
%typemap(argout, noblock=1, fragment=SWIG_From_frag(double)) double *OUTPUT, double &OUTPUT {
|
||||
%set_output(SWIG_From_dec(double)(*$1));
|
||||
}
|
||||
|
||||
// INOUT
|
||||
// Mappings for an argument that is both an input and output
|
||||
// parameter
|
||||
|
||||
/*
|
||||
The following methods can be applied to make a function parameter both
|
||||
an input and output value. This combines the behavior of both the
|
||||
"INPUT" and "OUTPUT" methods described earlier. Output values are
|
||||
returned in the form of a Scilab array.
|
||||
|
||||
int *INOUT
|
||||
short *INOUT
|
||||
long *INOUT
|
||||
long long *INOUT
|
||||
unsigned int *INOUT
|
||||
unsigned short *INOUT
|
||||
unsigned long *INOUT
|
||||
unsigned long long *INOUT
|
||||
unsigned char *INOUT
|
||||
bool *INOUT
|
||||
float *INOUT
|
||||
double *INOUT
|
||||
|
||||
For example, suppose you were trying to wrap the following function :
|
||||
|
||||
void neg(double *x) {
|
||||
*x = -(*x);
|
||||
}
|
||||
|
||||
You could wrap it with SWIG as follows :
|
||||
|
||||
%include typemaps.i
|
||||
void neg(double *INOUT);
|
||||
|
||||
or you can use the %apply directive :
|
||||
|
||||
%include typemaps.i
|
||||
%apply double *INOUT { double *x };
|
||||
void neg(double *x);
|
||||
|
||||
Unlike C, this mapping does not directly modify the input value.
|
||||
Rather, the modified input value shows up as the return value of the
|
||||
function. Thus, to apply this function to a Scilab variable you might
|
||||
do this :
|
||||
|
||||
$x = neg($x);
|
||||
|
||||
*/
|
||||
|
||||
%typemap(in) int *INOUT = int *INPUT;
|
||||
%typemap(in) short *INOUT = short *INPUT;
|
||||
%typemap(in) long *INOUT = long *INPUT;
|
||||
%typemap(in) unsigned *INOUT = unsigned *INPUT;
|
||||
%typemap(in) unsigned short *INOUT = unsigned short *INPUT;
|
||||
%typemap(in) unsigned long *INOUT = unsigned long *INPUT;
|
||||
%typemap(in) unsigned char *INOUT = unsigned char *INPUT;
|
||||
%typemap(in) signed char *INOUT = signed char *INPUT;
|
||||
%typemap(in) float *INOUT = float *INPUT;
|
||||
%typemap(in) double *INOUT = double *INPUT;
|
||||
|
||||
%typemap(in) int *INOUT = int *OUTPUT;
|
||||
%typemap(in) short *INOUT = short *OUTPUT;
|
||||
%typemap(in) long *INOUT = long *INPUT;
|
||||
%typemap(in) unsigned *INOUT = unsigned *OUTPUT;
|
||||
%typemap(in) unsigned short *INOUT = unsigned short *OUTPUT;
|
||||
%typemap(in) unsigned long *INOUT = unsigned long *OUTPUT;
|
||||
%typemap(in) unsigned char *INOUT = unsigned char *OUTPUT;
|
||||
%typemap(in) signed char *INOUT = signed char *OUTPUT;
|
||||
%typemap(in) float *INOUT = float *OUTPUT;
|
||||
%typemap(in) double *INOUT = double *OUTPUT;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue