Wiki

Changes between Version 3 and Version 4 of Enum

Show
Ignore:
Timestamp:
12/01/10 06:07:19 (14 years ago)
Author:
hopscc
Comment:

Update for ganged members and show inclusion testing

Legend:

Unmodified
Added
Removed
Modified
  • Enum

    v3 v4  
    44By default the underlying type of the enumeration elements is int and the first enumerator 
    55has the value 0 with the value of each successive enumerator increased by 1.[[BR]]  
    6 Enumerators can have initializers to override the default values. 
     6Enumerators can have initialisers to override the default values. 
    77 
    88In Cobra an enumeration is declared with the '''enum''' keyword followed by the enumeration name.[[BR]] 
    9 As this is a type the name must start with an uppercase letter.[[BR]] 
    10 Enumeration element names (with optional initialiser values) follow indented on subsequent lines. 
     9As this is a type the enum name must start with an uppercase letter.[[BR]] 
     10Enumeration element names (with optional initialiser values) follow individually on subsequent lines each equally indented 
     11or with multiple comma separated on the same line. 
     12 
     13{{{ 
     14#!cobra 
     15enum States 
     16    Init 
     17    Valid 
     18    Working 
     19    Dead 
     20 
     21enum Tasks 
     22    ChopWood, CarryWater 
     23    Enlightenment 
     24}}} 
    1125 
    1226Emumerations are referenced by the Enumeration class name dotted with the enumeration element name[[BR]] 
    1327or like a constructor call: {{{enumName(enumElementName) }}}. 
     28 
     29{{{ 
     30#!cobra 
     31e = MyEnum.Start 
     32e1 = MyEnum(Start) 
     33}}} 
    1434 
    1535Multiple elements can be or'd together by specifying multiple elementNames comma separated  
     
    4969        yesterday = Day(Thu) 
    5070        weekend = Days(Sat, Sun) 
     71 
     72        isWeekend = today in [Days.Sat, Days.Sun] # explicit test enum member inclusion 
     73 
     74 
     75enum OtherDays  
     76    Mon, Tue, Wed, Thu, Fri 
     77    Sat, Sun 
    5178}}} 
    5279 
    53 See the effect of System.!FlagsAttribute on an enum  
     80== Platform == 
     81On .Net see the effect of System.!FlagsAttribute on an enum  
    5482{{{ 
    5583#!cobra 
     
    6694        print options 
    6795        print options to int 
     96        assert (options & CarOptions.SunRoof) == CarOptions.SunRoof  # bitwise test combined options 
    6897 
    6998/# Output is