HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Friends
v1::group_ptr< T > Class Template Reference

#include <hikogui/observer/group_ptr.hpp>

Public Types

using notify_proto = T::_enable_group_ptr_notify_proto
 
using element_type = T
 

Public Member Functions

virtual ~group_ptr ()
 Destroy this group_ptr.
 
 group_ptr (group_ptr const &other) noexcept
 Copy construct from another group_ptr.
 
group_ptroperator= (group_ptr const &other) noexcept
 Copy assign from another group_ptr.
 
 group_ptr (group_ptr &&other) noexcept
 Move construct from another group_ptr.
 
group_ptroperator= (group_ptr &&other) noexcept
 Move assign from another group_ptr.
 
constexpr group_ptr () noexcept=default
 Construct an empty group_ptr.
 
constexpr group_ptr (std::nullptr_t) noexcept
 Construct an empty group_ptr.
 
void reset () noexcept
 Reset the group_ptr and make it empty.
 
template<forward_of< std::shared_ptr< enable_group_ptr< T, notify_proto > > > Ptr>
 group_ptr (Ptr &&ptr) noexcept
 Construct a group_ptr from a shared_ptr.
 
template<forward_of< std::shared_ptr< enable_group_ptr< T, notify_proto > > > Ptr>
group_ptroperator= (Ptr &&ptr) noexcept
 Construct a group_ptr from a shared_ptr.
 
T * get () const noexcept
 Get the pointer to the object that this group_ptr owns.
 
T * operator-> () const noexcept
 Dereference to member of the object that is owned by this group_ptr.
 
T & operator* () const noexcept
 Dereference the object that is owned by this group_ptr.
 
 operator bool () const noexcept
 Check if this group_ptr is not empty.
 
template<forward_of< notify_proto > Func>
void subscribe (Func &&func) noexcept
 Subscribe a callback function.
 
void unsubscribe () noexcept
 Unsubscribe the callback function.
 

Friends

class enable_group_ptr< T, notify_proto >
 

Detailed Description

template<typename T>
class v1::group_ptr< T >

A smart pointer which manages ownership as a group.

When group_ptrs are assigned to one another they will act as a group from this point forward. When a std::shared_ptr is as assigned to a group_ptr it will now be assigned to each group_ptr in this group.

You can unlink a group_ptr from others in the group only by reset(), assigning an empty std::shared_ptr, assigning a nullptr or move-assignment/construction.

Template Parameters
Sthe type containing the group_ptr.
Tthe type that the group_ptr is pointing at.

Constructor & Destructor Documentation

◆ ~group_ptr()

template<typename T >
virtual v1::group_ptr< T >::~group_ptr ( )
inlinevirtual

Destroy this group_ptr.

◆ group_ptr() [1/5]

template<typename T >
v1::group_ptr< T >::group_ptr ( group_ptr< T > const & other)
inlinenoexcept

Copy construct from another group_ptr.

This function will:

  • copy the std::shared_ptr from other.
  • join in the group with other.
  • make the callback subscription empty.
Parameters
otherThe other group_ptr to copy.

◆ group_ptr() [2/5]

template<typename T >
v1::group_ptr< T >::group_ptr ( group_ptr< T > && other)
inlinenoexcept

Move construct from another group_ptr.

This function will:

  • move the std::shared_ptr from other.
  • join in the group with other.
  • other leaves the group.
  • make the callback subscription empty.
Parameters
otherThe other group_ptr to copy.

◆ group_ptr() [3/5]

template<typename T >
constexpr v1::group_ptr< T >::group_ptr ( )
constexprdefaultnoexcept

Construct an empty group_ptr.

◆ group_ptr() [4/5]

template<typename T >
constexpr v1::group_ptr< T >::group_ptr ( std::nullptr_t )
inlineconstexprnoexcept

Construct an empty group_ptr.

◆ group_ptr() [5/5]

