Wiki

Changes between Version 5 and Version 6 of Enum

Show
Ignore:
Timestamp:
11/15/12 05:44:06 (5 years ago)
Author:
hopscc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Enum

    v5 v6  
    11= Enumeration =  
    22 
    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]]  
     3An enumeration is a distinct type consisting of a set of named constants or symbolic values (These are also sometimes known as an 
     4enumerator list or enumeration elements). [[BR]] 
     5On 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]]  
    56 
    6 Elements can have initialisers to override the default values if this is desired. 
     7Elements can have initialisers to override the default values if this is desired (or supported). 
    78 
    89In Cobra an enumeration is declared with the '''enum''' keyword followed by the enumeration name.[[BR]] 
    910As this is a type the enum name must start with an uppercase letter.[[BR]] 
    1011Enumeration element names (with optional initialiser values) follow individually on subsequent lines each equally indented 
    11 or with multiple comma separated on the same line. 
     12or with multiple values, comma separated on the same line. 
    1213 
    1314{{{ 
     
    3334}}} 
    3435 
    35 Multiple elements can be or'd together by specifying multiple elementNames comma separated  
     36Multiple elements can be collected together in a set by specifying multiple elementNames comma separated  
    3637within the constructor-like call. 
    3738{{{ 
     
    8889 
    8990== 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) 
     91Explicit 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) 
    9192 
    92 For maximum portability and readability try and avoid using initialiser values and use either a direct equality comparison  
    93 or the set inclusion form for testing enum member inclusion.  
     93For maximum portability and readability avoid using C-like bitpattern initialiser values and bitwise math operations for set inclusion 
     94and instead use either a direct equality comparison or the set inclusion form for testing enum member inclusion.  
    9495{{{ 
    9596#!cobra 
    96  if today == Day.Fri, ... 
     97enum CarOptions  
     98   None, SunRoof, Spoiler, FogLights, TintedWindows  
    9799 
    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  
    99109}}}  
    100110 
     
    116126        print options to int 
    117127        assert (options & CarOptions.SunRoof) == CarOptions.SunRoof  # bitwise test combined options 
     128        # above same as   assert CarOptions.SunRoof in options 
    118129 
    119130/# Output is