Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
PolymorphicValue< IFA, storage, CPY > Class Template Reference

#include "lib/polymorphic-value.hpp"

Description

template<class IFA, size_t storage, class CPY = IFA>
class lib::PolymorphicValue< IFA, storage, CPY >

Template to build polymorphic value objects.

Inline buffer with value semantics, yet holding and owning an object while concealing the concrete type, exposing only the public interface. Access to the contained object is by implicit conversion to this public interface. The actual implementation object might be placed into the buffer through a builder function; later, this buffer may be copied and passed on without knowing the actual contained type.

For using PolymorphicValue, several assumptions need to be fulfilled

  • any instance placed into the opaque buffer is below the specified maximum size
  • the caller cares for thread safety. No concurrent get calls while in mutation!
Warning
when a create or copy-into operation fails with exception, the whole PolymorphicValue object is in undefined state and must not be used henceforth.

Definition at line 365 of file polymorphic-value.hpp.

Classes

class  Adapter
 Implementation Helper: add support for copy operations. More...
 

Public Types

using Interface = IFA
 

Static Public Member Functions

template<class IMP , typename... ARGS>
static PolymorphicValue build (ARGS &&... args)
 

Public Member Functions

InterfacegetPayload ()
 
 operator Interface & ()
 
 operator Interface const & () const
 
Interfaceoperator-> () const
 
 ~PolymorphicValue ()
 
 PolymorphicValue (PolymorphicValue const &o)
 
PolymorphicValueoperator= (PolymorphicValue const &o)
 

Friends

bool operator== (PolymorphicValue const &v1, PolymorphicValue const &v2)
 
bool operator!= (PolymorphicValue const &v1, PolymorphicValue const &v2)
 

Protected Member Functions

template<class IMP , typename... ARGS>
 PolymorphicValue (IMP *, ARGS &&... args)
 

Private Types

enum  { siz = storage + _Traits::ADMIN_OVERHEAD }
 
typedef polyvalue::Trait< CPY > _Traits
 
typedef _Traits::CopyAPI _CopyHandlingAdapter
 
typedef _Traits::Assignment _AssignmentPolicy
 
template<typename IMP >
using TypeSelector = Adapter< IMP > *
 

Private Member Functions

IFA & accessEmbedded () const
 
void destroyEmbedded ()
 
_CopyHandlingAdapteraccessHandlingInterface () const
 
template<class IMP , typename... ARGS>
 PolymorphicValue (TypeSelector< IMP >, ARGS &&... args)
 

Private Attributes

std::byte buf_ [siz]
 Storage for embedded objects.
 

Constructor & Destructor Documentation

◆ PolymorphicValue() [1/3]

template<class IFA , size_t storage, class CPY = IFA>
template<class IMP , typename... ARGS>
PolymorphicValue ( TypeSelector< IMP >  ,
ARGS &&...  args 
)
inlineprivate

this is the actual working ctor, which must care to decorate the desired impl type with an additional adapter to support copy operations.

Definition at line 451 of file polymorphic-value.hpp.

References PolymorphicValue< IFA, storage, CPY >::buf_, and PolymorphicValue< IFA, storage, CPY >::siz.

◆ PolymorphicValue() [2/3]

template<class IFA , size_t storage, class CPY = IFA>
template<class IMP , typename... ARGS>
PolymorphicValue ( IMP *  ,
ARGS &&...  args 
)
inlineprotected

ctor for subclasses and builder functions. The constructor requires an additional type-selector argument. On invocation, the desired subclass/implementation object is immediately planted into the embedded buffer, passing through the given ctor arguments.

See also
factory functions for public use

Definition at line 467 of file polymorphic-value.hpp.

◆ ~PolymorphicValue()

template<class IFA , size_t storage, class CPY = IFA>
~PolymorphicValue ( )
inline

Definition at line 496 of file polymorphic-value.hpp.

References PolymorphicValue< IFA, storage, CPY >::destroyEmbedded().

+ Here is the call graph for this function:

◆ PolymorphicValue() [3/3]

template<class IFA , size_t storage, class CPY = IFA>
PolymorphicValue ( PolymorphicValue< IFA, storage, CPY > const &  o)
inline

Definition at line 501 of file polymorphic-value.hpp.

References PolymorphicValue< IFA, storage, CPY >::accessHandlingInterface(), PolymorphicValue< IFA, storage, CPY >::buf_, and CopySupport< IFA, BA >::cloneInto().

+ Here is the call graph for this function:

Member Typedef Documentation

◆ _Traits

template<class IFA , size_t storage, class CPY = IFA>
typedef polyvalue::Trait<CPY> _Traits
private

Definition at line 368 of file polymorphic-value.hpp.

◆ _CopyHandlingAdapter

template<class IFA , size_t storage, class CPY = IFA>
typedef _Traits::CopyAPI _CopyHandlingAdapter
private

