Lumiera  0.pre.03
»edit your freedom«
InPlaceBuffer< BA, siz, DEFAULT > Class Template Reference

#include "lib/opaque-holder.hpp"

Description

template<class BA, size_t siz = sizeof(BA), class DEFAULT = BA>
class lib::InPlaceBuffer< BA, siz, DEFAULT >

Buffer to place and maintain an object instance privately within another object.

Variation of a similar concept as with OpaqueHolder, but implemented here with reduced security and lesser overhead. InPlaceBuffer is just a chunk of storage, which can be accessed through a common base class interface and allows to place new objects there. It has no way to keep track of the actual object living currently in the buffer. Thus, using InPlaceBuffer requires the placed class(es) themselves to maintain their lifecycle, and especially it is mandatory for the base class to provide a virtual dtor. On the other hand, just the (alignment rounded) storage for the object(s) placed into the buffer is required.

Remarks
as a complement, PlantingHandle may be used on APIs to offer a lightweight way for clients to provide a callback.
Warning
InPlaceBuffer really takes ownership, and even creates a default constructed instance of the base class right away. Yet the requirement for a virtual dtor is deliberately not enforced here, to allow use for types without VTable.
Template Parameters
BAthe nominal Base/Interface class for a family of types
sizmaximum storage required for the targets to be held inline
DEFAULTthe default instance to place initially

Definition at line 613 of file opaque-holder.hpp.

Public Types

using Handle = PlantingHandle< BA, DEFAULT >
 a "planting handle" can be used to expose an opaque InPlaceBuffer through an API
 

Public Member Functions

template<class TY , typename... ARGS>
 InPlaceBuffer (TY *, ARGS &&...args)
 immediately emplace an embedded subclass type
 
template<class SUB >
SUB * access ()
 
template<class TY , typename... ARGS>
TY & create (ARGS &&...args)
 Abbreviation for placement new.
 
template<class SUB >
SUB & emplace (SUB &&implementation)
 move-construct an instance of subclass into the opaque buffer
 
BA & operator* () const
 
BA * operator-> () const
 
DEFAULT & reset ()
 

Static Public Member Functions

template<typename SUB >
static auto embedType ()
 helper to mark the subclass type to create. More...
 

Private Member Functions

void destroy ()
 
BA & getObj () const
 
void placeDefault ()
 
- Private Member Functions inherited from NonCopyable
 NonCopyable (NonCopyable const &)=delete
 
NonCopyableoperator= (NonCopyable const &)=delete
 

Private Attributes

char buf_ [siz]
 

Member Function Documentation

◆ embedType()

static auto embedType ( )
inlinestatic

helper to mark the subclass type to create.

Remarks
we can not specify explicit template arguments on ctor calls, so the only way is to use a dummy marker argument to pass the type. Use as InPlaceBuffer(embedType<XYZ>, arg1, arg2, arg3)

Definition at line 666 of file opaque-holder.hpp.

+ Inheritance diagram for InPlaceBuffer< BA, siz, DEFAULT >:
+ Collaboration diagram for InPlaceBuffer< BA, siz, DEFAULT >:

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