diff --git a/src/proc/mobject/session/scope-query.hpp b/src/proc/mobject/session/scope-query.hpp index 55152b82d..27d3e4f1b 100644 --- a/src/proc/mobject/session/scope-query.hpp +++ b/src/proc/mobject/session/scope-query.hpp @@ -46,7 +46,6 @@ #include "proc/mobject/session/query-resolver.hpp" #include -#include "lib/meta/function-closure.hpp" //////////////////////TODO namespace mobject { @@ -216,65 +215,5 @@ namespace session { }; - template - class SpecificContentsQuery - : public ContentsQuery - { - typedef typename ContentsQuery::ContentFilter ContentFilter; - - typedef Placement const& TypedPlacement; - - typedef function SpecialPredicate; - - /** - * Filter functor, built on top of a predicate, - * which is provided by the client on creation of this - * SpecivicContentsQuery instance. This allows for filtering - * based on operations of the specific type MO, as opposed to - * just using the bare MObject interface. - */ - class Filter - { - SpecialPredicate predicate_; - - public: - Filter (SpecialPredicate const& pred) - : predicate_(pred) - { } - - bool - operator() (PlacementMO const& anyMO) - { - if (!anyMO.isCompatible()) - return false; - - TypedPlacement interestingObject = static_cast (anyMO); - return predicate_(interestingObject); - } - }; - - Filter specialTest_; - - /** using a specialised version of the filtering, - * which doesn't only check the concrete type, - * but also applies a custom filter predicate - * @return function object, embedding a copy - * of the Filter functor. - */ - ContentFilter - buildContentFilter() const - { - return specialTest_; - } - - public: - SpecificContentsQuery (PlacementMO const& scope - ,SpecialPredicate const& specialPred) - : ContentsQuery (scope) - , specialTest_(specialPred) - { } - }; - - }} // namespace mobject::session #endif diff --git a/src/proc/mobject/session/specific-contents-query.hpp b/src/proc/mobject/session/specific-contents-query.hpp new file mode 100644 index 000000000..31066b94c --- /dev/null +++ b/src/proc/mobject/session/specific-contents-query.hpp @@ -0,0 +1,111 @@ +/* + SPECIFIC-CONTENTS-QUERY.hpp - pick specific contents from the model, using a filter + + Copyright (C) Lumiera.org + 2010, Hermann Vosseler + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + + +#ifndef MOBJECT_SESSION_SPECIFIC_CONTENTS_QUERY_H +#define MOBJECT_SESSION_SPECIFIC_CONTENTS_QUERY_H + + +#include "proc/mobject/session/scope-query.hpp" +#include "proc/mobject/placement.hpp" + +#include + + +namespace mobject { +namespace session { + + using std::tr1::function; + + + /** + * Specialised version of the ContentsQuery to pick some objects + * from the session, based on a filter predicate. As the parent type, + * ContentsQuery, the resolution of this query requires to explore the + * given scope depth first; but in addition to filter based on type, + * a client-provided predicate is applied to each result. + * @note this may degenerate on large sessions. + * @todo develop a system of sub-indices and specialised queries + */ + template + class SpecificContentsQuery + : public ContentsQuery + { + typedef typename ContentsQuery::ContentFilter ContentFilter; + + typedef Placement const& TypedPlacement; + + typedef function SpecialPredicate; + + /** + * Filter functor, built on top of a predicate, + * which is provided by the client on creation of this + * SpecivicContentsQuery instance. This allows for filtering + * based on operations of the specific type MO, as opposed to + * just using the bare MObject interface. + */ + class Filter + { + SpecialPredicate predicate_; + + public: + Filter (SpecialPredicate const& pred) + : predicate_(pred) + { } + + bool + operator() (PlacementMO const& anyMO) + { + if (!anyMO.isCompatible()) + return false; + + TypedPlacement interestingObject = static_cast (anyMO); + return predicate_(interestingObject); + } + }; + + Filter specialTest_; + + /** using a specialised version of the filtering, + * which doesn't only check the concrete type, + * but also applies a custom filter predicate + * @return function object, embedding a copy + * of the Filter functor. */ + ContentFilter + buildContentFilter() const + { + return specialTest_; + } + + + + public: + SpecificContentsQuery (PlacementMO const& scope + ,SpecialPredicate const& specialPred) + : ContentsQuery (scope) + , specialTest_(specialPred) + { } + }; + + +}} // namespace mobject::session +#endif diff --git a/tests/components/proc/mobject/session/scope-query-test.cpp b/tests/components/proc/mobject/session/scope-query-test.cpp index 4ef96d144..4f7a08474 100644 --- a/tests/components/proc/mobject/session/scope-query-test.cpp +++ b/tests/components/proc/mobject/session/scope-query-test.cpp @@ -22,8 +22,9 @@ #include "lib/test/run.hpp" -#include "proc/mobject/session/session-service-explore-scope.hpp" #include "proc/mobject/session/scope-query.hpp" +#include "proc/mobject/session/specific-contents-query.hpp" +#include "proc/mobject/session/session-service-explore-scope.hpp" #include "proc/mobject/session/test-scopes.hpp" #include "proc/mobject/session/clip.hpp" #include "lib/symbol.hpp" @@ -76,6 +77,7 @@ namespace test { } + /********************************************************************************************** * @test how to discover contents or location of a container-like part of the high-level model. * As this container-like object is just a concept and actually implemented by the @@ -91,7 +93,6 @@ namespace test { */ class ScopeQuery_test : public Test { - virtual void run (Arg) { @@ -107,7 +108,7 @@ namespace test { discover (ScopeQuery (scope, CONTENTS) , "contents depth-first, filtered to TestSubMO2"); discover (SpecificContentsQuery (scope, filter) , "contents depth-first, custom filtered DummyMO"); - + // note the filter is typed to accept DummyMO ScopeQuery allM021(scope, CONTENTS); ScopeQuery::iterator specialEl (issue(allM021)); ++specialEl; // step in to second solution found... @@ -122,6 +123,7 @@ namespace test { } + template static void discover (ScopeQuery const& query, Literal description)