Class ObjectRef#

Inheritance Relationships#

Derived Types#

Class Documentation#

class ObjectRef#

Base class of all object reference.

Subclassed by tvm::ffi::Array< tvm::ffi::Any >, tvm::ffi::Map< tvm::ffi::String, tvm::ffi::Function >, tvm::ffi::Array< T, typename >, tvm::ffi::Error, tvm::ffi::Function, tvm::ffi::Map< K, V, typename >, tvm::ffi::Module, tvm::ffi::Optional< T, std::enable_if_t< use_ptr_based_optional_v< T > > >, tvm::ffi::Shape, tvm::ffi::Tensor, tvm::ffi::Tuple< Types >, tvm::ffi::details::VariantBase< true >, tvm::ffi::reflection::AccessPath, tvm::ffi::reflection::AccessStep

Public Types

using ContainerType = Object#

type indicate the container type.

Public Functions

ObjectRef() = default#

default constructor

ObjectRef(const ObjectRef &other) = default#

copy constructor

ObjectRef(ObjectRef &&other) = default#

move constructor

inline explicit ObjectRef(ObjectPtr<Object> data)#

Constructor from existing object ptr.

inline explicit ObjectRef(UnsafeInit)#

Constructor from UnsafeInit.

inline bool same_as(const ObjectRef &other) const#

Comparator.

Parameters:

other – Another object ref.

Returns:

the compare result.

inline bool defined() const#
Returns:

whether the object is defined.

inline const Object *get() const#
Returns:

the internal object pointer

inline bool unique() const#
Returns:

whether the reference is unique

inline int use_count() const#
Returns:

The use count of the ptr, for debug purposes

template<typename ObjectType, typename = std::enable_if_t<std::is_base_of_v<Object, ObjectType>>>
inline const ObjectType *as() const#

Try to downcast the internal Object to a raw pointer of a corresponding type.

The function will return a nullptr if the cast failed.

if (const AddNode *ptr = node_ref.as<AddNode>()) {
  // This is an add node
}

Template Parameters:

ObjectType – the target type, must be a subtype of Object

Returns:

The pointer to the requested type.

template<typename ObjectRefType, typename = std::enable_if_t<std::is_base_of_v<ObjectRef, ObjectRefType>>>
inline std::optional<ObjectRefType> as() const#

Try to downcast the ObjectRef to Optional<T> of the requested type.

The function will return a std::nullopt if the cast or if the pointer is nullptr.

Template Parameters:

ObjectRefType – the target type, must be a subtype of ObjectRef

Returns:

The optional value of the requested type.

inline int32_t type_index() const#

Get the type index of the ObjectRef.

Returns:

The type index of the ObjectRef

inline std::string GetTypeKey() const#

Get the type key of the ObjectRef.

Returns:

The type key of the ObjectRef

Public Static Attributes

static constexpr bool _type_is_nullable = true#

Whether the reference can point to nullptr.

Protected Functions

inline Object *get_mutable() const#
Returns:

return a mutable internal ptr, can be used by sub-classes.

Protected Attributes

ObjectPtr<Object> data_#

Internal pointer that backs the reference.

Friends

friend struct ObjectPtrHash