UI-Coordinates/Navigator: identify misconception in the Builder

the original construction works only as long as we stick to the "classical" Builder syntax,
i.e. use chained calls of the builder functions. But as soon as we just invoke
some builder function for sake of the side-effect on the data within the builder,
this data is destroyed and moved out into the value return type, which unfortunately
is being thrown away right afterwards.

Thus: either make a builder really sideeffect-free, i.e. do each mutation
on a new copy (which is kind of inefficient and counterfeits the whole idea)
or just accept the side-effect and return only a reference.
In this case, we can still return a rvalue-Reference, since at the end
we want to move the product of the build process out into the destination.

This works only due to the C++ concept of sequence points, which ensures
the original object stays alive during the whole evaluation of such a chained
builder expression.

NOTE: the TreeMutator (in namespace lib::diff) also uses a similar Builder construction,
but in *that* case we really build a new product in each step and thus *must*
return a value object, otherwise the reference would already be dangling the
moment we leave the builder function.
This commit is contained in:
Fischlurch 2018-01-07 05:26:16 +01:00
parent 837aa81fc5
commit 0daeb02e4a
3 changed files with 59 additions and 16 deletions

View file

@ -214,6 +214,14 @@ namespace interact {
attempt_trivialResolution();
}
UICoordResolver (UICoord && uic, LocationQuery& queryAPI)
: Builder{std::move(uic)}
, query_{queryAPI}
, res_{}
{
attempt_trivialResolution();
}
/* === query functions === */
@ -297,7 +305,7 @@ namespace interact {
* @note if the coordinate spec can not be covered at all,
* it will be truncated to zero size
*/
UICoordResolver
UICoordResolver&&
cover()
{
if (isCoveredPartially() and not res_.covfefe)
@ -335,7 +343,7 @@ namespace interact {
* use the anchorage as indicated by that resolution,
* without interpolating the rest of the path.
*/
UICoordResolver
UICoordResolver&&
anchor()
{
if (canAnchor())
@ -346,7 +354,7 @@ namespace interact {
/** mutate the path to extend it while keeping it partially covered
*/
UICoordResolver
UICoordResolver&&
extend (Literal pathExtension)
{
if (not isCovered())

View file

@ -491,7 +491,7 @@ namespace interact {
/** change UI coordinate spec to define it to be rooted within the given window
* @note this function allows to _undefine_ the window, thus creating an incomplete spec */
Builder
Builder&&
window (Literal windowID)
{
uic_.setComponent (UIC_WINDOW, windowID);
@ -499,7 +499,7 @@ namespace interact {
}
/** augment UI coordinates to mandate a specific perspective to be active within the window */
Builder
Builder&&
persp (Literal perspectiveID)
{
uic_.setComponent (UIC_PERSP, perspectiveID);
@ -507,7 +507,7 @@ namespace interact {
}
/** augment UI coordinates to indicate a specific view to be used */
Builder
Builder&&
panel (Literal panelID)
{
uic_.setComponent (UIC_PANEL, panelID);
@ -515,7 +515,7 @@ namespace interact {
}
/** augment UI coordinates to indicate a specific view to be used */
Builder
Builder&&
view (Literal viewID)
{
uic_.setComponent (UIC_VIEW, viewID);
@ -523,7 +523,7 @@ namespace interact {
}
/** augment UI coordinates to indicate a specific tab within the view" */
Builder
Builder&&
tab (Literal tabID)
{
uic_.setComponent (UIC_TAB, tabID);
@ -531,7 +531,7 @@ namespace interact {
}
/** augment UI coordinates to indicate a tab specified by index number */
Builder
Builder&&
tab (uint tabIdx)
{
uic_.setComponent (UIC_TAB, Symbol{"#"+util::toString (tabIdx)});
@ -540,7 +540,7 @@ namespace interact {
/** augment UI coordinates to indicate that no tab specification is necessary
* @remarks typically this happens when a panel just holds a simple view */
Builder
Builder&&
noTab()
{
uic_.setComponent (UIC_TAB, UIC_ELIDED);
@ -552,7 +552,7 @@ namespace interact {
* @note the element might define a sequence of components separated by `'/'`,
* in which case several elements will be appended.
*/
Builder
Builder&&
append (Literal elm)
{
if (not isnil(elm))
@ -561,7 +561,7 @@ namespace interact {
}
/** augment partially defined UI coordinates by extending them towards the root */
Builder
Builder&&
prepend (Literal elmID)
{
if (not uic_.isIncomplete())
@ -577,7 +577,7 @@ namespace interact {
* @param pathDef a path, possibly with multiple components separated by `'/'`
* @note any existing path definition is completely replaced by the new path
*/
Builder
Builder&&
path (Literal pathDef)
{
uic_.setTailSequence (UIC_PATH, pathDef);
@ -585,7 +585,7 @@ namespace interact {
}
/** possibly shorten this path specification to a limited depth */
Builder
Builder&&
truncateTo (size_t depth)
{
uic_.truncateTo (depth);

View file

@ -9281,8 +9281,43 @@
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1515287694871" ID="ID_953283273" MODIFIED="1515287741026" TEXT="schon berechnet: eintragen">
<icon BUILTIN="flag-yellow"/>
<node CREATED="1515291343277" ID="ID_1704851738" MODIFIED="1515291349128" TEXT="explizites Cover machen"/>
<node BACKGROUND_COLOR="#fdfdcf" COLOR="#ff0000" CREATED="1515291350332" ID="ID_219986282" MODIFIED="1515291362081" TEXT="neue coverDepth mu&#xdf; sichtbar werden">
<icon BUILTIN="flag-pink"/>
<node COLOR="#338800" CREATED="1515291350332" ID="ID_219986282" MODIFIED="1515298798947" TEXT="neue coverDepth mu&#xdf; sichtbar werden">
<icon BUILTIN="button_ok"/>
<node CREATED="1515298565483" ID="ID_719457405" MODIFIED="1515298571802" TEXT="Autsch">
<icon BUILTIN="smily_bad"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1515298572994" ID="ID_1082678541" MODIFIED="1515298599961" TEXT="Denkfehler im Builder-Konzept!">
<icon BUILTIN="broken-line"/>
<node CREATED="1515298602326" ID="ID_13919667" MODIFIED="1515298692557" TEXT="R&#xfc;ckgabe ist Value...">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<body>
<p>
...und das hei&#223;t.
</p>
<p>
ein Value wird auch sofort konstruiert,
</p>
<p>
egal, ob man den dann gleich wegwirft.
</p>
</body>
</html></richcontent>
</node>
<node CREATED="1515298698849" ID="ID_1957524269" MODIFIED="1515298709411" TEXT="Objekt wird nach erstem Aufruf tats&#xe4;chlich zerst&#xf6;rt"/>
</node>
<node COLOR="#338800" CREATED="1515298710952" ID="ID_167586553" MODIFIED="1515298806412" TEXT="L&#xf6;sung: &amp;&amp; zur&#xfc;ckgeben">
<icon BUILTIN="button_ok"/>
</node>
<node CREATED="1515298722702" ID="ID_273407473" MODIFIED="1515298730297" TEXT="k&#xf6;nnte gef&#xe4;hrlich sein">
<icon BUILTIN="bell"/>
<node CREATED="1515298735548" ID="ID_966210103" MODIFIED="1515298746799" TEXT="Stichwort: Sequence Points"/>
<node CREATED="1515298747531" ID="ID_1013710090" MODIFIED="1515298752254" TEXT="im Debugger beobachtet"/>
<node CREATED="1515298753074" ID="ID_5305718" MODIFIED="1515298776867" TEXT="Builder-Syntax scheint zu funktionieren, wie erwartet"/>
<node CREATED="1515298777551" ID="ID_1384914895" MODIFIED="1515298789593" TEXT="explizite Aufruf-Syntax ebenso"/>
</node>
</node>
</node>
</node>