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. | |
Polymorphic copy and move through a base.
| T | Interface stored in the pointer. |
| SmartPointer | StormByte::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.
| using StormByte::Safe::Clonable< T, SmartPointer >::PointerType = SmartPointer |
SmartPointer alias.
|
constexprdefault |
Default constructor.
|
constexprdefault |
Copy constructor.
|
constexprdefaultnoexcept |
Move constructor.
|
constexprvirtualdefaultnoexcept |
Destructor.
|
pure virtual |
Deep copy into a new PointerType.
|
static |
Allocates Target on Base's heap and returns it as PointerType.
| Target | Concrete type (T or derived). |
| Args | Constructor argument types. |
| args | Forwarded to Target. |
PointerType.
|
pure virtual |
Moves this object into a new PointerType.
|
constexprdefaultnoexcept |
Move assignment.
|
constexprdefault |
Copy assignment.