Lumiera  0.pre.03
»edit your freedom«
config-rules.hpp
Go to the documentation of this file.
1 /*
2  CONFIG-RULES.hpp - interface for rule based configuration
3 
4  Copyright (C) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
62 #ifndef LUMIERA_CONFIG_RULES_H
63 #define LUMIERA_CONFIG_RULES_H
64 
65 #include "lib/p.hpp"
66 #include "lib/symbol.hpp"
67 #include "lib/meta/generator.hpp"
68 #include "common/query.hpp"
69 
70 #include <string>
71 
72 
73 
74 namespace lumiera {
75  namespace error {
76  LUMIERA_ERROR_DECLARE (CAPABILITY_QUERY);
77  }
78 
79  using std::string;
80  using lib::P;
81 
82 
83 
85 
86  namespace query {
87 
88  // The intention is to support the following style of Prolog code
89  //
90  // resolve(O, Cap) :- find(O), capabilities(Cap).
91  // resolve(O, Cap) :- make(O), capabilities(Cap).
92  // capabilities(Q) :- call(Q).
93  //
94  // stream(T, mpeg) :- type(T, fork), type(P, pipe), resolve(P, stream(P,mpeg)), placed_to(P, T).
95  //
96  // The type guard is inserted automatically, while the predicate implementations for
97  // find/1, make/1, stream/2, and placed_to/2 are to be provided by the target types.
98  //
99  // As a example, the goal ":-retrieve(T, stream(T,mpeg))." would search a Fork object (a "track"), try to
100  // retrieve a pipe object with stream-type=mpeg and associate the Fork with this Pipe. The
101  // predicate "stream(P,mpeg)" needs to be implemented (natively) for the pipe object.
102 
103  class Resolver
104  {
106  };
107 
108 
109  using lib::Symbol;
110  using lib::Literal;
111  using lumiera::Query;
112 
116 #define SYMBOL uint
117 
118 
119  template
120  < SYMBOL SYM, // Predicate symbol
121  typename SIG = bool(string) // Signature
122  >
123  class Pred
124  { };
125 
140  template<class TY>
142  {
143  static const TY NIL;
144 
145  template<SYMBOL SYM, typename SIG>
146  TY find (Pred<SYM,SIG> capability);
147 
148  template<SYMBOL SYM, typename SIG>
149  TY make (Pred<SYM,SIG> capability, TY& refObj =NIL);
150  };
151 
162  template<class TY>
164  {
165  protected:
166  virtual ~QueryHandler() { }
167  public:
175  virtual bool resolve (P<TY>& solution, Query<TY> const& q) = 0;
176  };
177 
178  // TODO: the Idea is to provide specialisations for the concrete types
179  // we want to participate in the ConfigRules system....
180  // Thus we get the possibility to create a specific return type,
181  // e.g. return a P<Pipe> but a Placement<Fork>, using the appropriate factory.
182  // Of course then the definitions need to be split up in separate headers.
183 
184 
185 
186 
187 
199  template<typename TYPES>
201  : public lib::meta::InstantiateForEach<TYPES, QueryHandler>
202  {
203  protected:
204  ConfigRules () {}
205  virtual ~ConfigRules() {}
206 
207  public:
210  virtual void reset() =0;
211 
212  // TODO: find out what operations we need to support here for the »real solution« (using Prolog)
213  };
214 
215  } // namespace query
216 
217 
218 
219 
220 
221 
222 
223  namespace query {
224 
229  void setFakeBypass(lumiera::QueryKey const& q);
230  bool isFakeBypass (lumiera::QueryKey const& q);
232 
233  } // namespace query
234 
235 } // namespace lumiera
236 #endif
void setFakeBypass(lumiera::QueryKey const &q)
backdoor for tests: the next config query with this query string will magically succeed with every ca...
Generic query interface for retrieving objects matching some capability query.
Basic and generic representation of an internal query.
the "front side" interface: the Steam-Layer code can use this QueryHandler to retrieve instances of t...
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:85
Apply a template to a collection of types.
Definition: generator.hpp:80
Helpers for working with lib::meta::Types (i.e.
Customised refcounting smart pointer.
#define LUMIERA_ERROR_DECLARE(err)
Forward declare an error constant.
Definition: error.h:71
#define SYMBOL
placeholder definition for later.
Token or Atom with distinct identity.
Definition: symbol.hpp:126
Marker types to indicate a literal string and a Symbol.
Wrapper for indexing and ordering.
Definition: query.hpp:397
the "back side" interface towards the classes participating in the configuration system (the config s...
Lumiera public interface.
Definition: advice.cpp:113
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:80
abstract entry, not yet allocated
Generic interface to express a query for specifically typed result elements exposing some capabilitie...
Definition: query.hpp:279
string resolve(fsys::path iniSpec)
use the general mechanism for resolving a search path to get the absolute path of the setup...
Definition: basic-setup.cpp:65