Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
tuple-record-init.hpp File Reference

Specialised adapter to consume a record of GenNode entries to build a tuple. More...

Go to the source code of this file.

Description

Specialised adapter to consume a record of GenNode entries to build a tuple.

This is a complement to lib::meta::TupleConstructor to deal with arguments passed in our "External Tree Description" form. This is relevant for structural diff and the invocation of actions driven by messages via the UI-Bus.

In those cases, a sequence of arguments will be passed within a run-time sequential container, as a sequence of GenNode entries. The latter are variant records, which means they can hold any of a small collection of basic types, like numbers, strings, time values etc. So we have to face two challenges here.

  • the sequence of types in a std::tuple is fixed at compile time, as is the sequence of constructor arguments to build a given tuple type. Thus we need a compile-time iteration over a run-time sequence container
  • the concrete type of the given initialisation value is opaque, hidden within the GenNode variant record. And especially this means that the concrete type is known only at runtime. But we need to generate the construction code at compile time. The remedy here is to use double dispatch, i.e. to build a trampoline table with all the basically possible conversion paths for one specific type within the target tuple. For example, if one component of our tuple is a long, we'll provide a conversion path for the case when the GenNode holds a short, an int, and – depending on the platform – when it holds a int64_t (please recall that long and int are the same type on 32bit platforms!). When encountering any other of the possible types within GenNode (e.g. string or TimeSpan), a type mismatch exception is raised.
See also
control::CommandDef usage example
TupleHelper_test
typelist.hpp
function.hpp
generator.hpp

Definition in file tuple-record-init.hpp.

Functions

 _Pragma ("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Woverloaded-virtual\"") namespace lib
 

Function Documentation

◆ _Pragma()

_Pragma ( "GCC diagnostic push"  )

the visitor type our converter is based on

specialised Accessor to retrieve a given target type from a run-time typed, opaque GenNode element. Since GenNode may hold some value from a (lib::diff::DataValues small and fixed selection of types), we prepare a converter function for each sensible conversion path to the given TAR target type. This converter will placement-construct a target value in a buffer reserved within this Accessor object.

Warning
template bloat: we get a converter for each possible conversion for each instantiation of this template, irrespective if we actually need it or not. The price is payed per distinct type used within some target tuple; we get a VTable and some conversion functions for each.
Note
RAII: when the ctor succeeds, we know the target element was built

Concrete specialisation to build a std::tuple from a sequence of GenNode elements, with run-time type compatibility check.

Remarks
intention is to use this within (TupleConstructor), as will happen automatically when invoking (buildTuple() ) with a Record<GenNode> as argument. The embedded template Access<i> will be initialised with (a reference) to the source record, followed by an attempt to convert it to the individual member type at position i within the target tuple.
Exceptions
error::Invalidwhen the number of types within the target exceeds the number of children within the source record. LUMIERA_ERROR_INDEX_BOUNDS
error::Invalidwhen some source GenNode element can not be sensibly converted to the corresponding type in the target tuple. LUMIERA_ERROR_WRONG_TYPE

Definition at line 64 of file tuple-record-init.hpp.

References util::toString(), and Type.

+ Here is the call graph for this function: