added support for unnamed C++ enum members

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5805 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-03-31 01:35:44 +00:00
commit e00522f427
3 changed files with 30 additions and 1 deletions

View file

@ -24,4 +24,11 @@ struct StructWithEnums {
enum SOME_ENUM& enum_test8() { return some_enum; };
};
struct Foo
{
enum {Hi, Hello } hola;
};
%}

View file

@ -403,3 +403,19 @@ static int NAME(TYPE x) {
%enddef
/* Auxiliar 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; };
*/
%insert("runtime") %{
#ifdef __cplusplus
template <class T, class V>
void swig_assign_unnamed(T& eval, const V& val)
{
eval = static_cast<T>(val);
}
#else
#define swig_assign_unnamed(eval, val) eval = val
#endif
%}

View file

@ -557,7 +557,13 @@ Swig_cmemberset_call(String_or_char *name, SwigType *type, String_or_char *self)
else self = NewString(self);
Replaceall(self,"this",Swig_cparm_name(0,0));
if (SwigType_type(type) != T_ARRAY) {
Printf(func,"if (%s) %s%s = %s",Swig_cparm_name(0,0), self,name, Swig_wrapped_var_deref(type, Swig_cparm_name(0,1)));
if (!Strstr(type,"$unnamed")) {
Printf(func,"if (%s) %s%s = %s",Swig_cparm_name(0,0), self,name,
Swig_wrapped_var_deref(type, Swig_cparm_name(0,1)));
} else {
Printf(func,"if (%s) swig_assign_unnamed(%s%s, %s)",Swig_cparm_name(0,0), self,name,
Swig_cparm_name(0,1));
}
}
Delete(self);
return(func);