Lumiera  0.pre.03
»edit your freedom«
ElementAccess::TypeConverter< TAR > Struct Template Reference

#include "stage/model/element-access.hpp"

Description

template<class TAR>
struct stage::model::ElementAccess::TypeConverter< TAR >

helper to perform conversion to the desired result type. This is a bit of tricky metaprogramming to deal with the problem that we can not assume a single base interface for all the UI elements or widgets accessible through UI-Coordinates. Rather we have to deal with a small set of possible base interfaces, and thus the actual access function returns a variant record holding a pointer, and internally tagged with the base interface type to apply. Now the public API functions are templated to the result type as expected by the invoking clinent and thus we get a matrix of possible cases; when the expected result type is reachable by dynamic downcast from the actual base interface type returned by the internal access function, we can perform this dynamic_cast. Otherwise the returned result proxy object is marked as empty.

Remarks
technically this solution relies on the lib::Variant::Visitor to provide a NOP default implementation. The TypeConverter template is instantiated with the desired target type and thus only overwrites the first case where an conversion is possible. In all other cases the default implementation does nothing and thus retains the embedded result proxy in empty state.

Definition at line 110 of file element-access.hpp.

Public Types

using Base = typename RawResult::FirstMatching< canUpcast >::Type
 
template<typename X >
using canUpcast = std::is_convertible< TAR *, X >
 

Public Member Functions

virtual void handle (Base &pb) override
 
- Public Member Functions inherited from Variant< TYPES >::Visitor
virtual ~Visitor ()
 this is an interface
 

Public Attributes

lib::Result< TAR & > result {error::Invalid{"not convertible to desired target widget"}}
 
+ Inheritance diagram for ElementAccess::TypeConverter< TAR >:
+ Collaboration diagram for ElementAccess::TypeConverter< TAR >:

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