API Documentation
Public Member Functions | List of all members
nkMemory::UniquePtr< T > Class Template Reference

Smart pointer owning the object instance it encapsulates. More...

Public Member Functions

 UniquePtr () noexcept
 
 UniquePtr (T *data) noexcept
 
template<typename U , typename = std::enable_if_t<std::is_base_of_v<T, U>>>
 UniquePtr (U *data) noexcept
 
 UniquePtr (const UniquePtr< T > &other)=delete
 
 UniquePtr (UniquePtr< T > &&other) noexcept
 
template<typename U , typename = std::enable_if_t<std::is_base_of_v<T, U>>>
 UniquePtr (UniquePtr< U > &&other) noexcept
 
 ~UniquePtr ()
 
T * get () const
 
bool empty () const
 
T * release ()
 
void reset (T *data=nullptr)
 
T & operator* ()
 
const T & operator* () const
 
T * operator-> ()
 
const T * operator-> () const
 
UniquePtr< T > & operator= (const UniquePtr< T > &other)=delete
 
UniquePtr< T > & operator= (UniquePtr< T > &&other) noexcept
 
 operator bool () const
 
bool operator! () const
 
 operator std::unique_ptr< T > ()
 
template<typename U , typename = std::enable_if_t<std::is_base_of_v<U, T>>>
 operator std::unique_ptr< U > ()
 
 UniquePtr (std::unique_ptr< T > stdPtr) noexcept
 
template<typename U , typename = std::enable_if_t<std::is_base_of_v<T, U>>>
 UniquePtr (std::unique_ptr< U > stdPtr) noexcept
 

Detailed Description

template<typename T>
class nkMemory::UniquePtr< T >

Smart pointer owning the object instance it encapsulates.

Globally, this is an equivalent of an std::unique_ptr. However, the aim is not to replace the use of the standard unique pointer in client code, but rather offer a safe way to transfer them to the engine through the method arguments. Its use should be transparent and emulate the way a unique_ptr is normally used.

Constructor & Destructor Documentation

◆ UniquePtr() [1/8]

template<typename T >
nkMemory::UniquePtr< T >::UniquePtr ( )
noexcept

Empty constructor.

◆ UniquePtr() [2/8]

template<typename T >
nkMemory::UniquePtr< T >::UniquePtr ( T *  data)
noexcept

Raw pointer constructor.

Parameters
dataThe pointer to take ownership of.
Remarks
The pointer passed will now be owned by the instance of the UniquePtr. As such, it will be deleted at the end of its lifetime.

◆ UniquePtr() [3/8]

template<typename T >
template<typename U , typename = std::enable_if_t<std::is_base_of_v<T, U>>>
nkMemory::UniquePtr< T >::UniquePtr ( U *  data)
noexcept

Raw pointer constructor, enabled for classes / structures for which the template typename is a base of the passed pointer instance.

Parameters
dataThe pointer to take ownership of.
Remarks
The pointer passed will now be owned by the instance of the UniquePtr. As such, it will be deleted at the end of its lifetime.

◆ UniquePtr() [4/8]

template<typename T >
nkMemory::UniquePtr< T >::UniquePtr ( const UniquePtr< T > &  other)
delete

Copy constructor not allowed, as ownership cannot be shared.

Parameters
other

◆ UniquePtr() [5/8]

template<typename T >
nkMemory::UniquePtr< T >::UniquePtr ( UniquePtr< T > &&  other)
noexcept

Move constructor.

Parameters
otherThe other pointer to move from.

◆ UniquePtr() [6/8]

template<typename T >
template<typename U , typename = std::enable_if_t<std::is_base_of_v<T, U>>>
nkMemory::UniquePtr< T >::UniquePtr ( UniquePtr< U > &&  other)
noexcept

Move constructor, enabled for classes / structures for which the template typename is a base of the passed pointer instance.

Parameters
otherThe other pointer to move from.

◆ ~UniquePtr()

