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

#include "lib/opaque-holder.hpp"

Description

template<class BA, class DEFAULT = BA>
class lib::PlantingHandle< BA, DEFAULT >

A handle to allow for safe »remote implantation« of an unknown subclass into a given opaque InPlaceBuffer, without having to disclose the concrete buffer type or size.

Remarks
this copyable value object is especially geared towards use as handle in APIs, allowing a not yet known implementation to implant an agent or collaboration partner into the likewise undisclosed innards of the service exposed.
Warning
the type BA must expose a virtual dtor, since the targeted InPlaceBuffer has to take ownership of the implanted object.
Note
the siz (buffer size) template parameter from #InPlaceBuffer is deliberately not part of the PlantingHandle<BA,DEFAULT> type, since buffer size can be considered an opaque implementation detail. As a consequence, we must capture this size information at construction time and store it at runtime #maxSiz_, to protect against buffer overrun.
See also
OpaqueUncheckedBuffer_test

Definition at line 113 of file record.hpp.

Public Member Functions

template<size_t maxSiz>
 PlantingHandle (InPlaceBuffer< BA, maxSiz, DEFAULT > &targetBuffer)
 
template<class SUB >
bool canCreate () const
 
template<class SUB , typename... ARGS>
SUB & create (ARGS &&...args)
 Abbreviation for placement new of a subclass SUB into the opaque buffer.
 
template<class SUB >
SUB & emplace (SUB &&implementation)
 move-construct an instance of a subclass into the opaque buffer
 
BA * get () const
 

Private Member Functions

template<class SUB >
void __ensure_can_create ()
 

Private Attributes

void * buffer_
 
size_t maxSiz_
 

Member Function Documentation

◆ __ensure_can_create()

void __ensure_can_create ( )
inlineprivate

Helper to ensure the opaque buffer provides sufficient storage

Template Parameters
SUBactual subclass type to be implanted into the opaque buffer

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

+ Collaboration diagram for PlantingHandle< BA, DEFAULT >:

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