1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
%module necpp
/* Part of the Ruby binding code for nec2++
Copyright (C) 2008-2010 Tim Molteno. tim@physics.otago.ac.nz
Released under the GPL v3.
*/
%{
#include "../src/libnecpp.h"
#include "../src/nec_exception.h"
%}
/* Handle exceptions thrown by nec2++ */
%exception {
try {
$action
}
catch (nec_exception* e) {
static VALUE cpperror = rb_define_class("CPPError", rb_eStandardError);
rb_raise(cpperror, e->get_message().c_str());
}
}
%include "typemaps.i"
/* Used for functions that output a new opaque pointer */
%typemap(in,numinputs=0) opaque_t *OUTPUT (opaque_t retval)
{
/* OUTPUT in */
retval = NULL;
$1 = &retval;
}
/* used for functions that take in an opaque pointer (or NULL)
and return a (possibly) different pointer */
%typemap(argout) opaque_t *OUTPUT, opaque_t *INOUT
{
/* OUTPUT argout */
%append_output(SWIG_NewPointerObj(SWIG_as_voidptr(retval$argnum), $1_descriptor, 0));
}
%typemap(in) opaque_t *INOUT (opaque_t retval)
{
/* INOUT in */
SWIG_ConvertPtr(obj1,SWIG_as_voidptrptr(&retval), 0, 0);
$1 = &retval;
}
/* No need for special IN typemap, it works anyway */
%include "../src/libnecpp.h"
|