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)
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 
88 #ifndef STAGE_INTERACT_VIEW_SPEC_DSL_H
89 #define STAGE_INTERACT_VIEW_SPEC_DSL_H
90 
91 #include "lib/error.hpp"
92 #include "lib/symbol.hpp"
93 #include "lib/depend.hpp"
94 #include "lib/meta/function.hpp"
99 
100 #include <functional>
101 #include <utility>
102 #include <string>
103 
104 
105 namespace stage {
106 namespace interact {
107 
108  using std::forward;
109  using std::string;
110 
111 
112 
120  using Locator = std::function<UICoord(Literal)>;
121 
122 
133  template<size_t depth>
135  : public Locator
136  {
137  LocationRule rules_;
138 
139  public:
140  LocatorSpec(LocationRule && ruleToDetermineLocation)
141  : Locator([&](Literal componentID) -> UICoord
142  {
143  lib::Depend<UILocationSolver> locationSolver;
144  return locationSolver().solve (rules_, depth, componentID);
145  })
146  , rules_{move (ruleToDetermineLocation)}
147  { }
148 
150  LocatorSpec(UICoord::Builder&& simpleLocationSpec)
151  : LocatorSpec{
152  LocationRule{
154  UICoord{std::move (simpleLocationSpec)}}}}
155  { }
156 
157  operator string() const
158  {
159  return string{rules_};
160  }
161  };
162 
169 
170 
176  using Allocator = std::function<UICoord(UICoord)>;
177 
178 
195  template<typename... ARGS>
196  class AllocSpec
197  : public std::function<Allocator(ARGS&&...)>
198  {
203  template<class FUN>
204  static auto
206  {
207  using lib::meta::_Fun;
208  using lib::meta::Split;
209  using lib::meta::Tuple;
210  using lib::meta::Types;
211  using lib::meta::func::_Sig;
213 
214  typedef typename _Fun<FUN>::Ret Ret;
215  typedef typename _Fun<FUN>::Args Args;
216  typedef typename Split<Args>::Head Arg1;
217  typedef typename Split<Args>::Tail FurtherArgs;
218 
219  static_assert (std::is_convertible<UICoord, Arg1>::value,
220  "Allocator function must accept UICoordinates (where to create/locate) as first argument");
221  static_assert (std::is_convertible<Ret, UICoord>::value,
222  "Allocator function must produce UICoordinates (of the actually allocated UI element)");
223  static_assert (std::is_convertible<FurtherArgs, Types<ARGS...>>::value,
224  "Additional parameters of the allocator function must match the AllocSpec<ARGS> template parameters");
225 
226 
227  using ArgTuple = Tuple<FurtherArgs>;
228 
229  return [=](auto&&... args) -> Allocator
230  {
231  ArgTuple params {forward<decltype(args)> (args)...};
232  return PApply<FUN,FurtherArgs>::bindBack (fun, params);
233  };
234  }
235 
236 
237  public:
238  template<class FUN>
239  AllocSpec(FUN&& fun)
240  : std::function<Allocator(ARGS&&...)> {buildPartialApplicator (forward<FUN> (fun))}
241  { }
242  };
243 
244 
245 } // namespace interact
246 namespace idi {
247 //bring definitions into scope for DSL use...
248  using interact::ViewSpec;
249  using interact::Allocator;
250 
251  using interact::AllocSpec;
252 
253  extern AllocSpec<uint> limitAllocation;
254 
255 
257  template<class V>
258  struct Descriptor
259  {
260  static_assert (not sizeof(V), "unknown generic view type");
261  };
262  // for the actual specialisations: see id-scheme.hpp
263 
264 
272  template<class VIEW>
273  inline Descriptor<VIEW>&
275  {
276  static Descriptor<VIEW> dslInstance;
277  return dslInstance;
278  }
279 
280 
281 }}// namespace stage::idi
282 #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:129
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:76
Helper for uniform access to function signature types.
Definition: function.hpp:99
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:280
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:37
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...