From 76fc4444379ec1fbd572a8f5a2d6a0118b419f20 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 2 Oct 2016 22:21:17 +0200 Subject: [PATCH] MutationMessage: implementation draft --- src/gui/ctrl/bus-controller.cpp | 2 +- src/gui/ctrl/mutation-message.hpp | 52 +++++++++++++++++++++++--- tests/gui/abstract-tangible-test.cpp | 9 +++-- tests/gui/test/mock-elm.hpp | 9 +++++ wiki/thinkPad.ichthyo.mm | 55 ++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 10 deletions(-) diff --git a/src/gui/ctrl/bus-controller.cpp b/src/gui/ctrl/bus-controller.cpp index 19c3add4d..91d64746c 100644 --- a/src/gui/ctrl/bus-controller.cpp +++ b/src/gui/ctrl/bus-controller.cpp @@ -73,7 +73,7 @@ namespace ctrl { } - MutationMessage::~MutationMessage() { } + diff_msg::Holder::~Holder() { } diff --git a/src/gui/ctrl/mutation-message.hpp b/src/gui/ctrl/mutation-message.hpp index b2a97721e..8c4f4bf50 100644 --- a/src/gui/ctrl/mutation-message.hpp +++ b/src/gui/ctrl/mutation-message.hpp @@ -52,12 +52,14 @@ #include "lib/error.hpp" //#include "lib/symbol.hpp" +#include "lib/opaque-holder.hpp" //#include "lib/util.hpp" //#include "lib/idi/entry-id.hpp" #include "lib/diff/diff-mutable.hpp" //#include //#include +#include #include @@ -73,6 +75,42 @@ namespace ctrl{ // using lib::diff::GenNode; using std::string; + namespace diff_msg { + + class Holder + { + public: + virtual ~Holder(); ///< this is an interface + virtual void applyTo (lib::diff::DiffMutable&) =0; + virtual string describe() const =0; + }; + + template + class Wrapped + : public Holder + { + DIFF diff_; + + virtual void + applyTo (lib::diff::DiffMutable& target) override + { + UNIMPLEMENTED("how to embed a diff sequence and apply this to the target"); + } + + virtual string + describe() const override + { + UNIMPLEMENTED("string representation of diff/mutation messages"); + } + + public: + Wrapped (DIFF&& diffSeq) + : diff_(std::move(diffSeq)) + { } + }; + + using Buffer = lib::InPlaceBuffer; + } /** * Message on the UI-Bus holding an embedded diff sequence. @@ -80,21 +118,25 @@ namespace ctrl{ * to expose a TreeMutator, and then apply the embedded diff. */ class MutationMessage + : public diff_msg::Buffer { - protected: public: - virtual ~MutationMessage(); ///< this is an interface + template + MutationMessage(DIFF&& diffSeq) + : diff_msg::Buffer{ embedType>() + , std::move(diffSeq)} + { } - virtual void + void applyTo (lib::diff::DiffMutable& target) { - UNIMPLEMENTED("how to embed a diff sequence and apply this to the target"); + access()->applyTo(target); } operator string() const { - UNIMPLEMENTED("string representation of diff/mutation messages"); + return unConst(this)->access()->describe(); } protected: diff --git a/tests/gui/abstract-tangible-test.cpp b/tests/gui/abstract-tangible-test.cpp index 2acb90bd7..a855f65b5 100644 --- a/tests/gui/abstract-tangible-test.cpp +++ b/tests/gui/abstract-tangible-test.cpp @@ -76,6 +76,7 @@ using lib::diff::DataCap; using proc::control::Command; using proc::control::CommandDef; using gui::interact::InvocationTrail; +using gui::ctrl::MutationMessage; @@ -580,8 +581,8 @@ namespace test { MockElm rootMock("root"); ID rootID = rootMock.getID(); - rootMock["α"] = "Centauri"; - CHECK ("Centauri" == rootMock["α"]); + rootMock.attrib["α"] = "Centauri"; + CHECK ("Centauri" == rootMock.attrib["α"]); CHECK (isnil (rootMock.scope)); @@ -626,10 +627,10 @@ namespace test { << "\n───╼━━━━━━━━━╾────────────────"< +#include +#include namespace gui { @@ -112,6 +114,7 @@ namespace test{ string error_; + /* ==== Tangible interface ==== */ virtual bool @@ -295,6 +298,12 @@ namespace test{ + /* ==== Attributes and mock children ==== */ + + std::map attrib; + std::vector scope; + + /* ==== Query/Verification API ==== */ ID getID() const diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 5bd00fa5d..cd9de3f0e 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -5590,6 +5590,61 @@ + + + + + + + + +

+ ....denn dann müßte der Benutzer die Mechanik sehr genau verstehen, und stets eine auto-Variable definieren. +

+

+ Sinnvoll wäre dieser Ansatz nur, wenn das UI-Bus-API eine MutationMessage const& nehmen würde, +

+

+ denn dann könnte man den Builder-Aufruf inline schreiben. +

+

+ Da wir aber stets den Diff moven und dann iterieren, scheidet const& aus +

+

+ Und für eine reine Ref erzeugt C++ niemals eine anonyme Instanz! +

+ + +
+
+ + + + + + +

+ ...und diesen mit VTable bestücken. +

+

+ Dafür wird die äußere Hülle non-virtual +

+

+ und kann noncopyable gemacht werden.. +

+

+ Das erlaubt dem Benutzer, einfach zu schreiben +

+

+ MutationMessage(blaBlubb()) +

+ + +
+ +
+ +