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) Lumiera.org
5  2017, 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 
90 #ifndef LIB_DIFF_MUTATION_MESSAGE_H
91 #define LIB_DIFF_MUTATION_MESSAGE_H
92 
93 
94 #include "lib/error.hpp"
95 #include "lib/iter-source.hpp"
96 #include "lib/iter-adapter-stl.hpp"
97 #include "lib/diff/tree-diff.hpp"
98 #include "lib/diff/gen-node.hpp"
99 #include "lib/format-util.hpp"
100 #include "lib/meta/util.hpp"
101 
102 #include <string>
103 
104 
105 namespace lib {
106 namespace diff{
107 
108  using std::string;
109  using std::__and_;
110  using std::__not_;
111  using lib::meta::enable_if;
114 
115  using DiffStep = TreeDiffLanguage::DiffStep;
116  using DiffSource = IterSource<DiffStep>;
117 
118 
119 
135  {
137 
138  MutationMessage() = default;
139  MutationMessage(MutationMessage&&) = default;
140  MutationMessage(MutationMessage const&) = default;
142  MutationMessage& operator= (MutationMessage const&) = default;
143  MutationMessage& operator= (MutationMessage &&) = default;
145 
151  explicit
152  MutationMessage(DiffSource* diffGenerationContext)
153  : _FrontEnd{DiffSource::build (diffGenerationContext)}
154  { }
155 
161  MutationMessage(std::initializer_list<DiffStep> const&& ili)
162  : MutationMessage{iter_stl::snapshot (move(ili))}
163  { }
164 
170  template<typename...ARGS>
171  MutationMessage(ARGS&& ...args)
172  : MutationMessage{ {std::forward<ARGS>(args)...} }
173  { }
174 
179  template<class IT>
180  MutationMessage(IT&& ii, enable_if< can_IterForEach<IT>, void*> =nullptr)
181  : _FrontEnd{iter_source::wrapIter (std::forward<IT>(ii))}
182  { }
183 
189  template<class CON>
190  MutationMessage(CON& container, enable_if< __and_< can_STL_ForEach<CON>
191  ,__not_<can_IterForEach<CON>>>, void*> =nullptr)
192  : _FrontEnd{iter_source::eachEntry(container)}
193  { }
194 
195 
204  };
205 
206 
207 
208  namespace { // Implementation: take snapshot to enable diagnostics
209 
212  : std::vector<DiffStep>
213  {
215  {
216  for ( ; srcMsg; ++srcMsg )
217  push_back (*srcMsg);
218  }
219  };
220 
221  using _VecIter = DiffSnapshot::iterator;
224 
235  : private DiffSnapshot
236  , public _Wrapped
237  {
238  public:
240  : DiffSnapshot{srcMsg}
241  , _Wrapped{_RangeIT{DiffSnapshot::begin(), DiffSnapshot::end()}}
242  { }
243 
244  virtual
245  operator string() const override
246  {
247  return "Diff--{"+util::join (static_cast<DiffSnapshot> (*this))+"}";
248  }
249  };
250  }
251 
262  inline MutationMessage&
264  {
265  return *this = MutationMessage{new MaterialisedDiffBuffer(*this)};
266  }
267 
268 
269 
270 
271 
272 }} // namespace lib::diff
273 #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:534
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:91
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:88
Trait template to detect a type usable immediately as "Lumiera Forward Iterator" in a specialised for...
Definition: trait.hpp:489
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".