Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
tree-diff-traits.hpp
Go to the documentation of this file.
1/*
2 TREE-DIFF-TRAITS.hpp - definitions to control tree mutator binding
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
41#ifndef LIB_DIFF_TREE_DIFF_TRAITS_H
42#define LIB_DIFF_TREE_DIFF_TRAITS_H
43
44
47#include "lib/null-value.hpp"
48#include "lib/util.hpp"
49
50#include <utility>
51#include <stack>
52
53namespace lib {
54namespace diff{
55
56
57 /* ======= Hints / Heuristics for the required TreeMutator buffer size ======= */
58
87 template<class TAR, typename SEL =void>
89 {
90 enum { siz = 200 };
91 };
92
93
94 constexpr size_t
96 {
97 return 0;
98 }
99
100
101 template<typename T>
102 constexpr T*
104 {
105 return static_cast<T*> (nullptr);
106 }
107
108 template<typename T>
110 {
111 enum { value = 0 < treeMutatorSize (getSelector<T>()) };
112 };
113
114
115 template<class TAR>
117 {
118 enum { siz = treeMutatorSize (getSelector<TAR>()) };
119 };
120
121
122
123
124 /* ======= derive TreeMutator binding for a given opaque data structure ======= */
125
126
127 using meta::enable_if;
128 using meta::Yes_t;
129 using meta::No_t;
130 using std::is_base_of;
131
136 template<typename T>
138 {
139
141
142 public:
143 enum{ value = HasFunSig_buildMutator<T>::value
144 and not is_base_of<DiffMutable, T>::value};
145 };
146
147
148
149
150
151 template<class TAR, typename SEL =void>
153 : std::false_type
154 {
155 static_assert (!sizeof(TAR), "TreeDiffTraits: Unable to access or build a TreeMutator for this target data.");
156 };
157
158 template<class TAR>
159 struct TreeDiffTraits<TAR, enable_if<is_base_of<DiffMutable, TAR>>>
160 : std::true_type
161 {
162 using Ret = DiffMutable&;
163 };
164
165 template<class TAR>
166 struct TreeDiffTraits<TAR, enable_if<exposes_MutatorBuilder<TAR>>>
167 : std::true_type
168 {
169 class Wrapper
170 : public DiffMutable
171 {
173
177 virtual void
179 {
180 subject_.buildMutator (handle);
181 }
182
183 public:
184 Wrapper(TAR& subj)
185 : subject_(subj)
186 { }
187 };
188
189 using Ret = Wrapper;
190 };
191
192
202 template<class TAR>
204 mutatorBinding (TAR& subject)
205 {
206 using Wrapper = TreeDiffTraits<TAR>::Ret;
207 return Wrapper(subject);
208 }
209
210
211
212
213}} // namespace lib::diff
214#endif /*LIB_DIFF_TREE_DIFF_TRAITS_H*/
A handle to allow for safe »remote implantation« of an unknown subclass into a given opaque InPlaceBu...
Marker or capability interface: an otherwise not further disclosed data structure,...
virtual void buildMutator(TreeMutator::Handle handle)
implement the TreeMutator interface, by forwarding to a known implementation function on the wrapped ...
helper to detect presence of a TreeMutator builder function
META_DETECT_FUNCTION(void, buildMutator,(TreeMutator::Handle))
Abstraction or descriptor interface for a data structure exposing the ability for mutation by receivi...
TreeDiffTraits< TAR >::Ret mutatorBinding(TAR &subject)
public access point to this configuration machinery
constexpr size_t treeMutatorSize(...)
constexpr T * getSelector()
char Yes_t
helper types to detect the overload resolution chosen by the compiler
Definition meta/util.hpp:99
enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition meta/util.hpp:87
Implementation namespace for support and library code.
Singleton-style holder for NIL or default values.
Heuristics to guide the allocation for nested TreeMutator.
Customisable intermediary to abstract generic tree mutation operations.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...