Lumiera  0.pre.03
»edit your freedom«
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) Lumiera.org
5  2016, 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 
50 #ifndef LIB_DIFF_TREE_DIFF_TRAITS_H
51 #define LIB_DIFF_TREE_DIFF_TRAITS_H
52 
53 
56 #include "lib/null-value.hpp"
57 #include "lib/util.hpp"
58 
59 #include <utility>
60 #include <stack>
61 
62 namespace lib {
63 namespace diff{
64 
65 
66  /* ======= Hints / Heuristics for the required TreeMutator buffer size ======= */
67 
96  template<class TAR, typename SEL =void>
98  {
99  enum { siz = 200 };
100  };
101 
102 
103  constexpr size_t
104  treeMutatorSize (...)
105  {
106  return 0;
107  }
108 
109 
110  template<typename T>
111  constexpr T*
112  getSelector()
113  {
114  return static_cast<T*> (nullptr);
115  }
116 
117  template<typename T>
119  {
120  enum { value = 0 < treeMutatorSize (getSelector<T>()) };
121  };
122 
123 
124  template<class TAR>
125  struct TreeMutatorSizeTraits<TAR, enable_if<defines_custom_BufferSize<TAR>> >
126  {
127  enum { siz = treeMutatorSize (getSelector<TAR>()) };
128  };
129 
130 
131 
132 
133  /* ======= derive TreeMutator binding for a given opaque data structure ======= */
134 
135 
136  using meta::enable_if;
137  using meta::Yes_t;
138  using meta::No_t;
139  using std::is_base_of;
140 
145  template<typename T>
147  {
148 
149  META_DETECT_FUNCTION (void, buildMutator, (TreeMutator::Handle));
150 
151  public:
152  enum{ value = HasFunSig_buildMutator<T>::value
153  and not is_base_of<DiffMutable, T>::value};
154  };
155 
156 
157 
158 
159 
160  template<class TAR, typename SEL =void>
162  : std::false_type
163  {
164  static_assert (!sizeof(TAR), "TreeDiffTraits: Unable to access or build a TreeMutator for this target data.");
165  };
166 
167  template<class TAR>
168  struct TreeDiffTraits<TAR, enable_if<is_base_of<DiffMutable, TAR>>>
169  : std::true_type
170  {
171  using Ret = DiffMutable&;
172  };
173 
174  template<class TAR>
175  struct TreeDiffTraits<TAR, enable_if<exposes_MutatorBuilder<TAR>>>
176  : std::true_type
177  {
178  class Wrapper
179  : public DiffMutable
180  {
181  TAR& subject_;
182 
186  virtual void
188  {
189  subject_.buildMutator (handle);
190  }
191 
192  public:
193  Wrapper(TAR& subj)
194  : subject_(subj)
195  { }
196  };
197 
198  using Ret = Wrapper;
199  };
200 
201 
211  template<class TAR>
212  typename TreeDiffTraits<TAR>::Ret
213  mutatorBinding (TAR& subject)
214  {
215  using Wrapper = typename TreeDiffTraits<TAR>::Ret;
216  return Wrapper(subject);
217  }
218 
219 
220 
221 
222 }} // namespace lib::diff
223 #endif /*LIB_DIFF_TREE_DIFF_TRAITS_H*/
Abstraction or descriptor interface for a data structure exposing the ability for mutation by receivi...
virtual void buildMutator(TreeMutator::Handle handle)
implement the TreeMutator interface, by forwarding to a known implementation function on the wrapped ...
Heuristics to guide the allocation for nested TreeMutator.
#define META_DETECT_FUNCTION(_RET_TYPE_, _FUN_NAME_, _ARGS_)
Detector for a specific member function.
Singleton-style holder for NIL or default values.
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
A handle to allow for safe »remote implantation« of an unknown subclass into a given opaque InPlaceBu...
Definition: record.hpp:113
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
helper to detect presence of a TreeMutator builder function
char Yes_t
helper types to detect the overload resolution chosen by the compiler
Definition: meta/util.hpp:104
Customisable intermediary to abstract generic tree mutation operations.
TreeDiffTraits< TAR >::Ret mutatorBinding(TAR &subject)
public access point to this configuration machinery
Marker or capability interface: an otherwise not further disclosed data structure, which can be transformed through "tree diff messages".