Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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 606 of file opaque-holder.hpp.

Classes

struct  TypeTag
 

Public Types

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

Static Public Member Functions

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

Public Member Functions

 ~InPlaceBuffer ()
 
 InPlaceBuffer ()
 
template<class SUB >
 InPlaceBuffer (SUB &&instance)
 immediately move-emplace an embedded subclass type
 
template<class TY , typename... ARGS>
 InPlaceBuffer (TypeTag< TY >, ARGS &&...args)
 immediately emplace an embedded subclass type
 
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
 
DEFAULT & reset ()
 
BA & operator* () const
 
BA * operator-> () const
 
template<class SUB >
SUB * access ()
 

Private Member Functions

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

Private Attributes

std::byte buf_ [siz]
 

Constructor & Destructor Documentation

◆ ~InPlaceBuffer()

template<class BA , size_t siz = sizeof(BA), class DEFAULT = BA>
~InPlaceBuffer ( )
inline

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

◆ InPlaceBuffer() [1/3]

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

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

◆ InPlaceBuffer() [2/3]

template<class BA , size_t siz = sizeof(BA), class DEFAULT = BA>
template<class SUB >
InPlaceBuffer ( SUB &&  instance)
inline

immediately move-emplace an embedded subclass type

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

◆ InPlaceBuffer() [3/3]

template<class BA , size_t siz = sizeof(BA), class DEFAULT = BA>
template<class TY , typename... ARGS>
InPlaceBuffer ( TypeTag< TY >  ,
ARGS &&...  args 
)
inline

immediately emplace an embedded subclass type

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


Class Documentation

◆ lib::InPlaceBuffer::TypeTag

struct lib::InPlaceBuffer::TypeTag
+ Collaboration diagram for InPlaceBuffer< BA, siz, DEFAULT >::TypeTag< TY >:

Member Typedef Documentation

◆ Handle

template<class BA , size_t siz = sizeof(BA), class DEFAULT = BA>
using Handle = PlantingHandle<BA, DEFAULT>

a "planting handle" can be used to expose an opaque InPlaceBuffer through an API

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

Member Function Documentation

◆ getObj()

template<class BA , size_t siz = sizeof(BA), class DEFAULT = BA>
BA & getObj ( ) const
inlineprivate

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

◆ placeDefault()

template<class BA , size_t siz = sizeof(BA), class DEFAULT = BA>
void placeDefault ( )
inlineprivate

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

◆ destroy()

template<class BA , size_t siz = sizeof(BA), class DEFAULT = BA>
void destroy ( )
inlineprivate

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

◆ embedType()

template<class BA , size_t siz = sizeof(BA), class DEFAULT = BA>
template<typename SUB >
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 662 of file opaque-holder.hpp.

◆ create()

template<class BA , size_t siz = sizeof(BA), class DEFAULT = BA>
template<class TY , typename... ARGS>
TY & create ( ARGS &&...  args)
inline

Abbreviation for placement new.

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

◆ emplace()

template<class BA , size_t siz = sizeof(BA), class DEFAULT = BA>
template<class SUB >
SUB & emplace ( SUB &&  implementation)
inline

move-construct an instance of subclass into the opaque buffer

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

◆ reset()

template<class BA , size_t siz = sizeof(BA), class DEFAULT = BA>
DEFAULT & reset ( )
inline

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

Referenced by DragRelocateController::resetState().

+ Here is the caller graph for this function:

◆ operator*()

template<class BA , size_t siz = sizeof(BA), class DEFAULT = BA>
BA & operator* ( ) const
inline

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

◆ operator->()

template<class BA , size_t siz = sizeof(BA), class DEFAULT = BA>
BA * operator-> ( ) const
inline

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

◆ access()

template<class BA , size_t siz = sizeof(BA), class DEFAULT = BA>
template<class SUB >
SUB * access ( )
inline

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

References AccessCasted< TAR >::access().

+ Here is the call graph for this function:

Member Data Documentation

◆ buf_

template<class BA , size_t siz = sizeof(BA), class DEFAULT = BA>
std::byte buf_[siz]
mutableprivate

Definition at line 611 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: