NVIDIA NvNeural SDK  2022.2
GPU inference framework for NVIDIA Nsight Deep Learning Designer
nvneural::RefPtr< TObject > Class Template Reference

Intrusive pointer using IRefObject's reference counting system. More...

#include <nvneural/RefPtr.h>

Classes

class  GenericOutputWrapper
 Version of OutputWrapper that presents a generic IRefObject** instead. More...
 
class  OutputWrapper
 Details type that allows version-safe use of out-pointer parameters without converting through an intermediate raw pointer variable or mismatching fromPointer/fromPointerNoAddRef. More...
 

Public Member Functions

template<typename TDestinationObject >
RefPtr< TDestinationObject > as () const noexcept
 Creates a new reference to the object using the specified interface. More...
 
TObject * detach () noexcept
 Returns the pointed-to object and releases ownership over its reference. More...
 
TObject * get () const noexcept
 Returns the pointed-to object. More...
 
 operator bool () const noexcept
 Returns true if this RefPtr points to a non-null object.
 
bool operator!= (const RefPtr< TObject > &other) const noexcept
 Compares reference pointers for underlying inequality.
 
bool operator!= (const TObject *pOther) const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
TObject & operator* () const noexcept
 Dereferences this RefPtr. More...
 
TObject * operator-> () const noexcept
 Dereferences this RefPtr. More...
 
RefPtroperator= (const RefPtr &copyFrom) noexcept
 Reassigns this RefPtr to point to a new object. More...
 
RefPtroperator= (RefPtr &&moveFrom) noexcept
 Reassigns this RefPtr to point to a new object. More...
 
RefPtroperator= (std::nullptr_t) noexcept
 Reassigns this RefPtr to point to nullptr. More...
 
bool operator== (const RefPtr< TObject > &other) const noexcept
 Compares reference pointers for underlying equality.
 
bool operator== (const TObject *pOther) const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
OutputWrapper put () &noexcept
 Returns an expression proxy that acts like a TObject** for receiving new pointers. More...
 
GenericOutputWrapper put_refobject () &noexcept
 Returns an expression proxy that acts like an IRefObject** for receiving new pointers. More...
 
 RefPtr () noexcept
 Initializes a RefPtr pointing to nullptr.
 
 RefPtr (const RefPtr &copyFrom) noexcept
 Initializes a new RefPtr pointing to a preexisting RefPtr-tracked object. More...
 
 RefPtr (RefPtr &&moveFrom) noexcept
 Initializes a new RefPtr pointing to a preexisting RefPtr-tracked object. More...
 
 ~RefPtr ()
 Releases the reference to the tracked object.
 

Static Public Member Functions

static RefPtr fromPointer (TObject *pObject)
 Initializes a RefPtr pointing to a specific object. More...
 
static RefPtr fromPointerNoAddRef (TObject *pObject)
 Initializes a RefPtr pointing to a specific object. More...
 

Friends

class GenericOutputWrapper
 
class OutputWrapper
 

Detailed Description

template<typename TObject>
class nvneural::RefPtr< TObject >

Intrusive pointer using IRefObject's reference counting system.

This should be your default representation of IRefObject pointers, though raw pointers may still be necessary to avoid reference cycles. Use caution when operating on raw IRefObject pointers and ensure refcounts stay consistent.

Template Parameters
TObjectAn interface class deriving from IRefObject

Constructor & Destructor Documentation

◆ RefPtr() [1/2]

template<typename TObject >
nvneural::RefPtr< TObject >::RefPtr ( const RefPtr< TObject > &  copyFrom)
inlinenoexcept

Initializes a new RefPtr pointing to a preexisting RefPtr-tracked object.

Adds a reference to the tracked object, because the previous RefPtr remains valid.

Parameters
copyFromA RefPtr to copy state from

◆ RefPtr() [2/2]

template<typename TObject >
nvneural::RefPtr< TObject >::RefPtr ( RefPtr< TObject > &&  moveFrom)
inlinenoexcept

Initializes a new RefPtr pointing to a preexisting RefPtr-tracked object.

Moves from the other RefPtr, so the object's reference count does not increase. The old pointer is reassigned to point to nullptr and can be reinitialized later if desired.

Parameters
moveFromA RefPtr to move state from

Member Function Documentation

◆ as()

