Enum Statement |
|
Enum Statement SyntaxThe Fractal Science Kit fractal generator enum statement is 1 of the statements used in the properties section of the program instructions to define the program's Properties. An enum statement defines a set of constants that can be used to improve readability in your code. Each enum item includes a name, a label, and an optional complex expression. The enum statement is frequently used in combination with an option statement (whose type field is set to the enum name) to generate a set of selectable items presented in a combobox control. The syntax of the enum statement is: enum <EnumName> { The enum name and each of the item names must be valid identifiers. The item label is a quoted string. The expression must evaluate to a complex constant and is optional. A constant is defined for each enum item. These constants are accessible in the other sections of your instructions. The name of the constant is the enum name followed by a period (.) and then the item name. The value of the constant associated with the 1st item is 0, the 2nd item is 1, the 3rd item is 2, etc. The item expression can be included to associate a secondary value with an item, if required. The secondary value is accessed from the associated enum option (see example below). Example: enum ProjectionTypes { This statement defines an enum named ProjectionTypes with 3 items. An enum can be used as an option type as in the following example: option Projection { This defines an option named Projection whose type is given by ProjectionTypes. Options based on enums result in combobox controls on the properties page. The combobox associated with the Projection option will have 3 items, one for each of the enum's items as shown below: Note the option's default specification given above is the enum name followed by a period (.) and then the item name. This is also how you access an enum value in your program. The following code shows how the Projection option can be used in your code: z = Polar(Sample.TrapValue, Sample.TrapAngleRaw) This could just as easily been coded as: z = Polar(Sample.TrapValue, Sample.TrapAngleRaw) Note how the use of the enum constants in the 1st example improves the readability of the code. Example: enum CriticalPoints { This example defines an enum named CriticalPoints and an option named CriticalPoint. An expression is included with each enum item. The expression must evaluate to a simple complex number and cannot use any of the options defined by the program. A combobox with 2 items will be created on the associated properties page to allow the user to adjust the value of the CriticalPoint option as shown below: The following code illustrates how you can access the expression value from your instructions: if (~IsJulia) { Here, z is set to the expression value associated with the currently selected item of the CriticalPoint option. |
Copyright © 2004-2019 Ross Hilbert |