Lumiera  0.pre.03
»edit your freedom«
tree-mutator-diffmutable-binding.hpp
Go to the documentation of this file.
1 /*
2  TREE-MUTATOR-DIFFMUTABLE-BINDING.hpp - default configuration to attach a collection of DiffMutable objects
3 
4  Copyright (C)
5  2021, 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 
45 #ifndef LIB_DIFF_TREE_MUTATOR_DIFFMUTABLE_BINDING_H
46 #define LIB_DIFF_TREE_MUTATOR_DIFFMUTABLE_BINDING_H
47 
48 
49 #include "lib/error.hpp"
50 #include "lib/meta/trait.hpp"
51 #include "lib/diff/gen-node.hpp"
55 
56 namespace lib {
57 namespace diff{
58 
59  namespace { // Mutator-Builder decorator components...
60 
62  using lib::meta::Yes_t;
63  using lib::meta::No_t;
64  using std::__and_;
65  using std::__or_;
66 
75  template<typename TY>
77  {
78  template<typename X,
79  typename SEL = decltype(std::declval<GenNode::ID>() == std::declval<X>().getID())>
80  struct Probe
81  { };
82 
83  template<class X>
84  static Yes_t check(Probe<X> * );
85  template<class>
86  static No_t check(...);
87 
88  public:
89  static const bool value = (sizeof(Yes_t)==sizeof(check<TY>(0)));
90  };
91 
92  template<typename T>
94  : Can_retrieve_and_compare_ID<typename meta::Strip<T>::Type>
95  { };
96 
97  template<typename T>
99  : meta::is_Subclass<T,DiffMutable>
100  { };
101 
102  template<typename T>
104  : __and_< meta::Unwrap<T>
105  , Is_DiffMutable<typename meta::Unwrap<T>::Type>>
106  { };
107 
108  template<typename T>
110  : __or_< Is_DiffMutable<T>
111  , Is_wrapped_DiffMutable<T>>
112  { } ;
113 
114 
119  template<class TAR, typename SEL =void>
120  struct _AccessID
121  {
122  static idi::BareEntryID const&
123  getID (TAR const&)
124  {
125  throw error::Logic ("TreeMutator::build() .attach(collection...) : Unable to access the target element's object ID. "
126  "Please define a »Matcher« explicitly by invoking the builder function \"matchElement\".");
127  }
128  };
129  template<class ELM>
130  struct _AccessID<ELM, enable_if<Can_access_ID<ELM>>>
131  {
132  static idi::BareEntryID const&
133  getID (ELM const& target)
134  {
135  return meta::unwrap(target).getID();
136  }
137  };
138 
139 
140 
150  template<class ELM>
151  struct _DefaultBinding<ELM, enable_if<can_recursively_bind_DiffMutable<ELM>>>
152  {
153  template<class COLL>
154  static auto
155  attachTo (COLL& coll)
156  {
157  return _EmptyBinding<ELM>::attachTo(coll)
158  .matchElement([](GenNode const& spec, ELM const& elm)
159  {
160  return spec.idi == _AccessID<ELM>::getID(elm);
161  })
162  .buildChildMutator ([&](ELM& target, GenNode::ID const&, TreeMutator::Handle buff) -> bool
163  {
164  DiffMutable& child = meta::unwrap(target);
165  child.buildMutator (buff);
166  return true;
167  });
168  }
169  };
170 
171 
172 
173 
174 
175  }//(END)Mutator-Builder decorator components...
176 
177 }} // namespace lib::diff
178 #endif /*LIB_DIFF_TREE_MUTATOR_DIFFMUTABLE_BINDING_H*/
type erased baseclass for building a combined hash and symbolic ID.
Definition: entry-id.hpp:133
Abstraction or descriptor interface for a data structure exposing the ability for mutation by receivi...
virtual void buildMutator(TreeMutator::Handle buffer)=0
build a custom implementation of the TreeMutator interface, suitably wired to cause appropriate chang...
Implementation namespace for support and library code.
typename enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition: meta/util.hpp:83
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:190
A handle to allow for safe »remote implantation« of an unknown subclass into a given opaque InPlaceBu...
Definition: record.hpp:104
char Yes_t
helper types to detect the overload resolution chosen by the compiler
Definition: meta/util.hpp:95
Generic building block for tree shaped (meta)data structures.
Metaprogramming helper to detect if the given target class allows us to build a default »Matcher« aut...
Helpers for type detection, type rewriting and metaprogramming.
Lumiera error handling (C++ interface).
Customisable intermediary to abstract generic tree mutation operations.
Special binding implementation for lib::diff::TreeMutator, allowing to map tree diff operations onto ...
verify compliance to an interface by subtype check
Definition: trait.hpp:323
Metaprogramming helper to retrieve the object identity, whenever the target object for the diff defin...
generic data element node within a tree
Definition: gen-node.hpp:222
Marker or capability interface: an otherwise not further disclosed data structure, which can be transformed through "tree diff messages".