Changes between Version 5 and Version 6 of Enum
- Timestamp:
- 11/15/12 05:44:06 (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Enum
v5 v6 1 1 = Enumeration = 2 2 3 An enumeration is a distinct type consisting of a set of named constants (enumerator list, enumeration elements). [[BR]] 4 On platforms that support it and where typed, the underlying type of the enumeration elements is int and the first enumeration element has the value 0 with the value of each successive enumerator increased by 1.[[BR]] 3 An enumeration is a distinct type consisting of a set of named constants or symbolic values (These are also sometimes known as an 4 enumerator list or enumeration elements). [[BR]] 5 On platforms that support it and where the implementation supports typing, the underlying type of the enumeration elements is int and the first default enumeration element has the value 0 with the value of each successive enumerator increased by 1.[[BR]] 5 6 6 Elements can have initialisers to override the default values if this is desired .7 Elements can have initialisers to override the default values if this is desired (or supported). 7 8 8 9 In Cobra an enumeration is declared with the '''enum''' keyword followed by the enumeration name.[[BR]] 9 10 As this is a type the enum name must start with an uppercase letter.[[BR]] 10 11 Enumeration element names (with optional initialiser values) follow individually on subsequent lines each equally indented 11 or with multiple comma separated on the same line.12 or with multiple values, comma separated on the same line. 12 13 13 14 {{{ … … 33 34 }}} 34 35 35 Multiple elements can be or'd togetherby specifying multiple elementNames comma separated36 Multiple elements can be collected together in a set by specifying multiple elementNames comma separated 36 37 within the constructor-like call. 37 38 {{{ … … 88 89 89 90 == Platform == 90 Explicit typing (!StorageType) of enumeration elements and bitwise operations on elements are only supported on platforms that implement enums as variants of numeric Types (.Net)91 Explicit typing (!StorageType) of enumeration elements and bitwise operations on elements are only supported on platforms that implement enums as variants of (integer) numeric Types (.Net) 91 92 92 For maximum portability and readability try and avoid using initialiser values and use either a direct equality comparison93 or the set inclusion form for testing enum member inclusion.93 For maximum portability and readability avoid using C-like bitpattern initialiser values and bitwise math operations for set inclusion 94 and instead use either a direct equality comparison or the set inclusion form for testing enum member inclusion. 94 95 {{{ 95 96 #!cobra 96 if today == Day.Fri, ... 97 enum CarOptions 98 None, SunRoof, Spoiler, FogLights, TintedWindows 97 99 98 assert CarOptions.SunRoof in options 100 if myOption == CarOptions.FogLights, ... 101 102 sportOptions = CarOptions(SunRoof, Spoiler) 103 .. 104 assert CarOptions.SunRoof in sportOptions 105 106 myOption = CarOption.SunRoof 107 assert myOption in sportOptions 108 99 109 }}} 100 110 … … 116 126 print options to int 117 127 assert (options & CarOptions.SunRoof) == CarOptions.SunRoof # bitwise test combined options 128 # above same as assert CarOptions.SunRoof in options 118 129 119 130 /# Output is