change the ContensQuery stub to fit into the QueryResolver in its current form
Actually, the implementation within PlacementIndex is missing. Moreover, I think now that PlacementIndex shouldn't implement QueryResolver directly.
This commit is contained in:
parent
2620c38ed9
commit
356fe8fd13
7 changed files with 100 additions and 54 deletions
|
|
@ -63,6 +63,8 @@ namespace mobject {
|
|||
typedef PlacementIndex::PRef PRef;
|
||||
typedef PlacementIndex::ID ID;
|
||||
|
||||
typedef PlacementIndex::QID QID; //////////TODO
|
||||
|
||||
|
||||
/** @internal Factory for creating a new placement index.
|
||||
* For use by the Session and for unit tests.
|
||||
|
|
@ -77,9 +79,11 @@ namespace mobject {
|
|||
|
||||
|
||||
bool
|
||||
PlacementIndex::canHandleQuery (session::Goal::QueryID qID) const
|
||||
PlacementIndex::canHandleQuery (QID qID) const
|
||||
{
|
||||
UNIMPLEMENTED ("decide by hard-wired check if the given Query can be resolved by PlacementIndex");
|
||||
return session::Goal::GENERIC == qID.kind;
|
||||
// thats not enough! need to check the typeID (match to Placement<MOX>, with some fixed MOX values)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -73,13 +73,15 @@ namespace mobject { ///////////////////////////////////////////TODO: shouldn't t
|
|||
typedef PlacementRef<MObject> PRef;
|
||||
typedef PlacementMO::ID const& ID;
|
||||
|
||||
typedef session::Goal::QueryID const& QID;
|
||||
|
||||
|
||||
PlacementMO& find (ID) const;
|
||||
|
||||
template<class MO>
|
||||
Placement<MO>& find (PlacementMO::Id<MO>) const;
|
||||
template<class MO>
|
||||
Placement<MO>& find (PlacementRef<MO> const&) const;
|
||||
Placement<MO>& find (PlacementRef<MO> const&) const;
|
||||
|
||||
PlacementMO& getScope (PlacementMO const&) const;
|
||||
PlacementMO& getScope (ID) const;
|
||||
|
|
@ -99,7 +101,7 @@ namespace mobject { ///////////////////////////////////////////TODO: shouldn't t
|
|||
query (PlacementMO& scope) const;
|
||||
|
||||
|
||||
bool canHandleQuery(session::Goal::QueryID) const;
|
||||
bool canHandleQuery(QID) const;
|
||||
|
||||
|
||||
/* == mutating operations == */
|
||||
|
|
@ -167,11 +169,16 @@ namespace mobject { ///////////////////////////////////////////TODO: shouldn't t
|
|||
}
|
||||
|
||||
|
||||
/** @todo use query-resolver-test as an example.....
|
||||
* return a result set object derived from Resolution
|
||||
* For the additional type filtering: build a filter iterator,
|
||||
* using a type-filtering predicate, based on Placement#isCompatible
|
||||
*/
|
||||
template<class MO>
|
||||
inline typename session::Query<Placement<MO> >::iterator
|
||||
PlacementIndex::query (PlacementMO& scope) const
|
||||
{
|
||||
UNIMPLEMENTED ("actually run the containment query");
|
||||
UNIMPLEMENTED ("actually run the containment query");
|
||||
}
|
||||
|
||||
inline Placement<MObject>&
|
||||
|
|
|
|||
|
|
@ -26,11 +26,9 @@
|
|||
|
||||
//#include "proc/mobject/mobject.hpp"
|
||||
#include "proc/mobject/placement.hpp"
|
||||
#include "proc/mobject/placement-index.hpp"
|
||||
#include "proc/mobject/session/query-resolver.hpp"
|
||||
//#include "lib/iter-adapter.hpp"
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
//#include <vector>
|
||||
//#include <string>
|
||||
|
||||
|
|
@ -48,22 +46,36 @@ namespace session {
|
|||
template<class MO>
|
||||
class ContentsQuery
|
||||
: public Query<Placement<MO> >
|
||||
, boost::noncopyable
|
||||
{
|
||||
typedef Query<Placement<MO> > _Query;
|
||||
typedef typename _Query::iterator iterator;
|
||||
|
||||
PPIdx index_;
|
||||
QueryResolver const& index_;
|
||||
PlacementMO const& container_;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
ContentsQuery (PPIdx index, PlacementMO const& scope)
|
||||
: index_(index)
|
||||
ContentsQuery (QueryResolver const& resolver, PlacementMO const& scope)
|
||||
: _Query (_Query::defineQueryTypeID (Goal::DISCOVERY))
|
||||
, index_(resolver)
|
||||
, container_(scope)
|
||||
{ }
|
||||
|
||||
typedef typename _Query::iterator iterator;
|
||||
|
||||
iterator
|
||||
operator() () const
|
||||
{
|
||||
return _Query::resolveBy (index_);
|
||||
}
|
||||
|
||||
PlacementMO const&
|
||||
searchScope ()
|
||||
{
|
||||
return container_;
|
||||
}
|
||||
|
||||
/////////////////////TODO maybe exposing a content filter predicate from here?
|
||||
|
||||
};
|
||||
///////////////////////////TODO currently just fleshing the API
|
||||
|
||||
|
|
|
|||
|
|
@ -62,17 +62,17 @@ namespace session {
|
|||
|
||||
/** factory used as dispatcher table
|
||||
* for resolving typed queries */
|
||||
typedef MultiFact< Resolution(Goal&) // nominal signature of fabrication
|
||||
, Goal::QueryID // select resolution function by kind-of-Query
|
||||
, BuildRefcountPtr // wrapper: manage result set by smart-ptr
|
||||
> DispatcherTable; //
|
||||
typedef MultiFact< Resolution(Goal const&) // nominal signature of fabrication
|
||||
, Goal::QueryID // select resolution function by kind-of-Query
|
||||
, BuildRefcountPtr // wrapper: manage result set by smart-ptr
|
||||
> DispatcherTable; //
|
||||
|
||||
struct QueryDispatcher
|
||||
: DispatcherTable
|
||||
{
|
||||
|
||||
PReso
|
||||
handle (Goal& query)
|
||||
handle (Goal const& query)
|
||||
{
|
||||
QID qID = query.getQID();
|
||||
ENSURE (contains (qID));
|
||||
|
|
@ -99,7 +99,7 @@ namespace session {
|
|||
* typed context and downcast the Goal appropriately
|
||||
*/
|
||||
PReso
|
||||
QueryResolver::issue (Goal& query) const
|
||||
QueryResolver::issue (Goal const& query) const
|
||||
{
|
||||
TODO ("ensure proper initialisation");
|
||||
|
||||
|
|
@ -111,7 +111,7 @@ namespace session {
|
|||
|
||||
|
||||
void
|
||||
QueryResolver::installResolutionCase (QID qID, function<Resolution*(Goal&)> resolutionFun)
|
||||
QueryResolver::installResolutionCase (QID qID, function<Resolution*(Goal const&)> resolutionFun)
|
||||
{
|
||||
ENSURE (!dispatcher_->contains (qID),
|
||||
"duplicate registration of query resolution function");
|
||||
|
|
|
|||
|
|
@ -81,7 +81,11 @@ namespace session {
|
|||
size_t type;
|
||||
};
|
||||
|
||||
QueryID getQID() { return id_; }
|
||||
QueryID const&
|
||||
getQID() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -147,10 +151,11 @@ namespace session {
|
|||
class Query
|
||||
: public Goal
|
||||
{
|
||||
protected:
|
||||
static QueryID
|
||||
defineQueryTypeID ()
|
||||
defineQueryTypeID (Kind queryType = Goal::GENERIC)
|
||||
{
|
||||
QueryID id = {Goal::GENERIC, getResultTypeID<RES>() };
|
||||
QueryID id = {queryType, getResultTypeID<RES>() };
|
||||
return id;
|
||||
}
|
||||
|
||||
|
|
@ -178,8 +183,14 @@ namespace session {
|
|||
|
||||
typedef lib::IterAdapter<Cursor,PReso> iterator;
|
||||
|
||||
iterator
|
||||
operator() (QueryResolver const& resolver);
|
||||
iterator operator() (QueryResolver const& resolver) const;
|
||||
iterator resolveBy (QueryResolver const& resolver) const;
|
||||
|
||||
|
||||
protected:
|
||||
Query (QueryID qID)
|
||||
: Goal (qID)
|
||||
{ }
|
||||
|
||||
};
|
||||
|
||||
|
|
@ -243,31 +254,42 @@ namespace session {
|
|||
* or failure of an external facility used for resolution.
|
||||
* @note a query may yield no results, in which case the iterator is empty.
|
||||
*/
|
||||
PReso issue (Goal& query) const;
|
||||
PReso issue (Goal const& query) const;
|
||||
|
||||
|
||||
|
||||
protected: /* === API for concrete query resolvers === */
|
||||
protected: /* ===== API for concrete query resolvers ===== */
|
||||
|
||||
virtual bool canHandleQuery (Goal::QueryID) const =0;
|
||||
virtual bool canHandleQuery (Goal::QueryID const&) const =0;
|
||||
|
||||
void installResolutionCase (Goal::QueryID const&,
|
||||
function<Resolution*(Goal&)>);
|
||||
function<Resolution*(Goal const&)>);
|
||||
|
||||
QueryResolver();
|
||||
};
|
||||
///////////////////////////TODO currently just fleshing the API
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename RES>
|
||||
inline typename Query<RES>::iterator
|
||||
Query<RES>::operator() (QueryResolver const& resolver)
|
||||
{
|
||||
PReso resultSet = resolver.issue (*this);
|
||||
Result first = resultSet->prepareResolution();
|
||||
Cursor& start = static_cast<Cursor&> (first);
|
||||
return iterator (resultSet, start);
|
||||
}
|
||||
Query<RES>::resolveBy (QueryResolver const& resolver) const
|
||||
{
|
||||
PReso resultSet = resolver.issue (*this);
|
||||
Result first = resultSet->prepareResolution();
|
||||
Cursor& start = static_cast<Cursor&> (first);
|
||||
return iterator (resultSet, start);
|
||||
}
|
||||
|
||||
|
||||
/** notational convenience shortcut,
|
||||
* synonymous to #resolveBy */
|
||||
template<typename RES>
|
||||
inline typename Query<RES>::iterator
|
||||
Query<RES>::operator() (QueryResolver const& resolver) const
|
||||
{
|
||||
return resolveBy (resolver);
|
||||
}
|
||||
|
||||
|
||||
}} // namespace mobject::session
|
||||
|
|
|
|||
|
|
@ -27,11 +27,11 @@
|
|||
#include "proc/mobject/session/query-resolver.hpp"
|
||||
#include "proc/mobject/session/contents-query.hpp"
|
||||
#include "proc/mobject/session/test-scopes.hpp"
|
||||
//#include "proc/mobject/placement-index.hpp"
|
||||
//#include "proc/mobject/placement-resolver.hpp"
|
||||
//#include "lib/util.hpp"
|
||||
|
||||
#include <iostream>
|
||||
//#include <string>
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ namespace test {
|
|||
using session::Query;
|
||||
//using util::isSameObject;
|
||||
//using lumiera::Time;
|
||||
//using std::string;
|
||||
using std::string;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
|
|
@ -68,24 +68,24 @@ namespace test {
|
|||
// Prepare an (test)Index backing the PlacementRefs
|
||||
PPIdx index = build_testScopes();
|
||||
PlacementMO scope (index->getRoot());
|
||||
QueryResolver const& resolver (*index);
|
||||
|
||||
discover (ContentsQuery<MObject> (index,scope));
|
||||
discover (ContentsQuery<DummyMO> (index,scope));
|
||||
discover (ContentsQuery<TestSubMO1> (index,scope));
|
||||
discover (ContentsQuery<TestSubMO2> (index,scope));
|
||||
discover (ContentsQuery<TestSubMO21>(index,scope));
|
||||
discover (ContentsQuery<MObject> (resolver,scope));
|
||||
discover (ContentsQuery<DummyMO> (resolver,scope));
|
||||
discover (ContentsQuery<TestSubMO1> (resolver,scope));
|
||||
discover (ContentsQuery<TestSubMO2> (resolver,scope));
|
||||
discover (ContentsQuery<TestSubMO21>(resolver,scope));
|
||||
}
|
||||
|
||||
|
||||
template<class MO>
|
||||
void
|
||||
discover (Query<MO> const& query)
|
||||
discover (ContentsQuery<MO> const& query)
|
||||
{
|
||||
#if false //////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET 384 !!!!!!!!!
|
||||
Query<MO>::iterator elm = query();
|
||||
while (elm)
|
||||
cout << *elm++ << endl;
|
||||
#endif ////////////////////////////////////////////////////////////////////////////////////////TODO lots of things unimplemented.....!!!!!
|
||||
for (typename ContentsQuery<MO>::iterator elm = query();
|
||||
elm;
|
||||
++elm)
|
||||
cout << string(*elm) << endl;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ namespace test {
|
|||
|
||||
namespace { // providing a test query resolving facility...
|
||||
|
||||
typedef Goal::QueryID const& QID;
|
||||
|
||||
/** an sequence of "solutions" to be "found" */
|
||||
template<typename TY>
|
||||
|
|
@ -125,7 +126,7 @@ namespace test {
|
|||
: public QueryResolver
|
||||
{
|
||||
bool
|
||||
canHandleQuery (Goal::QueryID qID) const
|
||||
canHandleQuery (QID qID) const
|
||||
{
|
||||
return Goal::GENERIC == qID.kind
|
||||
&& (wantResultType<int> (qID)
|
||||
|
|
@ -134,7 +135,7 @@ namespace test {
|
|||
|
||||
template<typename TY>
|
||||
bool
|
||||
wantResultType (Goal::QueryID qID) const
|
||||
wantResultType (QID qID) const
|
||||
{
|
||||
return qID.type == getResultTypeID<TY>();
|
||||
}
|
||||
|
|
@ -142,9 +143,9 @@ namespace test {
|
|||
|
||||
template<typename TY>
|
||||
static Resolution*
|
||||
resolutionFunction (Goal& goal)
|
||||
resolutionFunction (Goal const& goal)
|
||||
{
|
||||
Goal::QueryID const& qID = goal.getQID();
|
||||
QID qID = goal.getQID();
|
||||
REQUIRE (qID.kind == Goal::GENERIC
|
||||
&& qID.type == getResultTypeID<TY>());
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue