Lumiera  0.pre.03
»edit your freedom«
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 374 of file polymorphic-value.hpp.

Public Types

typedef IFA Interface
 

Public Member Functions

 PolymorphicValue (PolymorphicValue const &o)
 
Interface & getPayload ()
 
 operator Interface & ()
 
 operator Interface const & () const
 
Interface * operator-> () const
 
PolymorphicValueoperator= (PolymorphicValue const &o)
 

Static Public Member Functions

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

Classes

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

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 _Traits::Assignment _AssignmentPolicy
 
typedef _Traits::CopyAPI _CopyHandlingAdapter
 
typedef polyvalue::Trait< CPY > _Traits
 
template<typename IMP >
using TypeSelector = Adapter< IMP > *
 

Private Member Functions

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

Private Attributes

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

Constructor & Destructor Documentation

◆ PolymorphicValue() [1/2]

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 460 of file polymorphic-value.hpp.

◆ PolymorphicValue() [2/2]

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 476 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: