From 9ff7b1eaeb2434bf17f4d13840cf004954902198 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 30 Oct 2009 20:33:44 +0100 Subject: [PATCH] Implement registration of a resolution function. QueryResolver_test pass --- src/proc/mobject/session/query-resolver.cpp | 10 +++ src/proc/mobject/session/query-resolver.hpp | 20 +++-- tests/42query.tests | 4 - tests/43session.tests | 20 +++++ .../mobject/session/query-resolver-test.cpp | 89 +++++++++++++------ 5 files changed, 109 insertions(+), 34 deletions(-) diff --git a/src/proc/mobject/session/query-resolver.cpp b/src/proc/mobject/session/query-resolver.cpp index 8bfb65eb3..db4f86894 100644 --- a/src/proc/mobject/session/query-resolver.cpp +++ b/src/proc/mobject/session/query-resolver.cpp @@ -110,6 +110,16 @@ namespace session { } + void + QueryResolver::installResolutionCase (QID qID, function resolutionFun) + { + ENSURE (!dispatcher_->contains (qID), + "duplicate registration of query resolution function"); + + dispatcher_->defineProduction (qID, resolutionFun); + } + + }} // namespace mobject::session diff --git a/src/proc/mobject/session/query-resolver.hpp b/src/proc/mobject/session/query-resolver.hpp index 6c0d295c5..29ab318d3 100644 --- a/src/proc/mobject/session/query-resolver.hpp +++ b/src/proc/mobject/session/query-resolver.hpp @@ -33,6 +33,7 @@ #include #include +#include #include //#include //#include @@ -45,6 +46,8 @@ namespace session { using util::unConst; using boost::noncopyable; + using boost::scoped_ptr; + using std::tr1::function; class Goal; @@ -181,6 +184,9 @@ namespace session { }; + + + /** * ABC denoting the result set * of an individual query resolution @@ -222,14 +228,13 @@ namespace session { class QueryResolver : noncopyable { - boost::scoped_ptr dispatcher_; + scoped_ptr dispatcher_; + public: - virtual ~QueryResolver() ; - /** issue a query to retrieve contents * The query is handed over internally to a suitable resolver implementation. * @return concrete Resolution of the query (ResultSet), \em managed by smart-pointer. @@ -241,8 +246,13 @@ namespace session { PReso issue (Goal& query) const; - protected: - virtual bool canHandleQuery (Goal::QueryID qID) const =0; + + protected: /* === API for concrete query resolvers === */ + + virtual bool canHandleQuery (Goal::QueryID) const =0; + + void installResolutionCase (Goal::QueryID const&, + function); QueryResolver(); }; diff --git a/tests/42query.tests b/tests/42query.tests index 5d437cc41..664e2912a 100644 --- a/tests/42query.tests +++ b/tests/42query.tests @@ -2,10 +2,6 @@ TESTING "Proc Layer config rules Test Suite" ./test-lib --group=query -PLANNED "issuing typed queries" QueryResolver_test < #include @@ -44,15 +36,17 @@ namespace session { namespace test { using lib::test::showSizeof; - //using util::isSameObject; - //using lumiera::Time; using std::string; using std::cout; using std::endl; - namespace { // a test query resolving facility + + + + namespace { // providing a test query resolving facility... + /** an sequence of "solutions" to be "found" */ template class DummySolutions; @@ -65,12 +59,12 @@ namespace test { DummySolutions() : resNr_(7) {} int* next () { --resNr_; return &resNr_; } - bool exhausted() { return bool(resNr_); } + bool exhausted() { return !bool(resNr_); } }; template<> class DummySolutions - : DummySolutions + : public DummySolutions { string currentText_; @@ -84,19 +78,27 @@ namespace test { } }; + + /** + * a concrete "resolution" of the query + * is a set of "solutions", which can be + * explored by iteration. Thus, the result set + * has to implement the iteration control API + * as required by IterAdapter + */ template struct DummyResultSet : Resolution { DummySolutions solutions_; - + typedef typename Query::Cursor Cursor; - + Result prepareResolution() { Cursor cursor; - cursor.pointAt (solutions_.next()); + cursor.point_at (solutions_.next()); return cursor; } @@ -111,8 +113,15 @@ namespace test { cursor.point_at (solutions_.next()); } }; - - class TypeMatchFilter + + + + /** + * a (dummy) concrete query resolution facility. + * It is hard-wired to accept queries on int and string, + * generating a sequence of results for both cases + */ + class DummyTypedSolutionProducer : public QueryResolver { bool @@ -130,14 +139,44 @@ namespace test { return qID.type == getResultTypeID(); } + + template + static Resolution* + resolutionFunction (Goal& goal) + { + Goal::QueryID const& qID = goal.getQID(); + REQUIRE (qID.kind == Goal::GENERIC + && qID.type == getResultTypeID()); + + return new DummyResultSet(); + } + + public: + DummyTypedSolutionProducer() + : QueryResolver() + { + Goal::QueryID case1 = {Goal::GENERIC, getResultTypeID()}; + Goal::QueryID case2 = {Goal::GENERIC, getResultTypeID()}; + + installResolutionCase(case1, &resolutionFunction ); + installResolutionCase(case2, &resolutionFunction ); + } }; - + + + lib::Singleton testResolver; + QueryResolver& buildTestQueryResolver () { - UNIMPLEMENTED("build a special resolver just for this test and register it."); + return testResolver(); } - } + + } // (END) implementation of a test query resolving facility + + + + /*********************************************************************************** @@ -168,11 +207,11 @@ namespace test { static void explore (ITER ii) { - cout << "Query-Results: " << showSizeof(ii) << endl;; - while (ii) + cout << "Query-Results: " << showSizeof(ii) << endl; + for ( ; ii; ++ii ) cout << *ii << endl; } - + };