From f23dbe19864d6833425a6768bffc24302edaf04d Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 3 Sep 2026 01:42:18 +0200 Subject: [PATCH] Parameters: streamline automatic type conversion Can now express the automatic conversion between all allowed `BaseTypes` by invoking the `TypeHandler` interface directly. The interfaces were streamlined and storage size is managed automatically at compile time. --- src/lib/par/disposition.hpp | 22 +++++++++---------- src/lib/par/domain.hpp | 4 ++-- src/lib/par/param-type.hpp | 6 +++--- src/lib/par/parameter.hpp | 4 ++++ src/lib/par/provision.hpp | 8 +++++++ src/lib/par/spec.hpp | 4 ++-- tests/lib/par/parameter-test.cpp | 1 + wiki/thinkPad.ichthyo.mm | 37 ++++++++++++++++++++++++++++---- 8 files changed, 63 insertions(+), 23 deletions(-) diff --git a/src/lib/par/disposition.hpp b/src/lib/par/disposition.hpp index 642d3d6a1..2c9ba36b0 100644 --- a/src/lib/par/disposition.hpp +++ b/src/lib/par/disposition.hpp @@ -34,6 +34,8 @@ namespace lib { namespace par { + using ValStorage = ValBuffStorage; + /** * Implementation-Service: complete Parameter functionality. @@ -114,12 +116,10 @@ namespace par { retrieveInto (asValBuff (result)); } else - { // run full type-conversion double-dispatch - uint64_t valueBuffer; /////////////////////////////////////////////////OOO need a way to get a suitably sized intermediary buffer (without heap-allocation) - this->retrieveInto (asValBuff(valueBuffer)); - - FullDomain targetDomain; - this->transferTo (asValBuff(valueBuffer), targetDomain, asValBuff(result)); + { // run full type-conversion dispatch + ValStorage valueBuffer; + this->retrieveInto (valueBuffer); + this->extractAs (result, valueBuffer); } return result; } @@ -134,12 +134,10 @@ namespace par { setValFrom (asValBuff (changedVal)); } else - { // run full type-conversion double-dispatch - uint64_t valueBuffer; /////////////////////////////////////////////////OOO need a way to get a suitably sized intermediary buffer (without heap-allocation) - FullDomain targetDomain; - - targetDomain.transferTo (asValBuff(changedVal), *this, asValBuff(valueBuffer)); - this->setValFrom (asValBuff(valueBuffer)); + { // run full type-conversion dispatch + ValStorage valueBuffer; + this->conform (valueBuffer, changedVal); + this->setValFrom (valueBuffer); } } diff --git a/src/lib/par/domain.hpp b/src/lib/par/domain.hpp index 43bc72a3d..aa8489bbf 100644 --- a/src/lib/par/domain.hpp +++ b/src/lib/par/domain.hpp @@ -69,8 +69,8 @@ namespace par { : public PAR { public: - virtual void extractAs (X& targetVal, ValBuff const& valBuff) =0; - virtual void conform (ValBuff& targetBuff, X const& srcVal) =0; + virtual void extractAs (X& targetVal, ValBuff const& valBuff) const =0; + virtual void conform (ValBuff& targetBuff, X const& srcVal) =0; using PAR::extractAs; using PAR::conform; diff --git a/src/lib/par/param-type.hpp b/src/lib/par/param-type.hpp index 36ce49df0..a66af258d 100644 --- a/src/lib/par/param-type.hpp +++ b/src/lib/par/param-type.hpp @@ -59,8 +59,8 @@ _Pragma("GCC diagnostic ignored \"-Woverloaded-virtual\"") class TypeHandlerImpl : public PAR { - void extractAs (X& targetVal, ValBuff const& valBuff) override; - void conform (ValBuff& targetBuff, X const& srcVal) override; + void extractAs (X& targetVal, ValBuff const& valBuff) const override; + void conform (ValBuff& targetBuff, X const& srcVal) override; }; using TypeHandlerChain = meta::InstantiateChained; @@ -179,7 +179,7 @@ _Pragma("GCC diagnostic pop") template template inline void - DomainSetup::TypeHandlerImpl::extractAs (X& targetVal, ValBuff const& valBuff) + DomainSetup::TypeHandlerImpl::extractAs (X& targetVal, ValBuff const& valBuff) const { VAL const& srcVal = asValue (valBuff); assignConverted (targetVal, srcVal); diff --git a/src/lib/par/parameter.hpp b/src/lib/par/parameter.hpp index ad7fd4b97..dac996f19 100644 --- a/src/lib/par/parameter.hpp +++ b/src/lib/par/parameter.hpp @@ -120,6 +120,8 @@ namespace par { VAL Parameter::getVal() const { + static_assert (isBaseType, "only preconfigured parameter BaseTypes are supported"); + return unConst(this)->getPayload().extract(); } @@ -128,6 +130,8 @@ namespace par { void Parameter::setVal (VAL&& changedVal) { + static_assert (isBaseType, "only preconfigured parameter BaseTypes are supported"); + getPayload().setVal (changedVal); } diff --git a/src/lib/par/provision.hpp b/src/lib/par/provision.hpp index 5e20c1030..8f7f830f4 100644 --- a/src/lib/par/provision.hpp +++ b/src/lib/par/provision.hpp @@ -71,6 +71,14 @@ namespace par { } + template + struct ValBuffStorage + : ValBuff + { + std::byte data[bytes]; + }; + + /** diff --git a/src/lib/par/spec.hpp b/src/lib/par/spec.hpp index 8ff21898d..c879a0ec1 100644 --- a/src/lib/par/spec.hpp +++ b/src/lib/par/spec.hpp @@ -31,7 +31,6 @@ #include "lib/symbol.hpp" #include "lib/meta/typelist.hpp" #include "lib/meta/typelist-util.hpp" -#include "lib/meta/typeseq-util.hpp" @@ -50,7 +49,8 @@ namespace par { ,bool >; - static constexpr uint BASETYPE_CNT = meta::count(); + static constexpr uint BASETYPE_CNT = meta::count(); + static constexpr uint BASETYPE_MAX_SIZ = meta::maxSize(); template static constexpr bool isBaseType = meta::isInList::value; diff --git a/tests/lib/par/parameter-test.cpp b/tests/lib/par/parameter-test.cpp index 33b7596a4..b7cb2b82b 100644 --- a/tests/lib/par/parameter-test.cpp +++ b/tests/lib/par/parameter-test.cpp @@ -78,6 +78,7 @@ namespace test{ simpleUsage() { CHECK (sizeof(Parameter) <= 4 * sizeof(void*)); + CHECK (BASETYPE_MAX_SIZ <= sizeof(ValStorage)); Parameter par = Parameter::forType().build(); CHECK (0 == par.getVal()); diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index d7c97e9c1..d8540dbb1 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -84280,6 +84280,11 @@ + + + + + @@ -84655,7 +84660,7 @@ - + @@ -84735,6 +84740,26 @@ + + + + + + +

+ ValStorage  : ein konkreter ValBuff mit ausreichender Storage-size +

+ + +
+ + + + + + + +
@@ -84855,7 +84880,8 @@
- + + @@ -84871,6 +84897,9 @@ + + +
@@ -84959,8 +84988,8 @@
- - + +