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) 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 
36 #include "lib/multifact.hpp"
38 
39 namespace lumiera {
40 
41 
42 
43  /* generate vtables here... */
44 
46 
47  Resolution::~Resolution() { }
48 
49  QueryResolver::~QueryResolver() { }
50 
51 
52 
53  typedef Goal::QueryID const& QID;
54 
55 
56 
57 
58 
59 
60  /* == dispatch to resolve typed queries == */
61 
64 
65 
68  typedef MultiFact< Resolution*(Goal const&) // raw signature of fabrication
69  , Goal::QueryID // select resolution function by kind-of-Query
70  , BuildRefcountPtr // wrapper: manage result set by smart-ptr
72 
75  : public DispatcherTable
76  {
77  public:
78 
79  PReso
80  handle (Goal const& query)
81  {
82  QID qID = query.getQID();
83  ENSURE (contains (qID));
84 
85  return this->invokeFactory (qID, query);
86  } // qID picks the resolution function
87  };
88 
89 
90 
91  QueryResolver::QueryResolver ()
92  : dispatcher_(new QueryDispatcher)
93  { }
94 
95 
106  PReso
107  QueryResolver::issue (Goal const& query) const
108  {
109  REQUIRE (!dispatcher_->empty(), "attempt to issue a query without having installed any resolver (yet)");
110 
111  if (!canHandle (query))
112  throw lumiera::error::Invalid ("unable to resolve this kind of query");
113 
114  return dispatcher_->handle(query);
115  }
116 
117 
118  void
119  QueryResolver::installResolutionCase (QID qID, ResolutionMechanism resolutionFun)
120  {
121  ENSURE (!dispatcher_->contains (qID),
122  "duplicate registration of query resolution function");
123 
124  dispatcher_->defineProduction (qID, resolutionFun);
125  }
126 
127 
128 
129 
130 } // namespace lumiera
Query ABC: unspecific goal for resolution or retrieval.
Definition: query.hpp:125
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:199
Factory for creating a family of objects by ID.
Definition: multifact.hpp:262
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:113
Wrapper taking ownership, by wrapping into smart-ptr.
Definition: multifact.hpp:108