template<typename TObject >
template<typename TDestinationObject >
RefPtr<TDestinationObject> nvneural::RefPtr< TObject >::as ( ) const
inlinenoexcept

Creates a new reference to the object using the specified interface.

Returns
A new RefPtr, pointing to nullptr if the queryInterface operation fails.

◆ detach()

template<typename TObject >
TObject* nvneural::RefPtr< TObject >::detach ( )
inlinenoexcept

Returns the pointed-to object and releases ownership over its reference.

This function is useful when handing responsibility for the pointed-to data over to a different scope. The primary example here of such use cases is factory functions; the new data is valid, and should have refcount 1 so that the object can be freed once the callee is finished with it.

Because this mutates the RefPtr, this operation is not considered const.

Returns
The raw pointer tracked by this object

◆ fromPointer()

template<typename TObject >
static RefPtr nvneural::RefPtr< TObject >::fromPointer ( TObject *  pObject)
inlinestatic

Initializes a RefPtr pointing to a specific object.

Adds a reference to that object. You should use this function when the object existed previously and you want to ensure it remains valid. Do not use this function when creating objects directly, as it will lead to a reference leak. (Newly created objects have refcount 1, and this function adds another reference.)

Parameters
pObjectObject to track in this RefPtr

◆ fromPointerNoAddRef()

template<typename TObject >
static RefPtr nvneural::RefPtr< TObject >::fromPointerNoAddRef ( TObject *  pObject)
inlinestatic

Initializes a RefPtr pointing to a specific object.

Does NOT add a reference to that object. Use this function if a reference was already added to the object, such as during object creation.

Parameters
pObjectObject to track in this RefPtr

◆ get()

template<typename TObject >
TObject* nvneural::RefPtr< TObject >::get ( ) const
inlinenoexcept

Returns the pointed-to object.

Does not release ownership of the object. Use this function when passing owned data to other objects if you intend to retain ownership; the object will retain a valid reference count regardless of whether the callee decides to take its own reference.

Returns
The raw pointer tracked by this object

◆ operator*()

template<typename TObject >
TObject& nvneural::RefPtr< TObject >::operator* ( ) const
inlinenoexcept

Dereferences this RefPtr.

Held reference must not be to nullptr. If it is, invokes undefined behavior.

Returns
The dereferenced object tracked by this RefPtr

◆ operator->()

template<typename TObject >
TObject* nvneural::RefPtr< TObject >::operator-> ( ) const
inlinenoexcept

Dereferences this RefPtr.

Held reference must not be to nullptr. If it is, invokes undefined behavior.

Returns
The dereferenced object tracked by this RefPtr

◆ operator=() [1/3]

template<typename TObject >
RefPtr& nvneural::RefPtr< TObject >::operator= ( const RefPtr< TObject > &  copyFrom)
inlinenoexcept

Reassigns this RefPtr to point to a new object.

Releases any previously held reference. Adds a reference to the new object.

Parameters
copyFromA RefPtr to copy state from
Returns
The current RefPtr

◆ operator=() [2/3]

template<typename TObject >
RefPtr& nvneural::RefPtr< TObject >::operator= ( RefPtr< TObject > &&  moveFrom)
inlinenoexcept

Reassigns this RefPtr to point to a new object.

Releases any previously held reference. Takes the reference to the new object.

Parameters
moveFromA RefPtr to move state from
Returns
The current RefPtr

◆ operator=() [3/3]

template<typename TObject >
RefPtr& nvneural::RefPtr< TObject >::operator= ( std::nullptr_t  )
inlinenoexcept

Reassigns this RefPtr to point to nullptr.

Releases any previously held reference.

◆ put()

template<typename TObject >
OutputWrapper nvneural::RefPtr< TObject >::put ( ) &
inlinenoexcept

Returns an expression proxy that acts like a TObject** for receiving new pointers.

The currently held object is released.

This function is available only on lvalue RefPtrs to prevent accidental assignment to temporary objects (as with .as<IThing>().put()).

◆ put_refobject()

template<typename TObject >
GenericOutputWrapper nvneural::RefPtr< TObject >::put_refobject ( ) &
inlinenoexcept

Returns an expression proxy that acts like an IRefObject** for receiving new pointers.

The currently held object is released.

This function is available only on lvalue RefPtrs to prevent accidental assignment to temporary objects (as with .as<IThing>().put()).


The documentation for this class was generated from the following file: