xentara-plugin v2.0.3
The Xentara Plugin Framework
Loading...
Searching...
No Matches
xentara::skill::EnableSharedFromThis< Derived > Class Template Reference

A mixin class that enables getting a shared pointer from the this pointer. More...

#include <xentara/skill/EnableSharedFromThis.hpp>

Public Member Functions

constexpr EnableSharedFromThis () noexcept=default
 Default constructor.
 
 EnableSharedFromThis (const EnableSharedFromThis &) noexcept
 Dummy copy constructor that does not copy anything.
 
auto operator= (const EnableSharedFromThis &) noexcept -> EnableSharedFromThis &
 Dummy assignment operator that does nothing.
 
auto sharedFromThis () -> std::shared_ptr< Derived >
 Creates a shared pointer for this object.
 
auto sharedFromThis () const -> std::shared_ptr< const Derived >
 Creates a constant shared pointer for this object.
 
auto weakFromThis () -> std::weak_ptr< Derived >
 Creates a weak pointer for this object.
 
auto weakFromThis () const -> std::weak_ptr< const Derived >
 Creates a constant weak pointer for this object.
 

Protected Member Functions

template<typename Alias >
auto sharedFromThis (Alias *alias) const -> std::shared_ptr< Alias >
 Creates an aliasing shared pointer for an arbitrary alias object.
 

Detailed Description

template<typename Derived>
class xentara::skill::EnableSharedFromThis< Derived >

A mixin class that enables getting a shared pointer from the this pointer.

This class is similar to std::enable_shared_from_this, except that it is designed especially for Xentara skill elements. It works together with xentara::skill::ElementFactory in the same way as std::enable_shared_from_this works together with std::make_shared().

Additionally, this class has a convenience function

Examples
PublishingConfigAttributes.cpp.

Constructor & Destructor Documentation

◆ EnableSharedFromThis() [1/2]

template<typename Derived >
constexpr xentara::skill::EnableSharedFromThis< Derived >::EnableSharedFromThis ( )
constexprdefaultnoexcept

Default constructor.

◆ EnableSharedFromThis() [2/2]

template<typename Derived >
xentara::skill::EnableSharedFromThis< Derived >::EnableSharedFromThis ( const EnableSharedFromThis< Derived > &  )
noexcept

Dummy copy constructor that does not copy anything.

Member Function Documentation

◆ operator=()

template<typename Derived >
auto xentara::skill::EnableSharedFromThis< Derived >::operator= ( const EnableSharedFromThis< Derived > &  ) -> EnableSharedFromThis&
noexcept

Dummy assignment operator that does nothing.

◆ sharedFromThis() [1/3]

template<typename Derived >
auto xentara::skill::EnableSharedFromThis< Derived >::sharedFromThis ( ) -> std::shared_ptr<Derived>

Creates a shared pointer for this object.

◆ sharedFromThis() [2/3]

template<typename Derived >
auto xentara::skill::EnableSharedFromThis< Derived >::sharedFromThis ( ) const -> std::shared_ptr<const Derived>

Creates a constant shared pointer for this object.

◆ sharedFromThis() [3/3]

template<typename Derived >
template<typename Alias >
auto xentara::skill::EnableSharedFromThis< Derived >::sharedFromThis ( Alias *  alias) const -> std::shared_ptr<Alias>
protected

Creates an aliasing shared pointer for an arbitrary alias object.

This function uses the aliasing constructor (8) of std::shared_ptr to create a shared pointer to an arbitrary second object that shares ownership information with this object. This is usually done to create a shared pointer to a member variable of this object.

Parameters
aliasThe alias object that the pointer should point to. The lifetime of the alias object must be at least as least as long as the lifetime of this object.

◆ weakFromThis() [1/2]

template<typename Derived >
auto xentara::skill::EnableSharedFromThis< Derived >::weakFromThis ( ) -> std::weak_ptr<Derived>

Creates a weak pointer for this object.

◆ weakFromThis() [2/2]

template<typename Derived >
auto xentara::skill::EnableSharedFromThis< Derived >::weakFromThis ( ) const -> std::weak_ptr<const Derived>

Creates a constant weak pointer for this object.