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
This commit is contained in:
Marcelo Matus 2004-03-31 04:18:11 +00:00
commit 2ecbbbf107
3 changed files with 57 additions and 34 deletions

View file

@ -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

View file

@ -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 <class T, class V>
inline
void swig_assign_unnamed(T& eval, const V& val)
{
eval = static_cast<T>(val);
}
#endif
#else
#define swig_assign_unnamed(eval, val) eval = val
#endif
%}
%include unnamed.swg

42
SWIG/Lib/unnamed.swg Normal file
View file

@ -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 <class T, class V>
inline
void swig_assign_unnamed(T& eval, const V& val)
{
eval = static_cast<T>(val);
}
#endif
#else
#define swig_assign_unnamed(eval, val) eval = val
#endif
%}