Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
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
105namespace stage {
106namespace 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 {
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{
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>
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;
212
213 using Ret = _Fun<FUN>::Ret;
214 using Args = _Fun<FUN>::Args;
215 using Arg1 = Split<Args>::Head;
216 using FurtherArgs = Split<Args>::Tail;
217
218 static_assert (std::is_convertible<UICoord, Arg1>::value,
219 "Allocator function must accept UICoordinates (where to create/locate) as first argument");
220 static_assert (std::is_convertible<Ret, UICoord>::value,
221 "Allocator function must produce UICoordinates (of the actually allocated UI element)");
222 static_assert (std::is_convertible<FurtherArgs, Types<ARGS...>>::value,
223 "Additional parameters of the allocator function must match the AllocSpec<ARGS> template parameters");
224
225
226 using ArgTuple = Tuple<FurtherArgs>;
227
228 return [=](auto&&... args) -> Allocator
229 {
230 ArgTuple params {forward<decltype(args)> (args)...};
231 return PApply<FUN,FurtherArgs>::bindBack (fun, params);
232 };
233 }
234
235
236 public:
237 template<class FUN>
238 AllocSpec(FUN&& fun)
239 : std::function<Allocator(ARGS&&...)> {buildPartialApplicator (forward<FUN> (fun))}
240 { }
241 };
242
243
244} // namespace interact
245namespace idi {
246//bring definitions into scope for DSL use...
247 using interact::ViewSpec;
249
250 using interact::AllocSpec;
251
252 extern AllocSpec<uint> limitAllocation;
253
254
256 template<class V>
258 {
259 static_assert (not sizeof(V), "unknown generic view type");
260 };
261 // for the actual specialisations: see id-scheme.hpp
262
263
271 template<class VIEW>
272 inline Descriptor<VIEW>&
274 {
275 static Descriptor<VIEW> dslInstance;
276 return dslInstance;
277 }
278
279
280}}// namespace stage::idi
281#endif /*STAGE_INTERACT_VIEW_SPEC_DSL_H*/
Access point to singletons and other kinds of dependencies designated by type.
Definition depend.hpp:281
Inline string literal.
Definition symbol.hpp:78
Partial function application Takes a function and a value tuple, using the latter to close function a...
A specification to describe the strategy for allocating (placing, retrieving) a component view.
static auto buildPartialApplicator(FUN &&fun)
A rule to determine some location by matching against the UI-tree.
A specification to describe the desired location of a component view within the Lumiera UI.
LocatorSpec(UICoord::Builder &&simpleLocationSpec)
shortcut to allow initialisation from UI-Coordinate builder expression
LocatorSpec(LocationRule &&ruleToDetermineLocation)
Describe a location within the UI through structural/topological coordinates.
Definition ui-coord.hpp:131
Singleton services and Dependency Injection.
Lumiera error handling (C++ interface).
Partial function application and building a complete function closure.
Metaprogramming tools for detecting and transforming function types.
BuildTupleType< TYPES >::Type Tuple
Build a std::tuple from types given as type sequence.
Helper: separate parts of a type sequence.
variadic sequence of types
Definition typelist.hpp:102
AllocSpec< uint > limitAllocation
Descriptor< VIEW > & viewSpec()
Access point: Factory for "view specs".
Generic Component View descriptors.
LocatorSpec< UIC_VIEW > ViewSpec
A specification to describe the desired location of a component view within the Lumiera UI.
std::function< UICoord(Literal)> Locator
Locator is a functor to resolve to a topological location in the UI-tree.
std::function< UICoord(UICoord)> Allocator
Allocator is a functor to resolve a given, desired location of a view within the UI.
Lumiera GTK UI implementation root.
Definition guifacade.cpp:37
STL namespace.
Trait template for uniform access to function signature types.
Definition function.hpp:144
A single location specification to be matched and fulfilled.
Marker types to indicate a literal string and a Symbol.
Metaprogramming with tuples-of-types and the std::tuple record.
A topological addressing scheme to designate structural locations within the UI.
A solver to match incomplete coordinate specifications against the actual UI topology.