From 0daeb02e4a17b885ba9f42420122ec3d398604c2 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 7 Jan 2018 05:26:16 +0100 Subject: [PATCH] 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. --- src/gui/interact/ui-coord-resolver.hpp | 14 +++++++-- src/gui/interact/ui-coord.hpp | 22 +++++++-------- wiki/thinkPad.ichthyo.mm | 39 ++++++++++++++++++++++++-- 3 files changed, 59 insertions(+), 16 deletions(-) diff --git a/src/gui/interact/ui-coord-resolver.hpp b/src/gui/interact/ui-coord-resolver.hpp index a76371356..6c1ae1ffb 100644 --- a/src/gui/interact/ui-coord-resolver.hpp +++ b/src/gui/interact/ui-coord-resolver.hpp @@ -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()) diff --git a/src/gui/interact/ui-coord.hpp b/src/gui/interact/ui-coord.hpp index a6504e1f3..76dbc5d1c 100644 --- a/src/gui/interact/ui-coord.hpp +++ b/src/gui/interact/ui-coord.hpp @@ -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); diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 76c03f041..d257e74d6 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -9281,8 +9281,43 @@ - - + + + + + + + + + + + + + +

+ ...und das heißt. +

+

+ ein Value wird auch sofort konstruiert, +

+

+ egal, ob man den dann gleich wegwirft. +

+ +
+
+ + + + + + + + + + + +