Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mforbes
Created July 1, 2012 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mforbes/3029324 to your computer and use it in GitHub Desktop.
Save mforbes/3029324 to your computer and use it in GitHub Desktop.
SWIG example of multiple typechecks with different pecedences.
%typemap(typecheck, precedence=5000)(MyComplex) {
$1 = QuicklyCheckIfReallyIsMyComplex($input);
}
%typemap(typecheck, precedence=5500)(MyDouble) {
$1 = QuicklyCheckIfReallyIsMyDouble($input);
}
%typemap(typecheck, precedence=6000)(MyDouble) {
$1 = LongCheckToSeeIfCanBeConvertedToADouble($input);
}
%typemap(typecheck, precedence=6500)(MyComplex) {
$1 = LongCheckToSeeIfCanBeConvertedToAComplex($input);
}
%typemap(in)(MyDouble) { $1 = ProcessMyDouble($input); }
%typemap(in)(MyComplex) { $1 = ProcessMyComplex($input); }
MyDouble f(MyDouble x) { return x; }
MyComplex f(MyComplex x) { return x; }
@mforbes
Copy link
Author

mforbes commented Jul 1, 2012

This is compiled with:

swig -module mod -c++ -o typecheck_wrap.cpp -python typecheck_eg.i

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment