Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
tree-mutator-gen-node-binding.hpp
Go to the documentation of this file.
1/*
2 TREE-MUTATOR-GEN-NODE-BINDING.hpp - diff::TreeMutator implementation building block
3
4 Copyright (C)
5 2016, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12*/
13
14
50#ifndef LIB_DIFF_TREE_MUTATOR_GEN_NODE_BINDING_H
51#define LIB_DIFF_TREE_MUTATOR_GEN_NODE_BINDING_H
52
53
54#include "lib/diff/gen-node.hpp"
57
58#include <tuple>
59
60
61namespace lib {
62namespace diff{
63
64 namespace { // Mutator-Builder decorator components...
65
81 template<class PAR>
83 : public PAR
84 {
86
87 public:
88 ObjectTypeHandler(Rec::Mutator& targetObj, PAR&& chain)
89 : PAR(std::forward<PAR>(chain))
90 , targetObj_(targetObj)
91 { }
92
93 virtual bool
94 injectNew (GenNode const& spec) override
95 {
96 if (spec.isNamed() and spec.isTypeID())
97 {
98 targetObj_.setType(spec.data.get<string>());
99 return true;
100 }
101 else
102 return PAR::injectNew (spec);
103 }
104
105 virtual bool
106 assignElm (GenNode const& spec) override
107 {
108 if (spec.isNamed() and spec.isTypeID())
109 {
110 targetObj_.setType(spec.data.get<string>());
111 return true;
112 }
113 else
114 return PAR::assignElm (spec);
115 }
116 };
117
118 template<class MUT>
119 inline Builder<ObjectTypeHandler<MUT>>
120 filterObjectTypeAttribute (Rec::Mutator& targetTree, Builder<MUT>&& chain)
121 {
122 using ObTyHa = ObjectTypeHandler<MUT>;
123 return Builder<ObTyHa>{ObTyHa {targetTree, move(chain)}};
124 }
125
126
127
129
130 inline Storage&
132 {
133 return std::get<0> (targetTree.exposeToDiff());
134 }
135
136 inline Storage&
138 {
139 return std::get<1> (targetTree.exposeToDiff());
140 }
141
142
144 template<class PAR>
145 inline auto
147 {
148 auto rawBinding = this->attach (collection (accessChildren(targetTree)))
149 .attach (collection (accessAttribs(targetTree))
150 .isApplicableIf ([](GenNode const& spec) -> bool
151 { // »Selector« : treat key-value elements here
152 return spec.isNamed();
153 }));
154
155 return filterObjectTypeAttribute(targetTree, move(rawBinding));
156 }
157
158 }//(END)Mutator-Builder decorator components...
159
160
161}} // namespace lib::diff
162#endif /*LIB_DIFF_TREE_MUTATOR_GEN_NODE_BINDING_H*/
void setType(string const &newTypeID)
Definition record.hpp:448
Generic building block for tree shaped (meta)data structures.
Builder< ObjectTypeHandler< MUT > > filterObjectTypeAttribute(Rec::Mutator &targetTree, Builder< MUT > &&chain)
Implementation namespace for support and library code.
STL namespace.
generic data element node within a tree
Definition gen-node.hpp:224
bool isTypeID() const
Definition gen-node.hpp:343
bool isNamed() const
Definition gen-node.hpp:337
Builder-DSL to create and configure a concrete TreeMutator.
auto attach(BIN &&collectionBindingSetup)
set up a binding to a structure of "child objects", implemented through a typical STL container
Special binding implementation for lib::diff::TreeMutator, allowing to map tree diff operations onto ...
Customisable intermediary to abstract generic tree mutation operations.