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) Lumiera.org
5  2009, 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 
35 #ifndef LUMIERA_QUERY_RESOLVER_H
36 #define LUMIERA_QUERY_RESOLVER_H
37 
38 #include "lib/iter-adapter.hpp"
39 #include "common/query.hpp"
40 #include "lib/nocopy.hpp"
41 
42 #include <functional>
43 #include <memory>
44 #include <string>
45 
46 using std::function;
47 
48 namespace lumiera {
49 
50  using std::unique_ptr;
51  using std::string;
52 
53 
54  class Resolution;
55  class QueryResolver;
57 
60 
61 
66  class Resolution
68  {
69  public:
70  typedef Goal::Result Result;
71 
72  virtual ~Resolution();
73 
75  friend bool
76  checkPoint (PReso const&, Result const& pos)
77  {
78  return bool(pos);
79  }
80 
81  friend void
82  iterNext (PReso& resultSet, Result& pos)
83  {
84  resultSet->nextResult(pos);
85  }
86 
87 
88  virtual Result prepareResolution() =0;
89 
90  protected:
91 
92  virtual void nextResult(Result& pos) =0;
93  };
94 
95 
109  {
110  unique_ptr<QueryDispatcher> dispatcher_;
111 
112 
113  public:
114  virtual ~QueryResolver() ;
115 
116  virtual operator string () const =0;
117 
118 
127  PReso issue (Goal const& query) const;
128 
129  bool canHandle (Goal const&) const;
130 
131 
132 
133  protected: /* ===== API for concrete query resolvers ===== */
134 
135  virtual bool canHandleQuery (Goal::QueryID const&) const =0;
136 
137  using ResolutionMechanism = function<Resolution*(Goal const&)>;
138 
139  void installResolutionCase (Goal::QueryID const&,
140  ResolutionMechanism);
141 
142  QueryResolver();
143  };
144 
145 
146 
147 
148  template<typename RES>
149  inline typename Query<RES>::iterator
150  Query<RES>::resolveBy (QueryResolver const& resolver) const
151  {
152  PReso resultSet = resolver.issue (*this);
153  Result first = resultSet->prepareResolution();
154  Cursor& start = static_cast<Cursor&> (first); // note: type RES must be compatible!
155  return iterator (resultSet, start);
156  }
157 
158 
161  template<typename RES>
162  inline typename Query<RES>::iterator
163  Query<RES>::operator() (QueryResolver const& resolver) const
164  {
165  return resolveBy (resolver);
166  }
167 
168 
169  inline bool
170  QueryResolver::canHandle(Goal const& query) const
171  {
172  return canHandleQuery (query.getQID());
173  }
174 
175 
176 } // namespace lumiera
177 #endif
Query ABC: unspecific goal for resolution or retrieval.
Definition: query.hpp:125
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:46
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:113
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:279
Single Solution, possibly part of a result set.
Definition: query.hpp:163