Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
fake-configrules.hpp
Go to the documentation of this file.
1/*
2 FAKE-CONFIGRULES.hpp - dummy implementation of the config rules system
3
4 Copyright (C)
5 2008, 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
37#ifndef MOBJECT_SESSION_QUERY_FAKECONFIGRULES_H
38#define MOBJECT_SESSION_QUERY_FAKECONFIGRULES_H
39
42#include "lib/depend-inject.hpp"
43#include "lib/query-util.hpp"
44#include "lib/util.hpp"
45#include "lib/p.hpp"
46
47#include <boost/any.hpp>
48#include <string>
49#include <map>
50
51
52
53namespace steam {
54namespace mobject {
55namespace session {
56 namespace query {
57
58 namespace asset = steam::asset;
59
60 using asset::Pipe;
61 using asset::ProcPatt;
62 using asset::PProcPatt;
65 using lib::P;
66
67 using lumiera::Query;
70
71 using util::contains;
72 using util::isnil;
73
74 using boost::any;
75 using boost::any_cast;
76
77
78
79
80
81 namespace { // internal details
82
84 template<class TY>
85 struct WrapReturn { using Wrapper = P<TY>; };
86
87 template<>
88 struct WrapReturn<ProcPatt> { using Wrapper = PProcPatt; };
89
90
94 template<typename TY>
95 inline bool
96 is_defaults_query (Query<TY> const& querySpec)
97 {
98 return querySpec.usesPredicate ("default");
99 }
100
101 template<typename WRA>
102 inline bool
103 exists(WRA const& solution)
104 {
105 return bool(solution);
106 }
107
108 } // details (end)
109
110
111
122 : public steam::ConfigResolver
123 {
124 using Tab = std::map<QueryKey,any>;
125
128
129 protected:
130 MockTable ();
131 virtual void reset();
132 any const& fetch_from_table_for (QueryKey const& query);
133
134 // special cases....
135 template<class TY>
136 bool detect_case (typename WrapReturn<TY>::Wrapper&, Query<TY> const&);
137 bool fabricate_matching_new_Pipe (Query<Pipe> const& q, string const& pipeID, string const& streamID);
138 bool fabricate_just_new_Pipe (Query<Pipe> const& q);
142
143 template<class TY>
144 bool set_new_mock_solution (Query<TY> const& q, typename WrapReturn<TY>::Wrapper& candidate);
145
146
147 private:
148 void fill_mock_table ();
149
151 template<class STRU>
152 any&
153 item (string const& querySpec)
154 {
155 return answer_[Query<STRU>(querySpec)];
156 }
157 };
158
159
160 // GCC > 13 warns at class definition when a new overload shadows an inherited virtual function.
161 // While theoretically correct, in practice any call will be dispatched through the base interface
162 // and it is not even possible to reach the concrete classes (and the implementation function is private).
163 // The workaround with a `using` clause is not applicable, since the name is ambiguous (by design)
164 // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109740
165 _Pragma("GCC diagnostic push") \
166 _Pragma("GCC diagnostic ignored \"-Woverloaded-virtual\"")
167
168
169
174 template<class TY, class BASE>
175 class LookupPreconfigured : public BASE
176 {
177 using Ret = WrapReturn<TY>::Wrapper;
178
180 virtual bool
181 resolve (Ret& solution, Query<TY> const& q)
182 {
183 any const& entry = this->fetch_from_table_for(q);
184 if (!isnil (entry))
185 {
186 Ret const& candidate (any_cast<Ret const&> (entry));
187 if (! solution
188 or(solution and solution == candidate) // simulates a real unification
189 )
190 return exists (solution = candidate);
191 }
192 return try_special_case(solution, q);
193 }
194
195 bool
196 try_special_case (Ret& solution, Query<TY> const& q)
197 {
198 if (solution and isFakeBypass(q)) // backdoor for tests
199 return exists (solution);
200
201 if (is_defaults_query (q))
202 {
203 Query<TY> defaultsQuery = q.rebuild().removeTerm("default");
204 return exists (solution = Session::current->defaults (defaultsQuery));
205 } // may lead to recursion
206
207 if (this->detect_case (solution, q))
208 return resolve (solution, q);
209
210 return exists (solution = Ret()); // fail: return default-constructed empty smart ptr
211 }
212 };
213
214
216 template<class TY>
217 inline bool
218 MockTable::detect_case (typename WrapReturn<TY>::Wrapper&, Query<TY> const&)
219 {
220 return false;
221 }
222 template<>
223 inline bool
224 MockTable::detect_case (WrapReturn<Pipe>::Wrapper& candidate, Query<Pipe> const& q)
225 {
226 if (q.usesPredicate ("make"))
227 // used by tests to force fabrication of a new "solution"
228 return fabricate_just_new_Pipe (q);
229
230 const string pipeID = q.extractID("pipe");
231 const string streamID = q.extractID("stream");
232
233 if (candidate and pipeID == candidate->getPipeID())
234 return set_new_mock_solution (q, candidate); // "learn" this solution to be "valid"
235
236 if (!isnil(pipeID) and not isnil(streamID))
237 return fabricate_matching_new_Pipe (q, pipeID, streamID);
238
239 if (not candidate and (not isnil(streamID) or not isnil(pipeID)))
240 return fabricate_just_new_Pipe (q);
241
242 return false;
243 }
244
245 template<>
246 inline bool
247 MockTable::detect_case (WrapReturn<const ProcPatt>::Wrapper& candidate, Query<const ProcPatt> const& q)
248 {
249 const string streamID = q.extractID("stream");
250
251 if (not candidate and not isnil(streamID))
253 return false;
254 }
255
256 template<>
257 inline bool
258 MockTable::detect_case (WrapReturn<asset::Timeline>::Wrapper& candidate, Query<asset::Timeline> const& q)
259 {
260 if (!candidate)
262 return bool(candidate);
263 }
264
265 template<>
266 inline bool
267 MockTable::detect_case (WrapReturn<asset::Sequence>::Wrapper& candidate, Query<asset::Sequence> const& q)
268 {
269 if (!candidate)
271 return bool(candidate);
272 }
273
274
275
276
277
278
285 : public InstantiateChained < steam::InterfaceTypes
286 , LookupPreconfigured // building block used for each of the types
287 , MockTable // for implementing the base class (interface)
288 >
289 {
290 protected:
293 friend class lib::DependInject<ConfigResolver>::Local<MockConfigRules>;
294 public:
295 virtual ~MockConfigRules() {}
296
297
298 /* === implementation of additional functions on the ConfigRules interface goes here === */
299 };
300
301
302
303 } // namespace query
304}}} // namespace steam::mobject::session
305#endif
This framework allows to (re)configure the lib::Depend front-end for dependency-injection.
Helper to abstract creation and lifecycle of a dependency.
Definition depend.hpp:127
Build a single inheritance chain of template instantiations.
Wrapper for indexing and ordering.
Definition query.hpp:371
Builder & removeTerm(Symbol termPredicate)
remove the first term from this query definition, which matches the given predicate symbol
Definition query.hpp:507
Generic interface to express a query for specifically typed result elements exposing some capabilitie...
Definition query.hpp:254
bool usesPredicate(Symbol predicate) const
Definition query.hpp:572
Builder rebuild() const
Definition query.hpp:550
string extractID(Symbol predicate) const
convenience shortcut to extract a desired name-ID.
Definition query.hpp:564
user-visible Interface to the ConfigRules subsystem.
structural asset corresponding to the part of the model forming a processing pipe for generating medi...
Definition pipe.hpp:72
"Processing Pattern" is a structural Asset representing information how to build some part of the ren...
Definition procpatt.hpp:54
The (current) Session holds all the user visible content to be edited and manipulated within the Lumi...
Definition session.hpp:102
static session::SessManager & current
access point to the current Session
Definition session.hpp:120
virtual bool resolve(Ret &solution, Query< TY > const &q)
(dummy) implementation of the QueryHandler interface
bool try_special_case(Ret &solution, Query< TY > const &q)
Facade: Dummy Implementation of the query interface.
MockConfigRules()
to be used only by the singleton factory
the actual table holding preconfigured answers packaged as boost::any objects.
bool detect_case(typename WrapReturn< TY >::Wrapper &, Query< TY > const &)
Hook for treating very special cases for individual types only.
bool fabricate_Timeline_on_demand(Query< asset::Timeline > const &q)
special case: fabricate new Timeline, maybe using specific sub-objects as hinted by the IDs given wit...
bool fabricate_ProcPatt_on_demand(Query< const ProcPatt > const &q)
special case: create/retrieve new processing pattern for given stream ID...
any const & fetch_from_table_for(QueryKey const &query)
this is the (preliminary/mock) implementation handling queries for objects of a specific type and wit...
void fill_mock_table()
hard coded answers to configuration queries.
bool fabricate_matching_new_Pipe(Query< Pipe > const &q, string const &pipeID, string const &streamID)
special case: create a new pipe with matching pipe and stream IDs on the fly when referred....
any & item(string const &querySpec)
shortcut for simply accessing a table entry
bool fabricate_just_new_Pipe(Query< Pipe > const &q)
special case: create a new pipe for a specific stream ID
bool fabricate_Sequence_on_demand(Query< asset::Sequence > const &q)
special case: fabricate new Timeline, maybe using ID specs from the query...
bool set_new_mock_solution(Query< TY > const &q, typename WrapReturn< TY >::Wrapper &candidate)
for entering "valid" solutions on-the-fly from tests
virtual void reset()
clear the contents of the mock solution table.
Definition of the concrete frontend for rule based configuration within the session.
Per type specific configuration of instances created as service dependencies.
bool isFakeBypass(lumiera::QueryKey const &q)
The asset subsystem of the Steam-Layer.
bool is_defaults_query(Query< TY > const &querySpec)
helper detecting if a query actually intended to retrieve a "default" object.
_Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Woverloaded-virtual\"") template< class TY
building block providing the mock implementation for a single type.
Namespace of Session and user visible high-level objects.
Definition sequence.hpp:65
Steam-Layer implementation namespace root.
bool contains(MAP &map, typename MAP::key_type const &key)
shortcut for containment test on a map
Definition util.hpp:230
bool isnil(lib::time::Duration const &dur)
Customised refcounting smart pointer.
Utilities to support working with predicate queries.
Primary Interface to the current Session.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...