Lumiera  0.pre.03
»edit your freedom«
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 
61 namespace lib {
62 namespace diff{
63 
64  namespace { // Mutator-Builder decorator components...
65 
81  template<class PAR>
83  : public PAR
84  {
85  Rec::Mutator& targetObj_;
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 
128  using Storage = RecordSetup<GenNode>::Storage;
129 
130  inline Storage&
131  accessAttribs (Rec::Mutator& targetTree)
132  {
133  return std::get<0> (targetTree.exposeToDiff());
134  }
135 
136  inline Storage&
137  accessChildren (Rec::Mutator& targetTree)
138  {
139  return std::get<1> (targetTree.exposeToDiff());
140  }
141 
142 
144  template<class PAR>
145  inline auto
146  Builder<PAR>::attach (Rec::Mutator& targetTree)
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*/
Implementation namespace for support and library code.
Generic building block for tree shaped (meta)data structures.
Customisable intermediary to abstract generic tree mutation operations.
Special binding implementation for lib::diff::TreeMutator, allowing to map tree diff operations onto ...
auto collection(COLL &coll)
Entry point to a nested DSL for setup and configuration of a collection binding.
generic data element node within a tree
Definition: gen-node.hpp:222