diff --git a/Lib/perl5/reference.i b/Lib/perl5/reference.i new file mode 100644 index 000000000..ccb60bf2e --- /dev/null +++ b/Lib/perl5/reference.i @@ -0,0 +1,229 @@ +// REFERENCE +// Accept Perl references as pointers + +/* +The following methods make Perl references work like simple C +pointers. References can only be used for simple input/output +values, not C arrays however. It should also be noted that +REFERENCES are specific to Perl and not supported in other +scripting languages at this time. + + int *REFERENCE + short *REFERENCE + long *REFERENCE + unsigned int *REFERENCE + unsigned short *REFERENCE + unsigned long *REFERENCE + unsigned char *REFERENCE + float *REFERENCE + double *REFERENCE + +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 reference.i + void neg(double *REFERENCE); + +or you can use the %apply directive : + + %include reference.i + %apply double *REFERENCE { double *x }; + void neg(double *x); + +Unlike the INOUT mapping described in typemaps.i, this approach directly +modifies the value of a Perl reference. Thus, you could use it +as follows : + + $x = 3; + neg(\$x); + print "$x\n"; # Should print out -3. + +*/ + +%typemap(in) double *REFERENCE (double dvalue), double &REFERENCE(double dvalue) +{ + SV *tempsv; + if (!SvROK($input)) { + SWIG_croak("expected a reference"); + } + tempsv = SvRV($input); + if ((!SvNOK(tempsv)) && (!SvIOK(tempsv))) { + printf("Received %d\n", SvTYPE(tempsv)); + SWIG_croak("Expected a double reference."); + } + dvalue = SvNV(tempsv); + $1 = &dvalue; +} + +%typemap(in) float *REFERENCE (float dvalue), float &REFERENCE(float dvalue) +{ + SV *tempsv; + if (!SvROK($input)) { + SWIG_croak("expected a reference"); + } + tempsv = SvRV($input); + if ((!SvNOK(tempsv)) && (!SvIOK(tempsv))) { + SWIG_croak("expected a double reference"); + } + dvalue = (float) SvNV(tempsv); + $1 = &dvalue; +} + +%typemap(in) int *REFERENCE (int dvalue), int &REFERENCE (int dvalue) +{ + SV *tempsv; + if (!SvROK($input)) { + SWIG_croak("expected a reference"); + } + tempsv = SvRV($input); + if (!SvIOK(tempsv)) { + SWIG_croak("expected a integer reference"); + } + dvalue = SvIV(tempsv); + $1 = &dvalue; +} + +%typemap(in) short *REFERENCE (short dvalue), short &REFERENCE(short dvalue) +{ + SV *tempsv; + if (!SvROK($input)) { + SWIG_croak("expected a reference"); + } + tempsv = SvRV($input); + if (!SvIOK(tempsv)) { + SWIG_croak("expected a integer reference"); + } + dvalue = (short) SvIV(tempsv); + $1 = &dvalue; +} +%typemap(in) long *REFERENCE (long dvalue), long &REFERENCE(long dvalue) +{ + SV *tempsv; + if (!SvROK($input)) { + SWIG_croak("expected a reference"); + } + tempsv = SvRV($input); + if (!SvIOK(tempsv)) { + SWIG_croak("expected a integer reference"); + } + dvalue = (long) SvIV(tempsv); + $1 = &dvalue; +} +%typemap(in) unsigned int *REFERENCE (unsigned int dvalue), unsigned int &REFERENCE(unsigned int dvalue) +{ + SV *tempsv; + if (!SvROK($input)) { + SWIG_croak("expected a reference"); + } + tempsv = SvRV($input); + if (!SvIOK(tempsv)) { + SWIG_croak("expected a integer reference"); + } + dvalue = (unsigned int) SvUV(tempsv); + $1 = &dvalue; +} +%typemap(in) unsigned short *REFERENCE (unsigned short dvalue), unsigned short &REFERENCE(unsigned short dvalue) +{ + SV *tempsv; + if (!SvROK($input)) { + SWIG_croak("expected a reference"); + } + tempsv = SvRV($input); + if (!SvIOK(tempsv)) { + SWIG_croak("expected a integer reference"); + } + dvalue = (unsigned short) SvUV(tempsv); + $1 = &dvalue; +} +%typemap(in) unsigned long *REFERENCE (unsigned long dvalue), unsigned long &REFERENCE(unsigned long dvalue) +{ + SV *tempsv; + if (!SvROK($input)) { + SWIG_croak("expected a reference"); + } + tempsv = SvRV($input); + if (!SvIOK(tempsv)) { + SWIG_croak("expected a integer reference"); + } + dvalue = (unsigned long) SvUV(tempsv); + $1 = &dvalue; +} + +%typemap(in) unsigned char *REFERENCE (unsigned char dvalue), unsigned char &REFERENCE(unsigned char dvalue) +{ + SV *tempsv; + if (!SvROK($input)) { + SWIG_croak("expected a reference"); + } + tempsv = SvRV($input); + if (!SvIOK(tempsv)) { + SWIG_croak("expected a integer reference"); + } + dvalue = (unsigned char) SvUV(tempsv); + $1 = &dvalue; +} + +%typemap(in) signed char *REFERENCE (signed char dvalue), signed char &REFERENCE(signed char dvalue) +{ + SV *tempsv; + if (!SvROK($input)) { + SWIG_croak("expected a reference"); + } + tempsv = SvRV($input); + if (!SvIOK(tempsv)) { + SWIG_croak("expected a integer reference"); + } + dvalue = (signed char) SvIV(tempsv); + $1 = &dvalue; +} + +%typemap(in) bool *REFERENCE (bool dvalue), bool &REFERENCE(bool dvalue) +{ + SV *tempsv; + if (!SvROK($input)) { + SWIG_croak("expected a reference"); + } + tempsv = SvRV($input); + if (!SvIOK(tempsv)) { + SWIG_croak("expected a integer reference"); + } + dvalue = (bool) SvIV(tempsv); + $1 = &dvalue; +} + +%typemap(argout) double *REFERENCE, double &REFERENCE, + float *REFERENCE, float &REFERENCE +{ + SV *tempsv; + tempsv = SvRV($arg); + if (!$1) SWIG_croak("expected a reference"); + sv_setnv(tempsv, (double) *$1); +} + +%typemap(argout) int *REFERENCE, int &REFERENCE, + short *REFERENCE, short &REFERENCE, + long *REFERENCE, long &REFERENCE, + signed char *REFERENCE, unsigned char &REFERENCE, + bool *REFERENCE, bool &REFERENCE +{ + SV *tempsv; + tempsv = SvRV($input); + if (!$1) SWIG_croak("expected a reference"); + sv_setiv(tempsv, (IV) *$1); +} + +%typemap(argout) unsigned int *REFERENCE, unsigned int &REFERENCE, + unsigned short *REFERENCE, unsigned short &REFERENCE, + unsigned long *REFERENCE, unsigned long &REFERENCE, + unsigned char *REFERENCE, unsigned char &REFERENCE +{ + SV *tempsv; + tempsv = SvRV($input); + if (!$1) SWIG_croak("expected a reference"); + sv_setuv(tempsv, (UV) *$1); +} diff --git a/Lib/perl5/typemaps.i b/Lib/perl5/typemaps.i index 1f9b9c432..59577240b 100644 --- a/Lib/perl5/typemaps.i +++ b/Lib/perl5/typemaps.i @@ -1 +1,380 @@ +#if !defined(SWIG_USE_OLD_TYPEMAPS) %include +#else + +// +// SWIG Typemap library +// Dave Beazley +// May 5, 1997 +// +// Perl5 implementation +// +// This library provides standard typemaps for modifying SWIG's behavior. +// With enough entries in this file, I hope that very few people actually +// ever need to write a typemap. +// + +/* +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); + +*/ + +%define INPUT_TYPEMAP(type, converter) +%typemap(in) type *INPUT(type temp), type &INPUT(type temp) { + temp = (type) converter($input); + $1 = &temp; +} +%typemap(typecheck) type *INPUT = type; +%typemap(typecheck) type &INPUT = type; +%enddef + +INPUT_TYPEMAP(float, SvNV); +INPUT_TYPEMAP(double, SvNV); +INPUT_TYPEMAP(int, SvIV); +INPUT_TYPEMAP(long, SvIV); +INPUT_TYPEMAP(short, SvIV); +INPUT_TYPEMAP(signed char, SvIV); +INPUT_TYPEMAP(unsigned int, SvUV); +INPUT_TYPEMAP(unsigned long, SvUV); +INPUT_TYPEMAP(unsigned short, SvUV); +INPUT_TYPEMAP(unsigned char, SvUV); + +%typemap(in) bool *INPUT(bool temp), bool &INPUT(bool temp) { + temp = SvIV($input) ? true : false; + $1 = &temp; +} +%typemap(typecheck) bool *INPUT = bool; +%typemap(typecheck) bool &INPUT = bool; + +%typemap(in) long long *INPUT($*1_ltype temp), long long &INPUT($*1_ltype temp) { + temp = strtoll(SvPV($input,PL_na), 0, 0); + $1 = &temp; +} +%typemap(typecheck) long long *INPUT = long long; +%typemap(typecheck) long long &INPUT = long long; + +%typemap(in) unsigned long long *INPUT($*1_ltype temp), unsigned long long &INPUT($*1_ltype temp) { + temp = strtoull(SvPV($input,PL_na), 0, 0); + $1 = &temp; +} +%typemap(typecheck) unsigned long long *INPUT = unsigned long long; +%typemap(typecheck) unsigned long long &INPUT = unsigned long long; + + +#undef INPUT_TYPEMAP + +// OUTPUT typemaps. These typemaps are used for parameters that +// are output only. The output value is appended to the result as +// a list element. + +/* +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 Perl 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 + +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).: + + double modf(double x, double *ip); + +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 Perl output of the function would be an array containing both +output values. + +*/ + +// Force the argument to be ignored. + +%typemap(in,numinputs=0) int *OUTPUT(int temp), int &OUTPUT(int temp), + short *OUTPUT(short temp), short &OUTPUT(short temp), + long *OUTPUT(long temp), long &OUTPUT(long temp), + unsigned int *OUTPUT(unsigned int temp), unsigned int &OUTPUT(unsigned int temp), + unsigned short *OUTPUT(unsigned short temp), unsigned short &OUTPUT(unsigned short temp), + unsigned long *OUTPUT(unsigned long temp), unsigned long &OUTPUT(unsigned long temp), + unsigned char *OUTPUT(unsigned char temp), unsigned char &OUTPUT(unsigned char temp), + signed char *OUTPUT(signed char temp), signed char &OUTPUT(signed char temp), + bool *OUTPUT(bool temp), bool &OUTPUT(bool temp), + float *OUTPUT(float temp), float &OUTPUT(float temp), + double *OUTPUT(double temp), double &OUTPUT(double temp), + long long *OUTPUT($*1_ltype temp), long long &OUTPUT($*1_ltype temp), + unsigned long long *OUTPUT($*1_ltype temp), unsigned long long &OUTPUT($*1_ltype temp) +"$1 = &temp;"; + +%typemap(argout) int *OUTPUT, int &OUTPUT, + short *OUTPUT, short &OUTPUT, + long *OUTPUT, long &OUTPUT, + signed char *OUTPUT, signed char &OUTPUT, + bool *OUTPUT, bool &OUTPUT +{ + if (argvi >= items) { + EXTEND(sp,1); + } + $result = sv_newmortal(); + sv_setiv($result,(IV) *($1)); + argvi++; +} + +%typemap(argout) unsigned int *OUTPUT, unsigned int &OUTPUT, + unsigned short *OUTPUT, unsigned short &OUTPUT, + unsigned long *OUTPUT, unsigned long &OUTPUT, + unsigned char *OUTPUT, unsigned char &OUTPUT +{ + if (argvi >= items) { + EXTEND(sp,1); + } + $result = sv_newmortal(); + sv_setuv($result,(UV) *($1)); + argvi++; +} + + + +%typemap(argout) float *OUTPUT, float &OUTPUT, + double *OUTPUT, double &OUTPUT +{ + if (argvi >= items) { + EXTEND(sp,1); + } + $result = sv_newmortal(); + sv_setnv($result,(double) *($1)); + argvi++; +} + +%typemap(argout) long long *OUTPUT, long long &OUTPUT { + char temp[256]; + if (argvi >= items) { + EXTEND(sp,1); + } + sprintf(temp,"%lld", (long long)*($1)); + $result = sv_newmortal(); + sv_setpv($result,temp); + argvi++; +} + +%typemap(argout) unsigned long long *OUTPUT, unsigned long long &OUTPUT { + char temp[256]; + if (argvi >= items) { + EXTEND(sp,1); + } + sprintf(temp,"%llu", (unsigned long long)*($1)); + $result = sv_newmortal(); + sv_setpv($result,temp); + argvi++; +} + +// 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 Perl 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 Perl 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) bool *INOUT = bool *INPUT; +%typemap(in) float *INOUT = float *INPUT; +%typemap(in) double *INOUT = double *INPUT; +%typemap(in) long long *INOUT = long long *INPUT; +%typemap(in) unsigned long long *INOUT = unsigned long long *INPUT; + +%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) bool &INOUT = bool &INPUT; +%typemap(in) float &INOUT = float &INPUT; +%typemap(in) double &INOUT = double &INPUT; +%typemap(in) long long &INOUT = long long &INPUT; +%typemap(in) unsigned long long &INOUT = unsigned long long &INPUT; + + +%typemap(argout) int *INOUT = int *OUTPUT; +%typemap(argout) short *INOUT = short *OUTPUT; +%typemap(argout) long *INOUT = long *OUTPUT; +%typemap(argout) unsigned *INOUT = unsigned *OUTPUT; +%typemap(argout) unsigned short *INOUT = unsigned short *OUTPUT; +%typemap(argout) unsigned long *INOUT = unsigned long *OUTPUT; +%typemap(argout) unsigned char *INOUT = unsigned char *OUTPUT; +%typemap(argout) signed char *INOUT = signed char *OUTPUT; +%typemap(argout) bool *INOUT = bool *OUTPUT; +%typemap(argout) float *INOUT = float *OUTPUT; +%typemap(argout) double *INOUT = double *OUTPUT; +%typemap(argout) long long *INOUT = long long *OUTPUT; +%typemap(argout) unsigned long long *INOUT = unsigned long long *OUTPUT; + + +%typemap(argout) int &INOUT = int &OUTPUT; +%typemap(argout) short &INOUT = short &OUTPUT; +%typemap(argout) long &INOUT = long &OUTPUT; +%typemap(argout) unsigned &INOUT = unsigned &OUTPUT; +%typemap(argout) unsigned short &INOUT = unsigned short &OUTPUT; +%typemap(argout) unsigned long &INOUT = unsigned long &OUTPUT; +%typemap(argout) unsigned char &INOUT = unsigned char &OUTPUT; +%typemap(argout) signed char &INOUT = signed char &OUTPUT; +%typemap(argout) bool &INOUT = bool &OUTPUT; +%typemap(argout) float &INOUT = float &OUTPUT; +%typemap(argout) double &INOUT = double &OUTPUT; +%typemap(argout) long long &INOUT = long long &OUTPUT; +%typemap(argout) unsigned long long &INOUT = unsigned long long &OUTPUT; + + +/* Overloading information */ + +%typemap(typecheck) double *INOUT = double; +%typemap(typecheck) bool *INOUT = bool; +%typemap(typecheck) signed char *INOUT = signed char; +%typemap(typecheck) unsigned char *INOUT = unsigned char; +%typemap(typecheck) unsigned long *INOUT = unsigned long; +%typemap(typecheck) unsigned short *INOUT = unsigned short; +%typemap(typecheck) unsigned int *INOUT = unsigned int; +%typemap(typecheck) long *INOUT = long; +%typemap(typecheck) short *INOUT = short; +%typemap(typecheck) int *INOUT = int; +%typemap(typecheck) float *INOUT = float; +%typemap(typecheck) long long *INOUT = long long; +%typemap(typecheck) unsigned long long *INOUT = unsigned long long; + +%typemap(typecheck) double &INOUT = double; +%typemap(typecheck) bool &INOUT = bool; +%typemap(typecheck) signed char &INOUT = signed char; +%typemap(typecheck) unsigned char &INOUT = unsigned char; +%typemap(typecheck) unsigned long &INOUT = unsigned long; +%typemap(typecheck) unsigned short &INOUT = unsigned short; +%typemap(typecheck) unsigned int &INOUT = unsigned int; +%typemap(typecheck) long &INOUT = long; +%typemap(typecheck) short &INOUT = short; +%typemap(typecheck) int &INOUT = int; +%typemap(typecheck) float &INOUT = float; +%typemap(typecheck) long long &INOUT = long long; +%typemap(typecheck) unsigned long long &INOUT = unsigned long long; + +#endif + +// -------------------------------------------------------------------- +// Special types +// -------------------------------------------------------------------- + + +%include diff --git a/Lib/python/typemaps.i b/Lib/python/typemaps.i index 1f9b9c432..4f37d8cc4 100644 --- a/Lib/python/typemaps.i +++ b/Lib/python/typemaps.i @@ -1 +1,162 @@ +// +// SWIG Typemap library +// Dave Beazley +// May 5, 1997 +// +// Python implementation +// +// This library provides standard typemaps for modifying SWIG's behavior. +// With enough entries in this file, I hope that very few people actually +// ever need to write a typemap. +// +// Disclaimer : Unless you really understand how typemaps work, this file +// probably isn't going to make much sense. +// + +// ------------------------------------------------------------------------ +// Pointer handling +// +// These mappings provide support for input/output arguments and common +// uses for C/C++ 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 + double fadd(double *INPUT, double *INPUT); + +or you can use the %apply directive : + + %include + %apply double *INPUT { double *a, double *b }; + double fadd(double *a, double *b); + +*/ + +// OUTPUT typemaps. These typemaps are used for parameters that +// are output only. The output value is appended to the result as +// a list element. + +/* +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, they are returned in the form of a Python tuple. + + 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 + +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).K: + + double modf(double x, double *ip); + +You could wrap it with SWIG as follows : + + %include + double modf(double x, double *OUTPUT); + +or you can use the %apply directive : + + %include + %apply double *OUTPUT { double *ip }; + double modf(double x, double *ip); + +The Python output of the function would be a tuple containing both +output values. + +*/ + +// 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 Python tuple. + + 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 + void neg(double *INOUT); + +or you can use the %apply directive : + + %include + %apply double *INOUT { double *x }; + void neg(double *x); + +Unlike C, this mapping does not directly modify the input value (since +this makes no sense in Python). Rather, the modified input value shows +up as the return value of the function. Thus, to apply this function +to a Python variable you might do this : + + x = neg(x) + +Note : previous versions of SWIG used the symbol 'BOTH' to mark +input/output arguments. This is still supported, but will be slowly +phased out in future releases. + +*/ + %include diff --git a/Lib/ruby/file.i b/Lib/ruby/file.i new file mode 100644 index 000000000..54ed0a609 --- /dev/null +++ b/Lib/ruby/file.i @@ -0,0 +1,32 @@ +// FILE * +%{ +#ifdef __cplusplus +extern "C" { +#endif +#include "rubyio.h" +#ifdef __cplusplus +} +#endif +%} + +%typemap(in) FILE *READ { + OpenFile *of; + GetOpenFile($input, of); + rb_io_check_readable(of); + $1 = GetReadFile(of); + rb_read_check($1); +} + +%typemap(in) FILE *READ_NOCHECK { + OpenFile *of; + GetOpenFile($input, of); + rb_io_check_readable(of); + $1 = GetReadFile(of); +} + +%typemap(in) FILE *WRITE { + OpenFile *of; + GetOpenFile($input, of); + rb_io_check_writable(of); + $1 = GetWriteFile(of); +} diff --git a/Lib/ruby/progargcargv.i b/Lib/ruby/progargcargv.i new file mode 100644 index 000000000..6720bd791 --- /dev/null +++ b/Lib/ruby/progargcargv.i @@ -0,0 +1,34 @@ +/* +int PROG_ARGC +char **PROG_ARGV + + Some C function receive argc and argv from C main function. + This typemap provides ignore typemap which pass Ruby ARGV contents + as argc and argv to C function. +*/ + + + +// argc and argv +%typemap(in,numinputs=0) int PROG_ARGC { + $1 = RARRAY(rb_argv)->len + 1; +} + +%typemap(in,numinputs=0) char **PROG_ARGV { + int i, n; + VALUE ary = rb_eval_string("[$0] + ARGV"); + n = RARRAY(ary)->len; + $1 = (char **)malloc(n + 1); + for (i = 0; i < n; i++) { + VALUE v = rb_obj_as_string(RARRAY(ary)->ptr[i]); + $1[i] = (char *)malloc(RSTRING(v)->len + 1); + strcpy($1[i], RSTRING(v)->ptr); + } +} + +%typemap(freearg) char **PROG_ARGV { + int i, n = RARRAY(rb_argv)->len + 1; + for (i = 0; i < n; i++) free($1[i]); + free($1); +} + diff --git a/Lib/ruby/timeval.i b/Lib/ruby/timeval.i new file mode 100644 index 000000000..91b56916f --- /dev/null +++ b/Lib/ruby/timeval.i @@ -0,0 +1,64 @@ +/* + struct timeval * + time_t + + Ruby has builtin class Time. INPUT/OUTPUT typemap for timeval and + time_t is provided. + +*/ +%{ +#ifdef __cplusplus +extern "C" { +#endif +#ifdef HAVE_SYS_TIME_H +# include +struct timeval rb_time_timeval(VALUE); +#endif +#ifdef __cplusplus +} +#endif +%} + +%typemap(in) struct timeval *INPUT (struct timeval temp) +{ + if (NIL_P($input)) + $1 = NULL; + else { + temp = rb_time_timeval($input); + $1 = &temp; + } +} + +%typemap(in,numinputs=0) struct timeval *OUTPUT(struct timeval temp) +{ + $1 = &temp; +} + +%typemap(argout) struct timeval *OUTPUT +{ + $result = rb_time_new($1->tv_sec, $1->tv_usec); +} + +%typemap(out) struct timeval * +{ + $result = rb_time_new($1->tv_sec, $1->tv_usec); +} + +%typemap(out) struct timespec * +{ + $result = rb_time_new($1->tv_sec, $1->tv_nsec / 1000); +} + +// time_t +%typemap(in) time_t +{ + if (NIL_P($input)) + $1 = (time_t)-1; + else + $1 = NUM2LONG(rb_funcall($input, rb_intern("tv_sec"), 0)); +} + +%typemap(out) time_t +{ + $result = rb_time_new($1, 0); +} diff --git a/Lib/ruby/typemaps.i b/Lib/ruby/typemaps.i index 1f9b9c432..521b7e564 100644 --- a/Lib/ruby/typemaps.i +++ b/Lib/ruby/typemaps.i @@ -1 +1,316 @@ +#if !defined(SWIG_USE_OLD_TYPEMAPS) %include +#else +// +// typemaps for Ruby +// +// $Header$ +// +// Copyright (C) 2000 Network Applied Communication Laboratory, Inc. +// Copyright (C) 2000 Information-technology Promotion Agency, Japan +// +// Masaki Fukushima +// + +/* +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. +*/ + +// ------------------------------------------------------------------------ +// Pointer handling +// +// These mappings provide support for input/output arguments and common +// uses for C/C++ 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); + +*/ + +%define INPUT_TYPEMAP(type, converter) +%typemap(in) type *INPUT($*1_ltype temp), type &INPUT($*1_ltype temp) +{ + temp = ($*1_ltype) converter($input); + $1 = &temp; +} +%typemap(typecheck) type *INPUT = type; +%typemap(typecheck) type &INPUT = type; +%enddef + +INPUT_TYPEMAP(float, NUM2DBL); +INPUT_TYPEMAP(double, NUM2DBL); +INPUT_TYPEMAP(int, NUM2INT); +INPUT_TYPEMAP(short, NUM2SHRT); +INPUT_TYPEMAP(long, NUM2LONG); +INPUT_TYPEMAP(long long, NUM2LL); +INPUT_TYPEMAP(unsigned int, NUM2UINT); +INPUT_TYPEMAP(unsigned short, NUM2USHRT); +INPUT_TYPEMAP(unsigned long, NUM2ULONG); +INPUT_TYPEMAP(unsigned long long, NUM2ULL); +INPUT_TYPEMAP(unsigned char, NUM2UINT); +INPUT_TYPEMAP(signed char, NUM2INT); +INPUT_TYPEMAP(bool, RTEST); + +#undef INPUT_TYPEMAP + +// OUTPUT typemaps. These typemaps are used for parameters that +// are output only. The output value is appended to the result as +// a array element. + +/* +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, they are returned in the form of a Ruby 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 + +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).K: + + double modf(double x, double *ip); + +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 Ruby output of the function would be a Array containing both +output values. +*/ + +%include "fragments.i" + +%define OUTPUT_TYPEMAP(type, converter, convtype) +%typemap(in,numinputs=0) type *OUTPUT($*1_ltype temp), type &OUTPUT($*1_ltype temp) "$1 = &temp;"; +%typemap(argout, fragment="output_helper") type *OUTPUT, type &OUTPUT { + VALUE o = converter(convtype (*$1)); + $result = output_helper($result, o); +} +%enddef + +OUTPUT_TYPEMAP(int, INT2NUM, (int)); +OUTPUT_TYPEMAP(short, INT2NUM, (int)); +OUTPUT_TYPEMAP(long, INT2NUM, (long)); +OUTPUT_TYPEMAP(long long, LL2NUM, (long long)); +OUTPUT_TYPEMAP(unsigned int, UINT2NUM, (unsigned int)); +OUTPUT_TYPEMAP(unsigned short, UINT2NUM, (unsigned int)); +OUTPUT_TYPEMAP(unsigned long, UINT2NUM, (unsigned long)); +OUTPUT_TYPEMAP(unsigned long long, ULL2NUM, (unsigned long long)); +OUTPUT_TYPEMAP(unsigned char, UINT2NUM, (unsigned int)); +OUTPUT_TYPEMAP(signed char, INT2NUM, (int)); +OUTPUT_TYPEMAP(float, rb_float_new, (double)); +OUTPUT_TYPEMAP(double, rb_float_new, (double)); + +#undef OUTPUT_TYPEMAP + +%typemap(in,numinputs=0) bool *OUTPUT(bool temp), bool &OUTPUT(bool temp) "$1 = &temp;"; +%typemap(argout, fragment="output_helper") bool *OUTPUT, bool &OUTPUT { + VALUE o = (*$1) ? Qtrue : Qfalse; + $result = output_helper($result, o); +} + +// 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 Ruby 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 (since +this makes no sense in Ruby). Rather, the modified input value shows +up as the return value of the function. Thus, to apply this function +to a Ruby variable you might do this : + + x = neg(x) + +Note : previous versions of SWIG used the symbol 'BOTH' to mark +input/output arguments. This is still supported, but will be slowly +phased out in future releases. + +*/ + +%typemap(in) int *INOUT = int *INPUT; +%typemap(in) short *INOUT = short *INPUT; +%typemap(in) long *INOUT = long *INPUT; +%typemap(in) long long *INOUT = long 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 long long *INOUT = unsigned long long *INPUT; +%typemap(in) unsigned char *INOUT = unsigned char *INPUT; +%typemap(in) signed char *INOUT = signed char *INPUT; +%typemap(in) bool *INOUT = bool *INPUT; +%typemap(in) float *INOUT = float *INPUT; +%typemap(in) double *INOUT = double *INPUT; + +%typemap(in) int &INOUT = int &INPUT; +%typemap(in) short &INOUT = short &INPUT; +%typemap(in) long &INOUT = long &INPUT; +%typemap(in) long long &INOUT = long 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 long long &INOUT = unsigned long long &INPUT; +%typemap(in) unsigned char &INOUT = unsigned char &INPUT; +%typemap(in) signed char &INOUT = signed char &INPUT; +%typemap(in) bool &INOUT = bool &INPUT; +%typemap(in) float &INOUT = float &INPUT; +%typemap(in) double &INOUT = double &INPUT; + +%typemap(argout) int *INOUT = int *OUTPUT; +%typemap(argout) short *INOUT = short *OUTPUT; +%typemap(argout) long *INOUT = long *OUTPUT; +%typemap(argout) long long *INOUT = long long *OUTPUT; +%typemap(argout) unsigned *INOUT = unsigned *OUTPUT; +%typemap(argout) unsigned short *INOUT = unsigned short *OUTPUT; +%typemap(argout) unsigned long *INOUT = unsigned long *OUTPUT; +%typemap(argout) unsigned long long *INOUT = unsigned long long *OUTPUT; +%typemap(argout) unsigned char *INOUT = unsigned char *OUTPUT; +%typemap(argout) signed char *INOUT = signed char *OUTPUT; +%typemap(argout) bool *INOUT = bool *OUTPUT; +%typemap(argout) float *INOUT = float *OUTPUT; +%typemap(argout) double *INOUT = double *OUTPUT; + +%typemap(argout) int &INOUT = int &OUTPUT; +%typemap(argout) short &INOUT = short &OUTPUT; +%typemap(argout) long &INOUT = long &OUTPUT; +%typemap(argout) long long &INOUT = long long &OUTPUT; +%typemap(argout) unsigned &INOUT = unsigned &OUTPUT; +%typemap(argout) unsigned short &INOUT = unsigned short &OUTPUT; +%typemap(argout) unsigned long &INOUT = unsigned long &OUTPUT; +%typemap(argout) unsigned long long &INOUT = unsigned long long &OUTPUT; +%typemap(argout) unsigned char &INOUT = unsigned char &OUTPUT; +%typemap(argout) signed char &INOUT = signed char &OUTPUT; +%typemap(argout) bool &INOUT = bool &OUTPUT; +%typemap(argout) float &INOUT = float &OUTPUT; +%typemap(argout) double &INOUT = double &OUTPUT; + +/* Overloading information */ + +%typemap(typecheck) double *INOUT = double; +%typemap(typecheck) signed char *INOUT = signed char; +%typemap(typecheck) unsigned char *INOUT = unsigned char; +%typemap(typecheck) unsigned long *INOUT = unsigned long; +%typemap(typecheck) unsigned long long *INOUT = unsigned long long; +%typemap(typecheck) unsigned short *INOUT = unsigned short; +%typemap(typecheck) unsigned int *INOUT = unsigned int; +%typemap(typecheck) long *INOUT = long; +%typemap(typecheck) long long *INOUT = long long; +%typemap(typecheck) short *INOUT = short; +%typemap(typecheck) int *INOUT = int; +%typemap(typecheck) float *INOUT = float; + +%typemap(typecheck) double &INOUT = double; +%typemap(typecheck) signed char &INOUT = signed char; +%typemap(typecheck) unsigned char &INOUT = unsigned char; +%typemap(typecheck) unsigned long &INOUT = unsigned long; +%typemap(typecheck) unsigned long long &INOUT = unsigned long long; +%typemap(typecheck) unsigned short &INOUT = unsigned short; +%typemap(typecheck) unsigned int &INOUT = unsigned int; +%typemap(typecheck) long &INOUT = long; +%typemap(typecheck) long long &INOUT = long long; +%typemap(typecheck) short &INOUT = short; +%typemap(typecheck) int &INOUT = int; +%typemap(typecheck) float &INOUT = float; + +#endif + +// -------------------------------------------------------------------- +// Special types +// -------------------------------------------------------------------- +%include +%include +%include diff --git a/Lib/tcl/tclinterp.i b/Lib/tcl/tclinterp.i new file mode 100644 index 000000000..2d0c035f6 --- /dev/null +++ b/Lib/tcl/tclinterp.i @@ -0,0 +1,16 @@ +/* + +Tcl_Interp *interp + + Passes the current Tcl_Interp value directly to a C function. + This can be used to work with existing wrapper functions or + if you just need the interp value for some reason. When used, + the 'interp' parameter becomes hidden in the Tcl interface--that + is, you don't specify it explicitly. SWIG fills in its value + automatically. +*/ + +%typemap(in,numinputs=0) Tcl_Interp *interp { + $1 = interp; +} + diff --git a/Lib/tcl/tclresult.i b/Lib/tcl/tclresult.i new file mode 100644 index 000000000..3de7ffaeb --- /dev/null +++ b/Lib/tcl/tclresult.i @@ -0,0 +1,23 @@ +/* +int Tcl_Result + + Makes the integer return code of a function the return value + of a SWIG generated wrapper function. For example : + + int foo() { + ... do stuff ... + return TCL_OK; + } + + could be wrapped as follows : + + %include typemaps.i + %apply int Tcl_Result { int foo }; + int foo(); +*/ + +// If return code is a Tcl_Result, simply pass it on + +%typemap(out) int Tcl_Result { + return $1; +} diff --git a/Lib/tcl/typemaps.i b/Lib/tcl/typemaps.i index 1f9b9c432..82f2ed32c 100644 --- a/Lib/tcl/typemaps.i +++ b/Lib/tcl/typemaps.i @@ -1 +1,466 @@ +#if !defined(SWIG_USE_OLD_TYPEMAPS) %include +#else +/* ----------------------------------------------------------------------------- + * typemaps.i + * + * Swig typemap library for Tcl8. This file contains various sorts + * of typemaps for modifying Swig's code generation. + * + * Author: David Beazley (beazley@cs.uchicago.edu) + * + * ----------------------------------------------------------------------------- */ + +/* +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) double *INPUT(double temp), double &INPUT(double temp) +{ + if (Tcl_GetDoubleFromObj(interp,$input,&temp) == TCL_ERROR) { + SWIG_fail; + } + $1 = &temp; +} + +%typemap(in) float *INPUT(double dvalue, float temp), float &INPUT(double dvalue, float temp) +{ + if (Tcl_GetDoubleFromObj(interp,$input,&dvalue) == TCL_ERROR) { + SWIG_fail; + } + temp = (float) dvalue; + $1 = &temp; +} + +%typemap(in) int *INPUT(int temp), int &INPUT(int temp) +{ + if (Tcl_GetIntFromObj(interp,$input,&temp) == TCL_ERROR) { + SWIG_fail; + } + $1 = &temp; +} + +%typemap(in) short *INPUT(int ivalue, short temp), short &INPUT(int ivalue, short temp) +{ + if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) { + SWIG_fail; + } + temp = (short) ivalue; + $1 = &temp; +} + +%typemap(in) long *INPUT(int ivalue, long temp), long &INPUT(int ivalue, long temp) +{ + if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) { + SWIG_fail; + } + temp = (long) ivalue; + $1 = &temp; +} + +%typemap(in) unsigned int *INPUT(int ivalue, unsigned int temp), + unsigned int &INPUT(int ivalue, unsigned int temp) +{ + if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) { + SWIG_fail; + } + temp = (unsigned int) ivalue; + $1 = &temp; +} + +%typemap(in) unsigned short *INPUT(int ivalue, unsigned short temp), + unsigned short &INPUT(int ivalue, unsigned short temp) +{ + if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) { + SWIG_fail; + } + temp = (unsigned short) ivalue; + $1 = &temp; +} + +%typemap(in) unsigned long *INPUT(int ivalue, unsigned long temp), + unsigned long &INPUT(int ivalue, unsigned long temp) +{ + if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) { + SWIG_fail; + } + temp = (unsigned long) ivalue; + $1 = &temp; +} + +%typemap(in) unsigned char *INPUT(int ivalue, unsigned char temp), + unsigned char &INPUT(int ivalue, unsigned char temp) +{ + if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) { + SWIG_fail; + } + temp = (unsigned char) ivalue; + $1 = &temp; +} + +%typemap(in) signed char *INPUT(int ivalue, signed char temp), + signed char &INPUT(int ivalue, signed char temp) +{ + if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) { + SWIG_fail; + } + temp = (signed char) ivalue; + $1 = &temp; +} + +%typemap(in) bool *INPUT(int ivalue, bool temp), + bool &INPUT(int ivalue, bool temp) +{ + if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) { + SWIG_fail; + } + temp = ivalue ? true : false; + $1 = &temp; +} + +%typemap(in) long long *INPUT($*1_ltype temp), + long long &INPUT($*1_ltype temp) +{ + temp = ($*1_ltype) strtoll(Tcl_GetStringFromObj($input,NULL),0,0); + $1 = &temp; +} + +%typemap(in) unsigned long long *INPUT($*1_ltype temp), + unsigned long long &INPUT($*1_ltype temp) +{ + temp = ($*1_ltype) strtoull(Tcl_GetStringFromObj($input,NULL),0,0); + $1 = &temp; +} + +// OUTPUT typemaps. These typemaps are used for parameters that +// are output only. The output value is appended to the result as +// a list element. + +/* +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, they are returned in the form of a Tcl list. + + 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 + +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).K: + + double modf(double x, double *ip); + +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 Tcl output of the function would be a list containing both +output values. + +*/ + +%typemap(in,numinputs=0) int *OUTPUT(int temp), + short *OUTPUT(short temp), + long *OUTPUT(long temp), + unsigned int *OUTPUT(unsigned int temp), + unsigned short *OUTPUT(unsigned short temp), + unsigned long *OUTPUT(unsigned long temp), + unsigned char *OUTPUT(unsigned char temp), + signed char *OUTPUT(signed char temp), + bool *OUTPUT(bool temp), + float *OUTPUT(float temp), + double *OUTPUT(double temp), + long long *OUTPUT($*1_ltype temp), + unsigned long long *OUTPUT($*1_ltype temp), + int &OUTPUT(int temp), + short &OUTPUT(short temp), + long &OUTPUT(long temp), + unsigned int &OUTPUT(unsigned int temp), + unsigned short &OUTPUT(unsigned short temp), + unsigned long &OUTPUT(unsigned long temp), + signed char &OUTPUT(signed char temp), + bool &OUTPUT(bool temp), + unsigned char &OUTPUT(unsigned char temp), + float &OUTPUT(float temp), + double &OUTPUT(double temp), + long long &OUTPUT($*1_ltype temp), + unsigned long long &OUTPUT($*1_ltype temp) +"$1 = &temp;"; + +%typemap(argout) int *OUTPUT, int &OUTPUT, + short *OUTPUT, short &OUTPUT, + long *OUTPUT, long &OUTPUT, + unsigned int *OUTPUT, unsigned int &OUTPUT, + unsigned short *OUTPUT, unsigned short &OUTPUT, + unsigned long *OUTPUT, unsigned long &OUTPUT, + unsigned char *OUTPUT, unsigned char &OUTPUT, + signed char *OUTPUT, signed char &OUTPUT, + bool *OUTPUT, bool &OUTPUT +{ + Tcl_Obj *o; + o = Tcl_NewIntObj((int) *($1)); + Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o); +} + +%typemap(argout) float *OUTPUT, float &OUTPUT, + double *OUTPUT, double &OUTPUT +{ + Tcl_Obj *o; + o = Tcl_NewDoubleObj((double) *($1)); + Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o); +} + +%typemap(argout) long long *OUTPUT, long long &OUTPUT +{ + char temp[256]; + Tcl_Obj *o; + sprintf(temp,"%lld",(long long)*($1)); + o = Tcl_NewStringObj(temp,-1); + Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o); +} + +%typemap(argout) unsigned long long *OUTPUT, unsigned long long &OUTPUT +{ + char temp[256]; + Tcl_Obj *o; + sprintf(temp,"%llu",(unsigned long long)*($1)); + o = Tcl_NewStringObj(temp,-1); + Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o); +} + +// 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 Tcl list. + + 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 (since +this makes no sense in Tcl). Rather, the modified input value shows +up as the return value of the function. Thus, to apply this function +to a Tcl variable you might do this : + + set x [neg $x] + +*/ + + +%typemap(in) int *INOUT = int *INPUT; +%typemap(in) short *INOUT = short *INPUT; +%typemap(in) long *INOUT = long *INPUT; +%typemap(in) unsigned int *INOUT = unsigned int *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) bool *INOUT = bool *INPUT; +%typemap(in) float *INOUT = float *INPUT; +%typemap(in) double *INOUT = double *INPUT; +%typemap(in) long long *INOUT = long long *INPUT; +%typemap(in) unsigned long long *INOUT = unsigned long long *INPUT; + +%typemap(in) int &INOUT = int &INPUT; +%typemap(in) short &INOUT = short &INPUT; +%typemap(in) long &INOUT = long &INPUT; +%typemap(in) unsigned int &INOUT = unsigned int &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) bool &INOUT = bool &INPUT; +%typemap(in) float &INOUT = float &INPUT; +%typemap(in) double &INOUT = double &INPUT; +%typemap(in) long long &INOUT = long long &INPUT; +%typemap(in) unsigned long long &INOUT = unsigned long long &INPUT; + +%typemap(argout) int *INOUT = int *OUTPUT; +%typemap(argout) short *INOUT = short *OUTPUT; +%typemap(argout) long *INOUT = long *OUTPUT; +%typemap(argout) unsigned int *INOUT = unsigned int *OUTPUT; +%typemap(argout) unsigned short *INOUT = unsigned short *OUTPUT; +%typemap(argout) unsigned long *INOUT = unsigned long *OUTPUT; +%typemap(argout) unsigned char *INOUT = unsigned char *OUTPUT; +%typemap(argout) signed char *INOUT = signed char *OUTPUT; +%typemap(argout) bool *INOUT = bool *OUTPUT; +%typemap(argout) float *INOUT = float *OUTPUT; +%typemap(argout) double *INOUT = double *OUTPUT; +%typemap(argout) long long *INOUT = long long *OUTPUT; +%typemap(argout) unsigned long long *INOUT = unsigned long long *OUTPUT; + +%typemap(argout) int &INOUT = int &OUTPUT; +%typemap(argout) short &INOUT = short &OUTPUT; +%typemap(argout) long &INOUT = long &OUTPUT; +%typemap(argout) unsigned int &INOUT = unsigned int &OUTPUT; +%typemap(argout) unsigned short &INOUT = unsigned short &OUTPUT; +%typemap(argout) unsigned long &INOUT = unsigned long &OUTPUT; +%typemap(argout) unsigned char &INOUT = unsigned char &OUTPUT; +%typemap(argout) signed char &INOUT = signed char &OUTPUT; +%typemap(argout) bool &INOUT = bool &OUTPUT; +%typemap(argout) float &INOUT = float &OUTPUT; +%typemap(argout) double &INOUT = double &OUTPUT; +%typemap(argout) long long &INOUT = long long &OUTPUT; +%typemap(argout) unsigned long long &INOUT = unsigned long long &OUTPUT; + + +/* Overloading information */ + +%typemap(typecheck) double *INPUT = double; +%typemap(typecheck) bool *INPUT = bool; +%typemap(typecheck) signed char *INPUT = signed char; +%typemap(typecheck) unsigned char *INPUT = unsigned char; +%typemap(typecheck) unsigned long *INPUT = unsigned long; +%typemap(typecheck) unsigned short *INPUT = unsigned short; +%typemap(typecheck) unsigned int *INPUT = unsigned int; +%typemap(typecheck) long *INPUT = long; +%typemap(typecheck) short *INPUT = short; +%typemap(typecheck) int *INPUT = int; +%typemap(typecheck) float *INPUT = float; +%typemap(typecheck) long long *INPUT = long long; +%typemap(typecheck) unsigned long long *INPUT = unsigned long long; + +%typemap(typecheck) double &INPUT = double; +%typemap(typecheck) bool &INPUT = bool; +%typemap(typecheck) signed char &INPUT = signed char; +%typemap(typecheck) unsigned char &INPUT = unsigned char; +%typemap(typecheck) unsigned long &INPUT = unsigned long; +%typemap(typecheck) unsigned short &INPUT = unsigned short; +%typemap(typecheck) unsigned int &INPUT = unsigned int; +%typemap(typecheck) long &INPUT = long; +%typemap(typecheck) short &INPUT = short; +%typemap(typecheck) int &INPUT = int; +%typemap(typecheck) float &INPUT = float; +%typemap(typecheck) long long &INPUT = long long; +%typemap(typecheck) unsigned long long &INPUT = unsigned long long; + +%typemap(typecheck) double *INOUT = double; +%typemap(typecheck) bool *INOUT = bool; +%typemap(typecheck) signed char *INOUT = signed char; +%typemap(typecheck) unsigned char *INOUT = unsigned char; +%typemap(typecheck) unsigned long *INOUT = unsigned long; +%typemap(typecheck) unsigned short *INOUT = unsigned short; +%typemap(typecheck) unsigned int *INOUT = unsigned int; +%typemap(typecheck) long *INOUT = long; +%typemap(typecheck) short *INOUT = short; +%typemap(typecheck) int *INOUT = int; +%typemap(typecheck) float *INOUT = float; +%typemap(typecheck) long long *INOUT = long long; +%typemap(typecheck) unsigned long long *INOUT = unsigned long long; + +%typemap(typecheck) double &INOUT = double; +%typemap(typecheck) bool &INOUT = bool; +%typemap(typecheck) signed char &INOUT = signed char; +%typemap(typecheck) unsigned char &INOUT = unsigned char; +%typemap(typecheck) unsigned long &INOUT = unsigned long; +%typemap(typecheck) unsigned short &INOUT = unsigned short; +%typemap(typecheck) unsigned int &INOUT = unsigned int; +%typemap(typecheck) long &INOUT = long; +%typemap(typecheck) short &INOUT = short; +%typemap(typecheck) int &INOUT = int; +%typemap(typecheck) float &INOUT = float; +%typemap(typecheck) long long &INOUT = long long; +%typemap(typecheck) unsigned long long &INOUT = unsigned long long; + +#endif + +// -------------------------------------------------------------------- +// Special types +// -------------------------------------------------------------------- + +%include +%include