Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
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 not empty() and 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.

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...
 

Public Member Functions

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

Protected Member Functions

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

Private Types

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

Private Attributes

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

Constructor & Destructor Documentation

◆ ~InPlaceAnyHolder()

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
~InPlaceAnyHolder ( )
inline

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

References InPlaceAnyHolder< siz, AccessPolicy >::killBuffer().

+ Here is the call graph for this function:

◆ InPlaceAnyHolder() [1/3]

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
InPlaceAnyHolder ( )
inline

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

References InPlaceAnyHolder< siz, AccessPolicy >::make_emptyBuff().

+ Here is the call graph for this function:

◆ InPlaceAnyHolder() [2/3]

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
template<class SUB >
InPlaceAnyHolder ( SUB const &  obj)
inline

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

References InPlaceAnyHolder< siz, AccessPolicy >::place_inBuff().

+ Here is the call graph for this function:

◆ InPlaceAnyHolder() [3/3]

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
InPlaceAnyHolder ( InPlaceAnyHolder< siz, AccessPolicy > const &  ref)
inline

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

References InPlaceAnyHolder< siz, AccessPolicy >::clone_inBuff().

+ Here is the call graph for this function:

Member Typedef Documentation

◆ BaseP

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
using BaseP = AccessPolicy::Base *
private

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

Member Enumeration Documentation

◆ anonymous enum

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
anonymous enum
private
Enumerator
BUFFSIZE 

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

Member Function Documentation

◆ buff() [1/2]

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
Buffer & buff ( )
inlineprotected

◆ buff() [2/2]

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
const Buffer & buff ( ) const
inlineprotected

◆ killBuffer()

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
void killBuffer ( )
inlineprotected

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

References InPlaceAnyHolder< siz, AccessPolicy >::Buffer::~Buffer(), and InPlaceAnyHolder< siz, AccessPolicy >::buff().

Referenced by InPlaceAnyHolder< siz, AccessPolicy >::~InPlaceAnyHolder(), InPlaceAnyHolder< siz, AccessPolicy >::clear(), InPlaceAnyHolder< siz, AccessPolicy >::operator=(), and InPlaceAnyHolder< siz, AccessPolicy >::operator=().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ make_emptyBuff()

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
void make_emptyBuff ( )
inlineprotected

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

References InPlaceAnyHolder< siz, AccessPolicy >::storage_.

Referenced by InPlaceAnyHolder< siz, AccessPolicy >::InPlaceAnyHolder(), InPlaceAnyHolder< siz, AccessPolicy >::clear(), InPlaceAnyHolder< siz, AccessPolicy >::operator=(), and InPlaceAnyHolder< siz, AccessPolicy >::operator=().

+ Here is the caller graph for this function:

◆ place_inBuff()

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
template<class SUB >
void place_inBuff ( SUB const &  obj)
inlineprotected

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

References InPlaceAnyHolder< siz, AccessPolicy >::storage_.

Referenced by InPlaceAnyHolder< siz, AccessPolicy >::InPlaceAnyHolder(), and InPlaceAnyHolder< siz, AccessPolicy >::operator=().

+ Here is the caller graph for this function:

◆ clone_inBuff()

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
void clone_inBuff ( InPlaceAnyHolder< siz, AccessPolicy > const &  ref)
inlineprotected

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

References InPlaceAnyHolder< siz, AccessPolicy >::buff(), InPlaceAnyHolder< siz, AccessPolicy >::Buffer::clone(), and InPlaceAnyHolder< siz, AccessPolicy >::storage_.

Referenced by InPlaceAnyHolder< siz, AccessPolicy >::InPlaceAnyHolder(), and InPlaceAnyHolder< siz, AccessPolicy >::operator=().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ asBase()

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
BaseP asBase ( ) const
inlineprotected

<

backdoor e.g. for comparisons

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

References InPlaceAnyHolder< siz, AccessPolicy >::asBase(), InPlaceAnyHolder< siz, AccessPolicy >::buff(), and InPlaceAnyHolder< siz, AccessPolicy >::Buffer::getBase().

Referenced by InPlaceAnyHolder< siz, AccessPolicy >::asBase().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clear()

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
void clear ( )
inline

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

References InPlaceAnyHolder< siz, AccessPolicy >::killBuffer(), and InPlaceAnyHolder< siz, AccessPolicy >::make_emptyBuff().

+ Here is the call graph for this function:

◆ operator=() [1/2]

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
InPlaceAnyHolder & operator= ( InPlaceAnyHolder< siz, AccessPolicy > const &  ref)
inline

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

References InPlaceAnyHolder< siz, AccessPolicy >::clone_inBuff(), InPlaceAnyHolder< siz, AccessPolicy >::killBuffer(), and InPlaceAnyHolder< siz, AccessPolicy >::make_emptyBuff().

+ Here is the call graph for this function:

◆ operator=() [2/2]

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
template<class SUB >
InPlaceAnyHolder & operator= ( SUB const &  newContent)
inline

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

References InPlaceAnyHolder< siz, AccessPolicy >::buff(), InPlaceAnyHolder< siz, AccessPolicy >::empty(), InPlaceAnyHolder< siz, AccessPolicy >::killBuffer(), InPlaceAnyHolder< siz, AccessPolicy >::make_emptyBuff(), and InPlaceAnyHolder< siz, AccessPolicy >::place_inBuff().

+ Here is the call graph for this function:

◆ get()

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
template<class SUB >
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.

References InPlaceAnyHolder< siz, AccessPolicy >::buff(), InPlaceAnyHolder< siz, AccessPolicy >::empty(), and LERR_.

Referenced by WrappedStandardExeBuilder::invokeOriginalBuilder().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ empty()

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
bool empty ( ) const
inline

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

References InPlaceAnyHolder< siz, AccessPolicy >::buff(), and InPlaceAnyHolder< siz, AccessPolicy >::Buffer::empty().

Referenced by InPlaceAnyHolder< siz, AccessPolicy >::get(), and InPlaceAnyHolder< siz, AccessPolicy >::operator=().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isValid()

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
bool isValid ( ) const
inline

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

References InPlaceAnyHolder< siz, AccessPolicy >::buff(), and InPlaceAnyHolder< siz, AccessPolicy >::Buffer::isValid().

Referenced by InPlaceAnyHolder< siz, AccessPolicy >::operator bool().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator bool()

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
operator bool ( ) const
inlineexplicit

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

References InPlaceAnyHolder< siz, AccessPolicy >::isValid().

+ Here is the call graph for this function:

Member Data Documentation

◆ storage_

template<size_t siz, class AccessPolicy = InPlaceAnyHolder_unrelatedTypes>
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.

Referenced by InPlaceAnyHolder< siz, AccessPolicy >::buff(), InPlaceAnyHolder< siz, AccessPolicy >::buff(), InPlaceAnyHolder< siz, AccessPolicy >::clone_inBuff(), InPlaceAnyHolder< siz, AccessPolicy >::make_emptyBuff(), and InPlaceAnyHolder< siz, AccessPolicy >::place_inBuff().

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

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