Lumiera  0.pre.03
»edityourfreedom«
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 
76  using std::string;
77  using lib::P;
78 
79 
81 
82  namespace query {
83 
84  // The intention is to support the following style of Prolog code
85  //
86  // resolve(O, Cap) :- find(O), capabilities(Cap).
87  // resolve(O, Cap) :- make(O), capabilities(Cap).
88  // capabilities(Q) :- call(Q).
89  //
90  // stream(T, mpeg) :- type(T, fork), type(P, pipe), resolve(P, stream(P,mpeg)), placed_to(P, T).
91  //
92  // The type guard is inserted automatically, while the predicate implementations for
93  // find/1, make/1, stream/2, and placed_to/2 are to be provided by the target types.
94  //
95  // As a example, the goal ":-retrieve(T, stream(T,mpeg))." would search a Fork object (a "track"), try to
96  // retrieve a pipe object with stream-type=mpeg and associate the Fork with this Pipe. The
97  // predicate "stream(P,mpeg)" needs to be implemented (natively) for the pipe object.
98 
99  class Resolver
100  {
102  };
103 
104 
105  using lib::Symbol;
106  using lib::Literal;
107  using lumiera::Query;
108 
112 #define SYMBOL uint
113 
114 
115  template
116  < SYMBOL SYM, // Predicate symbol
117  typename SIG = bool(string) // Signature
118  >
119  class Pred
120  { };
121 
136  template<class TY>
138  {
139  static const TY NIL;
140 
141  template<SYMBOL SYM, typename SIG>
142  TY find (Pred<SYM,SIG> capability);
143 
144  template<SYMBOL SYM, typename SIG>
145  TY make (Pred<SYM,SIG> capability, TY& refObj =NIL);
146  };
147 
158  template<class TY>
160  {
161  protected:
162  virtual ~QueryHandler() { }
163  public:
171  virtual bool resolve (P<TY>& solution, Query<TY> const& q) = 0;
172  };
173 
174  // TODO: the Idea is to provide specialisations for the concrete types
175  // we want to participate in the ConfigRules system....
176  // Thus we get the possibility to create a specific return type,
177  // e.g. return a P<Pipe> but a Placement<Fork>, using the appropriate factory.
178  // Of course then the definitions need to be split up in separate headers.
179 
180 
181 
182 
183 
195  template<typename TYPES>
197  : public lib::meta::InstantiateForEach<TYPES, QueryHandler>
198  {
199  protected:
201  virtual ~ConfigRules() {}
202 
203  public:
206  virtual void reset() =0;
207 
208  // TODO: find out what operations we need to support here for the »real solution« (using Prolog)
209  };
210 
211 
212 
213 
214  LUMIERA_ERROR_DECLARE (CAPABILITY_QUERY);
215 
216  } // namespace query
217 
218 
219 
220 
221 
222 
223 
224  namespace query {
225 
230  void setFakeBypass(lumiera::QueryKey const& q);
231  bool isFakeBypass (lumiera::QueryKey const& q);
233 
234  } // namespace query
235 
236 } // namespace lumiera
237 #endif
Generic query interface for retrieving objects matching some capability query.
Basic and generic representation of an internal query.
the "front side" interface: the Proc-Layer code can use this QueryHandler to retrieve instances of th...
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:75
Apply a template to a collection of types.
Definition: generator.hpp:80
Helpers for working with lib::meta::Types (i.e.
void setFakeBypass(lumiera::QueryKey const &q)
backdoor for tests: the next config query with this query string will magically succeed with every ca...
Customised refcounting smart pointer.
#define SYMBOL
placeholder definition for later.
bool find(Query< Pipe > &q)
shortcut: run just a query without creating new instances
Token or Atom with distinct identity.
Definition: symbol.hpp:116
bool isFakeBypass(lumiera::QueryKey const &q)
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.
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:76
LUMIERA_ERROR_DECLARE(CAPABILITY_QUERY)
unresolvable capability query.
Generic interface to express a query for specifically typed result elements exposing some capabilitie...
Definition: query.hpp:279