Lumiera  0.pre.03
»edit your freedom«
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 
30 namespace lumiera {
31 
32 
33 
34  /* generate vtables here... */
35 
37 
38  Resolution::~Resolution() { }
39 
40  QueryResolver::~QueryResolver() { }
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 
82  QueryResolver::QueryResolver ()
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
110  QueryResolver::installResolutionCase (QID qID, ResolutionMechanism resolutionFun)
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
Query ABC: unspecific goal for resolution or retrieval.
Definition: query.hpp:116
PImpl of the generic QueryResolver.
ABC representing the result set of an individual query resolution.
framework and to resolve logical queries.
Framework for building a configurable factory, to generate families of related objects.
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:190
Factory for creating a family of objects by ID.
Definition: multifact.hpp:253
virtual ~Goal()
this is a marker baseclass
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
Wrapper taking ownership, by wrapping into smart-ptr.
Definition: multifact.hpp:99