DuxReiNummariae 1.0.0-alpha.23
Simple and powerful budgeting application
 
Loading...
Searching...
No Matches
drn::foundation::ObserverPtr< ObservedType > Class Template Reference

A smart pointer for observing another pointer. This means that it preforms no memory management on the lifetime of the observed pointer. This functionally acts as a marker for other developers that this pointer's does not need to be managed nor can it be accidentally deleted. More...

#include <ObserverPtr.hpp>

Inheritance diagram for drn::foundation::ObserverPtr< ObservedType >:
Collaboration diagram for drn::foundation::ObserverPtr< ObservedType >:

Public Types

using element_type = ObservedType
 The type the smart pointer is observing.
 
using pointer = ObservedType*
 The pointer type the smart pointer is observing.
 

Public Member Functions

 ObserverPtr (const ObserverPtr &)=default
 
 ObserverPtr (const std::unique_ptr< ObservedType > &observe)
 Full initialisation constructor for observing a standard unique pointer.
 
 ObserverPtr (const UniqueQtPtr< ObservedType > &observe)
 Full initialisation constructor for observing a Qt unique pointer.
 
 ObserverPtr (ObservedType *const observe=nullptr)
 Full initialisation constructor for observing a naked pointer.
 
 ObserverPtr (ObserverPtr &&)=default
 
 ~ObserverPtr ()=default
 
ObservedType * get () const noexcept
 An accessor to the underlying pointer being observed.
 
 operator bool () const noexcept
 Determines if this object is observing a pointer.
 
void operator delete (void *)=delete
 
 operator ObservedType * () const noexcept
 Conversion operator to the underlying pointer being observed.
 
bool operator!= (const ObservedType *observed) const
 Inequality operator for testing if this object points to another specified pointer.
 
bool operator!= (const ObserverPtr &other) const
 Inequality operator for testing if this object points to another specified pointer.
 
bool operator!= (const std::nullptr_t) const
 Inequality operator for testing if this object points to null.
 
ObservedType & operator* ()
 Dereference pointer to the observed pointer. The behaviour is undefined if the observed pointer is null.
 
ObservedType & operator* () const
 Dereference pointer to the observed pointer. The behaviour is undefined if the observed pointer is null.
 
ObservedType * operator-> ()
 Dereference pointer to the observed pointer. The behaviour is undefined if the observed pointer is null.
 
ObservedType * operator-> () const
 Dereference pointer to the observed pointer. The behaviour is undefined if the observed pointer is null.
 
bool operator< (const ObservedType *observed) const
 Less-than operator for testing if the address observed by this object appears before another specified naked pointer's address.
 
bool operator< (const ObserverPtr &other) const
 Less-than operator for testing if the address observed by this object appears before another specified pointer's address.
 
ObserverPtroperator= (const ObserverPtr &)=default
 
ObserverPtroperator= (const std::nullptr_t)
 An assignment operator for setting the object to be null.
 
ObserverPtroperator= (ObservedType *const observe)
 An assignment operator for setting the object to observe another pointer.
 
ObserverPtroperator= (ObserverPtr &&)=default
 
bool operator== (const ObservedType *observed) const
 Equality operator for testing if this object points to another specified pointer.
 
bool operator== (const ObserverPtr &other) const
 Equality operator for testing if this object points to another specified pointer.
 
bool operator== (const std::nullptr_t) const
 Equality operator for testing if this object points to null.
 

Detailed Description

template<typename ObservedType>
class drn::foundation::ObserverPtr< ObservedType >

A smart pointer for observing another pointer. This means that it preforms no memory management on the lifetime of the observed pointer. This functionally acts as a marker for other developers that this pointer's does not need to be managed nor can it be accidentally deleted.

@tparm ObservedType The type the smart pointer is observing.

Member Typedef Documentation

◆ element_type

template<typename ObservedType>
using drn::foundation::ObserverPtr< ObservedType >::element_type = ObservedType

The type the smart pointer is observing.

◆ pointer

template<typename ObservedType>
using drn::foundation::ObserverPtr< ObservedType >::pointer = ObservedType*

The pointer type the smart pointer is observing.

Constructor & Destructor Documentation

◆ ObserverPtr() [1/5]

template<typename ObservedType>
drn::foundation::ObserverPtr< ObservedType >::ObserverPtr ( ObservedType *const observe = nullptr)

Full initialisation constructor for observing a naked pointer.

Parameters
observeThe pointer that is to be observed.
Here is the caller graph for this function:

◆ ObserverPtr() [2/5]

template<typename ObservedType>
drn::foundation::ObserverPtr< ObservedType >::ObserverPtr ( const std::unique_ptr< ObservedType > & observe)

Full initialisation constructor for observing a standard unique pointer.

Parameters
observeThe pointer that is to be observed.

◆ ObserverPtr() [3/5]

template<typename ObservedType>
drn::foundation::ObserverPtr< ObservedType >::ObserverPtr ( const UniqueQtPtr< ObservedType > & observe)

Full initialisation constructor for observing a Qt unique pointer.

Parameters
observeThe pointer that is to be observed.

◆ ObserverPtr() [4/5]

template<typename ObservedType>
drn::foundation::ObserverPtr< ObservedType >::ObserverPtr ( const ObserverPtr< ObservedType > & )
default
Here is the call graph for this function:

◆ ObserverPtr() [5/5]

template<typename ObservedType>
drn::foundation::ObserverPtr< ObservedType >::ObserverPtr ( ObserverPtr< ObservedType > && )
default
Here is the call graph for this function:

◆ ~ObserverPtr()

template<typename ObservedType>
drn::foundation::ObserverPtr< ObservedType >::~ObserverPtr ( )
default

Member Function Documentation

◆ get()

