Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
defs-manager-impl.hpp
Go to the documentation of this file.
1/*
2 DEFS-MANAGER-IMPL.h - access to preconfigured default objects and definitions
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
33#ifndef LUMIERA_QUERY_DEFS_MANAGER_IMPL_H
34#define LUMIERA_QUERY_DEFS_MANAGER_IMPL_H
35
36
40#include "lib/format-string.hpp"
41#include "lib/error.hpp"
42
43using util::_Fmt;
44
47
48
49namespace lumiera{
50namespace query {
51
52
53
54
57 : defsRegistry_(new DefsRegistry)
58 {
59 INFO (session, "Configure technical defaults of the session.");
60
61 }
62
63
64
68
69
70 void
72 {
73 defsRegistry_.reset(new DefsRegistry);
74 }
75
76
77
78 template<class TAR>
79 P<TAR>
80 DefsManager::search (const Query<TAR>& capabilities)
81 {
82 P<TAR> res;
83 QueryHandler<TAR>& typeHandler = ConfigResolver::instance();
84 for (DefsRegistry::Iter<TAR> i = defsRegistry_->candidates(capabilities);
85 bool(*i) ; ++i )
86 {
87 res = *i;
88 typeHandler.resolve (res, capabilities);
89 if (res)
90 return res;
91 }
92 return res; // "no solution found"
93 }
94
95
96 template<class TAR>
97 P<TAR>
98 DefsManager::create (const Query<TAR>& capabilities)
99 {
100 P<TAR> res;
101 QueryHandler<TAR>& typeHandler = ConfigResolver::instance();
102 typeHandler.resolve (res, capabilities);
103 if (res)
104 defsRegistry_->put (res, capabilities);
105 return res;
106 }
107
108
109 template<class TAR>
110 bool
111 DefsManager::define (const P<TAR>& defaultObj, const Query<TAR>& capabilities)
112 {
113 P<TAR> candidate (defaultObj);
114 QueryHandler<TAR>& typeHandler = ConfigResolver::instance();
115 typeHandler.resolve (candidate, capabilities);
116 if (!candidate)
117 return false;
118 else
119 return defsRegistry_->put (candidate, capabilities);
120 }
121
122
123 template<class TAR>
124 bool
125 DefsManager::forget (const P<TAR>& defaultObj)
126 {
127 return defsRegistry_->forget (defaultObj);
128 }
129
130
131 template<class TAR>
132 P<TAR>
134 {
135 P<TAR> res (search (capabilities));
136 if (res)
137 return res;
138 else
139 res = create (capabilities); // not yet known as default, create new
140
141 if (!res)
142 throw error::Config (_Fmt("The following Query could not be resolved: %s.")
143 % capabilities.rebuild().asKey()
144 , LERR_(CAPABILITY_QUERY) );
145 else
146 return res;
147 }
148
149}} // namespace lumiera::query
150#endif /* LUMIERA_QUERY_DEFS_MANAGER_IMPL_H */
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition p.hpp:77
string asKey() const
Definition query.hpp:482
Generic interface to express a query for specifically typed result elements exposing some capabilitie...
Definition query.hpp:254
Builder rebuild() const
Definition query.hpp:550
bool forget(lib::P< TAR > const &)
remove the defaults registration of the given object, if there was such
DefsManager() noexcept
initialise the most basic internal defaults.
lib::P< TAR > create(Query< TAR > const &)
retrieve an object fulfilling the query and register it as default.
unique_ptr< impl::DefsRegistry > defsRegistry_
bool define(lib::P< TAR > const &, Query< TAR > const &=Query< TAR >())
register the given object as default, after ensuring it fulfils the query.
lib::P< TAR > search(Query< TAR > const &)
search through the registered defaults, never create anything.
lib::P< TAR > operator()(Query< TAR > const &)
common access point: retrieve the default object fulfilling some given conditions.
the "front side" interface: the Steam-Layer code can use this QueryHandler to retrieve instances of t...
virtual bool resolve(P< TY > &solution, Query< TY > const &q)=0
try to find or create an object of type TY fulfilling the given query.
used for enumerating solutions
user-visible Interface to the ConfigRules subsystem.
A front-end for using printf-style formatting.
Interface for accessing rule based configuration.
Management of defaults and default rules.
A piece of implementation code factored out into a separate header (include).
Lumiera error handling (C++ interface).
#define LERR_(_NAME_)
Definition error.hpp:45
Front-end for printf-style string template interpolation.
LumieraError< LERR_(CONFIG), Invalid > Config
Definition error.hpp:212
Lumiera public interface.
Definition advice.hpp:102
Namespace of Session and user visible high-level objects.
Definition sequence.hpp:65