Implement registration of a resolution function. QueryResolver_test pass

This commit is contained in:
Fischlurch 2009-10-30 20:33:44 +01:00
parent f70f8c4e4a
commit 9ff7b1eaeb
5 changed files with 109 additions and 34 deletions

View file

@ -110,6 +110,16 @@ namespace session {
}
void
QueryResolver::installResolutionCase (QID qID, function<Resolution*(Goal&)> resolutionFun)
{
ENSURE (!dispatcher_->contains (qID),
"duplicate registration of query resolution function");
dispatcher_->defineProduction (qID, resolutionFun);
}
}} // namespace mobject::session

View file

@ -33,6 +33,7 @@
#include <boost/noncopyable.hpp>
#include <boost/scoped_ptr.hpp>
#include <tr1/functional>
#include <tr1/memory>
//#include <vector>
//#include <string>
@ -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<QueryDispatcher> dispatcher_;
scoped_ptr<QueryDispatcher> 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<Resolution*(Goal&)>);
QueryResolver();
};

View file

@ -2,10 +2,6 @@ TESTING "Proc Layer config rules Test Suite" ./test-lib --group=query
PLANNED "issuing typed queries" QueryResolver_test <<END
END
PLANNED "sub-extensible ID" SubID_test <<END
END

View file

@ -67,6 +67,26 @@ PLANNED "Path of nested scopes" ScopePath_test <<END
END
TEST "issuing typed queries" QueryResolver_test <<END
out: Query-Results: sizeof\( .+IterAdapter.+Cursor.+shared_ptr.+Resolution
out: ^6$
out: ^5$
out: ^4$
out: ^3$
out: ^2$
out: ^1$
out: ^0$
out: Query-Results: sizeof\( .+IterAdapter.+Cursor.+shared_ptr.+Resolution
out: ^a$
out: ^ra$
out: ^era$
out: ^iera$
out: ^miera$
out: ^umiera$
out: ^Lumiera$
END
PLANNED "Query focus management" QueryFocus_test <<END
END

View file

@ -22,17 +22,9 @@
#include "lib/test/run.hpp"
//#include "lib/lumitime.hpp"
#include "lib/test/test-helper.hpp"
//#include "proc/mobject/placement-ref.hpp"
//#include "proc/mobject/session/test-scopes.hpp"
//#include "proc/mobject/placement-index.hpp"
#include "proc/mobject/session/query-resolver.hpp"
//#include "lib/symbol.hpp"
//#include "lib/access-casted.hpp"
//#include "lib/variant.hpp"
//#include "lib/meta/typelist.hpp"
//#include "lib/util.hpp"
#include "lib/singleton.hpp"
#include <iostream>
#include <string>
@ -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<typename TY>
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<string>
: DummySolutions<int>
: public DummySolutions<int>
{
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<typename TY>
struct DummyResultSet
: Resolution
{
DummySolutions<TY> solutions_;
typedef typename Query<TY>::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<TY>();
}
template<typename TY>
static Resolution*
resolutionFunction (Goal& goal)
{
Goal::QueryID const& qID = goal.getQID();
REQUIRE (qID.kind == Goal::GENERIC
&& qID.type == getResultTypeID<TY>());
return new DummyResultSet<TY>();
}
public:
DummyTypedSolutionProducer()
: QueryResolver()
{
Goal::QueryID case1 = {Goal::GENERIC, getResultTypeID<int>()};
Goal::QueryID case2 = {Goal::GENERIC, getResultTypeID<string>()};
installResolutionCase(case1, &resolutionFunction<int> );
installResolutionCase(case2, &resolutionFunction<string> );
}
};
lib::Singleton<DummyTypedSolutionProducer> 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;
}
};