PLaSK library
Loading...
Searching...
No Matches
plask::Holder< T > Struct Template Reference

Template for base class of object holder. More...

#include <plask/memory.hpp>

Public Member Functions

 Holder (T *held) noexcept
 Construct a holder with given held object.
 
 Holder (T &held) noexcept
 Construct a holder with given held object.
 
 Holder (const Holder< T > &to_copy)
 Copy constructor.
 
 Holder (Holder< T > &&to_move) noexcept
 Move constructor.
 
Holder< T > & operator= (const Holder &to_copy)
 Copy operator.
 
Holder< T > & operator= (Holder &&to_move) noexcept
 Move operator.
 
 ~Holder ()
 Delete held object using delete.
 

Protected Attributes

T * held
 Held object. Typically can be nullptr only after move assignment.
 

Detailed Description

template<typename T>
struct plask::Holder< T >

Template for base class of object holder.

It allows to hold polymorphic class inside one type.

Typically, subclasses adds some delegates methods to held object. Held object is stored by pointer, so it can store class derived from T. Stored object is deleted in destructor. Holder has all assign and copy constructors which use stored object clone() method.

Template Parameters
Ttype of class to hold, must have clone() method which make a copy of object

Definition at line 70 of file memory.hpp.

Constructor & Destructor Documentation

◆ Holder() [1/4]

template<typename T >
plask::Holder< T >::Holder ( T *  held)
inlinenoexcept

Construct a holder with given held object.

Parameters
heldobject to hold, should be not nullptr

Definition at line 83 of file memory.hpp.

◆ Holder() [2/4]

template<typename T >
plask::Holder< T >::Holder ( T &  held)
inlinenoexcept

Construct a holder with given held object.

Parameters
heldobject to hold, should be not nullptr

Definition at line 89 of file memory.hpp.

◆ Holder() [3/4]

template<typename T >
plask::Holder< T >::Holder ( const Holder< T > &  to_copy)
inline

Copy constructor.

Use held->clone().

Parameters
to_copyobject to copy

Definition at line 95 of file memory.hpp.

◆ Holder() [4/4]

template<typename T >
plask::Holder< T >::Holder ( Holder< T > &&  to_move)
inlinenoexcept

Move constructor.

It doesn't call held.clone().

Parameters
to_moveobject to move

Definition at line 103 of file memory.hpp.

◆ ~Holder()

template<typename T >
plask::Holder< T >::~Holder ( )
inline

Delete held object using delete.

Definition at line 128 of file memory.hpp.

Member Function Documentation

◆ operator=() [1/2]

template<typename T >
Holder< T > & plask::Holder< T >::operator= ( const Holder< T > &  to_copy)
inline

Copy operator.

Use held->clone().

Parameters
to_copyobject to copy

Definition at line 109 of file memory.hpp.

◆ operator=() [2/2]

template<typename T >
Holder< T > & plask::Holder< T >::operator= ( Holder< T > &&  to_move)
inlinenoexcept

Move operator.

It doesn't call held.clone().

Parameters
to_moveobject to move

Definition at line 122 of file memory.hpp.

Member Data Documentation

◆ held

template<typename T >
T* plask::Holder< T >::held
protected

Held object. Typically can be nullptr only after move assignment.

Definition at line 75 of file memory.hpp.


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