MySQL 8.4.2
Source Code Documentation
memory::Ref_ptr< T > Class Template Reference

Class that holds the pointer to a variable in a static and non-destructible way. More...

#include <ref_ptr.h>

Public Member Functions

 Ref_ptr ()=default
 Default class constructor. More...
 
 Ref_ptr (T &target)
 Class constructor that receives the reference to be managed. More...
 
 Ref_ptr (Ref_ptr< T > const &rhs)
 Copy constructor. More...
 
 Ref_ptr (Ref_ptr< T > &&rhs)
 Move constructor. More...
 
virtual ~Ref_ptr ()=default
 Default destructor. More...
 
Ref_ptr< T > & operator= (T &rhs)
 Assignment operator to instantiate the reference to be managed. More...
 
Ref_ptr< T > & operator= (Ref_ptr< T > const &rhs)
 Copy operator. More...
 
Ref_ptr< T > & operator= (Ref_ptr< T > &&rhs)
 Move operator. More...
 
bool operator! () const
 Negation operator. More...
 
T * operator-> () const
 Arrow operator to access the underlying object of type T. More...
 
T & operator* () const
 Star operator to access the underlying object of type T. More...
 
Ref_ptr< T > & reset ()
 Resets the managed reference and stops managing any pointer. More...
 
bool operator== (std::nullptr_t rhs) const
 Equality to nullptr operator. More...
 
bool operator!= (std::nullptr_t rhs) const
 Inequality to nullptr operator. More...
 
template<typename R >
bool operator== (memory::Ref_ptr< R > const &rhs) const
 Equality operator. More...
 
template<typename R >
bool operator!= (memory::Ref_ptr< R > const &rhs) const
 Inequality operator. More...
 

Private Attributes

T * m_underlying {nullptr}
 The reference to be managed. More...
 

Detailed Description

template<typename T>
class memory::Ref_ptr< T >

Class that holds the pointer to a variable in a static and non-destructible way.

The purpose is both to clearly state the ownership of the memory being pointed to and to avoid unwanted pointer operations (a delete on a pointer pointing to a stack memory block, for instance).

It's a convenience class for clearly stating the ownership of the underlying pointer and is used for interface and code clarity.

Constructor & Destructor Documentation

◆ Ref_ptr() [1/4]

template<typename T >
memory::Ref_ptr< T >::Ref_ptr ( )
default

Default class constructor.

◆ Ref_ptr() [2/4]

template<typename T >
memory::Ref_ptr< T >::Ref_ptr ( T &  target)

Class constructor that receives the reference to be managed.

Parameters
targetThe reference to be managed.

◆ Ref_ptr() [3/4]

template<typename T >
memory::Ref_ptr< T >::Ref_ptr ( memory::Ref_ptr< T > const &  rhs)

Copy constructor.

Parameters
rhsThe object to copy from.

◆ Ref_ptr() [4/4]

template<typename T >
memory::Ref_ptr< T >::Ref_ptr ( memory::Ref_ptr< T > &&  rhs)

Move constructor.

Parameters
rhsThe object to move from.

◆ ~Ref_ptr()

template<typename T >
virtual memory::Ref_ptr< T >::~Ref_ptr ( )
virtualdefault

Default destructor.

Member Function Documentation

◆ operator!()

template<typename T >
bool memory::Ref_ptr< T >::operator!

Negation operator.

Returns
true if there is no managed reference, false otherwise.

◆ operator!=() [1/2]

template<typename T >
template<typename R >
bool memory::Ref_ptr< T >::operator!= ( memory::Ref_ptr< R > const &  rhs) const

Inequality operator.

Parameters
rhsThe object to compare to.
Returns
true if the managed reference is not the same as one managed by the rhs object.

◆ operator!=() [2/2]

template<typename T >
bool memory::Ref_ptr< T >::operator!= ( std::nullptr_t  rhs) const

Inequality to nullptr operator.

Parameters
rhsnullptr value
Returns
false if the managed reference is not instantiated.

◆ operator*()

template<typename T >
T & memory::Ref_ptr< T >::operator*

Star operator to access the underlying object of type T.

Returns
A reference to the underlying object of type T.

◆ operator->()

template<typename T >
T * memory::Ref_ptr< T >::operator->

Arrow operator to access the underlying object of type T.

Returns
A pointer to the underlying object of type T.

◆ operator=() [1/3]

template<typename T >
memory::Ref_ptr< T > & memory::Ref_ptr< T >::operator= ( memory::Ref_ptr< T > &&  rhs)

Move operator.

Parameters
rhsThe object to move from.
Returns
A reference to this object.

◆ operator=() [2/3]

template<typename T >
memory::Ref_ptr< T > & memory::Ref_ptr< T >::operator= ( memory::Ref_ptr< T > const &  rhs)

Copy operator.

Parameters
rhsThe object to copy from.
Returns
A reference to this object.

◆ operator=() [3/3]

template<typename T >
memory::Ref_ptr< T > & memory::Ref_ptr< T >::operator= ( T &  rhs)

Assignment operator to instantiate the reference to be managed.

Parameters
rhsThe reference to be managed.
Returns
A reference to this object.

◆ operator==() [1/2]

template<typename T >
template<typename R >
bool memory::Ref_ptr< T >::operator== ( memory::Ref_ptr< R > const &  rhs) const

Equality operator.

Parameters
rhsThe object to compare to.
Returns
true if the managed reference is the same as one managed by the rhs object.

◆ operator==() [2/2]

template<typename T >
bool memory::Ref_ptr< T >::operator== ( std::nullptr_t  rhs) const

Equality to nullptr operator.

Parameters
rhsnullptr value
Returns
true if the managed reference is not instantiated.

◆ reset()

template<typename T >
memory::Ref_ptr< T > & memory::Ref_ptr< T >::reset ( void  )

Resets the managed reference and stops managing any pointer.

Returns
A reference to this object, for chaining purposes.

Member Data Documentation

◆ m_underlying

template<typename T >
T* memory::Ref_ptr< T >::m_underlying {nullptr}
private

The reference to be managed.


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