better use an enum for the ScopeQuery kinds

This commit is contained in:
Fischlurch 2009-11-18 04:53:49 +01:00
parent c01f774344
commit 11463da463
4 changed files with 37 additions and 38 deletions

View file

@ -326,7 +326,7 @@ namespace session {
REQUIRE (INSTANCEOF(ScopeQuery<MO>, &goal));
ScopeQuery<MO> const& query = static_cast<ScopeQuery<MO> const&> (goal);
Literal direction = query.searchDirection();
ScopeQueryKind direction = query.searchDirection();
PID scopeID = query.searchScope().getID(); ///////////////////////////////TICKET #411
return new ResultSet( bind (&PlacementIndexQueryResolver::setupExploration,
@ -336,28 +336,24 @@ namespace session {
}
/** the builder function used to set up the actual result set object
/** the builder function used to set up an concrete result set object
* when issuing the query. It is preconfigured by the resolutionFunction.
* The object returned from this function is taken over and managed by a
* smart-ptr, which is embedded within the iterator given to the client.
*/
Explorer*
PlacementIndexQueryResolver::setupExploration (PID startID, Literal direction)
PlacementIndexQueryResolver::setupExploration (PID startID, ScopeQueryKind direction)
{
if (direction == "contents")
return new DeepExplorer(index_->getReferrers(startID), index_);
else if (direction == "children")
return new ChildExplorer(index_->getReferrers(startID));
else if (direction == "parents")
return new UpExplorer(index_->getScope(startID),index_);
else if (direction == "path")
return new UpExplorer(index_->find(startID),index_);
else
throw lumiera::error::Invalid("unknown query direction"); //////TICKET #197
switch (direction)
{
case CONTENTS: return new DeepExplorer(index_->getReferrers(startID), index_);
case CHILDREN: return new ChildExplorer(index_->getReferrers(startID));
case PARENTS: return new UpExplorer(index_->getScope(startID),index_);
case PATH: return new UpExplorer(index_->find(startID),index_);
default:
throw lumiera::error::Invalid("unknown query direction"); //////TICKET #197
}
}

View file

@ -59,14 +59,13 @@
//#include "pre.hpp"
#include "proc/mobject/session/placement-index.hpp"
#include "proc/mobject/session/query-resolver.hpp"
#include "lib/symbol.hpp"
#include "proc/mobject/session/scope-query.hpp"
namespace mobject {
namespace session {
using lib::Literal;
class Explorer;
@ -93,7 +92,7 @@ namespace session {
virtual operator string() const { return "PlacementIndex"; }
Explorer* setupExploration (PlacementIndex::ID startID, Literal direction);
Explorer* setupExploration (PlacementIndex::ID startID, ScopeQueryKind direction);
template<typename MO>
void defineHandling();

View file

@ -27,7 +27,6 @@
#include "proc/mobject/placement.hpp"
#include "proc/mobject/session/query-resolver.hpp"
#include "lib/symbol.hpp"
#include <tr1/functional>
@ -35,7 +34,6 @@
namespace mobject {
namespace session {
using lib::Literal;
using std::tr1::bind;
using std::tr1::function;
using std::tr1::placeholders::_1;
@ -61,7 +59,6 @@ namespace session {
typedef Query<Placement<MO> > _Query;
typedef typename _Query::iterator _QIter;
protected:
DiscoveryQuery ()
: _Query (_Query::defineQueryTypeID (Goal::DISCOVERY))
, _QIter ()
@ -77,6 +74,13 @@ namespace session {
};
enum ScopeQueryKind
{ CONTENTS = 0 ///< discover any contained objects depth-first
, CHILDREN ///< discover the immediate children
, PARENTS ///< discover the enclosing scopes
, PATH ///< discover the path to root
};
/**
* Query a scope to discover it's contents or location.
@ -113,7 +117,7 @@ namespace session {
QueryResolver const& index_;
PlacementMO const& startPoint_;
Literal what_to_discover_;
ScopeQueryKind to_discover_;
public:
typedef typename _Par::ContentFilter ContentFilter;
@ -122,10 +126,10 @@ namespace session {
ScopeQuery (QueryResolver const& resolver,
PlacementMO const& scope,
Literal direction)
ScopeQueryKind direction)
: index_(resolver)
, startPoint_(scope)
, what_to_discover_(direction)
, to_discover_(direction)
{
resetResultIteration (_Query::resolveBy(index_));
}
@ -144,10 +148,10 @@ namespace session {
return startPoint_;
}
Literal
ScopeQueryKind
searchDirection () const
{
return what_to_discover_;
return to_discover_;
}
ContentFilter
@ -184,7 +188,7 @@ namespace session {
{
ContentsQuery (QueryResolver const& resolver,
PlacementMO const& scope)
: ScopeQuery<MO> (resolver,scope, "content")
: ScopeQuery<MO> (resolver,scope, CONTENTS)
{ }
};
@ -196,7 +200,7 @@ namespace session {
{
PathQuery (QueryResolver const& resolver,
PlacementMO const& scope)
: ScopeQuery<MO> (resolver,scope, "parents")
: ScopeQuery<MO> (resolver,scope, PARENTS)
{ }
};

View file

@ -67,16 +67,16 @@ namespace test {
QueryResolver const& resolver = SessionServiceExploreScope::getResolver();
PlacementMO const& scope = SessionServiceExploreScope::getScopeRoot();
discover (ScopeQuery<MObject> (resolver,scope, "contents"));
discover (ScopeQuery<DummyMO> (resolver,scope, "contents"));
discover (ScopeQuery<TestSubMO1> (resolver,scope, "contents"));
discover (ScopeQuery<TestSubMO2> (resolver,scope, "contents"));
discover (ScopeQuery<MObject> (resolver,scope, CONTENTS));
discover (ScopeQuery<DummyMO> (resolver,scope, CONTENTS));
discover (ScopeQuery<TestSubMO1> (resolver,scope, CONTENTS));
discover (ScopeQuery<TestSubMO2> (resolver,scope, CONTENTS));
ScopeQuery<TestSubMO21> specialEl(resolver,scope, "contents");
ScopeQuery<TestSubMO21> specialEl(resolver,scope, CONTENTS);
discover (ScopeQuery<MObject> (resolver,*specialEl, "parents"));
discover (ScopeQuery<MObject> (resolver,*specialEl, "path"));
discover (ScopeQuery<TestSubMO2> (resolver,*specialEl, "path"));
discover (ScopeQuery<MObject> (resolver,*specialEl, PARENTS));
discover (ScopeQuery<MObject> (resolver,*specialEl, PATH));
discover (ScopeQuery<TestSubMO2> (resolver,*specialEl, PATH));
discover (specialEl);
}