Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
element-access.hpp
Go to the documentation of this file.
1/*
2 ELEMENT-ACCESS.hpp - access to generic elements in the UI
3
4 Copyright (C)
5 2015, 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
42#ifndef STAGE_MODEL_ELEMENT_ACCESS_H
43#define STAGE_MODEL_ELEMENT_ACCESS_H
44
45
46#include "lib/error.hpp"
47#include "lib/nocopy.hpp"
48#include "lib/result.hpp"
49#include "include/limits.hpp"
50#include "lib/variant.hpp"
52#include "lib/access-casted.hpp"
54
55#include <string>
56
57
58namespace Gtk {
59 class Widget;
60}
61namespace stage {
62namespace model {
63 namespace error = lumiera::error;
64
65 using interact::UICoord;
66 using lib::meta::Types;
67 using std::string;
68
69 class Tangible;
70
79 {
80
81 public:
82 virtual ~ElementAccess () { }
83
84
85 /* == Access by Location == */
86
87 template<class TAR>
88 lib::Result<TAR&> access (UICoord const& destination);
89
90 UICoord locate_or_create (UICoord const& destination, size_t limitCreation = LUMIERA_MAX_ORDINAL_NUMBER);
91
92
93 protected:
95
97 virtual RawResult performAccessTo (UICoord::Builder &, size_t limitCreation) =0;
98
99 private:
100 template<class TAR>
101 struct TypeConverter;
102 };
103
104
105
106
123 template<class TAR>
126 {
127 lib::Result<TAR&> result{error::Invalid{"not convertible to desired target widget"}};
128
129 template<typename X> // note the "backward" use. We pick that base interface
130 using canUpcast = std::is_convertible<TAR*, X>; // into which our desired result type can be upcast, because
131 // we know the then following dynamic_cast (downcast) can succeed
133
134 virtual void
135 handle (Base& pb) override
136 {
137 if (pb)
138 {
139 TAR* downcasted = dynamic_cast<TAR*> (pb);
140 if (downcasted)
141 result = *downcasted;
142 }
143 else
144 result = lib::Result<TAR&>{error::State{"access returns empty answer"}};
145 }
146 };
147
148
149
150
151
152
161 template<class TAR>
162 inline lib::Result<TAR&>
163 ElementAccess::access (UICoord const& destination)
164 {
165 UICoord::Builder targetLocation{destination.rebuild()};
166 TypeConverter<TAR> converter;
167 RawResult targetElm = performAccessTo (targetLocation, 0);
168 targetElm.accept (converter);
169 return converter.result;
170 }
171
172
180 inline UICoord
181 ElementAccess::locate_or_create (UICoord const& destination, size_t limitCreation)
182 {
183 UICoord::Builder targetLocation{destination.rebuild()};
184 performAccessTo (targetLocation, limitCreation);
185 return targetLocation;
186 }
187
188
189
190
191
192}} // namespace stage::model
193#endif /*STAGE_MODEL_ELEMENT_ACCESS_H*/
Helper for accessing a value, employing either a conversion or downcast, depending on the relation of...
Representation of the result of some operation, EITHER a value or a failure.
Definition result.hpp:133
to be implemented by the client for visitation
Definition variant.hpp:234
Typesafe union record.
Definition variant.hpp:216
void accept(Visitor &visitor)
Definition variant.hpp:537
Derived specific exceptions within Lumiera's exception hierarchy.
Definition error.hpp:193
Describe a location within the UI through structural/topological coordinates.
Definition ui-coord.hpp:131
Builder rebuild() const
Definition ui-coord.hpp:755
Interface: access UI elements by navigating the UI topology.
UICoord locate_or_create(UICoord const &destination, size_t limitCreation=LUMIERA_MAX_ORDINAL_NUMBER)
Navigate to the designated component, possibly create the element and parents.
lib::Result< TAR & > access(UICoord const &destination)
Navigate the UI topology to access the designated component.
virtual RawResult performAccessTo(UICoord::Builder &, size_t limitCreation)=0
virtual ~ElementAccess()
this is an interface
Any copy and copy construction prohibited.
Definition nocopy.hpp:38
Lumiera error handling (C++ interface).
hard wired safety limits.
#define LUMIERA_MAX_ORDINAL_NUMBER
Definition limits.hpp:34
variadic sequence of types
Definition typelist.hpp:102
Helper to pick the first type from a type sequence, which fulfils the predicate (meta function) given...
Definition variant.hpp:157
LumieraError< LERR_(STATE)> State
Definition error.hpp:209
Lumiera GTK UI implementation root.
Definition guifacade.cpp:37
Mix-Ins to allow or prohibit various degrees of copying and cloning.
Intermediary value object to represent »either« an operation result or a failure.
std::is_convertible< TAR *, X > canUpcast
RawResult::FirstMatching< canUpcast >::Type Base
virtual void handle(Base &pb) override
Metaprogramming: Helpers for manipulating lists-of-types.
A topological addressing scheme to designate structural locations within the UI.
A typesafe union record to carry embedded values of unrelated type.