solution (draft) for the type field problem
unit test PASS but the resulting code is hard to understand should refactor it to use a binding class similar to the other binding cases
This commit is contained in:
parent
8530d50b7c
commit
17f8922775
4 changed files with 99 additions and 16 deletions
|
|
@ -294,7 +294,7 @@ namespace diff{
|
|||
|
||||
/** repeatedly accept, until after the designated location */
|
||||
virtual bool
|
||||
accept_until (GenNode const& spec)
|
||||
accept_until (GenNode const& spec) override
|
||||
{
|
||||
if (spec.matches (Ref::END)
|
||||
or
|
||||
|
|
@ -329,7 +329,7 @@ namespace diff{
|
|||
/** locate element already accepted into the target sequence
|
||||
* and assign the designated payload value to it. */
|
||||
virtual bool
|
||||
assignElm (GenNode const& spec)
|
||||
assignElm (GenNode const& spec) override
|
||||
{
|
||||
if (binding_.isApplicable(spec))
|
||||
{
|
||||
|
|
@ -343,7 +343,7 @@ namespace diff{
|
|||
/** locate the designated target element and build a suitable
|
||||
* sub-mutator for this element into the provided target buffer */
|
||||
virtual bool
|
||||
mutateChild (GenNode const& spec, TreeMutator::Handle targetBuff)
|
||||
mutateChild (GenNode const& spec, TreeMutator::Handle targetBuff) override
|
||||
{
|
||||
if (binding_.isApplicable(spec))
|
||||
{
|
||||
|
|
@ -357,7 +357,7 @@ namespace diff{
|
|||
/** verify all our pending (old) source elements where mentioned.
|
||||
* @note allows chained "onion-layers" to clean-up and verify.*/
|
||||
virtual bool
|
||||
completeScope()
|
||||
completeScope() override
|
||||
{
|
||||
return PAR::completeScope()
|
||||
and isnil(this->pos_);
|
||||
|
|
|
|||
|
|
@ -85,6 +85,49 @@ namespace diff{
|
|||
return std::get<1> (targetTree.exposeToDiff());
|
||||
}
|
||||
|
||||
template<class PAR>
|
||||
class ObjectTypeHandler
|
||||
: public PAR
|
||||
{
|
||||
Rec::Mutator& targetObj_;
|
||||
|
||||
public:
|
||||
ObjectTypeHandler(Rec::Mutator& targetObj, PAR&& chain)
|
||||
: PAR(std::forward<PAR>(chain))
|
||||
, targetObj_(targetObj)
|
||||
{ }
|
||||
|
||||
virtual bool
|
||||
injectNew (GenNode const& n) override
|
||||
{
|
||||
if (n.isNamed() and n.isTypeID())
|
||||
{
|
||||
targetObj_.setType(n.data.get<string>());
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return PAR::injectNew (n);
|
||||
}
|
||||
|
||||
virtual bool
|
||||
assignElm (GenNode const& n) override
|
||||
{
|
||||
if (n.isNamed() and n.isTypeID())
|
||||
{
|
||||
targetObj_.setType(n.data.get<string>());
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return PAR::assignElm (n);
|
||||
}
|
||||
};
|
||||
|
||||
template<class MUT>
|
||||
inline Builder<ObjectTypeHandler<MUT>>
|
||||
filterObjectType (Rec::Mutator& targetTree, Builder<MUT>&& baseBuilder)
|
||||
{
|
||||
return ObjectTypeHandler<MUT> {targetTree, move(baseBuilder)};
|
||||
}
|
||||
|
||||
|
||||
/** Entry point for DSL builder */
|
||||
|
|
@ -92,12 +135,13 @@ namespace diff{
|
|||
inline auto
|
||||
Builder<PAR>::attach (Rec::Mutator& targetTree)
|
||||
{
|
||||
return this->attach (collection (accessChildren(targetTree)))
|
||||
return filterObjectType(targetTree,
|
||||
this->attach (collection (accessChildren(targetTree)))
|
||||
.attach (collection (accessAttribs(targetTree))
|
||||
.isApplicableIf ([](GenNode const& spec) -> bool
|
||||
{
|
||||
return spec.isNamed(); // »Selector« : treat key-value elements here
|
||||
}));
|
||||
})));
|
||||
}
|
||||
|
||||
inline void
|
||||
|
|
|
|||
|
|
@ -1128,12 +1128,9 @@ namespace test{
|
|||
cout << "Sub-" << renderNode(subNode) <<endl; // some new content into our implementation defined sub scope!
|
||||
|
||||
// verify contents of nested scope after mutation
|
||||
cout <<"Type=="<<nestedRec.getType()<<endl; ///////////TODO Problem: type attribute not recognised!!!!
|
||||
// CHECK ("ξ" == nested.getType()); // type of nested node has been set to Xi
|
||||
CHECK ("ξ" == nestedRec.getType()); // type of nested node has been set to Xi
|
||||
attrs = nestedRec.attribs(); // look into the nested node's attributes...
|
||||
// CHECK ( *attrs == ATTRIB2);
|
||||
// CHECK ( *attrs == TYPE_X); //////////////TODO Problem: type attribute not recognised!!!!
|
||||
CHECK (*++attrs == ATTRIB2);
|
||||
CHECK ( *attrs == ATTRIB2);
|
||||
CHECK (isnil (++attrs));
|
||||
scope = nestedRec.scope(); // look into the nested nodes's scope contents...
|
||||
CHECK ( *scope == CHILD_B);
|
||||
|
|
@ -1145,10 +1142,11 @@ namespace test{
|
|||
// ...add a new attribute and immediately recurse into it
|
||||
mutator3.injectNew (ATTRIB_NODE);
|
||||
CHECK (mutator3.mutateChild (ATTRIB_NODE, placementHandle)); // NOTE: we're just recycling the buffer. InPlaceHolder handles lifecycle properly
|
||||
subMutatorBuffer->injectNew (TYPE_Z);
|
||||
subMutatorBuffer->injectNew (TYPE_X);
|
||||
subMutatorBuffer->injectNew (CHILD_A);
|
||||
subMutatorBuffer->injectNew (CHILD_A);
|
||||
subMutatorBuffer->injectNew (CHILD_A);
|
||||
subMutatorBuffer->assignElm (TYPE_Z); // NOTE use assignment to *change* the type field
|
||||
CHECK (subMutatorBuffer->completeScope()); // no pending "open ends" left in sub-scope
|
||||
CHECK (mutator3.completeScope()); // and likewise in the enclosing main scope
|
||||
|
||||
|
|
@ -1158,9 +1156,8 @@ namespace test{
|
|||
|
||||
// verify contents of this second nested scope
|
||||
CHECK (not isnil (attrRec));
|
||||
cout <<"Type=="<<attrRec.getType()<<endl; /////////////TODO Problem: type attribute not recognised!!!!
|
||||
// CHECK ("ζ" == attrNode.getType());
|
||||
// CHECK (isnil (attrNode.attribs())); ///////////////TODO Problem: type attribute not recognised!!!!
|
||||
CHECK ("ζ" == attrRec.getType());
|
||||
CHECK (isnil (attrRec.attribs()));
|
||||
scope = attrRec.scope();
|
||||
CHECK (not isnil (scope));
|
||||
CHECK ( *scope == CHILD_A);
|
||||
|
|
|
|||
|
|
@ -4346,8 +4346,9 @@
|
|||
<icon BUILTIN="smily_bad"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1472930979111" ID="ID_1629990314" MODIFIED="1472931001117" TEXT="Problem: Typ-Feld">
|
||||
<node CREATED="1472930979111" ID="ID_1629990314" MODIFIED="1472934775211" TEXT="Problem: Typ-Feld">
|
||||
<icon BUILTIN="messagebox_warning"/>
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node CREATED="1472931031568" ID="ID_1634653912" MODIFIED="1472931192300" TEXT="Kompromiß in GenNode">
|
||||
<font ITALIC="true" NAME="SansSerif" SIZE="12"/>
|
||||
<node CREATED="1472931061612" ID="ID_1482076461" MODIFIED="1472931066111" TEXT="halbherziges Design"/>
|
||||
|
|
@ -4401,6 +4402,47 @@
|
|||
<node CREATED="1472931326512" ID="ID_150253618" MODIFIED="1472931332867" TEXT="arbeitet direkt auf den Collections"/>
|
||||
<node CREATED="1472931333975" ID="ID_330064662" MODIFIED="1472931342433" TEXT="reicht Werte unbetrachtet 1:1 durch"/>
|
||||
</node>
|
||||
<node CREATED="1472931711315" ID="ID_1747250133" MODIFIED="1472934762565" TEXT="Lösung">
|
||||
<icon BUILTIN="idea"/>
|
||||
<node CREATED="1472931716482" ID="ID_1328626801" MODIFIED="1472931798657" TEXT="Lambdas nicht ausreichend">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
...mit den Lambdas kann ich nur die Sicht auf die Werte steuern,
|
||||
</p>
|
||||
<p>
|
||||
nicht aber das eigentliche Verhalten des Bindings.
|
||||
</p>
|
||||
<p>
|
||||
|
||||
</p>
|
||||
<p>
|
||||
Denn die Lambdas haben keinen Zugriff auf die Ziel-Datenstruktur!
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
</richcontent>
|
||||
<icon BUILTIN="messagebox_warning"/>
|
||||
</node>
|
||||
<node CREATED="1472931806958" ID="ID_321203237" MODIFIED="1472931822190" TEXT="müßte Binding-Operationen anpassen">
|
||||
<icon BUILTIN="smily_bad"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1472931829467" ID="ID_383672039" MODIFIED="1472934744607" STYLE="fork" TEXT="Dekorator">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node CREATED="1472934618917" ID="ID_1010335466" MODIFIED="1472934744607" TEXT="legt sich um den äußeren Collection-Binding-Layer"/>
|
||||
<node CREATED="1472934635426" ID="ID_610715894" MODIFIED="1472934744607" TEXT="greift bei der injectNew und assignElm-Operation ein"/>
|
||||
<node CREATED="1472934671013" ID="ID_1605900118" MODIFIED="1472934744607" TEXT="braucht Zugang zum Rec::Mutator">
|
||||
<icon BUILTIN="messagebox_warning"/>
|
||||
</node>
|
||||
<node CREATED="1472934695226" ID="ID_247894372" MODIFIED="1472934744607" TEXT="Code wird schwer lesbar"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1472934710032" ID="ID_1233852840" MODIFIED="1472934744607" TEXT="umformulieren">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1472782025318" ID="ID_387350632" MODIFIED="1472782043725" TEXT="Standard-Lambdas für GenNode">
|
||||
<node CREATED="1472782055217" ID="ID_1053081307" MODIFIED="1472782069243" TEXT="Selector -> ID-Vergleich"/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue