/* ELEMENT-QUERY.hpp - session sub-interface to query and retrieve elements 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_ELEMENT_QUERY_H #define MOBJECT_SESSION_ELEMENT_QUERY_H //#include "lib/p.hpp" //#include "lib/query.hpp" #include "proc/mobject/placement.hpp" #include "proc/mobject/mobject-ref.hpp" #include "proc/mobject/session/specific-contents-query.hpp" #include "proc/mobject/session/session-service-explore-scope.hpp" //#include #include #include namespace mobject { namespace session { // using lumiera::P; // using boost::scoped_ptr; using std::tr1::function; namespace { // type matching helper //////////////////////////////TICKET #644 combine/clean up! see also specific-contents-query.hpp template struct _PickRes; template struct _PickRes const&)> > { typedef MO Type; typedef MORef Result; typedef typename ScopeQuery::iterator Iterator; }; template struct _PickRes const&)> { typedef MO Type; typedef MORef Result; typedef typename ScopeQuery::iterator Iterator; }; template struct _PickRes const&)> { typedef MO Type; typedef MORef Result; typedef typename ScopeQuery::iterator Iterator; }; } /** * Access point to session global search and query functions. * This sub-component of the public session interface allows to * search and retrieve objects from the high-level-model, by type * and using additional filter predicates. * * WIP-WIP-WIP as of 6/2010 -- this might evolve into an extended * query facility, using specialised sub-indices and dedicated queries. * For now the motivation to package this as a separate interface module * was just to reduce the includes on the top level session API and to allow * for templated search functions, based on function objects. */ class ElementQuery : boost::noncopyable { public: template typename _PickRes::Result pick (PRED const& searchPredicate) { typedef typename _PickRes::Result ResultRef; typedef typename _PickRes::Iterator Iterator; Iterator iter (pickAllSuitable ( SessionServiceExploreScope::getScopeRoot() , searchPredicate , SessionServiceExploreScope::getResolver() )); ResultRef found; if (iter) // in case there is an result found.activate(*iter); // pick the first element found... return found; // or return an empty MObjectRef else } }; }} // namespace mobject::session #endif