Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
config-rules.hpp
Go to the documentation of this file.
1/*
2 CONFIG-RULES.hpp - interface for rule based configuration
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
53#ifndef LUMIERA_CONFIG_RULES_H
54#define LUMIERA_CONFIG_RULES_H
55
56#include "lib/p.hpp"
57#include "lib/symbol.hpp"
59#include "common/query.hpp"
60
61#include <string>
62
63
64
65namespace lumiera {
66 namespace error {
67 LUMIERA_ERROR_DECLARE (CAPABILITY_QUERY);
68 }
69
70 using std::string;
71 using lib::P;
72
73
74
76
77 namespace query {
78
79 // The intention is to support the following style of Prolog code
80 //
81 // resolve(O, Cap) :- find(O), capabilities(Cap).
82 // resolve(O, Cap) :- make(O), capabilities(Cap).
83 // capabilities(Q) :- call(Q).
84 //
85 // stream(T, mpeg) :- type(T, fork), type(P, pipe), resolve(P, stream(P,mpeg)), placed_to(P, T).
86 //
87 // The type guard is inserted automatically, while the predicate implementations for
88 // find/1, make/1, stream/2, and placed_to/2 are to be provided by the target types.
89 //
90 // As a example, the goal ":-retrieve(T, stream(T,mpeg))." would search a Fork object (a "track"), try to
91 // retrieve a pipe object with stream-type=mpeg and associate the Fork with this Pipe. The
92 // predicate "stream(P,mpeg)" needs to be implemented (natively) for the pipe object.
93
95 {
97 };
98
99
100 using lib::Symbol;
101 using lib::Literal;
102 using lumiera::Query;
103
107#define SYMBOL uint
108
109
110 template
111 < SYMBOL SYM, // Predicate symbol
112 typename SIG = bool(string) // Signature
113 >
114 class Pred
115 { };
116
131 template<class TY>
133 {
134 static const TY NIL;
135
136 template<SYMBOL SYM, typename SIG>
137 TY find (Pred<SYM,SIG> capability);
138
139 template<SYMBOL SYM, typename SIG>
140 TY make (Pred<SYM,SIG> capability, TY& refObj =NIL);
141 };
142
153 template<class TY>
155 {
156 protected:
157 virtual ~QueryHandler() { }
158 public:
166 virtual bool resolve (P<TY>& solution, Query<TY> const& q) = 0;
167 };
168
169 // TODO: the Idea is to provide specialisations for the concrete types
170 // we want to participate in the ConfigRules system....
171 // Thus we get the possibility to create a specific return type,
172 // e.g. return a P<Pipe> but a Placement<Fork>, using the appropriate factory.
173 // Of course then the definitions need to be split up in separate headers.
174
175
176
177
178
190 template<typename TYPES>
192 : public lib::meta::InstantiateForEach<TYPES, QueryHandler>
193 {
194 protected:
196 virtual ~ConfigRules() {}
197
198 public:
201 virtual void reset() =0;
202
203 // TODO: find out what operations we need to support here for the »real solution« (using Prolog)
204 };
205
206 } // namespace query
207
208
209
210
211
212
213
214 namespace query {
215
220 void setFakeBypass(lumiera::QueryKey const& q);
221 bool isFakeBypass (lumiera::QueryKey const& q);
223
224 } // namespace query
225
226} // namespace lumiera
227#endif
Inline string literal.
Definition symbol.hpp:78
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition p.hpp:77
Token or Atom with distinct identity.
Definition symbol.hpp:120
Apply a template to a collection of types.
Definition generator.hpp:71
Wrapper for indexing and ordering.
Definition query.hpp:371
Generic interface to express a query for specifically typed result elements exposing some capabilitie...
Definition query.hpp:254
Generic query interface for retrieving objects matching some capability query.
virtual void reset()=0
roll back to a pristine yet operational state.
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.
the "back side" interface towards the classes participating in the configuration system (the config s...
TY find(Pred< SYM, SIG > capability)
TY make(Pred< SYM, SIG > capability, TY &refObj=NIL)
#define SYMBOL
placeholder definition for later.
#define LUMIERA_ERROR_DECLARE(err)
Forward declare an error constant.
Definition error.h:62
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...
Lumiera public interface.
Definition advice.hpp:102
Customised refcounting smart pointer.
Basic and generic representation of an internal query.
Marker types to indicate a literal string and a Symbol.