From: Pascal <pas...@gm...> - 2007-05-11 11:03:10
|
Hi, I would like to understand if it is possible to do this kind of construction with swig? Let's have an enum where an entry is conditionned: AnEnum.h looks like #ifndef ANENUM_H #define ANENUM_H enum AnEnum { EnumVal1_ENU, EnumVal2_ENU, #ifdef _WITH_EXTENSION_ Extension_ENU, #endif EnumValN_ENU }; #endif // ANENUM_H To make it available in Python, the following Tools.i file was generated %module Tools %{ #include "AnEnum.h" %} %include "AnEnum.h" The wrap file was generated using the following options: swig.exe -c++ -python -D_WITH_EXTENSION_ -o Tools_wrap.cpp Tools.i If the Tools module is imported in Python, the enumeration entries are available Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import Tools >>> dir(Tools) ['EnumVal1_ENU', 'EnumVal2_ENU', 'EnumValN_ENU', 'Extension_ENU', '_Tools', '__builtins__', '__doc__', '__file__', '__name__', '_newclass', '_object', '_swig_getattr', '_ swig_repr', '_swig_setattr', '_swig_setattr_nondynamic', 'new', 'new_instancemethod'] >>> At this level, it's OK. But I would like to hide the Extension_ENU entry in another header file let's call it ExtensionEnumEntries.h: #ifndef EXTENSIONENUMENTRIES_H #define EXTENSIONENUMENTRIES_H Extension_ENU, #endif // EXTENSIONENUMENTRIES_H And change the AnEnum.h file into: #ifndef ANENUM_H #define ANENUM_H enum AnEnum { EnumVal1_ENU, EnumVal2_ENU, #ifdef _WITH_EXTENSION_ #include "ExtensionEnumEntries.h" #endif EnumValN_ENU }; #endif // ANENUM_H In this case, the process that generates the wrap file complains AnEnum.h: Error : Syntax error in input(1) the line errror corresponds to the #include "ExtensionEnumEntries.h" declaration. And of course the "hidden" entry is not available in the module. I am using SWIG Version 1.3.29. I tried adding -includeall in the swig call but this does not change anything. Here is my question: Can swig manage this kind of construction where information is "hidden" in header files? By the way, I would like also to use conditionnal inclusion of header file to declare member functions in the declaration of classes. Regards Pascal |