Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
query-resolver.hpp
Go to the documentation of this file.
1/*
2 QUERY-RESOLVER.hpp - framework for resolving generic queries
3
4 Copyright (C)
5 2009, 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
26#ifndef LUMIERA_QUERY_RESOLVER_H
27#define LUMIERA_QUERY_RESOLVER_H
28
29#include "lib/iter-adapter.hpp"
30#include "common/query.hpp"
31#include "lib/nocopy.hpp"
32
33#include <functional>
34#include <memory>
35#include <string>
36
37using std::function;
38
39namespace lumiera {
40
41 using std::unique_ptr;
42 using std::string;
43
44
45 class Resolution;
46 class QueryResolver;
47 class QueryDispatcher;
48
50 typedef std::shared_ptr<Resolution> PReso;
51
52
59 {
60 public:
62
63 virtual ~Resolution();
64
66 friend bool
67 checkPoint (PReso const&, Result const& pos)
68 {
69 return bool(pos);
70 }
71
72 friend void
73 iterNext (PReso& resultSet, Result& pos)
74 {
75 resultSet->nextResult(pos);
76 }
77
78
80
81 protected:
82
83 virtual void nextResult(Result& pos) =0;
84 };
85
86
100 {
101 unique_ptr<QueryDispatcher> dispatcher_;
102
103
104 public:
105 virtual ~QueryResolver() ;
106
107 virtual operator string () const =0;
108
109
118 PReso issue (Goal const& query) const;
119
120 bool canHandle (Goal const&) const;
121
122
123
124 protected: /* ===== API for concrete query resolvers ===== */
125
126 virtual bool canHandleQuery (Goal::QueryID const&) const =0;
127
128 using ResolutionMechanism = function<Resolution*(Goal const&)>;
129
132
134 };
135
136
137
138
139 template<typename RES>
141 Query<RES>::resolveBy (QueryResolver const& resolver) const
142 {
143 PReso resultSet = resolver.issue (*this);
144 Result first = resultSet->prepareResolution();
145 Cursor& start = static_cast<Cursor&> (first); // note: type RES must be compatible!
146 return iterator (resultSet, start);
147 }
148
149
152 template<typename RES>
155 {
156 return resolveBy (resolver);
157 }
158
159
160 inline bool
161 QueryResolver::canHandle(Goal const& query) const
162 {
163 return canHandleQuery (query.getQID());
164 }
165
166
167} // namespace lumiera
168#endif
Adapter for building an implementation of the »Lumiera Forward Iterator« concept.
Single Solution, possibly part of a result set.
Definition query.hpp:157
Query ABC: unspecific goal for resolution or retrieval.
Definition query.hpp:118
QueryID const & getQID() const
Definition query.hpp:144
Interface: a facility for resolving (some kind of) queries A concrete subclass has the ability to cre...
PReso issue(Goal const &query) const
issue a query to retrieve contents The query is handed over internally to a suitable resolver impleme...
void installResolutionCase(Goal::QueryID const &, ResolutionMechanism)
unique_ptr< QueryDispatcher > dispatcher_
virtual bool canHandleQuery(Goal::QueryID const &) const =0
bool canHandle(Goal const &) const
function< Resolution *(Goal const &)> ResolutionMechanism
iterator operator()(QueryResolver const &resolver) const
notational convenience shortcut, synonymous to Query<RES>::resolveBy()
iterator resolveBy(QueryResolver const &resolver) const
ABC representing the result set of an individual query resolution.
virtual Result prepareResolution()=0
virtual void nextResult(Result &pos)=0
friend void iterNext(PReso &resultSet, Result &pos)
friend bool checkPoint(PReso const &, Result const &pos)
IterAdapter attached here.
Any copy and copy construction prohibited.
Definition nocopy.hpp:38
Helper template(s) for creating Lumiera Forward Iterators.
Lumiera public interface.
Definition advice.hpp:102
std::shared_ptr< Resolution > PReso
Allow to take ownership of a result set.
Definition query.hpp:106
Mix-Ins to allow or prohibit various degrees of copying and cloning.
Basic and generic representation of an internal query.