Lumiera  0.pre.03
»edit your freedom«
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 
39 #include "common/config-rules.hpp"
40 #include "lib/format-string.hpp"
41 #include "lib/error.hpp"
42 
43 using util::_Fmt;
44 
47 
48 
49 namespace lumiera{
50 namespace 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>
133  DefsManager::operator() (const Query<TAR>& capabilities)
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 */
used for enumerating solutions
bool define(lib::P< TAR > const &, Query< TAR > const &=Query< TAR >())
register the given object as default, after ensuring it fulfils the query.
the "front side" interface: the Steam-Layer code can use this QueryHandler to retrieve instances of t...
lib::P< TAR > operator()(Query< TAR > const &)
common access point: retrieve the default object fulfilling some given conditions.
Front-end for printf-style string template interpolation.
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.
lib::P< TAR > create(Query< TAR > const &)
retrieve an object fulfilling the query and register it as default.
DefsManager() noexcept
initialise the most basic internal defaults.
A front-end for using printf-style formatting.
Namespace of Session and user visible high-level objects.
Definition: sequence.hpp:65
lib::P< TAR > search(Query< TAR > const &)
search through the registered defaults, never create anything.
Management of defaults and default rules.
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:190
A piece of implementation code factored out into a separate header (include).
bool forget(lib::P< TAR > const &)
remove the defaults registration of the given object, if there was such
Lumiera error handling (C++ interface).
Lumiera public interface.
Definition: advice.cpp:104
Interface for accessing rule based configuration.
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:71
user-visible Interface to the ConfigRules subsystem.
Generic interface to express a query for specifically typed result elements exposing some capabilitie...
Definition: query.hpp:270