Definition at line 369 of file polymorphic-value.hpp.

◆ _AssignmentPolicy

template<class IFA , size_t storage, class CPY = IFA>
typedef _Traits::Assignment _AssignmentPolicy
private

Definition at line 370 of file polymorphic-value.hpp.

◆ TypeSelector

template<class IFA , size_t storage, class CPY = IFA>
template<typename IMP >
using TypeSelector = Adapter<IMP>*
private

Definition at line 436 of file polymorphic-value.hpp.

◆ Interface

template<class IFA , size_t storage, class CPY = IFA>
using Interface = IFA

Definition at line 474 of file polymorphic-value.hpp.

Member Enumeration Documentation

◆ anonymous enum

template<class IFA , size_t storage, class CPY = IFA>
anonymous enum
private
Enumerator
siz 

Definition at line 371 of file polymorphic-value.hpp.

Member Function Documentation

◆ accessEmbedded()

template<class IFA , size_t storage, class CPY = IFA>
IFA & accessEmbedded ( ) const
inlineprivate

◆ destroyEmbedded()

template<class IFA , size_t storage, class CPY = IFA>
void destroyEmbedded ( )
inlineprivate

Definition at line 390 of file polymorphic-value.hpp.

References PolymorphicValue< IFA, storage, CPY >::accessEmbedded().

Referenced by PolymorphicValue< IFA, storage, CPY >::~PolymorphicValue().

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

◆ accessHandlingInterface()

template<class IFA , size_t storage, class CPY = IFA>
_CopyHandlingAdapter & accessHandlingInterface ( ) const
inlineprivate

Definition at line 440 of file polymorphic-value.hpp.

References Trait< TY, YES >::accessCopyHandlingInterface(), and PolymorphicValue< IFA, storage, CPY >::accessEmbedded().

Referenced by PolymorphicValue< IFA, storage, CPY >::PolymorphicValue(), and PolymorphicValue< IFA, storage, CPY >::operator=().

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

◆ getPayload()

template<class IFA , size_t storage, class CPY = IFA>
Interface & getPayload ( )
inline

Definition at line 477 of file polymorphic-value.hpp.

References PolymorphicValue< IFA, storage, CPY >::accessEmbedded().

+ Here is the call graph for this function:

◆ operator Interface &()

template<class IFA , size_t storage, class CPY = IFA>
operator Interface & ( )
inline

Definition at line 482 of file polymorphic-value.hpp.

References PolymorphicValue< IFA, storage, CPY >::accessEmbedded().

+ Here is the call graph for this function:

◆ operator Interface const &()

template<class IFA , size_t storage, class CPY = IFA>
operator Interface const & ( ) const
inline

Definition at line 486 of file polymorphic-value.hpp.

References PolymorphicValue< IFA, storage, CPY >::accessEmbedded().

+ Here is the call graph for this function:

◆ operator->()

template<class IFA , size_t storage, class CPY = IFA>
Interface * operator-> ( ) const
inline

Definition at line 491 of file polymorphic-value.hpp.

References PolymorphicValue< IFA, storage, CPY >::accessEmbedded().

+ Here is the call graph for this function:

◆ operator=()

template<class IFA , size_t storage, class CPY = IFA>
PolymorphicValue & operator= ( PolymorphicValue< IFA, storage, CPY > const &  o)
inline

Definition at line 507 of file polymorphic-value.hpp.

References PolymorphicValue< IFA, storage, CPY >::accessEmbedded(), PolymorphicValue< IFA, storage, CPY >::accessHandlingInterface(), and CopySupport< IFA, BA >::copyInto().

+ Here is the call graph for this function:

◆ build()

template<class IFA , size_t storage, class CPY = IFA>
template<class IMP , typename... ARGS>
static PolymorphicValue build ( ARGS &&...  args)
inlinestatic

Definition at line 517 of file polymorphic-value.hpp.

Member Data Documentation

◆ buf_

template<class IFA , size_t storage, class CPY = IFA>
std::byte buf_[siz]
mutableprivate

Friends And Related Symbol Documentation

◆ operator==

template<class IFA , size_t storage, class CPY = IFA>
bool operator== ( PolymorphicValue< IFA, storage, CPY > const &  v1,
PolymorphicValue< IFA, storage, CPY > const &  v2 
)
friend

Definition at line 527 of file polymorphic-value.hpp.

◆ operator!=

template<class IFA , size_t storage, class CPY = IFA>
bool operator!= ( PolymorphicValue< IFA, storage, CPY > const &  v1,
PolymorphicValue< IFA, storage, CPY > const &  v2 
)
friend

Definition at line 532 of file polymorphic-value.hpp.

+ Inheritance diagram for PolymorphicValue< IFA, storage, CPY >:
+ Collaboration diagram for PolymorphicValue< IFA, storage, CPY >:

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