Lumiera  0.pre.03
»edit your freedom«
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 
37 using std::function;
38 
39 namespace lumiera {
40 
41  using std::unique_ptr;
42  using std::string;
43 
44 
45  class Resolution;
46  class QueryResolver;
48 
51 
52 
57  class Resolution
59  {
60  public:
61  typedef Goal::Result Result;
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 
79  virtual Result prepareResolution() =0;
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 
130  void installResolutionCase (Goal::QueryID const&,
131  ResolutionMechanism);
132 
133  QueryResolver();
134  };
135 
136 
137 
138 
139  template<typename RES>
140  inline typename Query<RES>::iterator
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>
153  inline typename Query<RES>::iterator
154  Query<RES>::operator() (QueryResolver const& resolver) const
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
Query ABC: unspecific goal for resolution or retrieval.
Definition: query.hpp:116
PImpl of the generic QueryResolver.
std::shared_ptr< Resolution > PReso
Allow to take and transfer ownership of a result set.
Interface: a facility for resolving (some kind of) queries A concrete subclass has the ability to cre...
Basic and generic representation of an internal query.
ABC representing the result set of an individual query resolution.
Helper template(s) for creating Lumiera Forward Iterators.
Any copy and copy construction prohibited.
Definition: nocopy.hpp:37
Mix-Ins to allow or prohibit various degrees of copying and cloning.
iterator operator()(QueryResolver const &resolver) const
notational convenience shortcut, synonymous to Query<RES>::resolveBy()
PReso issue(Goal const &query) const
issue a query to retrieve contents The query is handed over internally to a suitable resolver impleme...
Lumiera public interface.
Definition: advice.cpp:104
friend bool checkPoint(PReso const &, Result const &pos)
IterAdapter attached here.
Adapter for building an implementation of the »Lumiera Forward Iterator« concept. ...
Generic interface to express a query for specifically typed result elements exposing some capabilitie...
Definition: query.hpp:270
Single Solution, possibly part of a result set.
Definition: query.hpp:154