The great merge
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
6fcc22a1f8
commit
516036631c
1508 changed files with 125983 additions and 44037 deletions
|
|
@ -16,11 +16,11 @@ RUBY = ruby
|
|||
SWIG = swig
|
||||
|
||||
# for C extension
|
||||
SWIGOPT = -ruby -feature $(FEATURE)
|
||||
SWIGOPT = -ruby
|
||||
WRAPPER = $(MODULE)_wrap.c
|
||||
|
||||
## for C++ extension
|
||||
#SWIGOPT = -ruby -c++ -feature $(FEATURE)
|
||||
#SWIGOPT = -ruby -c++
|
||||
#WRAPPER = $(MODULE)_wrap.cc
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
//
|
||||
// SWIG exception handling for Ruby
|
||||
//
|
||||
// $Header$
|
||||
//
|
||||
// Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
||||
// Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
||||
//
|
||||
// Masaki Fukushima
|
||||
//
|
||||
|
||||
%{
|
||||
#define SWIG_MemoryError rb_eFatal
|
||||
#define SWIG_IOError rb_eIOError
|
||||
#define SWIG_RuntimeError rb_eRuntimeError
|
||||
#define SWIG_IndexError rb_eIndexError
|
||||
#define SWIG_TypeError rb_eTypeError
|
||||
#define SWIG_DivisionByZero rb_eZeroDivError
|
||||
#define SWIG_OverflowError rb_eRuntimeException
|
||||
#define SWIG_SyntaxError rb_eSyntaxError
|
||||
#define SWIG_ValueError rb_eArgError
|
||||
#define SWIG_SystemError rb_eSystemError
|
||||
#define SWIG_UnknownError rb_eRuntimeError
|
||||
|
||||
#define SWIG_exception(a,b) rb_raise(a,b)
|
||||
|
||||
%}
|
||||
3
SWIG/Lib/ruby/extra-install.list
Normal file
3
SWIG/Lib/ruby/extra-install.list
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# see top-level Makefile.in
|
||||
Makefile.swig
|
||||
extconf.rb
|
||||
17
SWIG/Lib/ruby/fragments.i
Normal file
17
SWIG/Lib/ruby/fragments.i
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Helper function for Array output
|
||||
|
||||
%fragment("output_helper", "header") %{
|
||||
static VALUE output_helper(VALUE target, VALUE o) {
|
||||
if (NIL_P(target)) {
|
||||
target = o;
|
||||
} else {
|
||||
if (TYPE(target) != T_ARRAY) {
|
||||
VALUE o2 = target;
|
||||
target = rb_ary_new();
|
||||
rb_ary_push(target, o2);
|
||||
}
|
||||
rb_ary_push(target, o);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
%}
|
||||
|
|
@ -1,461 +0,0 @@
|
|||
//
|
||||
// Pointer library for Ruby
|
||||
//
|
||||
// $Header$
|
||||
//
|
||||
// Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
||||
// Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
||||
//
|
||||
// Masaki Fukushima
|
||||
//
|
||||
// Originally derived from python/ptrlang.i
|
||||
//
|
||||
|
||||
//
|
||||
// SWIG pointer conversion and utility library
|
||||
//
|
||||
// Dave Beazley
|
||||
// April 19, 1997
|
||||
//
|
||||
// Python specific implementation. This file is included
|
||||
// by the file ../pointer.i
|
||||
|
||||
|
||||
%{
|
||||
#include <ctype.h>
|
||||
|
||||
/* Types used by the library */
|
||||
static swig_type_info *SWIG_POINTER_int_p = 0;
|
||||
static swig_type_info *SWIG_POINTER_short_p =0;
|
||||
static swig_type_info *SWIG_POINTER_long_p = 0;
|
||||
static swig_type_info *SWIG_POINTER_float_p = 0;
|
||||
static swig_type_info *SWIG_POINTER_double_p = 0;
|
||||
static swig_type_info *SWIG_POINTER_char_p = 0;
|
||||
static swig_type_info *SWIG_POINTER_char_pp = 0;
|
||||
%}
|
||||
|
||||
%init %{
|
||||
SWIG_POINTER_int_p = SWIG_TypeQuery("int *");
|
||||
SWIG_POINTER_short_p = SWIG_TypeQuery("short *");
|
||||
SWIG_POINTER_long_p = SWIG_TypeQuery("long *");
|
||||
SWIG_POINTER_float_p = SWIG_TypeQuery("float *");
|
||||
SWIG_POINTER_double_p = SWIG_TypeQuery("double *");
|
||||
SWIG_POINTER_char_p = SWIG_TypeQuery("char *");
|
||||
SWIG_POINTER_char_pp = SWIG_TypeQuery("char **");
|
||||
%}
|
||||
|
||||
%{
|
||||
|
||||
/*------------------------------------------------------------------
|
||||
ptrvalue(ptr,type = 0)
|
||||
|
||||
Attempts to dereference a pointer value. If type is given, it
|
||||
will try to use that type. Otherwise, this function will attempt
|
||||
to "guess" the proper datatype by checking against all of the
|
||||
builtin C datatypes.
|
||||
------------------------------------------------------------------ */
|
||||
|
||||
static VALUE ptrvalue(VALUE _PTRVALUE, int index, char *type) {
|
||||
void *ptr;
|
||||
char *s;
|
||||
VALUE obj;
|
||||
|
||||
ptr = SWIG_ConvertPtr(_PTRVALUE,0);
|
||||
|
||||
/* If no datatype was passed, try a few common datatypes first */
|
||||
if (!type) {
|
||||
/* No datatype was passed. Type to figure out if it's a common one */
|
||||
if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_int_p)) {
|
||||
type = "int";
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_double_p)) {
|
||||
type = "double";
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_short_p)) {
|
||||
type = "short";
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_long_p)) {
|
||||
type = "long";
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_float_p)) {
|
||||
type = "float";
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_char_p)) {
|
||||
type = "char";
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_char_pp)) {
|
||||
type = "char *";
|
||||
} else {
|
||||
type = "unknown";
|
||||
}
|
||||
}
|
||||
if (!ptr) {
|
||||
rb_raise(rb_eTypeError,"Unable to dereference NULL pointer.");
|
||||
}
|
||||
/* Now we have a datatype. Try to figure out what to do about it */
|
||||
if (strcmp(type,"int") == 0) {
|
||||
obj = INT2NUM((long) *(((int *) ptr) + index));
|
||||
} else if (strcmp(type,"double") == 0) {
|
||||
obj = rb_float_new((double) *(((double *) ptr)+index));
|
||||
} else if (strcmp(type,"short") == 0) {
|
||||
obj = INT2NUM((long) *(((short *) ptr)+index));
|
||||
} else if (strcmp(type,"long") == 0) {
|
||||
obj = INT2NUM((long) *(((long *) ptr)+index));
|
||||
} else if (strcmp(type,"float") == 0) {
|
||||
obj = rb_float_new((double) *(((float *) ptr)+index));
|
||||
} else if (strcmp(type,"char") == 0) {
|
||||
obj = rb_str_new2(((char *) ptr)+index);
|
||||
} else if (strcmp(type,"char *") == 0) {
|
||||
char *c = *(((char **) ptr)+index);
|
||||
if (c) obj = rb_str_new2(c);
|
||||
else obj = rb_str_new2("NULL");
|
||||
} else {
|
||||
rb_raise(rb_eTypeError,"Unable to dereference unsupported datatype.");
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------
|
||||
ptrcreate(type,value = 0,numelements = 1)
|
||||
|
||||
Attempts to create a new object of given type. Type must be
|
||||
a basic C datatype. Will not create complex objects.
|
||||
------------------------------------------------------------------ */
|
||||
|
||||
static VALUE ptrcreate(char *type, VALUE _RBVALUE, int numelements) {
|
||||
void *ptr;
|
||||
VALUE obj;
|
||||
int sz;
|
||||
swig_type_info *cast;
|
||||
char temp[40];
|
||||
|
||||
/* Check the type string against a variety of possibilities */
|
||||
|
||||
if (strcmp(type,"int") == 0) {
|
||||
sz = sizeof(int)*numelements;
|
||||
cast = SWIG_POINTER_int_p;
|
||||
} else if (strcmp(type,"short") == 0) {
|
||||
sz = sizeof(short)*numelements;
|
||||
cast = SWIG_POINTER_short_p;
|
||||
} else if (strcmp(type,"long") == 0) {
|
||||
sz = sizeof(long)*numelements;
|
||||
cast = SWIG_POINTER_long_p;
|
||||
} else if (strcmp(type,"double") == 0) {
|
||||
sz = sizeof(double)*numelements;
|
||||
cast = SWIG_POINTER_double_p;
|
||||
} else if (strcmp(type,"float") == 0) {
|
||||
sz = sizeof(float)*numelements;
|
||||
cast = SWIG_POINTER_float_p;
|
||||
} else if (strcmp(type,"char") == 0) {
|
||||
sz = sizeof(char)*numelements;
|
||||
cast = SWIG_POINTER_char_p;
|
||||
} else if (strcmp(type,"char *") == 0) {
|
||||
sz = sizeof(char *)*(numelements+1);
|
||||
cast = SWIG_POINTER_char_pp;
|
||||
} else {
|
||||
rb_raise(rb_eTypeError,"Unable to create unknown datatype.");
|
||||
}
|
||||
|
||||
/* Create the new object */
|
||||
|
||||
ptr = (void *) malloc(sz);
|
||||
if (!ptr) {
|
||||
rb_raise(rb_eFatal,"Out of memory in swig_create.");
|
||||
}
|
||||
|
||||
/* Now try to set its default value */
|
||||
|
||||
if (_RBVALUE) {
|
||||
if (strcmp(type,"int") == 0) {
|
||||
int *ip,i,ivalue;
|
||||
ivalue = (int) NUM2LONG(_RBVALUE);
|
||||
ip = (int *) ptr;
|
||||
for (i = 0; i < numelements; i++)
|
||||
ip[i] = ivalue;
|
||||
} else if (strcmp(type,"short") == 0) {
|
||||
short *ip,ivalue;
|
||||
int i;
|
||||
ivalue = (short) NUM2LONG(_RBVALUE);
|
||||
ip = (short *) ptr;
|
||||
for (i = 0; i < numelements; i++)
|
||||
ip[i] = ivalue;
|
||||
} else if (strcmp(type,"long") == 0) {
|
||||
long *ip,ivalue;
|
||||
int i;
|
||||
ivalue = (long) NUM2LONG(_RBVALUE);
|
||||
ip = (long *) ptr;
|
||||
for (i = 0; i < numelements; i++)
|
||||
ip[i] = ivalue;
|
||||
} else if (strcmp(type,"double") == 0) {
|
||||
double *ip,ivalue;
|
||||
int i;
|
||||
ivalue = (double) NUM2DBL(_RBVALUE);
|
||||
ip = (double *) ptr;
|
||||
for (i = 0; i < numelements; i++)
|
||||
ip[i] = ivalue;
|
||||
} else if (strcmp(type,"float") == 0) {
|
||||
float *ip,ivalue;
|
||||
int i;
|
||||
ivalue = (float) NUM2DBL(_RBVALUE);
|
||||
ip = (float *) ptr;
|
||||
for (i = 0; i < numelements; i++)
|
||||
ip[i] = ivalue;
|
||||
} else if (strcmp(type,"char") == 0) {
|
||||
char *ip,*ivalue;
|
||||
ivalue = (char *) STR2CSTR(_RBVALUE);
|
||||
ip = (char *) ptr;
|
||||
strncpy(ip,ivalue,numelements-1);
|
||||
} else if (strcmp(type,"char *") == 0) {
|
||||
char **ip, *ivalue;
|
||||
int i;
|
||||
ivalue = (char *) STR2CSTR(_RBVALUE);
|
||||
ip = (char **) ptr;
|
||||
for (i = 0; i < numelements; i++) {
|
||||
if (ivalue) {
|
||||
ip[i] = (char *) malloc(strlen(ivalue)+1);
|
||||
strcpy(ip[i],ivalue);
|
||||
} else {
|
||||
ip[i] = 0;
|
||||
}
|
||||
}
|
||||
ip[numelements] = 0;
|
||||
}
|
||||
}
|
||||
/* Create the pointer value */
|
||||
|
||||
obj = SWIG_NewPointerObj(ptr,cast);
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------
|
||||
ptrset(ptr,value,index = 0,type = 0)
|
||||
|
||||
Attempts to set the value of a pointer variable. If type is
|
||||
given, we will use that type. Otherwise, we'll guess the datatype.
|
||||
------------------------------------------------------------------ */
|
||||
|
||||
static VALUE ptrset(VALUE _PTRVALUE, VALUE _RBVALUE, int index, char *type) {
|
||||
void *ptr;
|
||||
VALUE obj;
|
||||
|
||||
ptr = SWIG_ConvertPtr(_PTRVALUE,0);
|
||||
|
||||
/* If no datatype was passed, try a few common datatypes first */
|
||||
if (!type) {
|
||||
/* No datatype was passed. Type to figure out if it's a common one */
|
||||
if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_int_p)) {
|
||||
type = "int";
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_double_p)) {
|
||||
type = "double";
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_short_p)) {
|
||||
type = "short";
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_long_p)) {
|
||||
type = "long";
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_float_p)) {
|
||||
type = "float";
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_char_p)) {
|
||||
type = "char";
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_char_pp)) {
|
||||
type = "char *";
|
||||
} else {
|
||||
type = "unknown";
|
||||
}
|
||||
}
|
||||
if (!ptr) {
|
||||
rb_raise(rb_eTypeError,"Unable to set NULL pointer.");
|
||||
}
|
||||
|
||||
/* Now we have a datatype. Try to figure out what to do about it */
|
||||
if (strcmp(type,"int") == 0) {
|
||||
*(((int *) ptr)+index) = (int) NUM2LONG(_RBVALUE);
|
||||
} else if (strcmp(type,"double") == 0) {
|
||||
*(((double *) ptr)+index) = (double) NUM2DBL(_RBVALUE);
|
||||
} else if (strcmp(type,"short") == 0) {
|
||||
*(((short *) ptr)+index) = (short) NUM2LONG(_RBVALUE);
|
||||
} else if (strcmp(type,"long") == 0) {
|
||||
*(((long *) ptr)+index) = (long) NUM2LONG(_RBVALUE);
|
||||
} else if (strcmp(type,"float") == 0) {
|
||||
*(((float *) ptr)+index) = (float) NUM2DBL(_RBVALUE);
|
||||
} else if (strcmp(type,"char") == 0) {
|
||||
char *c = STR2CSTR(_RBVALUE);
|
||||
strcpy(((char *) ptr)+index, c);
|
||||
} else if (strcmp(type,"char *") == 0) {
|
||||
char *c = STR2CSTR(_RBVALUE);
|
||||
char **ca = (char **) ptr;
|
||||
if (ca[index]) free(ca[index]);
|
||||
if (strcmp(c,"NULL") == 0) {
|
||||
ca[index] = 0;
|
||||
} else {
|
||||
ca[index] = (char *) malloc(strlen(c)+1);
|
||||
strcpy(ca[index],c);
|
||||
}
|
||||
} else {
|
||||
rb_raise(rb_eTypeError,"Unable to set unsupported datatype.");
|
||||
}
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------
|
||||
ptradd(ptr,offset)
|
||||
|
||||
Adds a value to an existing pointer value. Will do a type-dependent
|
||||
add for basic datatypes. For other datatypes, will do a byte-add.
|
||||
------------------------------------------------------------------ */
|
||||
|
||||
static VALUE ptradd(VALUE _PTRVALUE, int offset) {
|
||||
|
||||
char *r;
|
||||
void *ptr,*junk;
|
||||
VALUE obj;
|
||||
swig_type_info *type;
|
||||
|
||||
ptr = SWIG_ConvertPtr(_PTRVALUE,0);
|
||||
|
||||
/* Check to see what kind of object _PTRVALUE is */
|
||||
|
||||
/* Try to handle a few common datatypes first */
|
||||
if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_int_p)) {
|
||||
ptr = (void *) (((int *) ptr) + offset);
|
||||
type = SWIG_POINTER_int_p;
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_double_p)) {
|
||||
ptr = (void *) (((double *) ptr) + offset);
|
||||
type = SWIG_POINTER_double_p;
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_short_p)) {
|
||||
ptr = (void *) (((short *) ptr) + offset);
|
||||
type = SWIG_POINTER_short_p;
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_long_p)) {
|
||||
ptr = (void *) (((long *) ptr) + offset);
|
||||
type = SWIG_POINTER_long_p;
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_float_p)) {
|
||||
ptr = (void *) (((float *) ptr) + offset);
|
||||
type = SWIG_POINTER_float_p;
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_char_p)) {
|
||||
ptr = (void *) (((char *) ptr) + offset);
|
||||
type = SWIG_POINTER_char_p;
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_char_pp)) {
|
||||
ptr = (void *) (((char *) ptr) + offset);
|
||||
type = SWIG_POINTER_char_pp;
|
||||
} else {
|
||||
rb_raise(rb_eTypeError,"Type error in ptradd. Argument is not a valid pointer value.");
|
||||
}
|
||||
obj = SWIG_NewPointerObj(ptr, type);
|
||||
return obj;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------
|
||||
ptrfree(ptr)
|
||||
|
||||
Destroys a pointer value
|
||||
------------------------------------------------------------------ */
|
||||
|
||||
VALUE ptrfree(VALUE _PTRVALUE) {
|
||||
void *ptr;
|
||||
|
||||
ptr = SWIG_ConvertPtr(_PTRVALUE,0);
|
||||
|
||||
/* Check to see if this pointer is a char ** */
|
||||
if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_char_pp)) {
|
||||
char **c = (char **) ptr;
|
||||
if (c) {
|
||||
int i = 0;
|
||||
while (c[i]) {
|
||||
free(c[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ptr)
|
||||
free((char *) ptr);
|
||||
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
%}
|
||||
%typemap(ruby,in) VALUE ptr, VALUE value {
|
||||
$target = $source;
|
||||
}
|
||||
|
||||
%typemap(ruby,out) VALUE ptrcast,
|
||||
VALUE ptrvalue,
|
||||
VALUE ptrcreate,
|
||||
VALUE ptrset,
|
||||
VALUE ptradd,
|
||||
VALUE ptrfree
|
||||
{
|
||||
$target = $source;
|
||||
}
|
||||
|
||||
%typemap(ruby,ret) int ptrset {
|
||||
if ($source == -1) return Qnil;
|
||||
}
|
||||
|
||||
VALUE ptrvalue(VALUE ptr, int index = 0, char *type = 0);
|
||||
// Returns the value that a pointer is pointing to (ie. dereferencing).
|
||||
// The type is automatically inferred by the pointer type--thus, an
|
||||
// integer pointer will return an integer, a double will return a double,
|
||||
// and so on. The index and type fields are optional parameters. When
|
||||
// an index is specified, this function returns the value of ptr[index].
|
||||
// This allows array access. When a type is specified, it overrides
|
||||
// the given pointer type. Examples :
|
||||
//
|
||||
// ptrvalue(a) # Returns the value *a
|
||||
// ptrvalue(a,10) # Returns the value a[10]
|
||||
// ptrvalue(a,10,"double") # Returns a[10] assuming a is a double *
|
||||
|
||||
VALUE ptrset(VALUE ptr, VALUE value, int index = 0, char *type = 0);
|
||||
// Sets the value pointed to by a pointer. The type is automatically
|
||||
// inferred from the pointer type so this function will work for
|
||||
// integers, floats, doubles, etc... The index and type fields are
|
||||
// optional. When an index is given, it provides array access. When
|
||||
// type is specified, it overrides the given pointer type. Examples :
|
||||
//
|
||||
// ptrset(a,3) # Sets the value *a = 3
|
||||
// ptrset(a,3,10) # Sets a[10] = 3
|
||||
// ptrset(a,3,10,"int") # Sets a[10] = 3 assuming a is a int *
|
||||
|
||||
VALUE ptrcreate(char *type, VALUE value = 0, int nitems = 1);
|
||||
// Creates a new object and returns a pointer to it. This function
|
||||
// can be used to create various kinds of objects for use in C functions.
|
||||
// type specifies the basic C datatype to create and value is an
|
||||
// optional parameter that can be used to set the initial value of the
|
||||
// object. nitems is an optional parameter that can be used to create
|
||||
// an array. This function results in a memory allocation using
|
||||
// malloc(). Examples :
|
||||
//
|
||||
// a = ptrcreate("double") # Create a new double, return pointer
|
||||
// a = ptrcreate("int",7) # Create an integer, set value to 7
|
||||
// a = ptrcreate("int",0,1000) # Create an integer array with initial
|
||||
// # values all set to zero
|
||||
//
|
||||
// This function only recognizes a few common C datatypes as listed below :
|
||||
//
|
||||
// int, short, long, float, double, char, char *, void
|
||||
//
|
||||
// All other datatypes will result in an error. However, other
|
||||
// datatypes can be created by using the ptrcast function. For
|
||||
// example:
|
||||
//
|
||||
// a = ptrcast(ptrcreate("int",0,100),"unsigned int *")
|
||||
|
||||
VALUE ptrfree(VALUE ptr);
|
||||
// Destroys the memory pointed to by ptr. This function calls free()
|
||||
// and should only be used with objects created by ptrcreate(). Since
|
||||
// this function calls free, it may work with other objects, but this
|
||||
// is generally discouraged unless you absolutely know what you're
|
||||
// doing.
|
||||
|
||||
VALUE ptradd(VALUE ptr, int offset);
|
||||
// Adds a value to the current pointer value. For the C datatypes of
|
||||
// int, short, long, float, double, and char, the offset value is the
|
||||
// number of objects and works in exactly the same manner as in C. For
|
||||
// example, the following code steps through the elements of an array
|
||||
//
|
||||
// a = ptrcreate("double",0,100); # Create an array double a[100]
|
||||
// b = a;
|
||||
// for i in range(0,100):
|
||||
// ptrset(b,0.0025*i); # set *b = 0.0025*i
|
||||
// b = ptradd(b,1); # b++ (go to next double)
|
||||
//
|
||||
// In this case, adding one to b goes to the next double.
|
||||
//
|
||||
// For all other datatypes (including all complex datatypes), the
|
||||
// offset corresponds to bytes. This function does not perform any
|
||||
// bounds checking and negative offsets are perfectly legal.
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
%typemap(ruby,varin) char * "
|
||||
Check_Type($source, T_STRING);
|
||||
if ($target) free($target);
|
||||
$target = xmalloc(RSTRING($source)->len + 1);
|
||||
strncpy($target, STR2CSTR($source), RSTRING($source)->len + 1);";
|
||||
|
|
@ -1,19 +1,520 @@
|
|||
/* ruby.swg */
|
||||
#include "ruby.h"
|
||||
/* ----------------------------------------------------------------------
|
||||
* ruby.swg
|
||||
*
|
||||
* Ruby configuation file.
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
#define NUM2USHRT(n) NUM2UINT(n)
|
||||
#define NUM2SHRT(n) (\
|
||||
(SHRT_MIN <= NUM2INT(n) && NUM2INT(n) <= SHRT_MAX)\
|
||||
? (short)NUM2INT(n)\
|
||||
: (rb_raise(rb_eArgError, "integer %d out of range of `short'",\
|
||||
NUM2INT(n)), (short)0)\
|
||||
)
|
||||
%runtime "rubyhead.swg"
|
||||
%runtime "common.swg"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# define VALUEFUNC(f) ((VALUE (*)(...))f)
|
||||
# define VOIDFUNC(f) ((void (*)(...))f)
|
||||
#ifdef SWIG_NOINCLUDE
|
||||
%runtime "rubydec.swg"
|
||||
#else
|
||||
# define VALUEFUNC(f) (f)
|
||||
# define VOIDFUNC(f) (f)
|
||||
%runtime "rubydef.swg"
|
||||
#endif
|
||||
|
||||
#define %alias %feature("alias")
|
||||
#define %freefunc %feature("freefunc")
|
||||
#define %markfunc %feature("markfunc")
|
||||
#define %mixin %feature("mixin")
|
||||
#define %predicate %feature("predicate", "1")
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Standard Typemaps
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
/* --- Input Values --- */
|
||||
|
||||
%typemap(in) int "$1 = NUM2INT($input);";
|
||||
%typemap(in) unsigned int "$1 = NUM2UINT($input);";
|
||||
%typemap(in) short "$1 = NUM2SHRT($input);";
|
||||
%typemap(in) unsigned short "$1 = NUM2USHRT($input);";
|
||||
%typemap(in) long "$1 = NUM2LONG($input);";
|
||||
%typemap(in) unsigned long "$1 = NUM2ULONG($input);";
|
||||
%typemap(in) signed char "$1 = ($1_ltype) NUM2INT($input);";
|
||||
%typemap(in) unsigned char "$1 = ($1_ltype) NUM2INT($input);";
|
||||
%typemap(in) char "$1 = NUM2CHR($input);";
|
||||
%typemap(in) float, double "$1 = ($1_ltype) NUM2DBL($input);";
|
||||
%typemap(in) bool "$1 = RTEST($input);";
|
||||
%typemap(in) char * "$1 = STR2CSTR($input);";
|
||||
%typemap(in) char [ANY] "$1 = STR2CSTR($input);";
|
||||
%typemap(in) enum SWIGTYPE "$1 = ($1_ltype) NUM2INT($input);";
|
||||
|
||||
/* Long long */
|
||||
|
||||
%typemap(in) long long "$1 = ($1_ltype) NUM2LL($input);";
|
||||
%typemap(in) unsigned long long "$1 = ($1_ltype) NUM2ULL($input);";
|
||||
|
||||
/* Typemaps for pointers. Note: the SWIG run-time type checker works
|
||||
even if a pointer happens to be mapped to a Ruby class */
|
||||
|
||||
%typemap(in) SWIGTYPE *,
|
||||
SWIGTYPE []
|
||||
"SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 1);"
|
||||
|
||||
/* Additional check for null references */
|
||||
%typemap(in) SWIGTYPE &
|
||||
"SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 1); if ($1 == NULL) rb_raise(rb_eTypeError, \"null reference\");"
|
||||
|
||||
/* Void pointer. Accepts any kind of pointer */
|
||||
%typemap(in) void *
|
||||
"SWIG_ConvertPtr($input, (void **) &$1, 0, 1);";
|
||||
|
||||
/* Object passed by value. Convert to a pointer */
|
||||
%typemap(in) SWIGTYPE {
|
||||
$&1_ltype ptr;
|
||||
SWIG_ConvertPtr($input, (void **) &ptr, $&1_descriptor, 1);
|
||||
if (ptr) $1 = *ptr;
|
||||
}
|
||||
|
||||
/* Pointer to a class member */
|
||||
%typemap(in) SWIGTYPE (CLASS::*) "SWIG_ConvertPacked($input, (void *) &$1, sizeof($1_type), $1_descriptor, 1);";
|
||||
|
||||
/* Const primitive references. Passed by value */
|
||||
|
||||
%typemap(in) const int & (int temp),
|
||||
const signed char & (signed char temp),
|
||||
const unsigned char & (unsigned char temp)
|
||||
"temp = ($*1_ltype) NUM2INT($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const short & (short temp)
|
||||
"temp = ($*1_ltype) NUM2SHRT($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const long & (long temp)
|
||||
"temp = ($*1_ltype) NUM2LONG($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const unsigned int & (unsigned int temp)
|
||||
"temp = ($*1_ltype) NUM2UINT($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const unsigned short & (unsigned short temp)
|
||||
"temp = ($*1_ltype) NUM2USHRT($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const unsigned long & (unsigned long temp)
|
||||
"temp = ($*1_ltype) NUM2ULONG($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const bool & (bool temp)
|
||||
"temp = ($*1_ltype) RTEST($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const float & (float temp),
|
||||
const double & (double temp)
|
||||
"temp = ($*1_ltype) NUM2DBL($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const long long & (long long temp)
|
||||
"temp = ($*1_ltype) NUM2LL($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const unsigned long long & (unsigned long long temp)
|
||||
"temp = ($*1_ltype) NUM2ULL($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const char &(char temp) {
|
||||
char *stemp = STR2CSTR($input);
|
||||
temp = *stemp;
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
/* --- Output typemaps --- */
|
||||
|
||||
%typemap(out) int, short, long, signed char, enum SWIGTYPE
|
||||
"$result = INT2NUM($1);";
|
||||
|
||||
%typemap(out) unsigned int, unsigned short, unsigned long, unsigned char
|
||||
"$result = UINT2NUM($1);";
|
||||
|
||||
|
||||
/* Long long */
|
||||
|
||||
%typemap(out) long long "$result = LL2NUM($1);";
|
||||
%typemap(out) unsigned long long "$result = ULL2NUM($1);";
|
||||
|
||||
/* Floating point output values */
|
||||
%typemap(out) double, float
|
||||
"$result = rb_float_new($1);";
|
||||
|
||||
/* Character */
|
||||
%typemap(out) char
|
||||
"$result = rb_str_new(&$1,1);";
|
||||
|
||||
/* Boolean */
|
||||
%typemap(out) bool
|
||||
"$result = $1 ? Qtrue : Qfalse;";
|
||||
|
||||
/* C string */
|
||||
%typemap(out) char *
|
||||
"$result = rb_str_new2($1);";
|
||||
|
||||
/* Pointers, references, and arrays */
|
||||
%typemap(out) SWIGTYPE*, SWIGTYPE &, SWIGTYPE []
|
||||
"$result = SWIG_NewPointerObj((void *) $1, $1_descriptor,$owner);";
|
||||
|
||||
/* Dynamic casts */
|
||||
%typemap(out) SWIGTYPE*DYNAMIC, SWIGTYPE &DYNAMIC {
|
||||
swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor, (void **) &$1);
|
||||
$result = SWIG_NewPointerObj((void *) $1, ty,$owner);
|
||||
}
|
||||
|
||||
/* Member pointer */
|
||||
%typemap(out) SWIGTYPE (CLASS::*) "$result = SWIG_NewPackedObj((void *) &$1, sizeof($1_type), $1_descriptor);";
|
||||
|
||||
/* Void */
|
||||
%typemap(out) void "$result = Qnil;";
|
||||
|
||||
/* Primitive types--return by value */
|
||||
%typemap(out) SWIGTYPE
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
$&1_ltype resultptr;
|
||||
resultptr = new $1_ltype(($1_ltype &)$1);
|
||||
$result = SWIG_NewPointerObj((void *) resultptr, $&1_descriptor, 1);
|
||||
}
|
||||
#else
|
||||
{
|
||||
$&1_ltype resultptr;
|
||||
resultptr = ($&1_ltype) malloc(sizeof($1_type));
|
||||
memmove(resultptr, &$1, sizeof($1_type));
|
||||
$result = SWIG_NewPointerObj((void *) resultptr, $&1_descriptor, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
%typemap(out) char [ANY] "$result = rb_str_new2($1);";
|
||||
|
||||
/* References to primitive types. Return by value */
|
||||
|
||||
%typemap(out) const int &,
|
||||
const short &,
|
||||
const long &,
|
||||
const signed char &
|
||||
"$result = INT2NUM((long) *($1));";
|
||||
|
||||
%typemap(out) const unsigned int &,
|
||||
const unsigned short &,
|
||||
const unsigned long &,
|
||||
const unsigned char &
|
||||
"$result = UINT2NUM((unsigned long) *($1));";
|
||||
|
||||
%typemap(out) const bool &
|
||||
"$result = *($1) ? Qtrue : Qfalse;";
|
||||
|
||||
%typemap(out) const float &, const double &
|
||||
"$result = rb_float_new((double) *($1));";
|
||||
|
||||
%typemap(out) const long long &
|
||||
"$result = LL2NUM(*($1));";
|
||||
|
||||
%typemap(out) const unsigned long long &
|
||||
"$result = ULL2NUM(*($1));";
|
||||
|
||||
%typemap(out) const char &
|
||||
"$result = rb_str_new($1, 1);";
|
||||
|
||||
/* --- Variable Input --- */
|
||||
|
||||
%typemap(varin) int "$1 = NUM2INT($input);";
|
||||
%typemap(varin) unsigned int "$1 = NUM2UINT($input);";
|
||||
%typemap(varin) short "$1 = NUM2SHRT($input);";
|
||||
%typemap(varin) unsigned short "$1 = NUM2USHRT($input);";
|
||||
%typemap(varin) long "$1 = NUM2LONG($input);";
|
||||
%typemap(varin) unsigned long "$1 = NUM2ULONG($input);";
|
||||
%typemap(varin) signed char "$1 = (signed char) NUM2INT($input);";
|
||||
%typemap(varin) unsigned char "$1 = (unsigned char) NUM2INT($input);";
|
||||
%typemap(varin) char "$1 = NUM2CHR($input);";
|
||||
%typemap(varin) float, double "$1 = ($1_ltype) NUM2DBL($input);";
|
||||
%typemap(varin) bool "$1 = RTEST($input);";
|
||||
|
||||
%typemap(varin) long long "$1 = NUM2LL($input);";
|
||||
%typemap(varin) unsigned long long "$1 = NUM2ULL($input);";
|
||||
|
||||
/* A string */
|
||||
#ifdef __cplusplus
|
||||
%typemap(varin) char * {
|
||||
char *temp = (char *) STR2CSTR($input);
|
||||
if ($1) delete [] $1;
|
||||
$1 = ($type) new char[strlen(temp)+1];
|
||||
strcpy((char*)$1,temp);
|
||||
}
|
||||
%typemap(varin,warning="451:Setting const char * variable may leak memory") const char * {
|
||||
char *temp = (char *) STR2CSTR($input);
|
||||
$1 = ($type) new char[strlen(temp)+1];
|
||||
strcpy((char*)$1,temp);
|
||||
}
|
||||
#else
|
||||
%typemap(varin) char * {
|
||||
char *temp = (char *) STR2CSTR($input);
|
||||
if ($1) free((char*) $1);
|
||||
$1 = ($type) malloc(strlen(temp)+1);
|
||||
strcpy((char*)$1,temp);
|
||||
}
|
||||
%typemap(varin,warning="451:Setting const char * variable may leak memory") const char * {
|
||||
char *temp = (char *) STR2CSTR($input);
|
||||
$1 = ($type) malloc(strlen(temp)+1);
|
||||
strcpy((char*)$1,temp);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
%typemap(varin) char [ANY] "strncpy($1,STR2CSTR($input),$1_dim0);";
|
||||
%typemap(varin) enum SWIGTYPE "$1 = ($1_type) NUM2INT($input);";
|
||||
|
||||
/* Typemaps for pointers. Note: the SWIG run-time type checker works
|
||||
even if a pointer happens to be mapped to a Ruby class */
|
||||
|
||||
%typemap(varin) SWIGTYPE *,
|
||||
SWIGTYPE &
|
||||
"SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 1);"
|
||||
|
||||
%typemap(varin) SWIGTYPE [] {
|
||||
rb_raise(rb_eRuntimeError, "Array $name is readonly");
|
||||
}
|
||||
|
||||
%typemap(varin) void *
|
||||
"SWIG_ConvertPtr($input, (void **) &$1, 0, 1);";
|
||||
|
||||
%typemap(varin) SWIGTYPE {
|
||||
$&1_ltype ptr;
|
||||
SWIG_ConvertPtr($input, (void **) &ptr, $&1_descriptor, 1);
|
||||
if (ptr) $1 = *ptr;
|
||||
}
|
||||
|
||||
%typemap(varin) SWIGTYPE (CLASS::*) {
|
||||
char temp[sizeof($1_type)];
|
||||
SWIG_ConvertPacked($input, (void *) temp, sizeof($1_type), $1_descriptor, 1);
|
||||
memmove((void *) &$1, temp, sizeof($1_type));
|
||||
}
|
||||
|
||||
/* --- Output typemaps --- */
|
||||
|
||||
%typemap(varout) int, short, long, signed char, enum SWIGTYPE
|
||||
"$result = INT2NUM($1);";
|
||||
|
||||
%typemap(varout) unsigned int, unsigned short, unsigned long, unsigned char
|
||||
"$result = UINT2NUM($1);";
|
||||
|
||||
%typemap(varout) long long "$result = LL2NUM($1);";
|
||||
%typemap(varout) unsigned long long "$result = ULL2NUM($1);";
|
||||
|
||||
/* Floats and doubles */
|
||||
%typemap(varout) double, float
|
||||
"$result = rb_float_new($1);";
|
||||
|
||||
/* Character */
|
||||
%typemap(varout) char
|
||||
"$result = rb_str_new(&$1,1);";
|
||||
|
||||
/* Boolean */
|
||||
%typemap(varout) bool
|
||||
"$result = $1 ? Qtrue : Qfalse;";
|
||||
|
||||
/* C string */
|
||||
%typemap(varout) char *
|
||||
"$result = rb_str_new2($1);";
|
||||
|
||||
/* Pointers, references, and arrays */
|
||||
%typemap(varout) SWIGTYPE*, SWIGTYPE []
|
||||
"$result = SWIG_NewPointerObj((void *) $1, $1_descriptor,0);";
|
||||
|
||||
%typemap(varout) SWIGTYPE &
|
||||
"$result = SWIG_NewPointerObj((void *) &$1, $1_descriptor,0);";
|
||||
|
||||
/* Void */
|
||||
%typemap(varout) void "$result = Qnil;";
|
||||
|
||||
/* Copy by value */
|
||||
%typemap(varout) SWIGTYPE "$result = SWIG_NewPointerObj((void *) &$1, $&1_descriptor, 1);";
|
||||
|
||||
%typemap(varout) char [ANY] "$result = rb_str_new2($1);";
|
||||
|
||||
/* Member pointer */
|
||||
%typemap(varout) SWIGTYPE (CLASS::*) "$result = SWIG_NewPackedObj((void *) &$1, sizeof($1_type), $1_descriptor);";
|
||||
|
||||
/* --- Constants --- */
|
||||
|
||||
%typemap(constant) int, short, long, signed char, enum SWIGTYPE
|
||||
"rb_define_const($module,\"$symname\", INT2NUM($1));";
|
||||
|
||||
%typemap(constant) unsigned int, unsigned short, unsigned long, unsigned char
|
||||
"rb_define_const($module,\"$symname\", UINT2NUM($1));";
|
||||
|
||||
%typemap(constant) long long
|
||||
"rb_define_const($module,\"$symname\", LL2NUM($1));";
|
||||
|
||||
%typemap(constant) unsigned long long
|
||||
"rb_define_const($module,\"$symname\", ULL2NUM($1));";
|
||||
|
||||
%typemap(constant) double, float
|
||||
"rb_define_const($module,\"$symname\", rb_float_new($1));";
|
||||
|
||||
%typemap(constant) char
|
||||
"rb_define_const($module,\"$symname\", rb_str_new(\"$1\",1));";
|
||||
|
||||
%typemap(constant) bool
|
||||
"rb_define_const($module,\"$symname\", ($1 ? Qtrue : Qfalse));";
|
||||
|
||||
%typemap(constant) char *
|
||||
"rb_define_const($module,\"$symname\", rb_str_new2(\"$1\"));";
|
||||
|
||||
%typemap(constant) SWIGTYPE*, SWIGTYPE &, SWIGTYPE []
|
||||
"rb_define_const($module,\"$symname\", SWIG_NewPointerObj((void *) $1, $1_descriptor,0));";
|
||||
|
||||
%typemap(constant) SWIGTYPE "rb_define_const($module,\"$symname\", SWIG_NewPointerObj((void *) &$1, $&1_descriptor, 0));";
|
||||
|
||||
%typemap(constant) SWIGTYPE (CLASS::*) "rb_define_const($module, \"$symname\", SWIG_NewPackedObj((void *) &$1, sizeof($type), $1_descriptor));";
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* typedef & typemaps for VALUE (passed through unmodified)
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
typedef unsigned long VALUE;
|
||||
|
||||
%typemap(ruby,in) VALUE "$1 = $input;";
|
||||
%typemap(ruby,out) VALUE "$result = $1;";
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* String & length
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typemap(in) (char *STRING, int LENGTH) {
|
||||
$1 = ($1_ltype) STR2CSTR($input);
|
||||
$2 = ($2_ltype) RSTRING($input)->len;
|
||||
}
|
||||
|
||||
/* Some ANSI C typemaps */
|
||||
|
||||
%apply long { size_t };
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Typechecking rules
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE {
|
||||
void *ptr;
|
||||
$1 = (NIL_P($input) || (TYPE($input) == T_DATA && SWIG_ConvertPtr($input, &ptr, $&1_descriptor, 0) != -1)) ? 1 : 0;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
|
||||
void *ptr;
|
||||
$1 = (NIL_P($input) || (TYPE($input) == T_DATA && SWIG_ConvertPtr($input, &ptr, $1_descriptor, 0) != -1)) ? 1 : 0;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_VOIDPTR) void * {
|
||||
void *ptr;
|
||||
$1 = (NIL_P($input) || (TYPE($input) == T_DATA && SWIG_ConvertPtr($input, &ptr, 0, 0) != -1)) ? 1 : 0;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_BOOL) bool {
|
||||
$1 = ($input == Qtrue || $input == Qfalse) ? 1 : 0;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INTEGER)
|
||||
int, short, long,
|
||||
unsigned int, unsigned short, unsigned long,
|
||||
signed char, unsigned char,
|
||||
long long, unsigned long long,
|
||||
const int &, const short &, const long &,
|
||||
const unsigned int &, const unsigned short &, const unsigned long &,
|
||||
const long long &, const unsigned long long &,
|
||||
enum SWIGTYPE
|
||||
{
|
||||
$1 = ((TYPE($input) == T_FIXNUM) || (TYPE($input) == T_BIGNUM)) ? 1 : 0;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_DOUBLE)
|
||||
float, double,
|
||||
const float &, const double &
|
||||
{
|
||||
$1 = ((TYPE($input) == T_FLOAT) || (TYPE($input) == T_FIXNUM) || (TYPE($input) == T_BIGNUM)) ? 1 : 0;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_CHAR) char {
|
||||
$1 = (TYPE($input) == T_STRING && (RSTRING($input)->len == 1)) ? 1 : 0;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_STRING) char * {
|
||||
$1 = (TYPE($input) == T_STRING) ? 1 : 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Exception handling
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typemap(throws) int,
|
||||
long,
|
||||
short,
|
||||
unsigned int,
|
||||
unsigned long,
|
||||
unsigned short {
|
||||
rb_exc_raise(rb_exc_new3(rb_eRuntimeError, INT2NUM($1)));
|
||||
}
|
||||
|
||||
%typemap(throws) SWIGTYPE {
|
||||
$&1_ltype temp = new $1_ltype($1);
|
||||
if ($&1_descriptor->clientdata) {
|
||||
rb_exc_raise(rb_exc_new3(((swig_class *) ($&1_descriptor->clientdata))->klass, SWIG_NewPointerObj(temp, $&1_descriptor, 1)));
|
||||
} else {
|
||||
rb_exc_raise(rb_exc_new3(rb_eRuntimeError, SWIG_NewPointerObj(temp, $&1_descriptor, 1)));
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(throws) char * {
|
||||
rb_raise(rb_eRuntimeError, $1);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Overloaded operator support
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
%rename(__add__) *::operator+;
|
||||
%rename(__pos__) *::operator+();
|
||||
%rename(__pos__) *::operator+() const;
|
||||
%rename(__sub__) *::operator-;
|
||||
%rename(__neg__) *::operator-();
|
||||
%rename(__neg__) *::operator-() const;
|
||||
%rename(__mul__) *::operator*;
|
||||
%rename(__div__) *::operator/;
|
||||
%rename(__mod__) *::operator%;
|
||||
%rename(__lshift__) *::operator<<;
|
||||
%rename(__rshift__) *::operator>>;
|
||||
%rename(__and__) *::operator&;
|
||||
%rename(__or__) *::operator|;
|
||||
%rename(__xor__) *::operator^;
|
||||
%rename(__invert__) *::operator~;
|
||||
%rename(__lt__) *::operator<;
|
||||
%rename(__le__) *::operator<=;
|
||||
%rename(__gt__) *::operator>;
|
||||
%rename(__ge__) *::operator>=;
|
||||
%rename(__eq__) *::operator==;
|
||||
|
||||
/* Special cases */
|
||||
%rename(__call__) *::operator();
|
||||
|
||||
/* Ignored operators */
|
||||
%ignorewarn("378:operator!= ignored") operator!=;
|
||||
%ignorewarn("365:operator+= ignored") operator+=;
|
||||
%ignorewarn("366:operator-= ignored") operator-=;
|
||||
%ignorewarn("367:operator*= ignored") operator*=;
|
||||
%ignorewarn("368:operator/= ignored") operator/=;
|
||||
%ignorewarn("369:operator%= ignored") operator%=;
|
||||
%ignorewarn("375:operator<<= ignored") operator<<=;
|
||||
%ignorewarn("376:operator>>= ignored") operator>>=;
|
||||
%ignorewarn("371:operator&= ignored") operator&=;
|
||||
%ignorewarn("372:operator|= ignored") operator|=;
|
||||
%ignorewarn("370:operator^= ignored") operator^=;
|
||||
%ignorewarn("362:operator= ignored") operator=;
|
||||
%ignorewarn("383:operator++ ignored") operator++;
|
||||
%ignorewarn("384:operator-- ignored") operator--;
|
||||
%ignorewarn("381:operator&& ignored") operator&&;
|
||||
%ignorewarn("382:operator|| ignored") operator||;
|
||||
// %ignorewarn("387:operator-> ignored") operator->;
|
||||
%ignorewarn("386:operator->* ignored") operator->*;
|
||||
%ignorewarn("389:operator[] ignored (consider using %extend)") operator[];
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
|
|
|||
|
|
@ -3,13 +3,18 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
SWIGEXPORT(void) SWIG_define_class(VALUE, swig_type_info *)
|
||||
SWIGEXPORT(VALUE) SWIG_NewPointerObj(void *, swig_type_info *);
|
||||
SWIGEXPORT(char *) SWIG_MangleStr(VALUE);
|
||||
SWIGEXPORT(void *) SWIG_ConvertPtr(VALUE, swig_type_info *);
|
||||
SWIGEXPORT(int) SWIG_CheckConvert(VALUE, swig_type_info *);
|
||||
SWIGIMPORT(void) SWIG_InitRuntime(void);
|
||||
SWIGIMPORT(void) SWIG_define_class(swig_type_info *);
|
||||
SWIGIMPORT(VALUE) SWIG_NewPointerObj(void *, swig_type_info *, int);
|
||||
SWIGIMPORT(VALUE) SWIG_NewClassInstance(VALUE, swig_type_info *);
|
||||
SWIGIMPORT(char *) SWIG_MangleStr(VALUE);
|
||||
SWIGIMPORT(int) SWIG_ConvertPtr(VALUE, void**, swig_type_info *, int);
|
||||
SWIGIMPORT(int) SWIG_CheckConvert(VALUE, swig_type_info *);
|
||||
SWIGIMPORT(char *) SWIG_PackData(char *c, void *ptr, int sz);
|
||||
SWIGIMPORT(char *) SWIG_UnpackData(char *c, void *ptr, int sz);
|
||||
SWIGIMPORT(VALUE) SWIG_NewPackedObj(void *ptr, int sz, swig_type_info *type);
|
||||
SWIGIMPORT(void) SWIG_ConvertPacked(VALUE obj, void *ptr, int sz, swig_type_info *ty, int flags);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,75 +3,121 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
static VALUE _mSWIG = Qnil;
|
||||
static VALUE _cSWIG_Pointer = Qnil;
|
||||
|
||||
/* Define ruby class for C type */
|
||||
/* Initialize Ruby runtime support */
|
||||
SWIGRUNTIME(void)
|
||||
SWIG_InitRuntime(void)
|
||||
{
|
||||
if (_mSWIG == Qnil) {
|
||||
_mSWIG = rb_define_module("SWIG");
|
||||
}
|
||||
}
|
||||
|
||||
/* Define Ruby class for C type */
|
||||
SWIGRUNTIME(void)
|
||||
SWIG_define_class(swig_type_info *type)
|
||||
{
|
||||
VALUE klass;
|
||||
char *klass_name = ALLOCA_N(char, 4 + strlen(type->name) + 1);
|
||||
|
||||
char *klass_name = (char *) malloc(4 + strlen(type->name) + 1);
|
||||
sprintf(klass_name, "TYPE%s", type->name);
|
||||
if (NIL_P(_cSWIG_Pointer)) {
|
||||
_cSWIG_Pointer = rb_define_class_under(_mSWIG, "Pointer", rb_cObject);
|
||||
rb_undef_method(CLASS_OF(_cSWIG_Pointer), "new");
|
||||
}
|
||||
klass = rb_define_class_under(_mSWIG, klass_name, _cSWIG_Pointer);
|
||||
free((void *) klass_name);
|
||||
}
|
||||
|
||||
/* Create a new pointer object */
|
||||
SWIGRUNTIME(VALUE)
|
||||
SWIG_NewPointerObj(void *ptr, swig_type_info *type)
|
||||
SWIG_NewPointerObj(void *ptr, swig_type_info *type, int own)
|
||||
{
|
||||
char *klass_name;
|
||||
swig_class *sklass;
|
||||
VALUE klass;
|
||||
|
||||
VALUE obj;
|
||||
|
||||
if (!ptr)
|
||||
return Qnil;
|
||||
|
||||
if (type->clientdata) {
|
||||
sklass = (swig_class *) type->clientdata;
|
||||
obj = Data_Wrap_Struct(sklass->klass, VOIDFUNC(sklass->mark), (own ? VOIDFUNC(sklass->destroy) : 0), ptr);
|
||||
} else {
|
||||
klass_name = (char *) malloc(4 + strlen(type->name) + 1);
|
||||
sprintf(klass_name, "TYPE%s", type->name);
|
||||
klass = rb_const_get(_mSWIG, rb_intern(klass_name));
|
||||
free((void *) klass_name);
|
||||
obj = Data_Wrap_Struct(klass, 0, 0, ptr);
|
||||
}
|
||||
rb_iv_set(obj, "__swigtype__", rb_str_new2(type->name));
|
||||
return obj;
|
||||
}
|
||||
|
||||
klass_name = ALLOCA_N(char, 4 + strlen(type->name) + 1);
|
||||
sprintf(klass_name, "TYPE%s", type->name);
|
||||
klass = rb_const_get(_mSWIG, rb_intern(klass_name));
|
||||
return Data_Wrap_Struct(klass, 0, 0, ptr);
|
||||
/* Create a new class instance (always owned) */
|
||||
SWIGRUNTIME(VALUE)
|
||||
SWIG_NewClassInstance(VALUE klass, swig_type_info *type)
|
||||
{
|
||||
VALUE obj;
|
||||
swig_class *sklass = (swig_class *) type->clientdata;
|
||||
obj = Data_Wrap_Struct(klass, VOIDFUNC(sklass->mark), VOIDFUNC(sklass->destroy), 0);
|
||||
rb_iv_set(obj, "__swigtype__", rb_str_new2(type->name));
|
||||
return obj;
|
||||
}
|
||||
|
||||
/* Get type mangle from class name */
|
||||
SWIGRUNTIME(char *)
|
||||
SWIG_MangleStr(VALUE obj)
|
||||
{
|
||||
char *c;
|
||||
|
||||
if (!rb_obj_is_kind_of(obj, _cSWIG_Pointer))
|
||||
return 0;
|
||||
|
||||
c = rb_class2name(rb_class_of(obj));
|
||||
c += strlen(c);
|
||||
while (*(--c) != ':');
|
||||
/* skip ":TYPE" */
|
||||
c += 5;
|
||||
return c;
|
||||
VALUE stype = rb_iv_get(obj, "__swigtype__");
|
||||
return STR2CSTR(stype);
|
||||
}
|
||||
|
||||
/* Convert a pointer value */
|
||||
SWIGRUNTIME(void *)
|
||||
SWIG_ConvertPtr(VALUE obj, swig_type_info *ty)
|
||||
SWIGRUNTIME(int)
|
||||
SWIG_ConvertPtr(VALUE obj, void **ptr, swig_type_info *ty, int flags)
|
||||
{
|
||||
char *c;
|
||||
void *ptr;
|
||||
swig_type_info *tc;
|
||||
|
||||
if ((c = SWIG_MangleStr(obj)) == NULL)
|
||||
rb_raise(rb_eTypeError, "Expected %s", ty->str);
|
||||
Data_Get_Struct(obj, void, ptr);
|
||||
/* Grab the pointer */
|
||||
if (NIL_P(obj)) {
|
||||
*ptr = 0;
|
||||
return 0;
|
||||
} else
|
||||
Data_Get_Struct(obj, void, *ptr);
|
||||
|
||||
/* Do type-checking if type info was provided */
|
||||
if (ty) {
|
||||
tc = SWIG_TypeCheck(c, ty);
|
||||
if (!tc) rb_raise(rb_eTypeError, "Expected %s", ty->str);
|
||||
ptr = SWIG_TypeCast(tc, ptr);
|
||||
if (ty->clientdata) {
|
||||
if (!rb_obj_is_kind_of(obj, ((swig_class *) (ty->clientdata))->klass)) {
|
||||
if (flags)
|
||||
rb_raise(rb_eTypeError, "wrong argument type (expected %s)", ty->str);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
if (*ptr == 0)
|
||||
rb_raise(rb_eRuntimeError, "This %s already released", ty->str);
|
||||
} else {
|
||||
if ((c = SWIG_MangleStr(obj)) == NULL) {
|
||||
if (flags)
|
||||
rb_raise(rb_eTypeError, "Expected %s", ty->str);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
tc = SWIG_TypeCheck(c, ty);
|
||||
if (!tc) {
|
||||
if (flags)
|
||||
rb_raise(rb_eTypeError, "Expected %s", ty->str);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
*ptr = SWIG_TypeCast(tc, *ptr);
|
||||
}
|
||||
}
|
||||
return ptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Check convert */
|
||||
|
|
@ -84,6 +130,84 @@ SWIG_CheckConvert(VALUE obj, swig_type_info *ty)
|
|||
return SWIG_TypeCheck(c,ty) != 0;
|
||||
}
|
||||
|
||||
/* Pack binary data into a string */
|
||||
SWIGRUNTIME(char *)
|
||||
SWIG_PackData(char *c, void *ptr, int sz) {
|
||||
static char hex[17] = "0123456789abcdef";
|
||||
int i;
|
||||
unsigned char *u = (unsigned char *) ptr;
|
||||
register unsigned char uu;
|
||||
for (i = 0; i < sz; i++,u++) {
|
||||
uu = *u;
|
||||
*(c++) = hex[(uu & 0xf0) >> 4];
|
||||
*(c++) = hex[uu & 0xf];
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
/* Unpack binary data from a string */
|
||||
SWIGRUNTIME(char *)
|
||||
SWIG_UnpackData(char *c, void *ptr, int sz) {
|
||||
register unsigned char uu = 0;
|
||||
register int d;
|
||||
unsigned char *u = (unsigned char *) ptr;
|
||||
int i;
|
||||
for (i = 0; i < sz; i++, u++) {
|
||||
d = *(c++);
|
||||
if ((d >= '0') && (d <= '9'))
|
||||
uu = ((d - '0') << 4);
|
||||
else if ((d >= 'a') && (d <= 'f'))
|
||||
uu = ((d - ('a'-10)) << 4);
|
||||
d = *(c++);
|
||||
if ((d >= '0') && (d <= '9'))
|
||||
uu |= (d - '0');
|
||||
else if ((d >= 'a') && (d <= 'f'))
|
||||
uu |= (d - ('a'-10));
|
||||
*u = uu;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
SWIGRUNTIME(VALUE)
|
||||
SWIG_NewPackedObj(void *ptr, int sz, swig_type_info *type) {
|
||||
char result[1024];
|
||||
char *r = result;
|
||||
if ((2*sz + 1 + strlen(type->name)) > 1000) return 0;
|
||||
*(r++) = '_';
|
||||
r = SWIG_PackData(r, ptr, sz);
|
||||
strcpy(r, type->name);
|
||||
return rb_str_new2(result);
|
||||
}
|
||||
|
||||
/* Convert a packed value value */
|
||||
SWIGRUNTIME(void)
|
||||
SWIG_ConvertPacked(VALUE obj, void *ptr, int sz, swig_type_info *ty, int flags) {
|
||||
swig_type_info *tc;
|
||||
char *c;
|
||||
|
||||
if (TYPE(obj) != T_STRING) goto type_error;
|
||||
c = STR2CSTR(obj);
|
||||
/* Pointer values must start with leading underscore */
|
||||
if (*c != '_') goto type_error;
|
||||
c++;
|
||||
c = SWIG_UnpackData(c, ptr, sz);
|
||||
if (ty) {
|
||||
tc = SWIG_TypeCheck(c, ty);
|
||||
if (!tc) goto type_error;
|
||||
}
|
||||
return;
|
||||
|
||||
type_error:
|
||||
|
||||
if (flags) {
|
||||
if (ty) {
|
||||
rb_raise(rb_eTypeError, "Type error. Expected %s", ty->name);
|
||||
} else {
|
||||
rb_raise(rb_eTypeError, "Expected a pointer");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
71
SWIG/Lib/ruby/rubyhead.swg
Normal file
71
SWIG/Lib/ruby/rubyhead.swg
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/* ruby.swg */
|
||||
/* Implementation : RUBY */
|
||||
#define SWIGRUBY 1
|
||||
|
||||
#include "ruby.h"
|
||||
|
||||
#define NUM2USHRT(n) NUM2UINT(n)
|
||||
#define NUM2SHRT(n) (\
|
||||
(SHRT_MIN <= NUM2INT(n) && NUM2INT(n) <= SHRT_MAX)\
|
||||
? (short)NUM2INT(n)\
|
||||
: (rb_raise(rb_eArgError, "integer %d out of range of `short'",\
|
||||
NUM2INT(n)), (short)0)\
|
||||
)
|
||||
|
||||
/* Ruby 1.7 defines NUM2LL(), LL2NUM() and ULL2NUM() macros */
|
||||
#ifndef NUM2LL
|
||||
#define NUM2LL(x) NUM2LONG((x))
|
||||
#endif
|
||||
#ifndef LL2NUM
|
||||
#define LL2NUM(x) INT2NUM((long) (x))
|
||||
#endif
|
||||
#ifndef ULL2NUM
|
||||
#define ULL2NUM(x) UINT2NUM((unsigned long) (x))
|
||||
#endif
|
||||
|
||||
/* Ruby 1.7 doesn't (yet) define NUM2ULL() */
|
||||
#ifndef NUM2ULL
|
||||
#ifdef HAVE_LONG_LONG
|
||||
#define NUM2ULL(x) rb_num2ull((x))
|
||||
#else
|
||||
#define NUM2ULL(x) NUM2ULONG(x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Need to be very careful about how these macros are defined, especially
|
||||
* when compiling C++ code or C code with an ANSI C compiler.
|
||||
*
|
||||
* VALUEFUNC(f) is a macro used to typecast a C function that implements
|
||||
* a Ruby method so that it can be passed as an argument to API functions
|
||||
* like rb_define_method() and rb_define_singleton_method().
|
||||
*
|
||||
* VOIDFUNC(f) is a macro used to typecast a C function that implements
|
||||
* either the "mark" or "free" stuff for a Ruby Data object, so that it
|
||||
* can be passed as an argument to API functions like Data_Wrap_Struct()
|
||||
* and Data_Make_Struct().
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifndef RUBY_METHOD_FUNC /* These definitions should work for Ruby 1.4.6 */
|
||||
# define VALUEFUNC(f) ((VALUE (*)()) f)
|
||||
# define VOIDFUNC(f) ((void (*)()) f)
|
||||
# else
|
||||
# ifndef ANYARGS /* These definitions should work for Ruby 1.6 */
|
||||
# define VALUEFUNC(f) ((VALUE (*)()) f)
|
||||
# define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
|
||||
# else /* These definitions should work for Ruby 1.7 */
|
||||
# define VALUEFUNC(f) ((VALUE (*)(ANYARGS)) f)
|
||||
# define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
|
||||
# endif
|
||||
# endif
|
||||
#else
|
||||
# define VALUEFUNC(f) (f)
|
||||
# define VOIDFUNC(f) (f)
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
VALUE klass;
|
||||
void (*mark)(void *);
|
||||
void (*destroy)(void *);
|
||||
} swig_class;
|
||||
35
SWIG/Lib/ruby/std_common.i
Normal file
35
SWIG/Lib/ruby/std_common.i
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
//
|
||||
// SWIG typemaps for STL - common utilities
|
||||
// Luigi Ballabio
|
||||
// Aug 3, 2002
|
||||
//
|
||||
// Ruby implementation
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
|
||||
#define SWIG_FLOAT_P(x) ((TYPE(x) == T_FLOAT) || FIXNUM_P(x))
|
||||
|
||||
bool SWIG_BOOL_P(VALUE) {
|
||||
// dummy test, RTEST should take care of everything
|
||||
return true;
|
||||
}
|
||||
bool SWIG_RB2BOOL(VALUE x) {
|
||||
return RTEST(x);
|
||||
}
|
||||
VALUE SWIG_BOOL2RB(bool b) {
|
||||
return b ? Qtrue : Qfalse;
|
||||
}
|
||||
double SWIG_NUM2DBL(VALUE x) {
|
||||
return (FIXNUM_P(x) ? FIX2INT(x) : NUM2DBL(x));
|
||||
}
|
||||
bool SWIG_STRING_P(VALUE x) {
|
||||
return TYPE(x) == T_STRING;
|
||||
}
|
||||
std::string SWIG_RB2STR(VALUE x) {
|
||||
return std::string(STR2CSTR(x));
|
||||
}
|
||||
VALUE SWIG_STR2RB(const std::string& s) {
|
||||
return rb_str_new2(s.c_str());
|
||||
}
|
||||
%}
|
||||
56
SWIG/Lib/ruby/std_string.i
Normal file
56
SWIG/Lib/ruby/std_string.i
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
//
|
||||
// SWIG typemaps for std::string
|
||||
// Luigi Ballabio
|
||||
// Apr 8, 2002
|
||||
//
|
||||
// Ruby implementation
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// std::string is typemapped by value
|
||||
// This can prevent exporting methods which return a string
|
||||
// in order for the user to modify it.
|
||||
// However, I think I'll wait until someone asks for it...
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
%include exception.i
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
%}
|
||||
|
||||
namespace std {
|
||||
|
||||
// Ruby wants class names to start with a capital letter
|
||||
%rename(String) string;
|
||||
class string;
|
||||
|
||||
%typemap(typecheck) string = char *;
|
||||
%typemap(typecheck) const string & = char *;
|
||||
|
||||
%typemap(in) string {
|
||||
if (TYPE($input) == T_STRING) {
|
||||
$1 = std::string(STR2CSTR($input));
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "not a string");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in) const string & (std::string temp) {
|
||||
if (TYPE($input) == T_STRING) {
|
||||
temp = std::string(STR2CSTR($input));
|
||||
$1 = &temp;
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "not a string");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(out) string {
|
||||
$result = rb_str_new2($1.c_str());
|
||||
}
|
||||
|
||||
%typemap(out) const string & {
|
||||
$result = rb_str_new2($1->c_str());
|
||||
}
|
||||
|
||||
}
|
||||
373
SWIG/Lib/ruby/std_vector.i
Normal file
373
SWIG/Lib/ruby/std_vector.i
Normal file
|
|
@ -0,0 +1,373 @@
|
|||
//
|
||||
// SWIG typemaps for std::vector
|
||||
// Luigi Ballabio
|
||||
// Apr 8, 2002
|
||||
//
|
||||
// Ruby implementation
|
||||
|
||||
%include std_common.i
|
||||
%include exception.i
|
||||
|
||||
%exception std::vector::__getitem__ {
|
||||
try {
|
||||
$action
|
||||
} catch (std::out_of_range& e) {
|
||||
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
%exception std::vector::__setitem__ {
|
||||
try {
|
||||
$action
|
||||
} catch (std::out_of_range& e) {
|
||||
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
%exception std::vector::pop {
|
||||
try {
|
||||
$action
|
||||
} catch (std::out_of_range& e) {
|
||||
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// std::vector
|
||||
//
|
||||
// The aim of all that follows would be to integrate std::vector with
|
||||
// Ruby as much as possible, namely, to allow the user to pass and
|
||||
// be returned Ruby arrays
|
||||
// const declarations are used to guess the intent of the function being
|
||||
// exported; therefore, the following rationale is applied:
|
||||
//
|
||||
// -- f(std::vector<T>), f(const std::vector<T>&), f(const std::vector<T>*):
|
||||
// the parameter being read-only, either a Ruby array or a
|
||||
// previously wrapped std::vector<T> can be passed.
|
||||
// -- f(std::vector<T>&), f(std::vector<T>*):
|
||||
// the parameter must be modified; therefore, only a wrapped std::vector
|
||||
// can be passed.
|
||||
// -- std::vector<T> f():
|
||||
// the vector is returned by copy; therefore, a Ruby array of T:s
|
||||
// is returned which is most easily used in other Ruby functions
|
||||
// -- std::vector<T>& f(), std::vector<T>* f(), const std::vector<T>& f(),
|
||||
// const std::vector<T>* f():
|
||||
// the vector is returned by reference; therefore, a wrapped std::vector
|
||||
// is returned
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
%{
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
%}
|
||||
|
||||
// exported class
|
||||
|
||||
namespace std {
|
||||
|
||||
%mixin vector "Enumerable";
|
||||
|
||||
template<class T> class vector {
|
||||
%typemap(in) vector<T> {
|
||||
if (rb_obj_is_kind_of($input,rb_cArray)) {
|
||||
unsigned int size = RARRAY($input)->len;
|
||||
$1 = std::vector<T >(size);
|
||||
for (unsigned int i=0; i<size; i++) {
|
||||
VALUE o = RARRAY($input)->ptr[i];
|
||||
T* x;
|
||||
SWIG_ConvertPtr(o, (void **) &x, $descriptor(T *), 1);
|
||||
(($1_type &)$1)[i] = *x;
|
||||
}
|
||||
} else {
|
||||
void *ptr;
|
||||
SWIG_ConvertPtr($input, &ptr, $&1_descriptor, 1);
|
||||
$1 = *(($&1_type) ptr);
|
||||
}
|
||||
}
|
||||
%typemap(in) const vector<T>& (std::vector<T> temp),
|
||||
const vector<T>* (std::vector<T> temp) {
|
||||
if (rb_obj_is_kind_of($input,rb_cArray)) {
|
||||
unsigned int size = RARRAY($input)->len;
|
||||
temp = std::vector<T >(size);
|
||||
$1 = &temp;
|
||||
for (unsigned int i=0; i<size; i++) {
|
||||
VALUE o = RARRAY($input)->ptr[i];
|
||||
T* x;
|
||||
SWIG_ConvertPtr(o, (void **) &x, $descriptor(T *), 1);
|
||||
temp[i] = *x;
|
||||
}
|
||||
} else {
|
||||
SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 1);
|
||||
}
|
||||
}
|
||||
%typemap(out) vector<T> {
|
||||
$result = rb_ary_new2($1.size());
|
||||
for (unsigned int i=0; i<$1.size(); i++) {
|
||||
T* x = new T((($1_type &)$1)[i]);
|
||||
rb_ary_store($result,i,
|
||||
SWIG_NewPointerObj((void *) x,
|
||||
$descriptor(T *), 1));
|
||||
}
|
||||
}
|
||||
%typecheck(SWIG_TYPECHECK_VECTOR) vector<T> {
|
||||
/* native sequence? */
|
||||
if (rb_obj_is_kind_of($input,rb_cArray)) {
|
||||
unsigned int size = RARRAY($input)->len;
|
||||
if (size == 0) {
|
||||
/* an empty sequence can be of any type */
|
||||
$1 = 1;
|
||||
} else {
|
||||
/* check the first element only */
|
||||
T* x;
|
||||
VALUE o = RARRAY($input)->ptr[0];
|
||||
if ((SWIG_ConvertPtr(o,(void **) &x,
|
||||
$descriptor(T *),0)) != -1)
|
||||
$1 = 1;
|
||||
else
|
||||
$1 = 0;
|
||||
}
|
||||
} else {
|
||||
/* wrapped vector? */
|
||||
std::vector<T >* v;
|
||||
if (SWIG_ConvertPtr($input,(void **) &v,
|
||||
$&1_descriptor,0) != -1)
|
||||
$1 = 1;
|
||||
else
|
||||
$1 = 0;
|
||||
}
|
||||
}
|
||||
%typecheck(SWIG_TYPECHECK_VECTOR) const vector<T>&,
|
||||
const vector<T>* {
|
||||
/* native sequence? */
|
||||
if (rb_obj_is_kind_of($input,rb_cArray)) {
|
||||
unsigned int size = RARRAY($input)->len;
|
||||
if (size == 0) {
|
||||
/* an empty sequence can be of any type */
|
||||
$1 = 1;
|
||||
} else {
|
||||
/* check the first element only */
|
||||
T* x;
|
||||
VALUE o = RARRAY($input)->ptr[0];
|
||||
if ((SWIG_ConvertPtr(o,(void **) &x,
|
||||
$descriptor(T *),0)) != -1)
|
||||
$1 = 1;
|
||||
else
|
||||
$1 = 0;
|
||||
}
|
||||
} else {
|
||||
/* wrapped vector? */
|
||||
std::vector<T >* v;
|
||||
if (SWIG_ConvertPtr($input,(void **) &v,
|
||||
$1_descriptor,1) != -1)
|
||||
$1 = 1;
|
||||
else
|
||||
$1 = 0;
|
||||
}
|
||||
}
|
||||
public:
|
||||
vector(unsigned int size = 0);
|
||||
vector(unsigned int size, const T& value);
|
||||
vector(const vector<T> &);
|
||||
|
||||
%rename(__len__) size;
|
||||
unsigned int size() const;
|
||||
%rename("empty?") empty;
|
||||
bool empty() const;
|
||||
%rename("clear!") clear;
|
||||
void clear();
|
||||
%rename(push) push_back;
|
||||
void push_back(const T& x);
|
||||
%extend {
|
||||
T pop() {
|
||||
if (self->size() == 0)
|
||||
throw std::out_of_range("pop from empty vector");
|
||||
T x = self->back();
|
||||
self->pop_back();
|
||||
return x;
|
||||
}
|
||||
T& __getitem__(int i) {
|
||||
int size = int(self->size());
|
||||
if (i<0) i += size;
|
||||
if (i>=0 && i<size)
|
||||
return (*self)[i];
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
void __setitem__(int i, const T& x) {
|
||||
int size = int(self->size());
|
||||
if (i<0) i+= size;
|
||||
if (i>=0 && i<size)
|
||||
(*self)[i] = x;
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
void each() {
|
||||
swig_type_info* type = SWIG_TypeQuery(#T " *");
|
||||
for (unsigned int i=0; i<self->size(); i++) {
|
||||
T* x = new T((*self)[i]);
|
||||
rb_yield(SWIG_NewPointerObj((void *) x, type, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// specializations for built-ins
|
||||
|
||||
%define specialize_std_vector(T,CHECK,CONVERT_FROM,CONVERT_TO)
|
||||
%mixin vector<T> "Enumerable";
|
||||
template<> class vector<T> {
|
||||
%typemap(in) vector<T> {
|
||||
if (rb_obj_is_kind_of($input,rb_cArray)) {
|
||||
unsigned int size = RARRAY($input)->len;
|
||||
$1 = std::vector<T >(size);
|
||||
for (unsigned int i=0; i<size; i++) {
|
||||
VALUE o = RARRAY($input)->ptr[i];
|
||||
if (CHECK(o))
|
||||
(($1_type &)$1)[i] = (T)(CONVERT_FROM(o));
|
||||
else
|
||||
rb_raise(rb_eTypeError,
|
||||
"wrong argument type"
|
||||
" (expected vector<" #T ">)");
|
||||
}
|
||||
} else {
|
||||
void *ptr;
|
||||
SWIG_ConvertPtr($input, &ptr, $&1_descriptor, 1);
|
||||
$1 = *(($&1_type) ptr);
|
||||
}
|
||||
}
|
||||
%typemap(in) const vector<T>& (std::vector<T> temp),
|
||||
const vector<T>* (std::vector<T> temp) {
|
||||
if (rb_obj_is_kind_of($input,rb_cArray)) {
|
||||
unsigned int size = RARRAY($input)->len;
|
||||
temp = std::vector<T >(size);
|
||||
$1 = &temp;
|
||||
for (unsigned int i=0; i<size; i++) {
|
||||
VALUE o = RARRAY($input)->ptr[i];
|
||||
if (CHECK(o))
|
||||
temp[i] = (T)(CONVERT_FROM(o));
|
||||
else
|
||||
rb_raise(rb_eTypeError,
|
||||
"wrong argument type"
|
||||
" (expected vector<" #T ">)");
|
||||
}
|
||||
} else {
|
||||
SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 1);
|
||||
}
|
||||
}
|
||||
%typemap(out) vector<T> {
|
||||
$result = rb_ary_new2($1.size());
|
||||
for (unsigned int i=0; i<$1.size(); i++)
|
||||
rb_ary_store($result,i,CONVERT_TO((($1_type &)$1)[i]));
|
||||
}
|
||||
%typecheck(SWIG_TYPECHECK_VECTOR) vector<T> {
|
||||
/* native sequence? */
|
||||
if (rb_obj_is_kind_of($input,rb_cArray)) {
|
||||
unsigned int size = RARRAY($input)->len;
|
||||
if (size == 0) {
|
||||
/* an empty sequence can be of any type */
|
||||
$1 = 1;
|
||||
} else {
|
||||
/* check the first element only */
|
||||
VALUE o = RARRAY($input)->ptr[0];
|
||||
if (CHECK(o))
|
||||
$1 = 1;
|
||||
else
|
||||
$1 = 0;
|
||||
}
|
||||
} else {
|
||||
/* wrapped vector? */
|
||||
std::vector<T >* v;
|
||||
if (SWIG_ConvertPtr($input,(void **) &v,
|
||||
$&1_descriptor,0) != -1)
|
||||
$1 = 1;
|
||||
else
|
||||
$1 = 0;
|
||||
}
|
||||
}
|
||||
%typecheck(SWIG_TYPECHECK_VECTOR) const vector<T>&,
|
||||
const vector<T>* {
|
||||
/* native sequence? */
|
||||
if (rb_obj_is_kind_of($input,rb_cArray)) {
|
||||
unsigned int size = RARRAY($input)->len;
|
||||
if (size == 0) {
|
||||
/* an empty sequence can be of any type */
|
||||
$1 = 1;
|
||||
} else {
|
||||
/* check the first element only */
|
||||
VALUE o = RARRAY($input)->ptr[0];
|
||||
if (CHECK(o))
|
||||
$1 = 1;
|
||||
else
|
||||
$1 = 0;
|
||||
}
|
||||
} else {
|
||||
/* wrapped vector? */
|
||||
std::vector<T >* v;
|
||||
if (SWIG_ConvertPtr($input,(void **) &v,
|
||||
$1_descriptor,1) != -1)
|
||||
$1 = 1;
|
||||
else
|
||||
$1 = 0;
|
||||
}
|
||||
}
|
||||
public:
|
||||
vector(unsigned int size = 0);
|
||||
vector(unsigned int size, const T& value);
|
||||
vector(const vector<T> &);
|
||||
|
||||
%rename(__len__) size;
|
||||
unsigned int size() const;
|
||||
%rename("empty?") empty;
|
||||
bool empty() const;
|
||||
%rename("clear!") clear;
|
||||
void clear();
|
||||
%rename(push) push_back;
|
||||
void push_back(T x);
|
||||
%extend {
|
||||
T pop() {
|
||||
if (self->size() == 0)
|
||||
throw std::out_of_range("pop from empty vector");
|
||||
T x = self->back();
|
||||
self->pop_back();
|
||||
return x;
|
||||
}
|
||||
T __getitem__(int i) {
|
||||
int size = int(self->size());
|
||||
if (i<0) i += size;
|
||||
if (i>=0 && i<size)
|
||||
return (*self)[i];
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
void __setitem__(int i, T x) {
|
||||
int size = int(self->size());
|
||||
if (i<0) i+= size;
|
||||
if (i>=0 && i<size)
|
||||
(*self)[i] = x;
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
void each() {
|
||||
for (unsigned int i=0; i<self->size(); i++)
|
||||
rb_yield(CONVERT_TO((*self)[i]));
|
||||
}
|
||||
}
|
||||
};
|
||||
%enddef
|
||||
|
||||
specialize_std_vector(bool,SWIG_BOOL_P,SWIG_RB2BOOL,SWIG_BOOL2RB);
|
||||
specialize_std_vector(int,FIXNUM_P,FIX2INT,INT2NUM);
|
||||
specialize_std_vector(short,FIXNUM_P,FIX2INT,INT2NUM);
|
||||
specialize_std_vector(long,FIXNUM_P,FIX2INT,INT2NUM);
|
||||
specialize_std_vector(unsigned int,FIXNUM_P,FIX2INT,INT2NUM);
|
||||
specialize_std_vector(unsigned short,FIXNUM_P,FIX2INT,INT2NUM);
|
||||
specialize_std_vector(unsigned long,FIXNUM_P,FIX2INT,INT2NUM);
|
||||
specialize_std_vector(double,SWIG_FLOAT_P,SWIG_NUM2DBL,rb_float_new);
|
||||
specialize_std_vector(float,SWIG_FLOAT_P,SWIG_NUM2DBL,rb_float_new);
|
||||
specialize_std_vector(std::string,SWIG_STRING_P,SWIG_RB2STR,SWIG_STR2RB);
|
||||
|
||||
}
|
||||
|
||||
9
SWIG/Lib/ruby/stl.i
Normal file
9
SWIG/Lib/ruby/stl.i
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
//
|
||||
// SWIG typemaps for STL types
|
||||
// Luigi Ballabio and Manu ???
|
||||
// Apr 26, 2002
|
||||
//
|
||||
|
||||
%include std_string.i
|
||||
%include std_vector.i
|
||||
|
||||
|
|
@ -9,19 +9,13 @@
|
|||
// Masaki Fukushima
|
||||
//
|
||||
|
||||
#ifdef AUTODOC
|
||||
%section "Typemap Library (Ruby)",info,after,pre,nosort,skip=1,chop_left=3,chop_right=0,chop_top=0,chop_bottom=0
|
||||
%text %{
|
||||
%include 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.
|
||||
%}
|
||||
|
||||
#endif
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Pointer handling
|
||||
|
|
@ -34,11 +28,7 @@ pointers.
|
|||
// These remap a C pointer to be an "INPUT" value which is passed by value
|
||||
// instead of reference.
|
||||
|
||||
|
||||
#ifdef AUTODOC
|
||||
%subsection "Input Methods"
|
||||
|
||||
%text %{
|
||||
/*
|
||||
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.
|
||||
|
|
@ -50,6 +40,7 @@ you would use a real value instead.
|
|||
unsigned short *INPUT
|
||||
unsigned long *INPUT
|
||||
unsigned char *INPUT
|
||||
bool *INPUT
|
||||
float *INPUT
|
||||
double *INPUT
|
||||
|
||||
|
|
@ -70,73 +61,37 @@ or you can use the %apply directive :
|
|||
%apply double *INPUT { double *a, double *b };
|
||||
double fadd(double *a, double *b);
|
||||
|
||||
%}
|
||||
#endif
|
||||
*/
|
||||
|
||||
%typemap(ruby,in) double *INPUT(double temp)
|
||||
%define INPUT_TYPEMAP(type, converter)
|
||||
%typemap(in) type *INPUT(type temp), type &INPUT(type temp)
|
||||
{
|
||||
temp = NUM2DBL($source);
|
||||
$target = &temp;
|
||||
temp = (type) converter($input);
|
||||
$1 = &temp;
|
||||
}
|
||||
%typemap(typecheck) type *INPUT = type;
|
||||
%typemap(typecheck) type &INPUT = type;
|
||||
%enddef
|
||||
|
||||
%typemap(ruby,in) float *INPUT(float temp)
|
||||
{
|
||||
temp = (float) NUM2DBL($source);
|
||||
$target = &temp;
|
||||
}
|
||||
INPUT_TYPEMAP(float, NUM2DBL);
|
||||
INPUT_TYPEMAP(double, NUM2DBL);
|
||||
INPUT_TYPEMAP(int, NUM2INT);
|
||||
INPUT_TYPEMAP(short, NUM2SHRT);
|
||||
INPUT_TYPEMAP(long, NUM2LONG);
|
||||
INPUT_TYPEMAP(unsigned int, NUM2UINT);
|
||||
INPUT_TYPEMAP(unsigned short, NUM2USHRT);
|
||||
INPUT_TYPEMAP(unsigned long, NUM2ULONG);
|
||||
INPUT_TYPEMAP(unsigned char, NUM2UINT);
|
||||
INPUT_TYPEMAP(signed char, NUM2INT);
|
||||
INPUT_TYPEMAP(bool, RTEST);
|
||||
|
||||
%typemap(ruby,in) int *INPUT(int temp)
|
||||
{
|
||||
temp = NUM2INT($source);
|
||||
$target = &temp;
|
||||
}
|
||||
#undef INPUT_TYPEMAP
|
||||
|
||||
%typemap(ruby,in) short *INPUT(short temp)
|
||||
{
|
||||
temp = NUM2SHRT($source);
|
||||
$target = &temp;
|
||||
}
|
||||
|
||||
%typemap(ruby,in) long *INPUT(long temp)
|
||||
{
|
||||
temp = NUM2LONG($source);
|
||||
$target = &temp;
|
||||
}
|
||||
%typemap(ruby,in) unsigned int *INPUT(unsigned int temp)
|
||||
{
|
||||
temp = NUM2UINT($source);
|
||||
$target = &temp;
|
||||
}
|
||||
%typemap(ruby,in) unsigned short *INPUT(unsigned short temp)
|
||||
{
|
||||
temp = NUM2USHRT($source);
|
||||
$target = &temp;
|
||||
}
|
||||
%typemap(ruby,in) unsigned long *INPUT(unsigned long temp)
|
||||
{
|
||||
temp = NUM2ULONG($source);
|
||||
$target = &temp;
|
||||
}
|
||||
%typemap(ruby,in) unsigned char *INPUT(unsigned char temp)
|
||||
{
|
||||
temp = (unsigned char)NUM2UINT($source);
|
||||
$target = &temp;
|
||||
}
|
||||
|
||||
%typemap(ruby,in) signed char *INPUT(signed char temp)
|
||||
{
|
||||
temp = (signed char)NUM2INT($source);
|
||||
$target = &temp;
|
||||
}
|
||||
|
||||
// OUTPUT typemaps. These typemaps are used for parameters that
|
||||
// are output only. The output value is appended to the result as
|
||||
// a array element.
|
||||
|
||||
#ifdef AUTODOC
|
||||
%subsection "Output Methods"
|
||||
|
||||
%text %{
|
||||
/*
|
||||
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
|
||||
|
|
@ -149,6 +104,7 @@ multiple output values, they are returned in the form of a Ruby Array.
|
|||
unsigned short *OUTPUT
|
||||
unsigned long *OUTPUT
|
||||
unsigned char *OUTPUT
|
||||
bool *OUTPUT
|
||||
float *OUTPUT
|
||||
double *OUTPUT
|
||||
|
||||
|
|
@ -171,74 +127,42 @@ or you can use the %apply directive :
|
|||
|
||||
The Ruby output of the function would be a Array containing both
|
||||
output values.
|
||||
%}
|
||||
#endif
|
||||
*/
|
||||
|
||||
// Helper function for Array output
|
||||
|
||||
%{
|
||||
static VALUE output_helper(VALUE target, VALUE o) {
|
||||
if (NIL_P(target)) {
|
||||
target = o;
|
||||
} else {
|
||||
if (TYPE(target) != T_ARRAY) {
|
||||
VALUE o2 = target;
|
||||
target = rb_ary_new();
|
||||
rb_ary_push(target, o2);
|
||||
}
|
||||
rb_ary_push(target, o);
|
||||
}
|
||||
return target;
|
||||
%include "fragments.i"
|
||||
|
||||
%define OUTPUT_TYPEMAP(type, converter, convtype)
|
||||
%typemap(in,numinputs=0) type *OUTPUT(type temp), type &OUTPUT(type temp) "$1 = &temp;";
|
||||
%typemap(argout, fragment="output_helper") type *OUTPUT, type &OUTPUT {
|
||||
VALUE o = converter(convtype (*$1));
|
||||
$result = output_helper($result, o);
|
||||
}
|
||||
%}
|
||||
%enddef
|
||||
|
||||
// Force the argument to be ignored.
|
||||
OUTPUT_TYPEMAP(int, INT2NUM, (int));
|
||||
OUTPUT_TYPEMAP(short, INT2NUM, (int));
|
||||
OUTPUT_TYPEMAP(long, INT2NUM, (int));
|
||||
OUTPUT_TYPEMAP(unsigned int, UINT2NUM, (unsigned int));
|
||||
OUTPUT_TYPEMAP(unsigned short, UINT2NUM, (unsigned int));
|
||||
OUTPUT_TYPEMAP(unsigned long, UINT2NUM, (unsigned int));
|
||||
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));
|
||||
|
||||
%typemap(ruby,ignore) 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),
|
||||
float *OUTPUT(float temp),
|
||||
double *OUTPUT(double temp)
|
||||
{
|
||||
$target = &temp;
|
||||
}
|
||||
#undef OUTPUT_TYPEMAP
|
||||
|
||||
%typemap(ruby,argout) int *OUTPUT,
|
||||
short *OUTPUT,
|
||||
long *OUTPUT,
|
||||
signed char *OUTPUT
|
||||
{
|
||||
$target = output_helper($target, INT2NUM(*$source));
|
||||
}
|
||||
|
||||
%typemap(ruby,argout) unsigned int *OUTPUT,
|
||||
unsigned short *OUTPUT,
|
||||
unsigned long *OUTPUT,
|
||||
unsigned char *OUTPUT
|
||||
{
|
||||
$target = output_helper($target, UINT2NUM(*$source));
|
||||
}
|
||||
|
||||
%typemap(ruby,argout) float *OUTPUT,
|
||||
double *OUTPUT
|
||||
{
|
||||
$target = output_helper($target, rb_float_new(*$source));
|
||||
%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
|
||||
|
||||
|
||||
#ifdef AUTODOC
|
||||
%subsection "Input/Output Methods"
|
||||
|
||||
%text %{
|
||||
/*
|
||||
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
|
||||
|
|
@ -251,6 +175,7 @@ returned in the form of a Ruby array.
|
|||
unsigned short *INOUT
|
||||
unsigned long *INOUT
|
||||
unsigned char *INOUT
|
||||
bool *INOUT
|
||||
float *INOUT
|
||||
double *INOUT
|
||||
|
||||
|
|
@ -281,101 +206,68 @@ to a Ruby variable you might do this :
|
|||
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.
|
||||
%}
|
||||
|
||||
#endif
|
||||
*/
|
||||
|
||||
%typemap(ruby,in) int *INOUT = int *INPUT;
|
||||
%typemap(ruby,in) short *INOUT = short *INPUT;
|
||||
%typemap(ruby,in) long *INOUT = long *INPUT;
|
||||
%typemap(ruby,in) unsigned *INOUT = unsigned *INPUT;
|
||||
%typemap(ruby,in) unsigned short *INOUT = unsigned short *INPUT;
|
||||
%typemap(ruby,in) unsigned long *INOUT = unsigned long *INPUT;
|
||||
%typemap(ruby,in) unsigned char *INOUT = unsigned char *INPUT;
|
||||
%typemap(ruby,in) float *INOUT = float *INPUT;
|
||||
%typemap(ruby,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) 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(ruby,argout) int *INOUT = int *OUTPUT;
|
||||
%typemap(ruby,argout) short *INOUT = short *OUTPUT;
|
||||
%typemap(ruby,argout) long *INOUT = long *OUTPUT;
|
||||
%typemap(ruby,argout) unsigned *INOUT = unsigned *OUTPUT;
|
||||
%typemap(ruby,argout) unsigned short *INOUT = unsigned short *OUTPUT;
|
||||
%typemap(ruby,argout) unsigned long *INOUT = unsigned long *OUTPUT;
|
||||
%typemap(ruby,argout) unsigned char *INOUT = unsigned char *OUTPUT;
|
||||
%typemap(ruby,argout) float *INOUT = float *OUTPUT;
|
||||
%typemap(ruby,argout) double *INOUT = double *OUTPUT;
|
||||
%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;
|
||||
|
||||
// Backwards compatibility
|
||||
|
||||
%typemap(ruby,in) int *BOTH = int *INOUT;
|
||||
%typemap(ruby,in) short *BOTH = short *INOUT;
|
||||
%typemap(ruby,in) long *BOTH = long *INOUT;
|
||||
%typemap(ruby,in) unsigned *BOTH = unsigned *INOUT;
|
||||
%typemap(ruby,in) unsigned short *BOTH = unsigned short *INOUT;
|
||||
%typemap(ruby,in) unsigned long *BOTH = unsigned long *INOUT;
|
||||
%typemap(ruby,in) unsigned char *BOTH = unsigned char *INOUT;
|
||||
%typemap(ruby,in) float *BOTH = float *INOUT;
|
||||
%typemap(ruby,in) double *BOTH = double *INOUT;
|
||||
|
||||
%typemap(ruby,argout) int *BOTH = int *INOUT;
|
||||
%typemap(ruby,argout) short *BOTH = short *INOUT;
|
||||
%typemap(ruby,argout) long *BOTH = long *INOUT;
|
||||
%typemap(ruby,argout) unsigned *BOTH = unsigned *INOUT;
|
||||
%typemap(ruby,argout) unsigned short *BOTH = unsigned short *INOUT;
|
||||
%typemap(ruby,argout) unsigned long *BOTH = unsigned long *INOUT;
|
||||
%typemap(ruby,argout) unsigned char *BOTH = unsigned char *INOUT;
|
||||
%typemap(ruby,argout) float *BOTH = float *INOUT;
|
||||
%typemap(ruby,argout) double *BOTH = double *INOUT;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// OUTPUT typemaps for user defined type.
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#ifdef AUTODOC
|
||||
%subsection "Output Methods for User-defined types"
|
||||
|
||||
%text %{
|
||||
The following method can be applied to turn a pointer to
|
||||
user-defined type returned through function aruguments into
|
||||
an output value.
|
||||
|
||||
User **OUTPUT
|
||||
|
||||
You can use the %apply directive :
|
||||
|
||||
%include typemaps.i
|
||||
%apply User **OUTPUT { Foo **OUTPUT };
|
||||
int foo_func(Foo **OUTPUT);
|
||||
|
||||
%}
|
||||
#endif
|
||||
|
||||
%typemap(ruby,ignore) User **OUTPUT(void *temp)
|
||||
{
|
||||
$target = ($type)&temp;
|
||||
}
|
||||
%typemap(ruby,argout) User **OUTPUT
|
||||
{
|
||||
$target = output_helper($target, Wrap_$basetype(*$source));
|
||||
}
|
||||
%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) 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;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Special types
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#ifdef AUTODOC
|
||||
%subsection "Special Methods"
|
||||
|
||||
%text %{
|
||||
/*
|
||||
The typemaps.i library also provides the following mappings :
|
||||
|
||||
struct timeval *
|
||||
time_t
|
||||
|
||||
Ruby has builtin class Time. INPUT/OUPUT typemap for timeval and
|
||||
Ruby has builtin class Time. INPUT/OUTPUT typemap for timeval and
|
||||
time_t is provided.
|
||||
|
||||
int PROG_ARGC
|
||||
|
|
@ -384,9 +276,7 @@ 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.
|
||||
%}
|
||||
|
||||
#endif
|
||||
*/
|
||||
|
||||
|
||||
// struct timeval *
|
||||
|
|
@ -403,71 +293,71 @@ struct timeval rb_time_timeval(VALUE);
|
|||
#endif
|
||||
%}
|
||||
|
||||
%typemap(ruby,in) struct timeval *INPUT (struct timeval temp)
|
||||
%typemap(in) struct timeval *INPUT (struct timeval temp)
|
||||
{
|
||||
if (NIL_P($source))
|
||||
$target = NULL;
|
||||
if (NIL_P($input))
|
||||
$1 = NULL;
|
||||
else {
|
||||
temp = rb_time_timeval($source);
|
||||
$target = &temp;
|
||||
temp = rb_time_timeval($input);
|
||||
$1 = &temp;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(ruby,ignore) struct timeval *OUTPUT(struct timeval temp)
|
||||
%typemap(in,numinputs=0) struct timeval *OUTPUT(struct timeval temp)
|
||||
{
|
||||
$target = &temp;
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(ruby,argout) struct timeval *OUTPUT
|
||||
%typemap(argout) struct timeval *OUTPUT
|
||||
{
|
||||
$target = rb_time_new($source->tv_sec, $source->tv_usec);
|
||||
$result = rb_time_new($1->tv_sec, $1->tv_usec);
|
||||
}
|
||||
|
||||
%typemap(ruby,out) struct timeval *
|
||||
%typemap(out) struct timeval *
|
||||
{
|
||||
$target = rb_time_new($source->tv_sec, $source->tv_usec);
|
||||
$result = rb_time_new($1->tv_sec, $1->tv_usec);
|
||||
}
|
||||
|
||||
%typemap(ruby,out) struct timespec *
|
||||
%typemap(out) struct timespec *
|
||||
{
|
||||
$target = rb_time_new($source->tv_sec, $source->tv_nsec / 1000);
|
||||
$result = rb_time_new($1->tv_sec, $1->tv_nsec / 1000);
|
||||
}
|
||||
|
||||
// time_t
|
||||
%typemap(ruby,in) time_t
|
||||
%typemap(in) time_t
|
||||
{
|
||||
if (NIL_P($source))
|
||||
$target = (time_t)-1;
|
||||
if (NIL_P($input))
|
||||
$1 = (time_t)-1;
|
||||
else
|
||||
$target = NUM2LONG(rb_funcall($source, rb_intern("tv_sec"), 0));
|
||||
$1 = NUM2LONG(rb_funcall($input, rb_intern("tv_sec"), 0));
|
||||
}
|
||||
|
||||
%typemap(ruby,out) time_t
|
||||
%typemap(out) time_t
|
||||
{
|
||||
$target = rb_time_new($source, 0);
|
||||
$result = rb_time_new($1, 0);
|
||||
}
|
||||
|
||||
// argc and argv
|
||||
%typemap(ruby,ignore) int PROG_ARGC {
|
||||
$target = RARRAY(rb_argv)->len + 1;
|
||||
%typemap(in,numinputs=0) int PROG_ARGC {
|
||||
$1 = RARRAY(rb_argv)->len + 1;
|
||||
}
|
||||
|
||||
%typemap(ruby,ignore) char **PROG_ARGV {
|
||||
%typemap(in,numinputs=0) char **PROG_ARGV {
|
||||
int i, n;
|
||||
VALUE ary = rb_eval_string("[$0] + ARGV");
|
||||
n = RARRAY(ary)->len;
|
||||
$target = (char **)malloc(n + 1);
|
||||
$1 = (char **)malloc(n + 1);
|
||||
for (i = 0; i < n; i++) {
|
||||
VALUE v = rb_obj_as_string(RARRAY(ary)->ptr[i]);
|
||||
$target[i] = (char *)malloc(RSTRING(v)->len + 1);
|
||||
strcpy($target[i], RSTRING(v)->ptr);
|
||||
$1[i] = (char *)malloc(RSTRING(v)->len + 1);
|
||||
strcpy($1[i], RSTRING(v)->ptr);
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(ruby,freearg) char **PROG_ARGV {
|
||||
%typemap(freearg) char **PROG_ARGV {
|
||||
int i, n = RARRAY(rb_argv)->len + 1;
|
||||
for (i = 0; i < n; i++) free($source[i]);
|
||||
free($source);
|
||||
for (i = 0; i < n; i++) free($1[i]);
|
||||
free($1);
|
||||
}
|
||||
|
||||
// FILE *
|
||||
|
|
@ -480,25 +370,49 @@ extern "C" {
|
|||
}
|
||||
#endif
|
||||
%}
|
||||
%typemap(ruby,in) FILE *READ {
|
||||
|
||||
%typemap(in) FILE *READ {
|
||||
OpenFile *of;
|
||||
Check_Type($source, T_FILE);
|
||||
GetOpenFile($source, of);
|
||||
GetOpenFile($input, of);
|
||||
rb_io_check_readable(of);
|
||||
$target = GetReadFile(of);
|
||||
rb_read_check($target);
|
||||
$1 = GetReadFile(of);
|
||||
rb_read_check($1);
|
||||
}
|
||||
%typemap(ruby,in) FILE *READ_NOCHECK {
|
||||
|
||||
%typemap(in) FILE *READ_NOCHECK {
|
||||
OpenFile *of;
|
||||
Check_Type($source, T_FILE);
|
||||
GetOpenFile($source, of);
|
||||
GetOpenFile($input, of);
|
||||
rb_io_check_readable(of);
|
||||
$target = GetReadFile(of);
|
||||
$1 = GetReadFile(of);
|
||||
}
|
||||
%typemap(ruby,in) FILE *WRITE {
|
||||
|
||||
%typemap(in) FILE *WRITE {
|
||||
OpenFile *of;
|
||||
Check_Type($source, T_FILE);
|
||||
GetOpenFile($source, of);
|
||||
GetOpenFile($input, of);
|
||||
rb_io_check_writable(of);
|
||||
$target = GetWriteFile(of);
|
||||
$1 = GetWriteFile(of);
|
||||
}
|
||||
|
||||
/* 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 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) 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 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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue