querying for specific objects (automatically pick target type)
This commit is contained in:
parent
7c4d57b408
commit
5e104b633a
3 changed files with 69 additions and 6 deletions
|
|
@ -114,13 +114,13 @@ namespace session {
|
|||
* Implemented by copying the scope at
|
||||
* leaf position of the current focus path
|
||||
*/
|
||||
QueryFocus::operator Scope() const
|
||||
inline QueryFocus::operator Scope() const
|
||||
{
|
||||
return currPath().getLeaf();
|
||||
}
|
||||
|
||||
/**@note returning a copy */
|
||||
ScopePath
|
||||
inline ScopePath
|
||||
QueryFocus::currentPath() const
|
||||
{
|
||||
return currPath();
|
||||
|
|
@ -131,7 +131,7 @@ namespace session {
|
|||
* within \em current focus. Resolution is
|
||||
* delegated to the \em current session */
|
||||
template<class MO>
|
||||
typename ScopeQuery<MO>::iterator
|
||||
inline typename ScopeQuery<MO>::iterator
|
||||
QueryFocus::query() const
|
||||
{
|
||||
ScopeLocator::instance().query<MO> (*this);
|
||||
|
|
@ -142,7 +142,7 @@ namespace session {
|
|||
* as immediate Child within \em current focus.
|
||||
* Resolution through \em current session */
|
||||
template<class MO>
|
||||
typename ScopeQuery<MO>::iterator
|
||||
inline typename ScopeQuery<MO>::iterator
|
||||
QueryFocus::explore() const
|
||||
{
|
||||
ScopeLocator::instance().explore<MO> (*this);
|
||||
|
|
|
|||
|
|
@ -107,5 +107,68 @@ namespace session {
|
|||
};
|
||||
|
||||
|
||||
|
||||
namespace { // type matching helper
|
||||
|
||||
template<class PRED>
|
||||
struct _PickResult;
|
||||
|
||||
template<class MO>
|
||||
struct _PickResult<function<bool(Placement<MO> const&)> >
|
||||
{
|
||||
typedef MO Type;
|
||||
typedef SpecificContentsQuery<MO> FilterQuery;
|
||||
typedef typename ScopeQuery<MO>::Iterator Iterator;
|
||||
};
|
||||
|
||||
template<class MO>
|
||||
struct _PickResult<bool(&)(Placement<MO> const&)>
|
||||
{
|
||||
typedef MO Type;
|
||||
typedef SpecificContentsQuery<MO> FilterQuery;
|
||||
typedef typename ScopeQuery<MO>::Iterator Iterator;
|
||||
};
|
||||
|
||||
template<class MO>
|
||||
struct _PickResult<bool(*)(Placement<MO> const&)>
|
||||
{
|
||||
typedef MO Type;
|
||||
typedef SpecificContentsQuery<MO> FilterQuery;
|
||||
typedef typename ScopeQuery<MO>::iterator Iterator;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/** convenience shortcut to issue a SpecialContentsQuery,
|
||||
* figuring out the actual return/filter type automatically,
|
||||
* based on the predicate given as parameter
|
||||
*/
|
||||
template<typename FUNC>
|
||||
inline typename _PickResult<FUNC>::FilterQuery
|
||||
pickAllSuitable(PlacementMO const& scope, FUNC predicate)
|
||||
{
|
||||
typedef typename _PickResult<FUNC>::FilterQuery Query;
|
||||
|
||||
return Query(scope, predicate);
|
||||
}
|
||||
|
||||
/** convenience shortcut (variant), automatically to build
|
||||
* and execute a suitable SpecialContentsQuery
|
||||
* @return iterator yielding placements of the type as
|
||||
* defined through the parameter of the predicate
|
||||
*/
|
||||
template<typename FUNC>
|
||||
inline typename _PickResult<FUNC>::Iterator
|
||||
pickAllSuitable(PlacementMO const& scope, FUNC predicate, QueryResolver const& resolver)
|
||||
{
|
||||
typedef typename _PickResult<FUNC>::FilterQuery Query;
|
||||
|
||||
return Query(scope, predicate ).resolveBy(resolver);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}} // namespace mobject::session
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -107,8 +107,8 @@ namespace test {
|
|||
discover (ScopeQuery<TestSubMO1> (scope, CONTENTS) , "contents depth-first, filtered to TestSubMO1");
|
||||
discover (ScopeQuery<TestSubMO2> (scope, CONTENTS) , "contents depth-first, filtered to TestSubMO2");
|
||||
|
||||
discover (SpecificContentsQuery<DummyMO> (scope, filter) , "contents depth-first, custom filtered DummyMO");
|
||||
// note the filter is typed to accept DummyMO
|
||||
discover (pickAllSuitable(scope, filter) , "contents depth-first, custom filtered DummyMO");
|
||||
// note filter is typed to accept DummyMO
|
||||
ScopeQuery<TestSubMO21> allM021(scope, CONTENTS);
|
||||
ScopeQuery<TestSubMO21>::iterator specialEl (issue(allM021));
|
||||
++specialEl; // step in to second solution found...
|
||||
|
|
|
|||
Loading…
Reference in a new issue