Lumiera
0.pre.03
»edit your freedom«
|
#include "lib/polymorphic-value.hpp"
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
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 |
PolymorphicValue & | operator= (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 |
_CopyHandlingAdapter & | accessHandlingInterface () const |
void | destroyEmbedded () |
Private Attributes | |
std::byte | buf_ [siz] |
Storage for embedded objects. | |
|
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.
|
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.
Definition at line 476 of file polymorphic-value.hpp.