diff --git a/src/proc/mobject/session/placement-index-query-resolver.cpp b/src/proc/mobject/session/placement-index-query-resolver.cpp index efc6224f8..b85ca6e6f 100644 --- a/src/proc/mobject/session/placement-index-query-resolver.cpp +++ b/src/proc/mobject/session/placement-index-query-resolver.cpp @@ -326,7 +326,7 @@ namespace session { REQUIRE (INSTANCEOF(ScopeQuery, &goal)); ScopeQuery const& query = static_cast 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 + } } diff --git a/src/proc/mobject/session/placement-index-query-resolver.hpp b/src/proc/mobject/session/placement-index-query-resolver.hpp index cbb847da8..26da4a824 100644 --- a/src/proc/mobject/session/placement-index-query-resolver.hpp +++ b/src/proc/mobject/session/placement-index-query-resolver.hpp @@ -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 void defineHandling(); diff --git a/src/proc/mobject/session/scope-query.hpp b/src/proc/mobject/session/scope-query.hpp index f575edd95..d0e2f41ab 100644 --- a/src/proc/mobject/session/scope-query.hpp +++ b/src/proc/mobject/session/scope-query.hpp @@ -27,7 +27,6 @@ #include "proc/mobject/placement.hpp" #include "proc/mobject/session/query-resolver.hpp" -#include "lib/symbol.hpp" #include @@ -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 > _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 (resolver,scope, "content") + : ScopeQuery (resolver,scope, CONTENTS) { } }; @@ -196,7 +200,7 @@ namespace session { { PathQuery (QueryResolver const& resolver, PlacementMO const& scope) - : ScopeQuery (resolver,scope, "parents") + : ScopeQuery (resolver,scope, PARENTS) { } }; diff --git a/tests/components/proc/mobject/session/scope-query-test.cpp b/tests/components/proc/mobject/session/scope-query-test.cpp index 5714eafeb..a242de72a 100644 --- a/tests/components/proc/mobject/session/scope-query-test.cpp +++ b/tests/components/proc/mobject/session/scope-query-test.cpp @@ -67,16 +67,16 @@ namespace test { QueryResolver const& resolver = SessionServiceExploreScope::getResolver(); PlacementMO const& scope = SessionServiceExploreScope::getScopeRoot(); - discover (ScopeQuery (resolver,scope, "contents")); - discover (ScopeQuery (resolver,scope, "contents")); - discover (ScopeQuery (resolver,scope, "contents")); - discover (ScopeQuery (resolver,scope, "contents")); + discover (ScopeQuery (resolver,scope, CONTENTS)); + discover (ScopeQuery (resolver,scope, CONTENTS)); + discover (ScopeQuery (resolver,scope, CONTENTS)); + discover (ScopeQuery (resolver,scope, CONTENTS)); - ScopeQuery specialEl(resolver,scope, "contents"); + ScopeQuery specialEl(resolver,scope, CONTENTS); - discover (ScopeQuery (resolver,*specialEl, "parents")); - discover (ScopeQuery (resolver,*specialEl, "path")); - discover (ScopeQuery (resolver,*specialEl, "path")); + discover (ScopeQuery (resolver,*specialEl, PARENTS)); + discover (ScopeQuery (resolver,*specialEl, PATH)); + discover (ScopeQuery (resolver,*specialEl, PATH)); discover (specialEl); }