template<typename T >
nkMemory::UniquePtr< T >::~UniquePtr ( )

Destructor.

◆ UniquePtr() [7/8]

template<typename T >
nkMemory::UniquePtr< T >::UniquePtr ( std::unique_ptr< T >  stdPtr)
noexcept

Constructor from a standard unique_ptr implementation.

Parameters
stdPtrThe pointer to move over.

◆ UniquePtr() [8/8]

template<typename T >
template<typename U , typename = std::enable_if_t<std::is_base_of_v<T, U>>>
nkMemory::UniquePtr< T >::UniquePtr ( std::unique_ptr< U >  stdPtr)
noexcept

Constructor from a standard unique_ptr implementation. Version enabled to support inheritance and conversion to a base type for the contained instance.

Parameters
stdPtrThe pointer to move over.

Member Function Documentation

◆ get()

template<typename T >
T* nkMemory::UniquePtr< T >::get ( ) const
Returns
The instance owned's raw pointer.
Remarks
Given the UniquePtr instance still keeps ownership of the pointer, the client code should not delete the returned pointer.

◆ empty()

template<typename T >
bool nkMemory::UniquePtr< T >::empty ( ) const
Returns
Whether the pointer is nullptr (true) or not (false).

◆ release()

template<typename T >
T* nkMemory::UniquePtr< T >::release ( )

Releases the contained instance, along with its ownership, without deleting it.

◆ reset()

template<typename T >
void nkMemory::UniquePtr< T >::reset ( T *  data = nullptr)

Resets the held instance with the one provided as a parameter, deleting the old one in the process.

Parameters
dataThe new pointer to the data to wrap.

◆ operator*() [1/2]

template<typename T >
T& nkMemory::UniquePtr< T >::operator* ( )

Star operator for direct access to the instance.

Returns
A reference over the instance contained.

◆ operator*() [2/2]

template<typename T >
const T& nkMemory::UniquePtr< T >::operator* ( ) const

Star operator for direct access to the instance, const version.

Returns
A const reference over the instance contained.

◆ operator->() [1/2]

template<typename T >
T* nkMemory::UniquePtr< T >::operator-> ( )

Arrow operator for direct access to the instance.

Returns
The underlying pointer to address.

◆ operator->() [2/2]

template<typename T >
const T* nkMemory::UniquePtr< T >::operator-> ( ) const

Arrow operator for direct access to the instance, const version.

Returns
The underlying pointer to address.

◆ operator=() [1/2]

template<typename T >
UniquePtr<T>& nkMemory::UniquePtr< T >::operator= ( const UniquePtr< T > &  other)
delete

Copy assignment operator is unavailable, as ownership can't be shared.

Parameters
other
Returns

◆ operator=() [2/2]

template<typename T >
UniquePtr<T>& nkMemory::UniquePtr< T >::operator= ( UniquePtr< T > &&  other)
noexcept

Move assignment operator.

Parameters
otherThe other pointer to copy from.
Returns
The reference over the updated calling instance.

◆ operator bool()

template<typename T >
nkMemory::UniquePtr< T >::operator bool ( ) const

Bool conversion operator. Equivalent of the empty method, returning false if the pointer is nullptr, true otherwise.

◆ operator!()

template<typename T >
bool nkMemory::UniquePtr< T >::operator! ( ) const

Not operator, negating the bool conversion operator.

Returns
The negated bool conversion, true if nullptr, false otherwise.

◆ operator std::unique_ptr< T >()

template<typename T >
nkMemory::UniquePtr< T >::operator std::unique_ptr< T > ( )

Conversion operator, to the standard unique_ptr implementation.

◆ operator std::unique_ptr< U >()

template<typename T >
template<typename U , typename = std::enable_if_t<std::is_base_of_v<U, T>>>
nkMemory::UniquePtr< T >::operator std::unique_ptr< U > ( )

Conversion operator, to the standard unique_ptr implementation. Version enabled to support inheritance and conversion to a base type for the contained instance.


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