From 2ecbbbf1078a210fc2c4fcd967f778fcf34d01f0 Mon Sep 17 00:00:00 2001 From: Marcelo Matus Date: Wed, 31 Mar 2004 04:18:11 +0000 Subject: [PATCH] moving the 'unnamed' macros outside swig.swg, for better mantainance git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5809 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../test-suite/python/cpp_enum_runme.py | 14 +++++++ SWIG/Lib/swig.swg | 35 +--------------- SWIG/Lib/unnamed.swg | 42 +++++++++++++++++++ 3 files changed, 57 insertions(+), 34 deletions(-) create mode 100644 SWIG/Examples/test-suite/python/cpp_enum_runme.py create mode 100644 SWIG/Lib/unnamed.swg diff --git a/SWIG/Examples/test-suite/python/cpp_enum_runme.py b/SWIG/Examples/test-suite/python/cpp_enum_runme.py new file mode 100644 index 000000000..ae8b35bba --- /dev/null +++ b/SWIG/Examples/test-suite/python/cpp_enum_runme.py @@ -0,0 +1,14 @@ +import cpp_enum + +f = cpp_enum.Foo() + +f.hola = f.Hi +if f.hola != f.Hi: + print f.hola + raise RuntimeError + +f.hola = f.Hello + +if f.hola != f.Hello: + print f.hola + raise RuntimeError diff --git a/SWIG/Lib/swig.swg b/SWIG/Lib/swig.swg index e376cbf07..eb2b6bc3e 100644 --- a/SWIG/Lib/swig.swg +++ b/SWIG/Lib/swig.swg @@ -402,37 +402,4 @@ static int NAME(TYPE x) { %} %enddef - -/* - Auxiliary methods for assigning unnamed type C++ variables, where - swig doesn't know the casting type, but C++ can derived it: - - struct Foo { enum {Hi, Hello } hola; }; - - Activate the following for compilers that do not support unnamed - template parameters (under your own risk). - - #define SWIG_UNNAMED_USE_MEMCPY -*/ -%insert("runtime") %{ -#ifdef __cplusplus -/* here, the C++ compilers that do not accept unnamed template parameters */ -#if defined(_SGI_COMPILER_VERSION) -#ifdef SWIG_UNNAMED_USE_MEMCPY -/* dangerous assigment, but for enums could work */ -#define swig_assign_unnamed(eval, val) memcpy(&(eval),&(val), sizeof(eval)) -#else -#define swig_assign_unnamed(eval, val) printf("unnamed member assigment not sopperted") -#endif -#else -template -inline -void swig_assign_unnamed(T& eval, const V& val) -{ - eval = static_cast(val); -} -#endif -#else -#define swig_assign_unnamed(eval, val) eval = val -#endif -%} +%include unnamed.swg diff --git a/SWIG/Lib/unnamed.swg b/SWIG/Lib/unnamed.swg new file mode 100644 index 000000000..71dfd9d40 --- /dev/null +++ b/SWIG/Lib/unnamed.swg @@ -0,0 +1,42 @@ +/* + Auxiliary methods for assigning unnamed type C++ variables, where + swig doesn't know the casting type, but C++ can derived it: + + struct Foo { enum {Hi, Hello } hola; }; + + These are very specific macros, that could keep growing as more + compilers require especial support, or could vanish latter if the + enum mapping changes drastically. Therefore, better we put them in + this separate file, so swig.swg doesn't change every time we update + something here. + +*/ + +%insert("runtime") %{ +#ifdef __cplusplus +// here, the C++ compilers that do not accept unnamed template parameters +#if defined(_SGI_COMPILER_VERSION) +// +// Activate the following macro for compilers that do not support +// unnamed template parameters, but where memcpy works. +// +//#define SWIG_UNNAMED_USE_MEMCPY +// +#ifdef SWIG_UNNAMED_USE_MEMCPY +// dangerous assigment, but for enums it should work. +#define swig_assign_unnamed(eval, val) memcpy(&(eval),&(val), sizeof(eval)) +#else +#define swig_assign_unnamed(eval, val) printf("unnamed member assigment not supported\n") +#endif +#else +template +inline +void swig_assign_unnamed(T& eval, const V& val) +{ + eval = static_cast(val); +} +#endif +#else +#define swig_assign_unnamed(eval, val) eval = val +#endif +%}