Template Class ObjectDef#

Inheritance Relationships#

Base Type#

  • public ReflectionDefBase

Class Documentation#

template<typename Class>
class ObjectDef : public ReflectionDefBase#

Helper to register Object’s reflection metadata.

namespace refl = tvm::ffi::reflection;
refl::ObjectDef<MyClass>().def_ro("my_field", &MyClass::my_field);

Template Parameters:

Class – The class type.

Public Functions

template<typename ...ExtraArgs>
inline explicit ObjectDef(ExtraArgs&&... extra_args)#

Constructor.

Template Parameters:

ExtraArgs – The extra arguments.

Parameters:

extra_args – The extra arguments.

template<typename T, typename BaseClass, typename ...Extra>
inline ObjectDef &def_ro(const char *name, T BaseClass::* field_ptr, Extra&&... extra)#

Define a readonly field.

Template Parameters:
  • Class – The class type.

  • T – The field type.

  • Extra – The extra arguments.

Parameters:
  • name – The name of the field.

  • field_ptr – The pointer to the field.

  • extra – The extra arguments that can be docstring or default value.

Returns:

The reflection definition.

template<typename T, typename BaseClass, typename ...Extra>
inline ObjectDef &def_rw(const char *name, T BaseClass::* field_ptr, Extra&&... extra)#

Define a read-write field.

Template Parameters:
  • Class – The class type.

  • T – The field type.

  • Extra – The extra arguments.

Parameters:
  • name – The name of the field.

  • field_ptr – The pointer to the field.

  • extra – The extra arguments that can be docstring or default value.

Returns:

The reflection definition.

template<typename Func, typename ...Extra>
inline ObjectDef &def(const char *name, Func &&func, Extra&&... extra)#

Define a method.

Template Parameters:
  • Func – The function type.

  • Extra – The extra arguments.

Parameters:
  • name – The name of the method.

  • func – The function to be registered.

  • extra – The extra arguments that can be docstring.

Returns:

The reflection definition.

template<typename Func, typename ...Extra>
inline ObjectDef &def_static(const char *name, Func &&func, Extra&&... extra)#

Define a static method.

Template Parameters:
  • Func – The function type.

  • Extra – The extra arguments.

Parameters:
  • name – The name of the method.

  • func – The function to be registered.

  • extra – The extra arguments that can be docstring.

Returns:

The reflection definition.

template<typename ...Args, typename ...Extra>
inline ObjectDef &def(init<Args...> init_func, Extra&&... extra)#

Register a constructor for this object type.

This method registers a static __init__ method that constructs an instance of the object with the specified argument types. The constructor can be invoked from Python or other FFI bindings.

Example:

refl::ObjectDef<MyObject>()
    .def(refl::init<int64_t, std::string>(), "Constructor docstring");

Template Parameters:
  • Args – The argument types for the constructor.

  • Extra – Additional arguments (e.g., docstring).

Parameters:
  • init_func – An instance of init<Args...> specifying constructor signature.

  • extraOptional additional metadata such as docstring.

Returns:

Reference to this ObjectDef for method chaining.