ElementAccess: (WIP) another unsuccessful attempt
Problem is, we can not even compile the conversion in the "other branch". Thus we need to find some way to pick the suitable branch at compile time. Quite similar to the solution found for binding Rec<GenNode> onto a typed Tuple
This commit is contained in:
parent
91b83f5ede
commit
35ea547fd1
2 changed files with 66 additions and 21 deletions
|
|
@ -56,6 +56,7 @@
|
|||
#include "lib/nocopy.hpp"
|
||||
#include "lib/result.hpp"
|
||||
#include "include/limits.h"
|
||||
#include "lib/variant.hpp"
|
||||
#include "lib/access-casted.hpp"
|
||||
#include "gui/interact/ui-coord.hpp"
|
||||
//#include "lib/format-string.hpp"
|
||||
|
|
@ -73,6 +74,7 @@ namespace model {
|
|||
namespace error = lumiera::error;
|
||||
|
||||
using interact::UICoord;
|
||||
using lib::meta::Types;
|
||||
// using util::isnil;
|
||||
using std::string;
|
||||
|
||||
|
|
@ -105,16 +107,7 @@ namespace model {
|
|||
|
||||
|
||||
protected:
|
||||
struct RawResult
|
||||
{
|
||||
model::Tangible* tangible = nullptr;
|
||||
Gtk::Widget* gtkWidget = nullptr;
|
||||
|
||||
RawResult (model::Tangible& t) : tangible{&t} { }
|
||||
RawResult (Gtk::Widget& w) : gtkWidget{&w} { }
|
||||
RawResult() =default;
|
||||
// standard copy
|
||||
};
|
||||
using RawResult = lib::Variant<Types<model::Tangible*, Gtk::Widget*>>;
|
||||
|
||||
/** @internal drill down according to coordinates, maybe create element */
|
||||
virtual RawResult performAccessTo (UICoord, size_t limitCreation) =0;
|
||||
|
|
@ -138,14 +131,7 @@ namespace model {
|
|||
inline ElementAccess::Result<TAR&>
|
||||
ElementAccess::access (UICoord destination)
|
||||
{
|
||||
RawResult targetElm = performAccessTo (destination, 0);
|
||||
if (targetElm.tangible)
|
||||
return util::AccessCasted<TAR&>::access (targetElm.tangible);
|
||||
else
|
||||
if (targetElm.gtkWidget)
|
||||
return util::AccessCasted<TAR&>::access (targetElm.gtkWidget);
|
||||
else
|
||||
return "In current UI, there is no element at location "+string(destination);
|
||||
return access_or_create<TAR> (destination, 0);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -159,7 +145,23 @@ namespace model {
|
|||
inline ElementAccess::Result<TAR&>
|
||||
ElementAccess::access_or_create (UICoord destination, size_t limitCreation)
|
||||
{
|
||||
UNIMPLEMENTED ("delegate to a suitable polymorphic navigation/creation function");
|
||||
struct TypeConverter
|
||||
: RawResult::Visitor
|
||||
{
|
||||
Result<TAR&> result;
|
||||
|
||||
void accept (model::Tangible* t) { result = util::AccessCasted<TAR&>::access (t); }
|
||||
void accept (Gtk::Widget* w) { result = util::AccessCasted<TAR&>::access (w); }
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////TODO Verdammter Mist!!!! es werden WIEDER beide Zweige compiliert, aber nur einer geht!!!
|
||||
RawResult targetElm = performAccessTo (destination, limitCreation);
|
||||
if (targetElm.tangible)
|
||||
return util::AccessCasted<TAR&>::access (targetElm.tangible);
|
||||
else
|
||||
if (targetElm.gtkWidget)
|
||||
return util::AccessCasted<TAR&>::access (targetElm.gtkWidget);
|
||||
else
|
||||
return "In current UI, there is no element at location "+string(destination);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -12748,6 +12748,11 @@
|
|||
<icon BUILTIN="broken-line"/>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1523229374586" ID="ID_1962044591" MODIFIED="1523229381985" TEXT="sigc::trackable">
|
||||
<icon BUILTIN="button_cancel"/>
|
||||
<node CREATED="1523229383305" ID="ID_1786273483" MODIFIED="1523229392595" TEXT="hat kein RTTI"/>
|
||||
<node CREATED="1523229393567" ID="ID_1067337253" MODIFIED="1523229403706" TEXT="wohl bewußte Design-Entscheidung"/>
|
||||
</node>
|
||||
<node CREATED="1523228995279" ID="ID_924400738" MODIFIED="1523229065936" TEXT="muß mich wohl auf eine Menge von Basis-Typen festlegen">
|
||||
<icon BUILTIN="smily_bad"/>
|
||||
<node CREATED="1523229075403" ID="ID_808081590" MODIFIED="1523229080671" TEXT="model::Tangible"/>
|
||||
|
|
@ -12869,9 +12874,47 @@
|
|||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1523222380124" ID="ID_1101595897" MODIFIED="1523228027969" TEXT="muß prüfen, ob der Cast möglich ist">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node CREATED="1523229139923" ID="ID_636796034" MODIFIED="1523229145773" TEXT="Variant?"/>
|
||||
<node CREATED="1523229147593" ID="ID_1510668106" MODIFIED="1523229166296" TEXT="if-else-Kaskade?">
|
||||
<node CREATED="1523229139923" ID="ID_636796034" MODIFIED="1523229481422" TEXT="Variant?">
|
||||
<icon BUILTIN="forward"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1523229483619" ID="ID_1116388815" MODIFIED="1523232763524" TEXT="wohl einzige Lösung?"/>
|
||||
<node BACKGROUND_COLOR="#fdfdcf" COLOR="#ff0000" CREATED="1523232748878" ID="ID_153055029" MODIFIED="1523232770707" TEXT="AUA --- geht auch nicht">
|
||||
<icon BUILTIN="broken-line"/>
|
||||
<node CREATED="1523232788680" ID="ID_849117954" MODIFIED="1523232797628" TEXT="Ändert nix am Grundproblem">
|
||||
<icon BUILTIN="smily_bad"/>
|
||||
</node>
|
||||
<node CREATED="1523232798911" ID="ID_351873038" MODIFIED="1523232810481" TEXT="AccessCasted für Zieltyp"/>
|
||||
<node CREATED="1523232811805" ID="ID_577095101" MODIFIED="1523232886443" TEXT="läßt sich nur bei kompatiblem Basistyp überhaupt instantiieren">
|
||||
<icon BUILTIN="messagebox_warning"/>
|
||||
</node>
|
||||
<node CREATED="1523232888115" ID="ID_800807629" MODIFIED="1523232908023">
|
||||
<richcontent TYPE="NODE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
aber genau das ist hier jeweils nur <i>in einem Fall</i> gegeben
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
</richcontent>
|
||||
</node>
|
||||
<node CREATED="1523232932724" ID="ID_386898631" MODIFIED="1523232938983" TEXT="Runtime-Compiletime-Problem">
|
||||
<node CREATED="1523232945043" ID="ID_45452812" MODIFIED="1523232954053" TEXT="erst zur Laufzeit wissen wir, was zurückkommt"/>
|
||||
<node CREATED="1523233007258" ID="ID_1076174983" MODIFIED="1523233019060" TEXT="aber zur Compilezeit müssen wir schon den Cast vorbereiten"/>
|
||||
</node>
|
||||
<node CREATED="1523233031479" ID="ID_1135973571" MODIFIED="1523233048184" TEXT="Idee: Visitor spezialisieren">
|
||||
<node CREATED="1523233049316" ID="ID_278890079" MODIFIED="1523233057943" TEXT="er implementiert überhaupt nur den Fall, der geht"/>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1523229496001" ID="ID_190653452" MODIFIED="1523229516738" TEXT="bedeutet...">
|
||||
<icon BUILTIN="messagebox_warning"/>
|
||||
<node CREATED="1523229517523" ID="ID_1510464943" MODIFIED="1523229517523" TEXT="Variant-Visitor"/>
|
||||
<node CREATED="1523229519846" ID="ID_307916731" MODIFIED="1523229533208" TEXT="Einschränkungen für die Test-Dummies"/>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1523229147593" ID="ID_1510668106" MODIFIED="1523229476684" TEXT="if-else-Kaskade?">
|
||||
<icon BUILTIN="button_cancel"/>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1523225025493" ID="ID_1731501078" MODIFIED="1523225070764" TEXT="der interne Aufruf kann einen Pointer liefern">
|
||||
|
|
|
|||
Loading…
Reference in a new issue