Lumiera  0.pre.03
»edit your freedom«
tree-mutator.hpp
Go to the documentation of this file.
1 /*
2  TREE-MUTATOR.hpp - flexible binding to map generic tree changing operations
3 
4  Copyright (C)
5  2015, 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 
86 #ifndef LIB_DIFF_TREE_MUTATOR_H
87 #define LIB_DIFF_TREE_MUTATOR_H
88 
89 
90 #include "lib/error.hpp"
91 #include "lib/nocopy.hpp"
92 #include "lib/symbol.hpp"
93 #include "lib/meta/trait.hpp"
94 #include "lib/diff/gen-node.hpp"
95 #include "lib/opaque-holder.hpp"
96 #include "lib/iter-adapter-stl.hpp"
97 #include "lib/format-string.hpp"
98 #include "lib/idi/entry-id.hpp"
99 
100 #include <utility>
101 #include <string>
102 
103 
104 namespace lib {
105 namespace diff{
106 
107  namespace error = lumiera::error;
108 
109  using lib::Symbol;
110  using std::string;
111  using util::_Fmt;
112  using lib::idi::BareEntryID;
113 
114 
115 
116 
117  class TestMutationTarget; // for unit testing
118 
119 
120  namespace {
121  template<class PAR>
122  struct Builder;
123  }
124 
125 
138  {
139 
140  public:
141  virtual ~TreeMutator();
142 
143  // only default and move construction allowed
144  TreeMutator () =default;
145  TreeMutator (TreeMutator&&) =default;
146 
147 
148 
149  /* ==== operation API ==== */
150 
157  virtual void
158  init() { }
159 
160  virtual bool
161  hasSrc ()
162  {
163  return false;
164  // do nothing by default
165  }
166 
169  virtual bool
171  {
172  // do nothing by default
173  return false;
174  }
175 
177  virtual bool
178  matchSrc (GenNode const&)
179  {
180  // do nothing by default
181  return false;
182  }
183 
194  virtual void
195  skipSrc (GenNode const&)
196  {
197  // do nothing by default
198  }
199 
201  virtual bool
203  {
204  // do nothing by default
205  return false;
206  }
207 
209  virtual bool
210  accept_until (GenNode const& spec)
211  {
212  return (Ref::END == spec or Ref::ATTRIBS == spec);
213  // contents are exhausted by default,
214  // yet we're unable to find something specific
215  }
216 
218  virtual bool
219  findSrc (GenNode const&)
220  {
221  // do nothing by default
222  return false;
223  }
224 
230  virtual bool
232  {
233  // do nothing by default
234  return false;
235  }
236 
237 
239 
245  virtual bool
247  {
248  // do nothing by default
249  return false;
250  }
251 
256  virtual bool
258  {
259  // nothing to clean-up or verify by default
260  return true;
261  }
262 
263 
264 
270  static Builder<TreeMutator> build();
271  };
272 
273 
274 
275 
276 
277  namespace { // Mutator-Builder decorator components...
278 
279  using std::forward;
280  using std::move;
281 
282 
291  template<class PAR>
292  struct Builder
293  : PAR
294  {
295  explicit
296  Builder(PAR&& par)
297  : PAR{forward<PAR> (par)}
298  { }
299 
300  template<typename BIN, typename...ARGS>
301  Builder<BIN>
302  chainedBuilder (ARGS&&...args)
303  {
304  return Builder<BIN> (BIN{forward<ARGS>(args)..., move(*this)});
305  }
306 
307 
308 
309  /* ==== binding API ==== */
310 
332  template<typename CLO>
333  auto change (Symbol attributeID, CLO setterClosure);
334 
335 
351  template<typename CLO>
352  auto mutateAttrib (Symbol attributeID, CLO mutatorBuilderClosure);
353 
358  template<typename CLO>
359  auto mutateAttrib (idi::BareEntryID const& rawID, CLO mutatorBuilderClosure);
360 
361 
406  template<typename BIN>
407  auto attach (BIN&& collectionBindingSetup);
408 
409 
420  auto attach (Rec::Mutator& targetTree);
421 
422 
426  auto attachDummy (TestMutationTarget& dummy);
427 
428 
430  auto ignoreAllChanges();
431 
432 
442  template<typename LIS>
443  auto onSeqChange (LIS changeListener);
444 
450  template<typename LIS>
451  auto onLocalChange (LIS changeListener);
452  };
453 
454  }//(END) Mutator-Builder...
455 
456 
457  inline Builder<TreeMutator>
459  {
460  return Builder<TreeMutator>{TreeMutator()};
461  }
462 
463 
464 }} // namespace lib::diff
465 
466 
467  /* == implementation detail headers == */
468 
474 
475 
476 
477 #endif /*LIB_DIFF_TREE_MUTATOR_H*/
type erased baseclass for building a combined hash and symbolic ID.
Definition: entry-id.hpp:133
virtual bool matchSrc(GenNode const &)
ensure the next source element matches with given spec
Builder-DSL to create and configure a concrete TreeMutator.
virtual bool completeScope()
ensure the scope addressed by this TreeMutator was processed and exhausted without mismatch ...
Test adapter to watch and verify how the TreeMutator binds to custom tree data structures.
virtual bool acceptSrc(GenNode const &)
accept existing element, when matching the given spec
Types marked with this mix-in may be moved but not copied.
Definition: nocopy.hpp:49
virtual bool findSrc(GenNode const &)
locate designated element and accept it at current position
Front-end for printf-style string template interpolation.
virtual bool injectNew(GenNode const &)
establish new element at current position
A front-end for using printf-style formatting.
Special binding implementation for TreeMutator, allowing to map tree diff operations onto native obje...
Implementation namespace for support and library code.
static Builder< TreeMutator > build()
DSL: start building a custom adapted tree mutator, where the operations are tied by closures or wrapp...
Token or Atom with distinct identity.
Definition: symbol.hpp:117
Mix-Ins to allow or prohibit various degrees of copying and cloning.
A handle to allow for safe »remote implantation« of an unknown subclass into a given opaque InPlaceBu...
Definition: record.hpp:104
static const Ref END
symbolic ID ref "_END_"
Definition: gen-node.hpp:862
Special supplement for TreeMutator, to attach listeners for notification on specific changes...
Marker types to indicate a literal string and a Symbol.
virtual void skipSrc(GenNode const &)
skip next src element and advance abstract source position.
Helper allowing type erasure while holding the actual object inline.
Generic building block for tree shaped (meta)data structures.
virtual bool assignElm(GenNode const &)
locate the designated target element (must be already accepted into the target sequence).
virtual bool accept_until(GenNode const &spec)
repeatedly accept, until after the designated location
Special binding implementation for TreeMutator, allowing to map tree diff operations onto an »Externa...
Helpers for type detection, type rewriting and metaprogramming.
Lumiera error handling (C++ interface).
Special binding implementation for TreeMutator, allowing to accept and ignore any tree diff without t...
static const Ref ATTRIBS
symbolic ID ref "_ATTRIBS_"
Definition: gen-node.hpp:865
Special binding implementation for lib::diff::TreeMutator, allowing to map tree diff operations onto ...
Bare symbolic and hash ID used for accounting of asset like entries.
Preconfigured adapters for some STL container standard usage situations.
virtual bool mutateChild(GenNode const &, Handle)
locate the designated target element and build a suitable sub-mutator for this element into the provi...
generic data element node within a tree
Definition: gen-node.hpp:222
virtual void init()
initialisation immediately before start of diff application
Customisable intermediary to abstract mutating operations on arbitrary, hierarchical object-like data...