/MEng/Enum

ClassPath:MEng.
Parent ClassPath:MEng.Object
Copyable:Yes
Final:Yes

MEng.Enum is the abstract base class from which all enumerated types are derived. Enumerated types can be created as a nested type within class. So they aren't really first class citizens relative to normal classes, but they do have their own class path, which is the parent class path plus the name of the new enumerated class.

This class provides some Required methods that are magically overridden in each nested enumerated class that you create. You don't have to do anything to make this happen. These methods allow certain things to be done to enumerations without regard to their actual type, so that they can be treated polymorphically for certain things. This implicitly created class for each actual enumerated type also has a set of methods, which are described in this document, after methods for this class are defined.

Each enumerated type has a set of defined values. Each value has a name, a text description, and an ordinal value. Here is an example of an enumerated type definition:

Types=
    Enum=TestEnum
            Value1 : "Text for value 1";
            Value2 : "Text for value 2";
            Value3 : "Text for value 3";
            Value4 : "Text for value 4";
    EndEnum;
EndTypes;

The value names are on on the left side of the colon and the value descriptions are on the right side. The ordinal value is implicit, starting at zero for the first value and increasing sequentially upwards for each new value.

 

Nested Classes:

Enum=EnumErrors
    BadOrdinal    : "%(1) is not a valid ordinal for enum %(2)"
    NameNotFound  : "%(1) is not a valid item name for enum %(2)");
    TextNotFound  : "The passed text did not match any value for enum %(1)");
EndEnum;

This enumerated type defines the enumeration specific exceptions that this class might throw. Note though that other exceptions might be thrown from other classes used by this class.

 

Constructors:

Constructor();

There is one default constructor, which will set the initial to the first defined value, i.e. an ordinal value of zero. You would never call this directly, it just exists for derived classes to call.

 

Final, Const Methods:

IsAtMax() Returns MEng.Boolean;
IsAtMin() Returns MEng.Boolean;

Returns True if the enumerated value is at it's maximum or minimum value, else returns False. This is convenient if you are polymorphically enumerating through the values of an enumerated value.

GetOrdinal() Returns MEng.Card4;

Returns the current ordinal value of the object, which is in the form of a Card4 value.

 

Final, Non-Const Methods:

Dec();

If the enumerated value is not at it's minimum value, it will be decremented to the previous value.

Inc();

If the enumerated value is not at it's maximum value, it will be incremented to the next value.

SetOrdinal([In] MEng.Card4 ToSet);

Sets the value of this object via it's ordinal. The passed value must be a valid ordinal value for the actual enumerated type of this object, or it will throw a BadOrdinal exception.

SetToMax();
SetToMin();

Sets the the value to the minimum or maximum value for this object's enumerated type.

 

Required, Const Methods:

See the derived class documentation below for the comments on these methods.

FormatList
(
    [Out]  MEng.String ToFill
    , [In] MEng.String Prefix
    , [In] MEng.Char    SepChar
    , [In] MEng.Boolean UseName
);

GetName() Returns MEng.String;

GetText() Returns MEng.String;

 

Required, Non-Const Methods:

See the derived class documentation below for the comments on these methods.

FromName([In] MEng.String ToFind);

FromText([In] MEng.String ToFind);

 

Derived Class Methods

This section covers the methods that are generated automatically for the magic class that gets created whenever an enumerated type is defined in a class. This class will derive from the based MEng.Enum class above.

Note that, since the type is varied here, the actual class name or class path are represented by NNN and PPP. If you notice, all of these classes are those that require parameters that are of the actual enumerated type, whereas the ones above do not, which is why they can be provided generically in the parent class.

 

Constructors:

Constructor();
Constructor([In] MEng.PPP.NNN InitVal);

There is a default constructor which will set the initial value to the first defined value for this type. And there is a second constructor that takes an initial value, which will either be another object of the same type or a literal value of this type.

 

Final, Const Methods:

Equal([In] MEng.PPP.NNN ToComp) Returns MEng.Boolean;
operator=
(
    [In] MEng.PPP.NNN ToComp1
    , [In] MEng.PPP.NNN ToComp2
)   Returns MEng.Boolean;

Compares the two objects and returns True if they are equal and False if they are unequal. Neither object is affected. They do the same thing, are only only syntactically different.

GtThan([In] MEng.PPP.NNN ToComp) Returns MEng.Boolean;
operator>([In] MEng.PPP.NNN Src1, [In] MEng.PPP.NNN Src2) Returns MEng.Boolean;
GtThanEq([In] MEng.PPP.NNN ToComp) Returns MEng.Boolean;
operator>=([In] MEng.PPP.NNN Src1, [In] MEng.PPP.NNN Src2) Returns MEng.Boolean;

Compares the two objects and returns True if the left hand object is greater (or greater than or equal), else it returns False. Neither object is affected. The two sets do the same thing, and are just syntactically different. This is based on the ordinal value of the two objects.

LsThan([In] MEng.PPP.NNN ToComp) Returns MEng.Boolean;
operator<([In] MEng.PPP.NNN Src1, [In] MEng.PPP.NNN Src2) Returns MEng.Boolean;
LsThanEq([In] MEng.PPP.NNN ToComp) Returns MEng.Boolean;
operator<=([In] MEng.PPP.NNN Src1, [In] MEng.PPP.NNN Src2) Returns MEng.Boolean;

Compares the two objects and returns True if the left hand object is less than (or less than or equal) the right hand object, else it returns False. Neither object is affected. The two sets do the same thing, and are just syntactically different. This is based on the ordinal value of the two objects.

 

Final, Const Overrides:

These methods override required methods in the base enum class. These allow you to get information out of the an enumerated value polymorphically.

FormatList
(
    [Out]  MEng.String ToFill
    , [In] MEng.String Prefix
    , [In] MEng.Char    SepChar
    , [In] MEng.Boolean UseName
);

This method will format either the names or the text values of this enumerated type out to the ToFill string, prefixing the string with the passed Prefix string and separating the values with the SepChar character. So an enumerated type for the map directions, a prefix of "Directions:" and a sep char of a comma, might come out like this:

Directions: North, South, East, West

The UseName parameter indicates whether you want the names or the text values to be formatted out. So use True to get the names of the values, and False to get the text values.

GetName() Returns MEng.String;

Returns the name (the left hand part of the enumerated value definition) of the current value of this object.

GetText() Returns MEng.String;

Returns the text (the right hand part of the enumerated value definition) of the current value of this object.

 

Final, Non-Const Overrides:

These methods override required methods in the base enum class.  These allow you to update an enumerated value polymorphically.

FromName([In] MEng.String ToFind);

Tries to find a value of this enumerated type which has a name that matches the passed text. The comparison is case sensitive since enumerated value names are case sensitive. If a value with that name is found, then the ordinal of this object is set to that value, else the NameNotFound exception is thrown.

FromText([In] MEng.String ToFind);

Tries to find a value of this enumerated type which has a value that matches the passed text. The comparison is case sensitive. If a value with the passed text is found, then the ordinal of this object is set to that value, else the TextNotFound exception is thrown.

Note that this matches the text, not the name. Use FromName() to match the name.