DuxReiNummariae 1.1.0-alpha.19
Simple and powerful budgeting application
Loading...
Searching...
No Matches
drn::foundation::Clonable< BaseType, DerivedType > Struct Template Reference

Interface for creating polymorphic deep-copyable objects. More...

#include <Mixins.hpp>

Inheritance diagram for drn::foundation::Clonable< BaseType, DerivedType >:
Collaboration diagram for drn::foundation::Clonable< BaseType, DerivedType >:

Public Member Functions

std::shared_ptr< BaseType > cloneShared (const DerivedType &toClone) const
 Creates a shared polymorphic deep copy of the specified object.
std::unique_ptr< BaseType > cloneUnique (const DerivedType &toClone) const
 Creates a unique polymorphic deep copy of the specified object.

Detailed Description

template<typename BaseType, typename DerivedType>
struct drn::foundation::Clonable< BaseType, DerivedType >

Interface for creating polymorphic deep-copyable objects.

Template Parameters
BaseTypeThe base type of the derived object to be cloned.
DerivedTypeThe derived type of the object to be cloned.

Member Function Documentation

◆ cloneShared()

template<typename BaseType, typename DerivedType>
std::shared_ptr< BaseType > drn::foundation::Clonable< BaseType, DerivedType >::cloneShared ( const DerivedType & toClone) const
nodiscard

Creates a shared polymorphic deep copy of the specified object.

It generates a shared deep copy of the provided object, ensuring that the object's full dynamic type is preserved.

Precondition
The derived type must be a valid subclass of BaseType.
Parameters
toCloneThe object to be cloned.
Returns
A shared pointer to the deep copy of the specified object.

◆ cloneUnique()

template<typename BaseType, typename DerivedType>
std::unique_ptr< BaseType > drn::foundation::Clonable< BaseType, DerivedType >::cloneUnique ( const DerivedType & toClone) const
nodiscard

Creates a unique polymorphic deep copy of the specified object.

It generates a deep copy of the provided object, ensuring that the object's full dynamic type is preserved.

Precondition
The derived type must be a valid subclass of BaseType.
Parameters
toCloneThe object to be cloned.
Returns
The deep copy of the specified object.