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

A smart pointer class ensuring the Qt reference counting for automatic memory management. QtPtr is a template-based smart pointer class that ensures Qt's reference counting manages the lifetime of a dynamically allocated object. When the parent owning an object is destroyed or reset, the managed object is automatically deleted. Additionally, when the observed object is destructed, the object observing will turn null. More...

#include <QtMemory.hpp>

Inheritance diagram for drn::foundation::QtPtr< ObjectType >:
Collaboration diagram for drn::foundation::QtPtr< ObjectType >:

Public Member Functions

 QtPtr (const QtPtr &)=default
 
 QtPtr (const UniqueQtPtr< ObjectType > &observe)
 Constructs a QtPtr that observes a given UniqueQtPtr object.
 
 QtPtr (ObjectType *const observe=nullptr)
 Constructs a QtPtr that observes a given Qt object.
 
 QtPtr (QtPtr &&) noexcept=default
 
 ~QtPtr ()
 Disconnects the Qt connection associated with the pointer if the observed object is derived from QObject.
 
QtPtroperator= (const QtPtr &)=default
 
QtPtroperator= (QtPtr &&) noexcept=default
 
UniqueQtPtr< ObjectType > releaseUnique ()
 Releases the ownership of the Qt object.
 
- Public Member Functions inherited from drn::foundation::ObserverPtr< ObjectType >
 ObserverPtr (const ObserverPtr &)=default
 
 ObserverPtr (const std::unique_ptr< ObjectType > &observe)
 Full initialisation constructor for observing a standard unique pointer.
 
 ObserverPtr (const UniqueQtPtr< ObjectType > &observe)
 Full initialisation constructor for observing a Qt unique pointer.
 
 ObserverPtr (ObjectType *const observe=nullptr)
 Full initialisation constructor for observing a naked pointer.
 
 ObserverPtr (ObserverPtr &&)=default
 
 ~ObserverPtr ()=default
 
ObjectType * 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 ObjectType * () const noexcept
 Conversion operator to the underlying pointer being observed.
 
bool operator!= (const ObjectType *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.
 
ObjectType & operator* ()
 Dereference pointer to the observed pointer. The behaviour is undefined if the observed pointer is null.
 
ObjectType & operator* () const
 Dereference pointer to the observed pointer. The behaviour is undefined if the observed pointer is null.
 
ObjectType * operator-> ()
 Dereference pointer to the observed pointer. The behaviour is undefined if the observed pointer is null.
 
ObjectType * operator-> () const
 Dereference pointer to the observed pointer. The behaviour is undefined if the observed pointer is null.
 
bool operator< (const ObjectType *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= (ObjectType *const observe)
 An assignment operator for setting the object to observe another pointer.
 
ObserverPtroperator= (ObserverPtr &&)=default
 
bool operator== (const ObjectType *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.
 

Additional Inherited Members

- Public Types inherited from drn::foundation::ObserverPtr< ObjectType >
using element_type
 The type the smart pointer is observing.
 
using pointer
 The pointer type the smart pointer is observing.
 

Detailed Description

template<typename ObjectType>
class drn::foundation::QtPtr< ObjectType >

A smart pointer class ensuring the Qt reference counting for automatic memory management. QtPtr is a template-based smart pointer class that ensures Qt's reference counting manages the lifetime of a dynamically allocated object. When the parent owning an object is destroyed or reset, the managed object is automatically deleted. Additionally, when the observed object is destructed, the object observing will turn null.

Template Parameters
ObjectTypeThe type of the object stored.

Constructor & Destructor Documentation

◆ QtPtr() [1/4]

template<typename ObjectType>
drn::foundation::QtPtr< ObjectType >::QtPtr ( ObjectType *const observe = nullptr)

Constructs a QtPtr that observes a given Qt object.

Parameters
observeThe Qt object to be observed.
Here is the caller graph for this function:

◆ QtPtr() [2/4]

template<typename ObjectType>
drn::foundation::QtPtr< ObjectType >::QtPtr ( const UniqueQtPtr< ObjectType > & observe)

Constructs a QtPtr that observes a given UniqueQtPtr object.

Parameters
observeThe unique Qt object to be observed.
Here is the call graph for this function:

◆ QtPtr() [3/4]

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

◆ QtPtr() [4/4]

template<typename ObjectType>
drn::foundation::QtPtr< ObjectType >::QtPtr ( QtPtr< ObjectType > && )
defaultnoexcept
Here is the call graph for this function:

◆ ~QtPtr()

template<typename ObjectType>
drn::foundation::QtPtr< ObjectType >::~QtPtr ( )

Disconnects the Qt connection associated with the pointer if the observed object is derived from QObject.

Here is the call graph for this function:

Member Function Documentation

◆ operator=() [1/2]

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

◆ operator=() [2/2]

template<typename ObjectType>
QtPtr & drn::foundation::QtPtr< ObjectType >::operator= ( QtPtr< ObjectType > && )
defaultnoexcept
Here is the call graph for this function:

◆ releaseUnique()

template<typename ObjectType>
UniqueQtPtr< ObjectType > drn::foundation::QtPtr< ObjectType >::releaseUnique ( )

Releases the ownership of the Qt object.

The method removes the Qt object’s association with its parent, preventing Qt’s internal memory management from automatically deleting the object when the parent is destroyed. The caller is responsible for managing the memory.

Postcondition
The object is disassociated from its parent in the case of Qt objects.
Returns
The object that was released.
Warning
The caller is responsible for managing the memory of the object that is returned.
Here is the call graph for this function:
Here is the caller graph for this function: