Class EnumObj#

Inheritance Relationships#

Base Type#

Class Documentation#

class EnumObj : public tvm::ffi::Object#

Base class for FFI-registered enums.

Each registered variant is a unique, process-wide singleton with a dense ordinal (_value) and string _name. Subclasses may add declared fields — part of the variant’s schema, set at registration time via reflection::EnumDef. Separately, any consumer may attach extensible attributes (per-variant metadata stored outside the variant’s fields) via EnumDef::set_attr or the Python Enum.def_attr surface, without modifying EnumClsObj.

Public Functions

EnumObj() = default#
inline EnumObj(int64_t value, String name)#

Construct an EnumObj with an explicit ordinal and name.

Parameters:
  • value – The dense ordinal (0-indexed per enum class).

  • name – The instance name key.

Public Members

int64_t _value#

Declared field: dense ordinal assigned at registration time (0-indexed per class).

String _name#

Declared field: instance name (e.g., "Add" for Op.Add).

Public Static Functions

template<typename EnumClsObj>
static inline Enum Get(const String &name)#

Look up the registered singleton for EnumClsObj by name.

Reads from the per-class reflection::type_attr::kEnumEntries registry populated by reflection::EnumDef<EnumClsObj>. Instances are unique per (type_key, name) pair for the life of the process, so the returned Enum compares equal (by pointer) to every other lookup of the same name. Throws RuntimeError if no instance with the given name is registered for EnumClsObj.

Template Parameters:

EnumClsObj – An Object subclass deriving from EnumObj.

Parameters:

name – The instance name to look up (e.g., "Add").

Returns:

The registered Enum singleton.