From edbb2410a08602290cd4cdfa5c56eaf0547a642e Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 20 Jun 2010 04:30:42 +0200 Subject: [PATCH] factor out a new session API sub-module for the global query functions --- src/proc/mobject/mobject-ref.hpp | 14 +- src/proc/mobject/session.hpp | 8 +- src/proc/mobject/session/defsmanager.hpp | 2 +- src/proc/mobject/session/element-query.hpp | 121 ++++++++++++++++++ src/proc/mobject/session/session-impl.cpp | 1 + .../session/session-interface-modules.hpp | 5 +- src/proc/mobject/session/session.cpp | 2 + .../session/specific-contents-query.hpp | 6 +- 8 files changed, 150 insertions(+), 9 deletions(-) create mode 100644 src/proc/mobject/session/element-query.hpp diff --git a/src/proc/mobject/mobject-ref.hpp b/src/proc/mobject/mobject-ref.hpp index 4523b3448..06d58866b 100644 --- a/src/proc/mobject/mobject-ref.hpp +++ b/src/proc/mobject/mobject-ref.hpp @@ -33,12 +33,12 @@ ** operator, and it allows to access the Placement within the session. Moreover, as an ** convenience shortcut, some of Placement's query operations are directly exposed. ** - ** !Lifecycle + ** \par Lifecycle ** An MObjectRef is always created inactive. It needs to be activated explicitly, ** providing either a direct (language) ref to an Placement within the session, ** or an PlacementRef tag, or another MObjecRef. It can be closed (detached). ** - ** !Type handling + ** \par Type handling ** Like any smart-ptr MObjectRef is templated on the actual type of the pointee. ** It can be built or re-assigned from a variety of sources, given the runtime type ** of the referred pointee is compatible to this template parameter type. This @@ -125,6 +125,16 @@ namespace mobject { } + /** allow to use a MObjectRef like a (bar) PlacementRef + * @note not test if this MObjectRef is NIL */ + PlacementRef const& + getRef() const + { + return pRef_; + } + + + /** resolves the referred placement to an * ExplicitPlacement and returns the found start time */ diff --git a/src/proc/mobject/session.hpp b/src/proc/mobject/session.hpp index f0071ad36..0c4ad3efa 100644 --- a/src/proc/mobject/session.hpp +++ b/src/proc/mobject/session.hpp @@ -51,7 +51,7 @@ #include "proc/mobject/placement.hpp" #include "proc/mobject/mobject-ref.hpp" -#include "proc/mobject/session/defsmanager.hpp" +#include "proc/mobject/session/defsmanager.hpp" ////////////////////////////TICKET #643 forward declare this? #include "lib/ref-array.hpp" #include "lib/singleton.hpp" #include "lib/symbol.hpp" @@ -71,6 +71,7 @@ namespace mobject { namespace session { class SessManager; + class ElementQuery; class Fixture; typedef std::tr1::shared_ptr PFix; } @@ -106,11 +107,13 @@ namespace mobject { { protected: typedef session::DefsManager& DefaultsAccess; + typedef session::ElementQuery& ElementsAccess; typedef lib::RefArray& TimelineAccess; typedef lib::RefArray& SequenceAccess; Session (DefaultsAccess + ,ElementsAccess ,TimelineAccess ,SequenceAccess) throw(); virtual ~Session (); @@ -119,9 +122,10 @@ namespace mobject { public: static bool initFlag; ///////////////TICKET #518 yet another hack; actually need to care for session manager startup. - static session::SessManager& current; + static session::SessManager& current; ///< access point to the current Session DefaultsAccess defaults; ///< manages default configured objects + ElementsAccess elements; TimelineAccess timelines; ///< collection of timelines (top level) SequenceAccess sequences; ///< collection of sequences diff --git a/src/proc/mobject/session/defsmanager.hpp b/src/proc/mobject/session/defsmanager.hpp index ac4bfa673..8de9207bd 100644 --- a/src/proc/mobject/session/defsmanager.hpp +++ b/src/proc/mobject/session/defsmanager.hpp @@ -29,7 +29,7 @@ #include "lib/query.hpp" #include -#include +#include diff --git a/src/proc/mobject/session/element-query.hpp b/src/proc/mobject/session/element-query.hpp new file mode 100644 index 000000000..6c290c184 --- /dev/null +++ b/src/proc/mobject/session/element-query.hpp @@ -0,0 +1,121 @@ +/* + 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 diff --git a/src/proc/mobject/session/session-impl.cpp b/src/proc/mobject/session/session-impl.cpp index 4a689063a..c735dd92f 100644 --- a/src/proc/mobject/session/session-impl.cpp +++ b/src/proc/mobject/session/session-impl.cpp @@ -40,6 +40,7 @@ namespace session { SessionImpl::SessionImpl () : SessionInterfaceModules() , Session( defaultsManager_ + , elementQueryAPI_ , timelineRegistry_ , sequenceRegistry_ ) , contents_( MObject::create (defaultsManager_)) diff --git a/src/proc/mobject/session/session-interface-modules.hpp b/src/proc/mobject/session/session-interface-modules.hpp index 376b36bab..3252a863c 100644 --- a/src/proc/mobject/session/session-interface-modules.hpp +++ b/src/proc/mobject/session/session-interface-modules.hpp @@ -1,5 +1,5 @@ /* - SESSION-INTERFACE-MODULES.hpp - holds the complete session data to be edited by the user + SESSION-INTERFACE-MODULES.hpp - composing the public session API from several interface modules Copyright (C) Lumiera.org 2010, Hermann Vosseler @@ -41,6 +41,7 @@ ** correspond to the roots of track trees, attached below model root. ** ** \par maintaining the link between session, timelines and sequences + ** ** Timeline and Sequence are implemented as asset::Struct, causing them to be ** maintained by the AssetManager, which in turn is attached to the session::Root ** (WIP 3/2010: yet to be implemented). Creation and destruction of timelines and @@ -71,6 +72,7 @@ #include "proc/asset/timeline.hpp" #include "proc/asset/sequence.hpp" #include "proc/mobject/session/defsmanager.hpp" +#include "proc/mobject/session/element-query.hpp" @@ -92,6 +94,7 @@ namespace session { : boost::noncopyable { DefsManager defaultsManager_; + ElementQuery elementQueryAPI_; TimelineTracker timelineRegistry_; SequenceTracker sequenceRegistry_; }; diff --git a/src/proc/mobject/session/session.cpp b/src/proc/mobject/session/session.cpp index 6c47011c3..ba414dc65 100644 --- a/src/proc/mobject/session/session.cpp +++ b/src/proc/mobject/session/session.cpp @@ -122,9 +122,11 @@ namespace mobject { Session::Session (DefaultsAccess defs + ,ElementsAccess quer ,TimelineAccess tils ,SequenceAccess seqs) throw() : defaults(defs) + , elements(quer) , timelines(tils) , sequences(seqs) { } diff --git a/src/proc/mobject/session/specific-contents-query.hpp b/src/proc/mobject/session/specific-contents-query.hpp index 4b9d218d0..0fbf713e7 100644 --- a/src/proc/mobject/session/specific-contents-query.hpp +++ b/src/proc/mobject/session/specific-contents-query.hpp @@ -109,7 +109,7 @@ namespace session { namespace { // type matching helper - + ///////////////////////////////TICKET #644 combine/clean up! see also element-query.hpp template struct _PickResult; @@ -118,7 +118,7 @@ namespace session { { typedef MO Type; typedef SpecificContentsQuery FilterQuery; - typedef typename ScopeQuery::Iterator Iterator; + typedef typename ScopeQuery::iterator Iterator; }; template @@ -126,7 +126,7 @@ namespace session { { typedef MO Type; typedef SpecificContentsQuery FilterQuery; - typedef typename ScopeQuery::Iterator Iterator; + typedef typename ScopeQuery::iterator Iterator; }; template