Skip to content

LiteFX::SharedObject

Base class for an object that can be shared.

Synopsis

Declared in <litefx/containers.hpp>

class SharedObject
    : public std::enable_shared_from_this<SharedObject>

Description

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 SharedObject::Allocator in your class, as shown in the example below.

Example


class Foo : public SharedObject {
    friend struct SharedObject::Allocator<Foo>;

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 Classes

NameDescription
std::enable_shared_from_this<SharedObject>

Type Aliases

Name
_Esft_type

Member Functions

NameDescription
~SharedObject [destructor] [virtual]Destroys the shared object.
shared_from_this Returns a shared pointer to the current object instance.
weak_from_this Returns a weak pointer to the current object instance.

Protected Types

NameDescription
Allocator An allocator used to allocate the shared object.

Protected Member Functions

NameDescription
SharedObject [constructor]Initializes a new shared object.
operator= Assignment operators

Protected Static Member Functions

NameDescription
create Generic factory method used to create instances of the shared object.

Derived Classes

NameDescription
Blitter Utility class that can be used to issue blit commands and generate mip maps.
IBuffer Base interface for buffer objects.
ICommandBuffer The interface for a command buffer.
ICommandQueue The interface for a command queue.
IDescriptorSetLayout The interface for a descriptor set layout.
IFrameBuffer The interface for a frame buffer.
IGraphicsAdapter Represents a physical graphics adapter.
IGraphicsDevice The interface for a graphics device that.
IGraphicsFactory The interface for a graphics factory.
IImage Describes a generic image.
IIndexBufferLayout Describes a index buffer layout.
IInputAssembler The interface for an input assembler state.
IPipelineLayout The interface for a pipeline layout.
IRasterizer Represents the rasterizer state of a RenderPipeline.
IRenderPass The interface for a render pass.
ISampler Describes a texture sampler.
IShaderProgram The interface for a shader program.
IVertexBufferLayout Describes a vertex buffer layout.
TimingEvent An event that is used to measure timestamps in a command queue.

See Also

https://en.cppreference.com/w/cpp/memory/enable_shared_from_this