Base class for an object that can be shared.
More...
#include <containers.hpp>
Inherits std::enable_shared_from_this< SharedObject >.
Inherited by LiteFX::Rendering::Backends::DirectX12BottomLevelAccelerationStructure::DirectX12BottomLevelAccelerationStructureImpl, LiteFX::Graphics::Blitter< TBackend >, LiteFX::Rendering::IBuffer, LiteFX::Rendering::ICommandBuffer, LiteFX::Rendering::ICommandQueue, LiteFX::Rendering::IDescriptorSetLayout, LiteFX::Rendering::IFrameBuffer, LiteFX::Rendering::IGraphicsAdapter, LiteFX::Rendering::IGraphicsDevice, LiteFX::Rendering::IGraphicsFactory, LiteFX::Rendering::IImage, LiteFX::Rendering::IIndexBufferLayout, LiteFX::Rendering::IInputAssembler, LiteFX::Rendering::IPipelineLayout, LiteFX::Rendering::IRasterizer, LiteFX::Rendering::IRenderPass, LiteFX::Rendering::ISampler, LiteFX::Rendering::IShaderProgram, LiteFX::Rendering::IVertexBufferLayout, LiteFX::Rendering::TimingEvent, and LiteFX::Rendering::Backends::VulkanBottomLevelAccelerationStructure::VulkanBottomLevelAccelerationStructureImpl.
|
virtual | ~SharedObject () noexcept=default |
| Destroys the shared object.
|
|
template<typename TSelf > |
auto | shared_from_this (this TSelf &&self) noexcept |
| Returns a shared pointer to the current object instance.
|
|
template<typename TSelf > |
auto | weak_from_this (this TSelf &&self) noexcept -> WeakPtr< std::remove_reference_t< TSelf > > |
| Returns a weak pointer to the current object instance.
|
|
|
template<typename T , typename... TArgs> |
static auto | create (TArgs &&... args) -> SharedPtr< T > |
| Generic factory method used to create instances of the shared object.
|
|
Base class for an object that can be shared.
This is an improved version of std::enable_shared_from_this
that supports inheritance. When inheriting from this class, follow the same practices as you would for std::enable_shared_from_this
: do not provide any public constructors; instead provide a private constructor and a publicly accessible static factory method, that returns a shared pointer.
Note that the above rule does not apply for objects that are stored within a PimplPtr, as those are handled correctly by the pointer implementation.
You may want to create objects by creating a static factory method that calls the protected SharedObject::create method. This has the advantage of allocating a single memory block for both, the object and the shared pointers control block. To do this, make sure to declare friendship to SharedAllocator in your class, as shown in the example below.
private:
explicit Foo(
int a, std::string b) { }
public:
static inline auto create(int a, std::string b) {
return SharedObject::create>
Foo<(a, b);
}
}
Base class for an object that can be shared.
Definition containers.hpp:1075
An allocator used to allocate the shared object.
Definition containers.hpp:1098
◆ SharedObject() [1/3]
LiteFX::SharedObject::SharedObject |
( |
| ) |
|
|
protecteddefaultnoexcept |
Initializes a new shared object.
◆ SharedObject() [2/3]
◆ SharedObject() [3/3]
◆ ~SharedObject()
virtual LiteFX::SharedObject::~SharedObject |
( |
| ) |
|
|
virtualdefaultnoexcept |
Destroys the shared object.
◆ create()
template<typename T , typename... TArgs>
static auto LiteFX::SharedObject::create |
( |
TArgs &&... | args | ) |
-> SharedPtr<T> |
|
inlinestaticprotected |
Generic factory method used to create instances of the shared object.
- Template Parameters
-
T | The type of the class that inherits from SharedObject. |
TArgs | The types of the arguments passed to the shared object's constructor. |
- Parameters
-
args | The arguments that are forwarded to the shared object's constructor. |
- Returns
- A shared pointer of the shared object.
- See also
- Allocator
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ shared_from_this()
template<typename TSelf >
auto LiteFX::SharedObject::shared_from_this |
( |
this TSelf && | self | ) |
|
|
inlinenoexcept |
Returns a shared pointer to the current object instance.
◆ weak_from_this()
template<typename TSelf >
auto LiteFX::SharedObject::weak_from_this |
( |
this TSelf && | self | ) |
-> WeakPtr<std::remove_reference_t<TSelf>>
|
|
inlinenoexcept |
Returns a weak pointer to the current object instance.