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) Lumiera.org
5  2021, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
54 #ifndef LIB_DIFF_TREE_MUTATOR_DIFFMUTABLE_BINDING_H
55 #define LIB_DIFF_TREE_MUTATOR_DIFFMUTABLE_BINDING_H
56 
57 
58 #include "lib/error.hpp"
59 #include "lib/meta/trait.hpp"
60 #include "lib/diff/gen-node.hpp"
64 
65 namespace lib {
66 namespace diff{
67 
68  namespace { // Mutator-Builder decorator components...
69 
71  using lib::meta::Yes_t;
72  using lib::meta::No_t;
73  using std::__and_;
74  using std::__or_;
75 
84  template<typename TY>
86  {
87  template<typename X,
88  typename SEL = decltype(std::declval<GenNode::ID>() == std::declval<X>().getID())>
89  struct Probe
90  { };
91 
92  template<class X>
93  static Yes_t check(Probe<X> * );
94  template<class>
95  static No_t check(...);
96 
97  public:
98  static const bool value = (sizeof(Yes_t)==sizeof(check<TY>(0)));
99  };
100 
101  template<typename T>
103  : Can_retrieve_and_compare_ID<typename meta::Strip<T>::Type>
104  { };
105 
106  template<typename T>
108  : meta::is_Subclass<T,DiffMutable>
109  { };
110 
111  template<typename T>
113  : __and_< meta::Unwrap<T>
114  , Is_DiffMutable<typename meta::Unwrap<T>::Type>>
115  { };
116 
117  template<typename T>
119  : __or_< Is_DiffMutable<T>
120  , Is_wrapped_DiffMutable<T>>
121  { } ;
122 
123 
128  template<class TAR, typename SEL =void>
129  struct _AccessID
130  {
131  static idi::BareEntryID const&
132  getID (TAR const&)
133  {
134  throw error::Logic ("TreeMutator::build() .attach(collection...) : Unable to access the target element's object ID. "
135  "Please define a »Matcher« explicitly by invoking the builder function \"matchElement\".");
136  }
137  };
138  template<class ELM>
139  struct _AccessID<ELM, enable_if<Can_access_ID<ELM>>>
140  {
141  static idi::BareEntryID const&
142  getID (ELM const& target)
143  {
144  return meta::unwrap(target).getID();
145  }
146  };
147 
148 
149 
159  template<class ELM>
160  struct _DefaultBinding<ELM, enable_if<can_recursively_bind_DiffMutable<ELM>>>
161  {
162  template<class COLL>
163  static auto
164  attachTo (COLL& coll)
165  {
166  return _EmptyBinding<ELM>::attachTo(coll)
167  .matchElement([](GenNode const& spec, ELM const& elm)
168  {
169  return spec.idi == _AccessID<ELM>::getID(elm);
170  })
171  .buildChildMutator ([&](ELM& target, GenNode::ID const&, TreeMutator::Handle buff) -> bool
172  {
173  DiffMutable& child = meta::unwrap(target);
174  child.buildMutator (buff);
175  return true;
176  });
177  }
178  };
179 
180 
181 
182 
183 
184  }//(END)Mutator-Builder decorator components...
185 
186 }} // namespace lib::diff
187 #endif /*LIB_DIFF_TREE_MUTATOR_DIFFMUTABLE_BINDING_H*/
type erased baseclass for building a combined hash and symbolic ID.
Definition: entry-id.hpp:142
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:92
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:199
A handle to allow for safe »remote implantation« of an unknown subclass into a given opaque InPlaceBu...
Definition: record.hpp:113
char Yes_t
helper types to detect the overload resolution chosen by the compiler
Definition: meta/util.hpp:104
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:318
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:231
Marker or capability interface: an otherwise not further disclosed data structure, which can be transformed through "tree diff messages".