Parameters: implement simple value extraction for base types
...so this is not yet a visitor, rather the building blocks required to be able to extract values and to assign and conform values And my intention is to build something akin to a set of conversion rules
This commit is contained in:
parent
82b7acac57
commit
7d35790e11
3 changed files with 123 additions and 20 deletions
|
|
@ -37,6 +37,7 @@
|
|||
#include "lib/meta/typelist.hpp"
|
||||
//#include "lib/meta/typelist-util.hpp"
|
||||
#include "lib/meta/generator.hpp"
|
||||
#include "lib/meta/trait.hpp"
|
||||
|
||||
|
||||
namespace lib {
|
||||
|
|
@ -60,11 +61,28 @@ namespace par {
|
|||
return * static_cast<ValBuff const *> (rawMem);
|
||||
}
|
||||
|
||||
template<typename X>
|
||||
constexpr inline X&
|
||||
asValue (ValBuff& storage)
|
||||
{
|
||||
void* rawMem{& storage};
|
||||
return * static_cast<X*> (rawMem);
|
||||
}
|
||||
|
||||
template<typename X>
|
||||
constexpr inline X const&
|
||||
asValue (ValBuff const& storage)
|
||||
{
|
||||
void const * rawMem{& storage};
|
||||
return * static_cast<X const *> (rawMem);
|
||||
}
|
||||
|
||||
|
||||
template<typename X>
|
||||
class TypeHandler
|
||||
{
|
||||
public:
|
||||
virtual void extractAs (X&, ValBuff&) =0;
|
||||
virtual void extractAs (X&, ValBuff const&) =0;
|
||||
};
|
||||
|
||||
// using lib::meta::typeseq;
|
||||
|
|
@ -113,18 +131,14 @@ _Pragma("GCC diagnostic ignored \"-Woverloaded-virtual\"")
|
|||
|
||||
|
||||
template<typename U>
|
||||
struct TypeDomainSetup
|
||||
struct TypeSetup
|
||||
{
|
||||
|
||||
template<typename X, class BAS>
|
||||
class TypeHandlerImpl
|
||||
: public BAS
|
||||
{
|
||||
void
|
||||
extractAs (X& srcVal, ValBuff& valBuff) override
|
||||
{
|
||||
UNIMPLEMENTED ("extract into Buffer");
|
||||
}
|
||||
void extractAs (X& targetVal, ValBuff const& valBuff) override;
|
||||
};
|
||||
|
||||
using TypeHandlerChain = meta::InstantiateChained<BaseTypes::List, TypeHandlerImpl, Domain>;
|
||||
|
|
@ -134,12 +148,33 @@ _Pragma("GCC diagnostic ignored \"-Woverloaded-virtual\"")
|
|||
|
||||
template<typename X>
|
||||
class BaseDomain
|
||||
: public TypeDomainSetup<X>::TypeHandlerChain
|
||||
: public TypeSetup<X>::TypeHandlerChain
|
||||
{
|
||||
public:
|
||||
};
|
||||
|
||||
|
||||
/* ===== type conversion details ===== */
|
||||
|
||||
template<typename U>
|
||||
template<typename X, class BAS>
|
||||
inline void
|
||||
TypeSetup<U>::TypeHandlerImpl<X,BAS>::extractAs (X& targetVal, ValBuff const& valBuff)
|
||||
{
|
||||
if constexpr (std::is_assignable_v<X&, U const&>)
|
||||
{
|
||||
targetVal = asValue<U> (valBuff);
|
||||
}
|
||||
else
|
||||
if constexpr (std::is_constructible_v<X, U const&>)
|
||||
{
|
||||
targetVal.~X();
|
||||
new(&targetVal) X (asValue<U> (valBuff));
|
||||
}
|
||||
else
|
||||
static_assert (!sizeof(X), "this type conversion is not supported");
|
||||
}
|
||||
|
||||
|
||||
}} // namespace lib::par
|
||||
#endif /*LIB_PAR_DOMAIN_H*/
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
#include "test/run.hpp"
|
||||
//#include "test/test-helper.hpp"
|
||||
#include "lib/par/domain.hpp"
|
||||
//#include "lib/format-cout.hpp"
|
||||
#include "test/diagnostic-output.hpp"////////////TODO
|
||||
|
||||
//#include <utility>
|
||||
//#include <string>
|
||||
|
|
@ -70,7 +70,7 @@ namespace test{
|
|||
{
|
||||
seedRand();
|
||||
basics();
|
||||
verify_typeVisitor();
|
||||
verify_valueAccess();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ namespace test{
|
|||
|
||||
|
||||
void
|
||||
verify_typeVisitor()
|
||||
verify_valueAccess()
|
||||
{
|
||||
BaseDomain<int> domInt;
|
||||
Domain& d1{domInt};
|
||||
|
|
@ -92,9 +92,15 @@ namespace test{
|
|||
uint target1{0};
|
||||
CHECK (not target1);
|
||||
|
||||
TypeHandler<uint>& dd1{d1};
|
||||
dd1.extractAs (target1, src1);
|
||||
TypeHandler<uint>& du1{d1};
|
||||
du1.extractAs (target1, src1);
|
||||
CHECK (target1 == uint(val1));
|
||||
|
||||
float target2{0};
|
||||
|
||||
TypeHandler<float>& df1{d1};
|
||||
df1.extractAs (target2, src1);
|
||||
CHECK (target2 == float(val1));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -82879,7 +82879,15 @@
|
|||
<node BACKGROUND_COLOR="#c8c0b6" CREATED="1784489444352" ID="ID_1412623970" MODIFIED="1784489521150" TEXT="doch! das funktioniert weiterhin">
|
||||
<icon BUILTIN="idea"/>
|
||||
</node>
|
||||
<node CREATED="1784489483382" ID="ID_617432070" MODIFIED="1784491530502" TEXT="allerdings darf der Aufruf selber keine Ambiguität erzueugen...">
|
||||
<node CREATED="1784489483382" ID="ID_617432070" MODIFIED="1784502126671">
|
||||
<richcontent TYPE="NODE"><html>
|
||||
<head/>
|
||||
<body>
|
||||
<p>
|
||||
allerdings darf der Aufruf selber <font color="#a70e0e">keine Ambiguität</font> erzueugen...
|
||||
</p>
|
||||
</body>
|
||||
</html></richcontent>
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head/>
|
||||
<body>
|
||||
|
|
@ -82907,6 +82915,7 @@
|
|||
</body>
|
||||
</html></richcontent>
|
||||
<linktarget COLOR="#ffe99c" DESTINATION="ID_617432070" ENDARROW="Default" ENDINCLINATION="236;9;" ID="Arrow_ID_1412212027" SOURCE="ID_711986937" STARTARROW="None" STARTINCLINATION="236;9;"/>
|
||||
<linktarget COLOR="#fe8953" DESTINATION="ID_617432070" ENDARROW="Default" ENDINCLINATION="368;0;" ID="Arrow_ID_1535827259" SOURCE="ID_1219008003" STARTARROW="None" STARTINCLINATION="463;38;"/>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1783209469407" ID="ID_490480880" MODIFIED="1783209607495" TEXT="mit einer linearisierten Vererbunskette gibt's lediglich eine Warnung">
|
||||
|
|
@ -82994,7 +83003,45 @@
|
|||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1783101484020" ID="ID_1158137372" MODIFIED="1783101497340" TEXT="entwicklen per ParameterDomain_test"/>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1783101484020" ID="ID_1158137372" MODIFIED="1784502236650" TEXT="entwicklen per ParameterDomain_test">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node COLOR="#984388" CREATED="1784502242602" ID="ID_635909141" MODIFIED="1784502276027" TEXT="okok .... das artet in Arbeit aus ....">
|
||||
<icon BUILTIN="smiley-oh"/>
|
||||
</node>
|
||||
<node CREATED="1784501919054" ID="ID_1834839968" MODIFIED="1784501936727" TEXT="beginne mit Templates für frei-stehende cross-Type-Zugriffe">
|
||||
<node BACKGROUND_COLOR="#e0ceaa" COLOR="#690f14" CREATED="1784501937939" ID="ID_1946888391" MODIFIED="1784501952147">
|
||||
<richcontent TYPE="NODE"><html>
|
||||
<head/>
|
||||
<body>
|
||||
<p>
|
||||
das ist noch <i>kein</i> Visitor
|
||||
</p>
|
||||
</body>
|
||||
</html></richcontent>
|
||||
<icon BUILTIN="messagebox_warning"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#d9c0bd" COLOR="#990033" CREATED="1784502003675" ID="ID_115402714" MODIFIED="1784502055057" TEXT="essentiell daß die Domain zum tatsächlichen Inhalt des ValBuff paßt">
|
||||
<icon BUILTIN="clanbomber"/>
|
||||
</node>
|
||||
<node CREATED="1784501953246" ID="ID_1520405558" MODIFIED="1784502078308" TEXT="essentiell daß der richtige Type-Handler explizit gewählt wird">
|
||||
<icon BUILTIN="smiley-neutral"/>
|
||||
<node CREATED="1784502084663" ID="ID_1219008003" MODIFIED="1784502137582" TEXT="sonst gibts Probleme mit Ambituität">
|
||||
<arrowlink COLOR="#fe8953" DESTINATION="ID_617432070" ENDARROW="Default" ENDINCLINATION="368;0;" ID="Arrow_ID_1535827259" STARTARROW="None" STARTINCLINATION="463;38;"/>
|
||||
</node>
|
||||
<node CREATED="1784502096998" ID="ID_35168456" MODIFIED="1784502221459" TEXT="ärgerlich — aber isso">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head/>
|
||||
<body>
|
||||
<p>
|
||||
Glaube nicht, daß ich mich damit aufhalten sollte; das führt direkt in das lästige Thema mit den automatischen Konversionen zwischen Basistypen — wenn überhaupt sollte eine Spezialbehandlung dafür in ein Regelwerk gelenkt werden (und darauf ziehlt doch das ganze Setup mit dem Visitor ab....)
|
||||
</p>
|
||||
</body>
|
||||
</html></richcontent>
|
||||
<icon BUILTIN="yes"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
|
|
@ -184216,7 +184263,7 @@ class Something
|
|||
<linktarget COLOR="#415ab4" DESTINATION="ID_197491932" ENDARROW="Default" ENDINCLINATION="-1574;159;" ID="Arrow_ID_1382804093" SOURCE="ID_1579820839" STARTARROW="None" STARTINCLINATION="-2029;0;"/>
|
||||
<icon BUILTIN="info"/>
|
||||
</node>
|
||||
<node CREATED="1774627260591" FOLDED="true" ID="ID_1784884752" MODIFIED="1774628681299" TEXT="Grundzüge">
|
||||
<node CREATED="1774627260591" ID="ID_1784884752" MODIFIED="1784495142011" TEXT="Grundzüge">
|
||||
<icon BUILTIN="back"/>
|
||||
<node CREATED="1774627283191" ID="ID_115112464" MODIFIED="1774628259773">
|
||||
<richcontent TYPE="NODE"><html>
|
||||
|
|
@ -184260,7 +184307,11 @@ class Something
|
|||
</body>
|
||||
</html></richcontent>
|
||||
<node CREATED="1774627743029" ID="ID_1990543481" MODIFIED="1774627754085" TEXT="es erzeugt einen SFINAE-Scope"/>
|
||||
<node CREATED="1774627755233" ID="ID_1578349738" MODIFIED="1774627765109" TEXT="sein Ergebnis ist constexpr bool"/>
|
||||
<node CREATED="1774627755233" ID="ID_1578349738" MODIFIED="1774627765109" TEXT="sein Ergebnis ist constexpr bool">
|
||||
<node COLOR="#2c1951" CREATED="1784495496764" HGAP="27" ID="ID_1533050856" MODIFIED="1784495547265" TEXT="true ⟻ wenn alle enthaltenen Ausdrücke gebildet werden können" VSHIFT="2">
|
||||
<font NAME="SansSerif" SIZE="11"/>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1774627767320" ID="ID_1887793857" MODIFIED="1774628409651" TEXT="er erzeugt declval-Parameter">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head/>
|
||||
|
|
@ -184303,12 +184354,12 @@ class Something
|
|||
</body>
|
||||
</html></richcontent>
|
||||
</node>
|
||||
<node CREATED="1774627839278" ID="ID_477641322" MODIFIED="1774627981787" TEXT="requires-Klausel">
|
||||
<node CREATED="1774627839278" ID="ID_477641322" MODIFIED="1784495900932" TEXT="requires-Klausel">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head/>
|
||||
<body>
|
||||
<p>
|
||||
die Requires-Klausel darf nicht scheitern
|
||||
die Requires-Klausel darf nicht scheitern; insofern muß das Argument der Requires-Klausel (≙ ein constraint oder concept) syntaktisch korrekt gebildet werden können, und es muß zur Compile-Zeit zu true evaluieren.
|
||||
</p>
|
||||
</body>
|
||||
</html></richcontent>
|
||||
|
|
@ -184324,9 +184375,20 @@ class Something
|
|||
</p>
|
||||
</body>
|
||||
</html></richcontent>
|
||||
<node CREATED="1784495716108" HGAP="32" ID="ID_1258175475" MODIFIED="1784495809959" TEXT="requires requires {...}" VSHIFT="7">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head/>
|
||||
<body>
|
||||
<p>
|
||||
Das ist eine Requires-<b>Klausel</b> die einen anonymen Constraint prüft (der als eingeschachtelter Requires-<b>Ausdruck</b> formuliert wurde)
|
||||
</p>
|
||||
</body>
|
||||
</html></richcontent>
|
||||
<icon BUILTIN="idea"/>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1774562489996" ID="ID_1581229318" MODIFIED="1774563657284" TEXT="Iteratoren">
|
||||
</node>
|
||||
<node CREATED="1774562489996" FOLDED="true" ID="ID_1581229318" MODIFIED="1774563657284" TEXT="Iteratoren">
|
||||
<linktarget COLOR="#4c86e5" DESTINATION="ID_1581229318" ENDARROW="Default" ENDINCLINATION="-2159;523;" ID="Arrow_ID_58259000" SOURCE="ID_389716197" STARTARROW="None" STARTINCLINATION="-1280;85;"/>
|
||||
<node CREATED="1774562670530" ID="ID_1893015368" LINK="https://en.cppreference.com/w/cpp/iterator.html" MODIFIED="1774562682659" TEXT="siehe: »Iterator-Library«">
|
||||
<icon BUILTIN="info"/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue