Lumiera  0.pre.03
»edit your freedom«
InPlaceAnyHolder< siz, AccessPolicy > Class Template Reference

#include "lib/opaque-holder.hpp"

Description

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
class lib::InPlaceAnyHolder< siz, AccessPolicy >

Inline buffer to hold and own an object while concealing the concrete type.

The object is given either as ctor parameter or by direct assignment; it is copy-constructed into the buffer. It is necessary to specify the required buffer storage space as a template parameter. InPlaceAnyHolder may be created empty or cleared afterwards, and this #empty() state may be detected at runtime. In a similar vein, when the stored object has a bool validity check, this can be accessed though isValid(). Moreover !empty() && isValid() may be tested as by bool conversion of the Holder object. The whole compound is copyable if and only if the contained object is copyable.

Note
assertion failure when trying to place an instance not fitting into given size.
not threadsafe!
Todo:
add support for moving of rvalue refs

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

Public Member Functions

template<class SUB >
 InPlaceAnyHolder (SUB const &obj)
 
 InPlaceAnyHolder (InPlaceAnyHolder const &ref)
 
void clear ()
 
bool empty () const
 
template<class SUB >
SUB & get () const
 re-accessing the concrete contained object. More...
 
bool isValid () const
 
 operator bool () const
 
InPlaceAnyHolderoperator= (InPlaceAnyHolder const &ref)
 
template<class SUB >
InPlaceAnyHolderoperator= (SUB const &newContent)
 

Classes

struct  Buff
 concrete subclass to manage a specific kind of contained object. More...
 
struct  Buffer
 Inner capsule managing the contained object (interface) More...
 
struct  EmptyBuff
 special case: no stored object More...
 

Protected Member Functions

BaseP asBase () const
 < More...
 
Bufferbuff ()
 
const Bufferbuff () const
 
void clone_inBuff (InPlaceAnyHolder const &ref)
 
void killBuffer ()
 
void make_emptyBuff ()
 
template<class SUB >
void place_inBuff (SUB const &obj)
 

Private Types

enum  { BUFFSIZE = sizeof(Buffer) }
 
typedef AccessPolicy::Base * BaseP
 

Private Attributes

char storage_ [BUFFSIZE]
 embedded buffer actually holding the concrete Buff object, which in turn holds and manages the target object. More...
 

Member Function Documentation

◆ asBase()

BaseP asBase ( ) const
inlineprotected

<

backdoor e.g. for comparisons

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

◆ get()

SUB& get ( ) const
inline

re-accessing the concrete contained object.

This requires exact knowledge of the actual type of the element currently in storage. OpaqueHolder does not provide any "probing" or visitation mechanism.

Remarks
You might consider lib::Variant or some visitor instead.
Exceptions
lumiera::error::Logicwhen conversion/access fails
lumiera::error::Invalidwhen accessing an empty holder

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

Referenced by WrappedStandardExeBuilder::__call__().

+ Here is the caller graph for this function:

Member Data Documentation

◆ storage_

char storage_[BUFFSIZE]
private

embedded buffer actually holding the concrete Buff object, which in turn holds and manages the target object.

Note
Invariant: always contains a valid Buffer subclass

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

+ Inheritance diagram for InPlaceAnyHolder< siz, AccessPolicy >:
+ Collaboration diagram for InPlaceAnyHolder< siz, AccessPolicy >:

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