Lumiera  0.pre.03
»edit your freedom«
view-spec-dsl.hpp
Go to the documentation of this file.
1 /*
2  VIEW-SPEC-DSL.hpp - configuration of view allocation patterns
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 
97 #ifndef STAGE_INTERACT_VIEW_SPEC_DSL_H
98 #define STAGE_INTERACT_VIEW_SPEC_DSL_H
99 
100 #include "lib/error.hpp"
101 #include "lib/symbol.hpp"
102 #include "lib/depend.hpp"
103 #include "lib/meta/function.hpp"
104 #include "lib/meta/tuple-helper.hpp"
108 
109 #include <functional>
110 #include <utility>
111 #include <string>
112 
113 
114 namespace stage {
115 namespace interact {
116 
117  using std::forward;
118  using std::string;
119 
120 
121 
129  using Locator = std::function<UICoord(Literal)>;
130 
131 
142  template<size_t depth>
144  : public Locator
145  {
146  LocationRule rules_;
147 
148  public:
149  LocatorSpec(LocationRule && ruleToDetermineLocation)
150  : Locator([&](Literal componentID) -> UICoord
151  {
152  lib::Depend<UILocationSolver> locationSolver;
153  return locationSolver().solve (rules_, depth, componentID);
154  })
155  , rules_{move (ruleToDetermineLocation)}
156  { }
157 
159  LocatorSpec(UICoord::Builder&& simpleLocationSpec)
160  : LocatorSpec{
161  LocationRule{
163  UICoord{std::move (simpleLocationSpec)}}}}
164  { }
165 
166  operator string() const
167  {
168  return string{rules_};
169  }
170  };
171 
178 
179 
185  using Allocator = std::function<UICoord(UICoord)>;
186 
187 
204  template<typename... ARGS>
205  class AllocSpec
206  : public std::function<Allocator(ARGS&&...)>
207  {
212  template<class FUN>
213  static auto
215  {
216  using lib::meta::_Fun;
217  using lib::meta::Split;
218  using lib::meta::Tuple;
219  using lib::meta::Types;
220  using lib::meta::func::_Sig;
222 
223  typedef typename _Fun<FUN>::Ret Ret;
224  typedef typename _Fun<FUN>::Args Args;
225  typedef typename Split<Args>::Head Arg1;
226  typedef typename Split<Args>::Tail FurtherArgs;
227 
228  static_assert (std::is_convertible<UICoord, Arg1>::value,
229  "Allocator function must accept UICoordinates (where to create/locate) as first argument");
230  static_assert (std::is_convertible<Ret, UICoord>::value,
231  "Allocator function must produce UICoordinates (of the actually allocated UI element)");
232  static_assert (std::is_convertible<FurtherArgs, Types<ARGS...>>::value,
233  "Additional parameters of the allocator function must match the AllocSpec<ARGS> template parameters");
234 
235 
236  using ArgTuple = Tuple<FurtherArgs>;
237 
238  return [=](auto&&... args) -> Allocator
239  {
240  ArgTuple params {forward<decltype(args)> (args)...};
241  return PApply<FUN,FurtherArgs>::bindBack (fun, params);
242  };
243  }
244 
245 
246  public:
247  template<class FUN>
248  AllocSpec(FUN&& fun)
249  : std::function<Allocator(ARGS&&...)> {buildPartialApplicator (forward<FUN> (fun))}
250  { }
251  };
252 
253 
254 } // namespace interact
255 namespace idi {
256 //bring definitions into scope for DSL use...
257  using interact::ViewSpec;
258  using interact::Allocator;
259 
260  using interact::AllocSpec;
261 
262  extern AllocSpec<uint> limitAllocation;
263 
264 
266  template<class V>
267  struct Descriptor
268  {
269  static_assert (not sizeof(V), "unknown generic view type");
270  };
271  // for the actual specialisations: see id-scheme.hpp
272 
273 
281  template<class VIEW>
282  inline Descriptor<VIEW>&
284  {
285  static Descriptor<VIEW> dslInstance;
286  return dslInstance;
287  }
288 
289 
290 }}// namespace stage::idi
291 #endif /*STAGE_INTERACT_VIEW_SPEC_DSL_H*/
std::function< UICoord(UICoord)> Allocator
Allocator is a functor to resolve a given, desired location of a view within the UI, resulting in creation or allocation of the view – which happens as side-effect. The result of this invocation are the UI coordinates of an existing or newly created view.
Describe a location within the UI through structural/topological coordinates.
Definition: ui-coord.hpp:138
typename BuildTupleType< TYPES >::Type Tuple
Build a std::tuple from types given as type sequence.
static auto buildPartialApplicator(FUN &&fun)
Generic Component View descriptors.
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:85
Helper for uniform access to function signature types.
Definition: function.hpp:108
A specification to describe the desired location of a component view within the Lumiera UI...
Partial function application and building a complete function closure.
Access point to singletons and other kinds of dependencies designated by type.
Definition: depend.hpp:289
Metaprogramming with tuples-of-types and the std::tuple record.
Partial function application Takes a function and a value tuple, using the latter to close function a...
Descriptor< VIEW > & viewSpec()
Access point: Factory for "view specs".
A single location specification to be matched and fulfilled.
Metaprogramming tools for transforming functor types.
Marker types to indicate a literal string and a Symbol.
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
A topological addressing scheme to designate structural locations within the UI.
Helper: separate parts of a type sequence.
A solver to match incomplete coordinate specifications against the actual UI topology.
Singleton services and Dependency Injection.
Lumiera error handling (C++ interface).
A rule to determine some location by matching against the UI-tree.
LocatorSpec(UICoord::Builder &&simpleLocationSpec)
shortcut to allow initialisation from UI-Coordinate builder expression
std::function< UICoord(Literal)> Locator
Locator is a functor to resolve to a topological location in the UI-tree.
LocatorSpec< UIC_VIEW > ViewSpec
A specification to describe the desired location of a component view within the Lumiera UI...
A specification to describe the strategy for allocating (placing, retrieving) a component view...