template<typename T >
template<forward_of< std::shared_ptr< enable_group_ptr< T, notify_proto > > > Ptr>
v1::group_ptr< T >::group_ptr ( Ptr && ptr)
inlinenoexcept

Construct a group_ptr from a shared_ptr.

Parameters
ptrAn object that is convertible to a std::shared_ptr pointing to and object that is compatible with this group_ptr.

This function will not reset the subscription of a callback.

Member Function Documentation

◆ get()

template<typename T >
T * v1::group_ptr< T >::get ( ) const
inlinenoexcept

Get the pointer to the object that this group_ptr owns.

Returns
The pointer to object that this group_ptr owns. Or nullptr if the group_ptr is empty.

◆ operator bool()

template<typename T >
v1::group_ptr< T >::operator bool ( ) const
inlineexplicitnoexcept

Check if this group_ptr is not empty.

Return values
trueWhen this group_ptr is not empty.
falseWhen this group_ptr is not empty.

◆ operator*()

template<typename T >
T & v1::group_ptr< T >::operator* ( ) const
inlinenoexcept

Dereference the object that is owned by this group_ptr.

Note
It is undefined behavior to dereference an empty group_ptr.
Returns
A non-const reference to the object that is owned by this group_ptr.

◆ operator->()

template<typename T >
T * v1::group_ptr< T >::operator-> ( ) const
inlinenoexcept

Dereference to member of the object that is owned by this group_ptr.

Note
It is undefined behavior to dereference an empty group_ptr.
Returns
A non-const pointer to the object that is owned by this group_ptr.

◆ operator=() [1/3]

template<typename T >
group_ptr & v1::group_ptr< T >::operator= ( group_ptr< T > && other)
inlinenoexcept

Move assign from another group_ptr.

If other is non-empty this function will:

  • assign the pointer from other to all members of the group.
  • all members of the group will join the group of other.
  • other will leave the group.
  • leave the callback subscription as-is.

If other is empty this function will:

  • leave the group.
  • make the pointer empty.
  • leave the callback subscription as-is.
Parameters
otherThe other group_ptr to copy.
Returns
a reference to this.

◆ operator=() [2/3]

template<typename T >
group_ptr & v1::group_ptr< T >::operator= ( group_ptr< T > const & other)
inlinenoexcept

Copy assign from another group_ptr.

If other is non-empty this function will:

  • assign the pointer from other to all members of the group.
  • all members of the group will join the group of other.
  • leave the callback subscription as-is.

If other is empty this function will:

  • leave the group.
  • make the pointer empty.
  • leave the callback subscription as-is.
Parameters
otherThe other group_ptr to copy.
Returns
a reference to this.

◆ operator=() [3/3]

template<typename T >
template<forward_of< std::shared_ptr< enable_group_ptr< T, notify_proto > > > Ptr>
group_ptr & v1::group_ptr< T >::operator= ( Ptr && ptr)
inlinenoexcept

Construct a group_ptr from a shared_ptr.

Parameters
ptrAn object that is convertible to a std::shared_ptr pointing to and object that is compatible with this group_ptr. If the shared_ptr is empty it will perform the same function as reset().

This function will not reset the subscription of a callback.

◆ reset()

template<typename T >
void v1::group_ptr< T >::reset ( )
inlinenoexcept

Reset the group_ptr and make it empty.

This function will unlink the group_ptr from other group_ptrs.

This function will not reset the subscription of a callback.

◆ subscribe()

template<typename T >
template<forward_of< notify_proto > Func>
void v1::group_ptr< T >::subscribe ( Func && func)
inlinenoexcept

Subscribe a callback function.

The subscribed callback function can be called by the notify_group_ptr() function of the object that is owned by the group_ptr.

Only a single function can be subscribed. This function will overwrite a previous subscribed function.

Parameters
funcA function object corresponding to the notify_proto prototype.

◆ unsubscribe()

template<typename T >
void v1::group_ptr< T >::unsubscribe ( )
inlinenoexcept

Unsubscribe the callback function.


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