Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
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"
97#include "lib/format-string.hpp"
98#include "lib/idi/entry-id.hpp"
99
100#include <utility>
101#include <string>
102
103
104namespace lib {
105namespace diff{
106
107 namespace error = lumiera::error;
108
109 using lib::Symbol;
110 using std::string;
111 using util::_Fmt;
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;
146
147
148
149 /* ==== operation API ==== */
150
157 virtual void
158 init() { }
159
160 virtual bool
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
179 {
180 // do nothing by default
181 return false;
182 }
183
194 virtual void
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
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>
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*/
A handle to allow for safe »remote implantation« of an unknown subclass into a given opaque InPlaceBu...
Token or Atom with distinct identity.
Definition symbol.hpp:120
Test adapter to watch and verify how the TreeMutator binds to custom tree data structures.
Customisable intermediary to abstract mutating operations on arbitrary, hierarchical object-like data...
virtual ~TreeMutator()
this is an interface
Definition tree-diff.cpp:42
static Builder< TreeMutator > build()
DSL: start building a custom adapted tree mutator, where the operations are tied by closures or wrapp...
virtual bool accept_until(GenNode const &spec)
repeatedly accept, until after the designated location
virtual bool injectNew(GenNode const &)
establish new element at current position
virtual bool findSrc(GenNode const &)
locate designated element and accept it at current position
virtual bool completeScope()
ensure the scope addressed by this TreeMutator was processed and exhausted without mismatch
virtual bool assignElm(GenNode const &)
locate the designated target element (must be already accepted into the target sequence).
virtual bool acceptSrc(GenNode const &)
accept existing element, when matching the given spec
virtual void init()
initialisation immediately before start of diff application
TreeMutator(TreeMutator &&)=default
virtual bool mutateChild(GenNode const &, Handle)
locate the designated target element and build a suitable sub-mutator for this element into the provi...
virtual bool matchSrc(GenNode const &)
ensure the next source element matches with given spec
virtual void skipSrc(GenNode const &)
skip next src element and advance abstract source position.
type erased baseclass for building a combined hash and symbolic ID.
Definition entry-id.hpp:134
Types marked with this mix-in may be moved but not copied.
Definition nocopy.hpp:50
A front-end for using printf-style formatting.
Bare symbolic and hash ID used for accounting of asset like entries.
Lumiera error handling (C++ interface).
Front-end for printf-style string template interpolation.
Generic building block for tree shaped (meta)data structures.
Preconfigured adapters for some STL container standard usage situations.
Implementation namespace for support and library code.
Mix-Ins to allow or prohibit various degrees of copying and cloning.
Helper allowing type erasure while holding the actual object inline.
generic data element node within a tree
Definition gen-node.hpp:224
static const Ref END
symbolic ID ref "_END_"
Definition gen-node.hpp:863
static const Ref ATTRIBS
symbolic ID ref "_ATTRIBS_"
Definition gen-node.hpp:866
Builder-DSL to create and configure a concrete TreeMutator.
auto attach(Rec::Mutator &targetTree)
set up binding to a GenNode tree: Special setup to build a concrete TreeMutator.
auto attach(BIN &&collectionBindingSetup)
set up a binding to a structure of "child objects", implemented through a typical STL container
auto onLocalChange(LIS changeListener)
attach a listener function, to be invoked on any local change.
auto change(Symbol attributeID, CLO setterClosure)
set up a binding to represent an "attribute" through a data or object field.
auto mutateAttrib(idi::BareEntryID const &rawID, CLO mutatorBuilderClosure)
auto mutateAttrib(Symbol attributeID, CLO mutatorBuilderClosure)
set up a binding for an object valued "attribute" or named scope.
auto onSeqChange(LIS changeListener)
attach a listener function, to be invoked on structural changes.
Marker types to indicate a literal string and a Symbol.
Helpers for type detection, type rewriting and metaprogramming.
Special binding implementation for TreeMutator, allowing to map tree diff operations onto native obje...
Special binding implementation for lib::diff::TreeMutator, allowing to map tree diff operations onto ...
Special binding implementation for TreeMutator, allowing to map tree diff operations onto an »Externa...
Special supplement for TreeMutator, to attach listeners for notification on specific changes,...
Special binding implementation for TreeMutator, allowing to accept and ignore any tree diff without t...