NAP
Public Member Functions | List of all members
ObjectPtr< T > Class Template Reference

#include <rtti/objectptr.h>

Public Member Functions

 ObjectPtr ()=default
 
virtual ~ObjectPtr () override
 
 ObjectPtr (T *ptr)
 
 ObjectPtr (const ObjectPtr< T > &other)
 
 ObjectPtr (ObjectPtr< T > &&other)
 
ObjectPtr< T > & operator= (const ObjectPtr< T > &other)
 
ObjectPtr< T > & operator= (ObjectPtr< T > &&other)
 
T * get () const
 
T * get ()
 
template<typename OTHER >
 ObjectPtr (const ObjectPtr< OTHER > &other)
 
template<typename OTHER >
 ObjectPtr (ObjectPtr< OTHER > &&other)
 
template<typename OTHER >
ObjectPtr< T > & operator= (const ObjectPtr< OTHER > &other)
 
template<typename OTHER >
ObjectPtr< T > & operator= (ObjectPtr< OTHER > &&other)
 
const T & operator* () const
 
T & operator* ()
 
T * operator-> () const
 
T * operator-> ()
 
bool operator== (const ObjectPtr< T > &other) const
 
template<typename OTHER >
bool operator== (const ObjectPtr< OTHER > &other) const
 
template<typename OTHER >
bool operator== (const OTHER *ptr) const
 
bool operator== (std::nullptr_t) const
 
bool operator!= (const ObjectPtr< T > &other) const
 
template<typename OTHER >
bool operator!= (const ObjectPtr< OTHER > &other) const
 
template<typename OTHER >
bool operator!= (const OTHER *ptr) const
 
bool operator!= (std::nullptr_t) const
 
bool operator< (const ObjectPtr< T > &other) const
 
bool operator> (const ObjectPtr< T > &other) const
 
bool operator<= (const ObjectPtr< T > &other) const
 
bool operator>= (const ObjectPtr< T > &other) const
 
- Public Member Functions inherited from ObjectPtrBase
virtual ~ObjectPtrBase ()=default
 
rttr::type getWrappedType () const
 

Description

template<typename T>
class nap::rtti::ObjectPtr< T >

Acts like a regular pointer. Accessing the pointer does not have different performance characteristics than accessing a regular pointer. Moving/copying an ObjectPtr has a small overhead, as it removes/adds itself from the ObjectPtrManager in such cases.

The purpose of ObjectPtr is that the internal pointer can be changed by the system. Therefore it is not allowed to store the internal pointer or a reference to the internal pointer, as it may get replaced (and destructed) by the system. This occurs when hot reloading changes into the running application.

When creating resources at runtime that require a link to another rtti::Object, it is perfectly safe (and valid) to create the referenced object and wrap it in an ObjectPtr<T>, before assigning it. In that case you do have to manually manage the lifetime of the created objects.

Inheritance diagram for ObjectPtr< T >:
[legend]
Collaboration diagram for ObjectPtr< T >:
[legend]

Constructor & Destructor Documentation

◆ ObjectPtr() [1/6]

ObjectPtr ( )
default

◆ ~ObjectPtr()

~ObjectPtr
overridevirtual

◆ ObjectPtr() [2/6]

ObjectPtr ( T *  ptr)

◆ ObjectPtr() [3/6]

ObjectPtr ( const ObjectPtr< T > &  other)

◆ ObjectPtr() [4/6]

ObjectPtr ( ObjectPtr< T > &&  other)

◆ ObjectPtr() [5/6]

ObjectPtr ( const ObjectPtr< OTHER > &  other)

◆ ObjectPtr() [6/6]

ObjectPtr ( ObjectPtr< OTHER > &&  other)

Member Function Documentation

◆ get() [1/2]

T* get ( )

◆ get() [2/2]

T* get ( ) const

◆ operator!=() [1/4]

bool operator!= ( const ObjectPtr< OTHER > &  other) const

◆ operator!=() [2/4]

bool operator!= ( const ObjectPtr< T > &  other) const

◆ operator!=() [3/4]

bool operator!= ( const OTHER *  ptr) const

◆ operator!=() [4/4]

bool operator!= ( std::nullptr_t  ) const

◆ operator*() [1/2]

T& operator* ( )

◆ operator*() [2/2]

const T& operator* ( ) const

◆ operator->() [1/2]

T* operator-> ( )

◆ operator->() [2/2]

T* operator-> ( ) const

◆ operator<()

bool operator< ( const ObjectPtr< T > &  other) const

◆ operator<=()

bool operator<= ( const ObjectPtr< T > &  other) const

◆ operator=() [1/4]

ObjectPtr<T>& operator= ( const ObjectPtr< OTHER > &  other)

◆ operator=() [2/4]

ObjectPtr<T>& operator= ( const ObjectPtr< T > &  other)

◆ operator=() [3/4]

ObjectPtr<T>& operator= ( ObjectPtr< OTHER > &&  other)

◆ operator=() [4/4]

ObjectPtr<T>& operator= ( ObjectPtr< T > &&  other)

◆ operator==() [1/4]

bool operator== ( const ObjectPtr< OTHER > &  other) const

◆ operator==() [2/4]

bool operator== ( const ObjectPtr< T > &  other) const

◆ operator==() [3/4]

bool operator== ( const OTHER *  ptr) const

◆ operator==() [4/4]

bool operator== ( std::nullptr_t  ) const

◆ operator>()

bool operator> ( const ObjectPtr< T > &  other) const

◆ operator>=()

bool operator>= ( const ObjectPtr< T > &  other) const