template<typename ObservedType>
ObservedType * drn::foundation::ObserverPtr< ObservedType >::get ( ) const
noexcept

An accessor to the underlying pointer being observed.

Returns
The pointer being observed.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator bool()

template<typename ObservedType>
drn::foundation::ObserverPtr< ObservedType >::operator bool ( ) const
explicitnoexcept

Determines if this object is observing a pointer.

Returns
True when this object is not null, false otherwise.

◆ operator delete()

template<typename ObservedType>
void drn::foundation::ObserverPtr< ObservedType >::operator delete ( void * )
delete

◆ operator ObservedType *()

template<typename ObservedType>
drn::foundation::ObserverPtr< ObservedType >::operator ObservedType * ( ) const
explicitnoexcept

Conversion operator to the underlying pointer being observed.

Returns
The pointer being observed.

◆ operator!=() [1/3]

template<typename ObservedType>
bool drn::foundation::ObserverPtr< ObservedType >::operator!= ( const ObservedType * observed) const

Inequality operator for testing if this object points to another specified pointer.

Parameters
observedThe other observed pointer to compare against.
Returns
True when both pointers do not point to the same address, false otherwise.

◆ operator!=() [2/3]

template<typename ObservedType>
bool drn::foundation::ObserverPtr< ObservedType >::operator!= ( const ObserverPtr< ObservedType > & other) const

Inequality operator for testing if this object points to another specified pointer.

Parameters
otherThe other observed pointer to compare against.
Returns
True when both pointers do not point to the same address, false otherwise.
Here is the call graph for this function:

◆ operator!=() [3/3]

template<typename ObservedType>
bool drn::foundation::ObserverPtr< ObservedType >::operator!= ( const std::nullptr_t ) const

Inequality operator for testing if this object points to null.

Returns
True when the object it points to is not null, false otherwise.

◆ operator*() [1/2]

template<typename ObservedType>
ObservedType & drn::foundation::ObserverPtr< ObservedType >::operator* ( )

Dereference pointer to the observed pointer. The behaviour is undefined if the observed pointer is null.

Returns
The pointer being observed.

◆ operator*() [2/2]

template<typename ObservedType>
ObservedType & drn::foundation::ObserverPtr< ObservedType >::operator* ( ) const

Dereference pointer to the observed pointer. The behaviour is undefined if the observed pointer is null.

Returns
The pointer being observed.

◆ operator->() [1/2]

template<typename ObservedType>
ObservedType * drn::foundation::ObserverPtr< ObservedType >::operator-> ( )

Dereference pointer to the observed pointer. The behaviour is undefined if the observed pointer is null.

Returns
The pointer being observed.

◆ operator->() [2/2]

template<typename ObservedType>
ObservedType * drn::foundation::ObserverPtr< ObservedType >::operator-> ( ) const

Dereference pointer to the observed pointer. The behaviour is undefined if the observed pointer is null.

Returns
The pointer being observed.

◆ operator<() [1/2]

template<typename ObservedType>
bool drn::foundation::ObserverPtr< ObservedType >::operator< ( const ObservedType * observed) const

Less-than operator for testing if the address observed by this object appears before another specified naked pointer's address.

Parameters
observedThe observed pointer to compare against.
Returns
True when this object's address is less-than the address of the supplied pointer's address, false otherwise.

◆ operator<() [2/2]

template<typename ObservedType>
bool drn::foundation::ObserverPtr< ObservedType >::operator< ( const ObserverPtr< ObservedType > & other) const

Less-than operator for testing if the address observed by this object appears before another specified pointer's address.

Parameters
otherThe observed pointer to compare against.
Returns
True when this object's address is less-than the address of the supplied pointer's address, false otherwise.
Here is the call graph for this function:

◆ operator=() [1/4]

template<typename ObservedType>
ObserverPtr & drn::foundation::ObserverPtr< ObservedType >::operator= ( const ObserverPtr< ObservedType > & )
default
Here is the call graph for this function:

◆ operator=() [2/4]

template<typename ObservedType>
ObserverPtr & drn::foundation::ObserverPtr< ObservedType >::operator= ( const std::nullptr_t )

An assignment operator for setting the object to be null.

Returns
The current object.
Here is the call graph for this function:

◆ operator=() [3/4]

template<typename ObservedType>
ObserverPtr & drn::foundation::ObserverPtr< ObservedType >::operator= ( ObservedType *const observe)

An assignment operator for setting the object to observe another pointer.

Parameters
observeThe pointer that is to be observed.
Returns
The current object.
Here is the call graph for this function:

◆ operator=() [4/4]

template<typename ObservedType>
ObserverPtr & drn::foundation::ObserverPtr< ObservedType >::operator= ( ObserverPtr< ObservedType > && )
default
Here is the call graph for this function:

◆ operator==() [1/3]

template<typename ObservedType>
bool drn::foundation::ObserverPtr< ObservedType >::operator== ( const ObservedType * observed) const

Equality operator for testing if this object points to another specified pointer.

Parameters
observedThe other observed pointer to compare against.
Returns
True when both pointers point to the same address, false otherwise.

◆ operator==() [2/3]

template<typename ObservedType>
bool drn::foundation::ObserverPtr< ObservedType >::operator== ( const ObserverPtr< ObservedType > & other) const

Equality operator for testing if this object points to another specified pointer.

Parameters
otherThe other observed pointer to compare against.
Returns
True when both pointers point to the same address, false otherwise.
Here is the call graph for this function:

◆ operator==() [3/3]

template<typename ObservedType>
bool drn::foundation::ObserverPtr< ObservedType >::operator== ( const std::nullptr_t ) const

Equality operator for testing if this object points to null.

Returns
True when the object it points to is null, false otherwise.