Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
query-resolver.cpp
Go to the documentation of this file.
1/*
2 QueryResolver - interface for discovering contents of a scope
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
27#include "lib/multifact.hpp"
29
30namespace lumiera {
31
32
33
34 /* generate vtables here... */
35
37
39
41
42
43
44 typedef Goal::QueryID const& QID;
45
46
47
48
49
50
51 /* == dispatch to resolve typed queries == */
52
55
56
59 typedef MultiFact< Resolution*(Goal const&) // raw signature of fabrication
60 , Goal::QueryID // select resolution function by kind-of-Query
61 , BuildRefcountPtr // wrapper: manage result set by smart-ptr
63
66 : public DispatcherTable
67 {
68 public:
69
70 PReso
71 handle (Goal const& query)
72 {
73 QID qID = query.getQID();
74 ENSURE (contains (qID));
75
76 return this->invokeFactory (qID, query);
77 } // qID picks the resolution function
78 };
79
80
81
83 : dispatcher_(new QueryDispatcher)
84 { }
85
86
97 PReso
98 QueryResolver::issue (Goal const& query) const
99 {
100 REQUIRE (!dispatcher_->empty(), "attempt to issue a query without having installed any resolver (yet)");
101
102 if (!canHandle (query))
103 throw lumiera::error::Invalid ("unable to resolve this kind of query");
104
105 return dispatcher_->handle(query);
106 }
107
108
109 void
111 {
112 ENSURE (!dispatcher_->contains (qID),
113 "duplicate registration of query resolution function");
114
115 dispatcher_->defineProduction (qID, resolutionFun);
116 }
117
118
119
120
121} // namespace lumiera
Factory for creating a family of objects by ID.
bool contains(ID id) const
Product invokeFactory(ID const &id, ARGS &&...args)
more legible alias for the function operator
Query ABC: unspecific goal for resolution or retrieval.
Definition query.hpp:118
virtual ~Goal()
this is a marker baseclass
QueryID const & getQID() const
Definition query.hpp:144
PImpl of the generic QueryResolver.
PReso handle(Goal const &query)
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_
bool canHandle(Goal const &) const
function< Resolution *(Goal const &)> ResolutionMechanism
ABC representing the result set of an individual query resolution.
Framework for building a configurable factory, to generate families of related objects.
LumieraError< LERR_(INVALID)> Invalid
Definition error.hpp:211
Lumiera public interface.
Definition advice.hpp:102
Goal::QueryID const & QID
std::shared_ptr< Resolution > PReso
Allow to take ownership of a result set.
Definition query.hpp:106
framework and to resolve logical queries.
Wrapper taking ownership, by wrapping into smart-ptr.