Lumiera  0.pre.03
»edit your freedom«
mutation-message.hpp
Go to the documentation of this file.
1 /*
2  MUTATION-MESSAGE.hpp - message to cause changes to generic model elements
3 
4  Copyright (C)
5  2017, 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 
81 #ifndef LIB_DIFF_MUTATION_MESSAGE_H
82 #define LIB_DIFF_MUTATION_MESSAGE_H
83 
84 
85 #include "lib/error.hpp"
86 #include "lib/iter-source.hpp"
87 #include "lib/iter-adapter-stl.hpp"
88 #include "lib/diff/tree-diff.hpp"
89 #include "lib/diff/gen-node.hpp"
90 #include "lib/format-util.hpp"
91 #include "lib/meta/util.hpp"
92 
93 #include <string>
94 
95 
96 namespace lib {
97 namespace diff{
98 
99  using std::string;
100  using std::__and_;
101  using std::__not_;
102  using lib::meta::enable_if;
105 
106  using DiffStep = TreeDiffLanguage::DiffStep;
107  using DiffSource = IterSource<DiffStep>;
108 
109 
110 
126  {
128 
129  MutationMessage() = default;
130  MutationMessage(MutationMessage&&) = default;
131  MutationMessage(MutationMessage const&) = default;
133  MutationMessage& operator= (MutationMessage const&) = default;
134  MutationMessage& operator= (MutationMessage &&) = default;
136 
142  explicit
143  MutationMessage(DiffSource* diffGenerationContext)
144  : _FrontEnd{DiffSource::build (diffGenerationContext)}
145  { }
146 
152  MutationMessage(std::initializer_list<DiffStep> const&& ili)
153  : MutationMessage{iter_stl::snapshot (move(ili))}
154  { }
155 
161  template<typename...ARGS>
162  MutationMessage(ARGS&& ...args)
163  : MutationMessage{ {std::forward<ARGS>(args)...} }
164  { }
165 
170  template<class IT>
171  MutationMessage(IT&& ii, enable_if< can_IterForEach<IT>, void*> =nullptr)
172  : _FrontEnd{iter_source::wrapIter (std::forward<IT>(ii))}
173  { }
174 
180  template<class CON>
181  MutationMessage(CON& container, enable_if< __and_< can_STL_ForEach<CON>
182  ,__not_<can_IterForEach<CON>>>, void*> =nullptr)
183  : _FrontEnd{iter_source::eachEntry(container)}
184  { }
185 
186 
195  };
196 
197 
198 
199  namespace { // Implementation: take snapshot to enable diagnostics
200 
203  : std::vector<DiffStep>
204  {
206  {
207  for ( ; srcMsg; ++srcMsg )
208  push_back (*srcMsg);
209  }
210  };
211 
212  using _VecIter = DiffSnapshot::iterator;
215 
226  : private DiffSnapshot
227  , public _Wrapped
228  {
229  public:
231  : DiffSnapshot{srcMsg}
232  , _Wrapped{_RangeIT{DiffSnapshot::begin(), DiffSnapshot::end()}}
233  { }
234 
235  virtual
236  operator string() const override
237  {
238  return "Diff--{"+util::join (static_cast<DiffSnapshot> (*this))+"}";
239  }
240  };
241  }
242 
253  inline MutationMessage&
255  {
256  return *this = MutationMessage{new MaterialisedDiffBuffer(*this)};
257  }
258 
259 
260 
261 
262 
263 }} // namespace lib::diff
264 #endif /*LIB_DIFF_MUTATION_MESSAGE_H*/
Decorator to be layered transparently on top of MutationMessage.
Trait template to detect a type usable with the STL for-each loop.
Definition: trait.hpp:555
Simple and lightweight helpers for metaprogramming and type detection.
MutationMessage(ARGS &&...args)
Convenience builder to take an arbitrary number of DiffStep arguments.
MutationMessage(CON &container, enable_if< __and_< can_STL_ForEach< CON >, __not_< can_IterForEach< CON >>>, void *>=nullptr)
Convenience builder to use elements form any STL-like container.
Opaque message to effect a structural change on a target, which is likewise only known in an abstract...
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
MutationMessage(DiffSource *diffGenerationContext)
MutationMessage builder: take ownership of an opaque heap allocated context from which the concrete d...
MutationMessage(IT &&ii, enable_if< can_IterForEach< IT >, void *>=nullptr)
Convenience builder to piggyback any Lumiera Forward Iterator.
Iteration source interface to abstract a data source, which then can be accessed through IterAdapter ...
Definition: iter-source.hpp:79
Trait template to detect a type usable immediately as "Lumiera Forward Iterator" in a specialised for...
Definition: trait.hpp:510
Generic building block for tree shaped (meta)data structures.
MutationMessage(std::initializer_list< DiffStep > const &&ili)
Convenience builder for consuming an brace enclosed initializer_list.
MutationMessage & updateDiagnostics()
enable support to show content of the message.
A token language to represent structural changes in a tree like hierarchical data structure...
Lumiera error handling (C++ interface).
static iterator build(IterSource &sourceImpl)
build an iterator frontend for the given source,
Collection of small helpers and convenience shortcuts for diagnostics & formatting.
Accessing a STL element range through a Lumiera forward iterator, An instance of this iterator adapte...
Preconfigured adapters for some STL container standard usage situations.
Extension module to build an opaque data source, accessible as Lumiera Forward Iterator.
Standard implementation of the IterSource interface: a wrapped "Lumiera Forward Iterator".