An enumerated type in the Xc++ language is specified in a similar manner to a normal C/C++ enumerated type. For example
$enum+ class FontStyle
{
Normal,
Oblique,
Italic
};
defines an enumerated type named FontStyle. The identifiers Normal, Oblique and Italic are called tags. In C++ code an expression such as FontStyle::Oblique is a literal which denote a value of type FontStyle.
By default the first tag appearing in the definition is the default value for a variable of type FontStyle. So the following code won’t trip the assertion:
FontStyle f1; // default constructor
assert(f1 == FontStyle::Normal);
The default value can be overridden using the ‘default’ keyword. For example
$enum+ class FontStyle
{
Normal,
default Oblique,
Italic
};
A variable of type FontStyle can be constructed with a given value. For example:
FontStyle f2(FontStyle::Oblique); // copy constructor
A variable of type FontStyle can be assigned a given value. For example:
f1 = FontStyle::Oblique; // assignment
FontStyle::LEN is a compile time constant which equals the number of tags (in this case 3). It can for example be used to declare the size of an array.
int A[FontStyle::LEN]; // array A has size 3
The tags of an enumerated type have associated integer values that by default begin at 0 for the first tag that appears in the definition and increment from there. An enumerated type supports an implicit conversion to type int. For example
int x = FontStyle::Oblique; // Same as setting x = 1
All 6 comparison operations (< <= == != > >=) are defined on an enumerated type according to the integral values of the tags. E.g.
assert(FontStyle::Normal < FontStyle::Oblique);
Values of the tags can be specified. For example:
$enum+ class FontWeight
{
Thin = 100,
Ultralight = 200,
Light = 300,
Book = 380,
default Normal = 400,
Medium = 500,
Semibold = 600,
Bold = 700,
Ultrabold = 800,
Heavy = 900,
Ultraheavy = 1000
};
The expected way to allow for schema evolution is to:
This ensures the values of tags do not change over time, and also because tags are never deleted they are available when dealing with old versions of objects in the database.
A tag is marked as deprecated with a minus character. For example
$enum+ class FontStyle
{
Normal,
-Oblique,
Italic
};
When a $enum is reflected an instance of a ReflectedEnum is registered in the ReflectedEnum registry.