factor out a new session API sub-module for the global query functions

This commit is contained in:
Fischlurch 2010-06-20 04:30:42 +02:00
parent daba3f2a09
commit edbb2410a0
8 changed files with 150 additions and 9 deletions

View file

@ -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<MO> const&
getRef() const
{
return pRef_;
}
/** resolves the referred placement to an
* ExplicitPlacement and returns the found start time
*/

View file

@ -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<Fixture> PFix;
}
@ -106,11 +107,13 @@ namespace mobject {
{
protected:
typedef session::DefsManager& DefaultsAccess;
typedef session::ElementQuery& ElementsAccess;
typedef lib::RefArray<asset::PTimeline>& TimelineAccess;
typedef lib::RefArray<asset::PSequence>& 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

View file

@ -29,7 +29,7 @@
#include "lib/query.hpp"
#include <boost/scoped_ptr.hpp>
#include <boost/utility.hpp>
#include <boost/noncopyable.hpp>

View file

@ -0,0 +1,121 @@
/*
ELEMENT-QUERY.hpp - session sub-interface to query and retrieve elements
Copyright (C) Lumiera.org
2010, Hermann Vosseler <Ichthyostega@web.de>
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 <boost/scoped_ptr.hpp>
#include <boost/noncopyable.hpp>
#include <tr1/functional>
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<class PRED>
struct _PickRes;
template<class MO>
struct _PickRes<function<bool(Placement<MO> const&)> >
{
typedef MO Type;
typedef MORef<MO> Result;
typedef typename ScopeQuery<MO>::iterator Iterator;
};
template<class MO>
struct _PickRes<bool(&)(Placement<MO> const&)>
{
typedef MO Type;
typedef MORef<MO> Result;
typedef typename ScopeQuery<MO>::iterator Iterator;
};
template<class MO>
struct _PickRes<bool(*)(Placement<MO> const&)>
{
typedef MO Type;
typedef MORef<MO> Result;
typedef typename ScopeQuery<MO>::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 PRED>
typename _PickRes<PRED>::Result
pick (PRED const& searchPredicate)
{
typedef typename _PickRes<PRED>::Result ResultRef;
typedef typename _PickRes<PRED>::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

View file

@ -40,6 +40,7 @@ namespace session {
SessionImpl::SessionImpl ()
: SessionInterfaceModules()
, Session( defaultsManager_
, elementQueryAPI_
, timelineRegistry_
, sequenceRegistry_ )
, contents_( MObject::create (defaultsManager_))

View file

@ -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 <Ichthyostega@web.de>
@ -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_;
};

View file

@ -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)
{ }

View file

@ -109,7 +109,7 @@ namespace session {
namespace { // type matching helper
///////////////////////////////TICKET #644 combine/clean up! see also element-query.hpp
template<class PRED>
struct _PickResult;
@ -118,7 +118,7 @@ namespace session {
{
typedef MO Type;
typedef SpecificContentsQuery<MO> FilterQuery;
typedef typename ScopeQuery<MO>::Iterator Iterator;
typedef typename ScopeQuery<MO>::iterator Iterator;
};
template<class MO>
@ -126,7 +126,7 @@ namespace session {
{
typedef MO Type;
typedef SpecificContentsQuery<MO> FilterQuery;
typedef typename ScopeQuery<MO>::Iterator Iterator;
typedef typename ScopeQuery<MO>::iterator Iterator;
};
template<class MO>