diff --git a/CHANGES.current b/CHANGES.current index aff98df24..9304d636a 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.3 (in progress) =========================== +2014-12-07: wsfulton + Add support for C++11 strongly typed enumerations. + 2014-11-21: wsfulton [Java C#] Fix multiply defined error when using %rename of enum items when using the "simple enum" wrappers. diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html index 04c40a6d6..b7e1d638c 100644 --- a/Doc/Manual/CPlusPlus11.html +++ b/Doc/Manual/CPlusPlus11.html @@ -495,59 +495,59 @@ struct DerivedStruct : BaseStruct {
SWIG parses the new enum class syntax and forward declarator for the enums:
+SWIG supports strongly typed enumerations and parses the new enum class syntax and forward declarator for the enums, such as:
enum class MyEnum : unsigned int;
The strongly typed enumerations are treated the same as the ordinary and anonymous enums. -This is because the required nested class support in SWIG is new and has not yet been incorporated into the wrapping of these strongly typed enum classes. -This is usually not a problem, however, -there may be some name clashes. For example, the following code:
++Strongly typed enums are often used to avoid name clashes such as the following: +
struct Color {
- enum class PrintingColors : unsigned int {
- Cyan, Magenta, Yellow, Black
+ enum class RainbowColors : unsigned int {
+ Red, Orange, Yellow, Green, Blue, Indigo, Violet
};
- enum class BasicColors {
- Red, Green, Blue
+ enum class WarmColors {
+ Yellow, Orange, Red
};
-
- enum class AllColors {
- // produces warnings because of duplicate names
- Yellow, Orange, Red, Magenta, Blue, Cyan, Green, Pink, Black, White
- };
-};
-A workaround is to write these as a series of separate classes containing anonymous enums:
- -
-struct PrintingColors {
- enum : unsigned int {
- Cyan, Magenta, Yellow, Black
- };
-};
-
-struct BasicColors {
- enum : unsigned int {
- Red, Green, Blue
- };
-};
-
-struct AllColors {
- enum : unsigned int {
- Yellow, Orange, Red, Magenta, Blue, Cyan, Green, Pink, Black, White
+ // Note normal enum
+ enum PrimeColors {
+ Red=100, Green, Blue
};
};
-Expect to see this improved in a future version of SWIG. +There are various ways that the target languages handle enums, so it is not possible to precisely state how they are handled in this section. +However, generally, most scripting languages mangle in the strongly typed enumeration's class name, +but do not use any additional mangling for normal enumerations. For example, in Python, the following code
++print Color.RainbowColors_Red, Color.WarmColors_Red, Color.Red +
+results in +
+ ++0 2 100 +
+The strongly typed languages often wrap normal enums into an enum class and so treat normal enums and strongly typed enums the same. +The equivalent in Java is: +
+ ++System.out.println(Color.RainbowColors.Red.swigValue() + " " + Color.WarmColors.Red.swigValue() + " " + Color.PrimeColors.Red.swigValue()); +