StormByte 2.0.0
C++26 foundation of the StormByte suite
 
Loading...
Searching...
No Matches
StormByte::Safe::Clonable< T, SmartPointer > Class Template Referenceabstract

Polymorphic copy and move through a base. More...

#include <StormByte/safe/clonable.hxx>

Public Types

using PointerType = SmartPointer
 SmartPointer alias.
 

Public Member Functions

constexpr Clonable ()=default
 Default constructor.
 
constexpr Clonable (const Clonable &)=default
 Copy constructor.
 
constexpr Clonable (Clonable &&) noexcept=default
 Move constructor.
 
constexpr Clonable & operator= (const Clonable &)=default
 Copy assignment.
 
constexpr Clonable & operator= (Clonable &&) noexcept=default
 Move assignment.
 
virtual constexpr ~Clonable () noexcept=default
 Destructor.
 
virtual PointerType Clone () const =0
 Deep copy into a new PointerType.
 
virtual PointerType Move ()=0
 Moves this object into a new PointerType.
 

Static Public Member Functions

template<class Target , typename... Args>
static PointerType MakePointer (Args &&... args)
 Allocates Target on Base's heap and returns it as PointerType.
 

Detailed Description

template<class T, typename SmartPointer = Shared<T>>
requires ValidSmartPointer<SmartPointer, T>
class StormByte::Safe::Clonable< T, SmartPointer >

Polymorphic copy and move through a base.

Template Parameters
TInterface stored in the pointer.
SmartPointerStormByte::Safe::Shared<T> (default) or StormByte::Safe::Unique<T>.

Not an owner. StormByte::Safe::Shared<T> and StormByte::Safe::Unique<T> own the object on Base's heap. Clonable is the interface: Clone and Move return that owner for the dynamic type, so the caller does not name the derived class. MakePointer forwards to Shared::MakePointer or Unique::MakePointer.

Clonable<T> is Clonable<T, Shared<T>>. Unique ownership is Clonable<T, Unique<T>>. std::shared_ptr and std::unique_ptr are not a PointerType.

Safe to derive from in another DLL. Storage goes through the exported Heap::Allocate / Heap::Free, so it is always Base's heap. Every module instantiates its own Clonable<T> (vtable and typeinfo); STORMBYTE_PUBLIC_TYPE gives those copies default visibility on ELF and Mach-O, so dynamic_cast and typeid agree across modules even when the deriving module builds with hidden visibility (on ELF the loader also merges them into one object). T must be exported by its own module.

Member Typedef Documentation

◆ PointerType

template<class T , typename SmartPointer = Shared<T>>
using StormByte::Safe::Clonable< T, SmartPointer >::PointerType = SmartPointer

SmartPointer alias.

Constructor & Destructor Documentation

◆ Clonable() [1/3]

template<class T , typename SmartPointer = Shared<T>>
constexpr StormByte::Safe::Clonable< T, SmartPointer >::Clonable ( )
constexprdefault

Default constructor.

◆ Clonable() [2/3]

template<class T , typename SmartPointer = Shared<T>>
constexpr StormByte::Safe::Clonable< T, SmartPointer >::Clonable ( const Clonable< T, SmartPointer > &  )
constexprdefault

Copy constructor.

◆ Clonable() [3/3]

template<class T , typename SmartPointer = Shared<T>>
constexpr StormByte::Safe::Clonable< T, SmartPointer >::Clonable ( Clonable< T, SmartPointer > &&  )
constexprdefaultnoexcept

Move constructor.

◆ ~Clonable()

template<class T , typename SmartPointer = Shared<T>>
virtual constexpr StormByte::Safe::Clonable< T, SmartPointer >::~Clonable ( )
constexprvirtualdefaultnoexcept

Destructor.

Member Function Documentation

◆ Clone()

template<class T , typename SmartPointer = Shared<T>>
virtual PointerType StormByte::Safe::Clonable< T, SmartPointer >::Clone ( ) const
pure virtual

Deep copy into a new PointerType.

Returns
Owning pointer to the clone.

◆ MakePointer()

template<class T , typename SmartPointer = Shared<T>>
template<class Target , typename... Args>
static PointerType StormByte::Safe::Clonable< T, SmartPointer >::MakePointer ( Args &&...  args)
static

Allocates Target on Base's heap and returns it as PointerType.

Template Parameters
TargetConcrete type (T or derived).
ArgsConstructor argument types.
Parameters
argsForwarded to Target.
Returns
StormByte::Safe::Shared<T> or StormByte::Safe::Unique<T> according to PointerType.

◆ Move()

template<class T , typename SmartPointer = Shared<T>>
virtual PointerType StormByte::Safe::Clonable< T, SmartPointer >::Move ( )
pure virtual

Moves this object into a new PointerType.

Returns
Owning pointer to the moved instance.

◆ operator=() [1/2]

template<class T , typename SmartPointer = Shared<T>>
constexpr Clonable & StormByte::Safe::Clonable< T, SmartPointer >::operator= ( Clonable< T, SmartPointer > &&  )
constexprdefaultnoexcept

Move assignment.

◆ operator=() [2/2]

template<class T , typename SmartPointer = Shared<T>>
constexpr Clonable & StormByte::Safe::Clonable< T, SmartPointer >::operator= ( const Clonable< T, SmartPointer > &  )
constexprdefault

Copy assignment.


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