Template Class EnumDef#
Defined in File enum_def.h
Inheritance Relationships#
Base Type#
public ReflectionDefBase
Class Documentation#
-
template<typename EnumClsObj, typename = std::enable_if_t<std::is_base_of_v<EnumObj, EnumClsObj>>>
class EnumDef : public ReflectionDefBase# Builder that registers a single enum instance on
EnumClsObj.Each
EnumDef<EnumClsObj>("Name")call allocates a fresh dense ordinal (= len(existing entries)), constructs a variant with_valueand_namepopulated, and writes it into the per-class registry stored in thetype_attr::kEnumEntriesTypeAttr column. Subsequent.set_attr(...)calls write extensible attributes — per-variant metadata attached outside the variant’s declared fields — into the per-classtype_attr::kEnumAttrscolumn. Python bindings of the sametype_keysee every C++-registered variant and every extensible attribute through the matchingEnum.def_attrsurface.namespace refl = ::tvm::ffi::reflection; refl::EnumDef<OpObj>("Add").set_attr("has_side_effects", false); refl::EnumDef<OpObj>("Mul").set_attr("has_side_effects", false);
Public Functions
-
inline explicit EnumDef(const char *instance_name)#
Register a new instance named
instance_nameonEnumClsObj.- Parameters:
instance_name – The instance’s string name (e.g.,
"Add").
-
template<typename T>
inline EnumDef &set_attr(const char *attr_name, T value)# Write an extensible attribute for this enum variant.
Writes land in the per-class
type_attr::kEnumAttrscolumn and are visible to every binder of the sametype_key— including Python readers viaEnum.def_attr/Enum.attr_dict. Distinct from declared fields onEnumClsObj: declared fields are part of the variant’s schema and set during construction, whereas extensible attributes live outside the variant object and may be attached by any consumer at any time.- Template Parameters:
T – The value type.
- Parameters:
attr_name – The extensible-attribute name (e.g.,
"has_side_effects").value – The value to store for this variant’s ordinal.
- Returns:
Reference to this builder for chaining.
-
inline int64_t ordinal() const#
Return the ordinal assigned to this instance.
-
inline explicit EnumDef(const char *instance_name)#