Represents information about a $enum declaration in the Xc++ language.
$struct+ ReflectedEnum
{
$ConstStringZ GetName() const { return m_name; }
// Returns true if the enum values have been redefined (i.e. they are not simply 0,1,2...)
$bool ValuesRedefined() const { return m_values != nullptr; }
// Returns the number of distinct enum values
$int32 GetCount() const { return m_count; }
// Returns the ith enum value, which is just i if the enum values are simply 0,1,2,...
$int32 GetValue(int32 i) const { return m_values ? m_values[i] : i; }
// Returns true if the ith enum value is enabled (i.e. no deprecated)
$bool GetEnable(int32 i) const { return m_enabled ? m_enabled[i] : true; }
// Returns the ith enum string
$ConstStringZ GetString(int32 i) const { return m_strings[i]; }
//////////////// State //////////////////
ConstStringZ m_name;
const octet_t* m_metaData;
ConstStringZ const* m_stringTable;
int32 m_count;
ConstStringZ const* m_strings;
const int32* m_values;
const bool* m_enabled; // nullptr if all enum values are enabled
};
ConstStringZ m_name
The fully qualified name of the enumerated type represented as a pointer to a UTF-8 encoded null-terminated string (see ConstStringZ).
const octet_t* m_metaData
Pointer to metadata byte code on the enumerated type or null if no metadata declared.
ConstStringZ const* m_stringTable
The address of an array of pointers to UTF-8 encoded null-terminated strings (see ConstStringZ), which is the string table associated with the byte code used to represent the metadata on the enumerated type. May be null if no string table is required.
int32 m_count
The number of tags in the enumerated type, including tags that have been dropped.
ConstStringZ const* m_strings
The address of an array of pointers to UTF-8 encoded null-terminated strings of size m_count (see ConstStringZ), which are the strings of the tags in the order in which they appear in the definition. Includes the tags which have been dropped.
const int32* m_values
The address of an array of int32 values of size m_count which are the values of the tags. Includes the tags which have been dropped. m_values is null if it would be the case that for each i, m_value[i] = i.
const bool* m_enabled
The address of an array of bool values of size m_count which are false for the tags which have been dropped (by preceding the tag identifier with '-'). m_enabled is null if it would be the case that for each i, m_enabled[i] = true.
$enum+ EColour
{
red = 10,
-green = 20,
blue = 30
};
GetCount() = 3
GetValue(0) = 10
GetValue(1) = 20
GetValue(2) = 30
GetString(0) = "red"
GetString(1) = "green"
GetString(2) = "blue"
GetEnable(0) = true
GetEnable(1) = false
GetEnable(2) = true
This generates the following C++ implementation
namespace ns
{
enum EColour : int
{
red=10,
green=20,
blue=30
};
ceda::ReflectedEnum const& _GetReflected(EColour const*);
inline ceda::TypeOps const& _GetTypeOps(EColour const*) { return ceda::GetTypeOps<ceda::int32>(); }
inline ceda::Archive& operator<<(ceda::Archive& _ar,EColour _x) { ceda::SerialiseVariableLengthUint32(_ar, (int)_x); return _ar; }
inline ceda::InputArchive operator>>(ceda::InputArchive _ar,EColour& _x) { return ceda::DeserialiseVariableLengthUint(_ar, (int&)_x); }
} //ns
namespace ceda
{
template<> struct TypeTraits<ns::EColour>
{
static const bool is_exported = 1;
static const bool is_reflected = 1;
static const bool is_registered = 1;
static const ceda::ETypeTraitKind kind = ceda::TTK_enum;
static const bool has_metadata = 0;
};
} // namespace ceda
The following code is generated to register a ReflectedEnum for EColour:
//### $enum+ ns::EColour
namespace ceda { XTarget* Ceda_Core_Object_exObject_GetXTarget(); }
namespace ns
{
ceda::ReflectedEnum const& _GetReflected(EColour const*)
{
static ceda::ConstStringZ EColour_strings[] =
{
"red",
"green",
"blue",
};
static const ceda::int32 EColour_values[] =
{
10,
20,
30,
};
static const bool EColour_enabled[] =
{
true,
false,
true,
};
static const ceda::ReflectedEnum EColour_enum =
{
"ns::EColour",
0,
0,
3,
EColour_strings,
EColour_values,
EColour_enabled
};
return EColour_enum;
}
// Registration of $enum+ ns::EColour
void _Register_EColour()
{
cxVerify(ceda::RegisterReflectedEnum(&_GetReflected( (EColour*) 0),ceda::Ceda_Core_Object_exObject_GetXTarget()) == ceda::NSE_OK);
}
} // ns