2009-06-06 06:18:37 +02:00
/*
SESSION - IMPL . hpp - holds the complete session data to be edited by the user
Copyright ( C ) Lumiera . org
2008 , 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 0213 9 , USA .
*/
/** @file session-impl.hpp
2009-11-11 06:01:25 +01:00
* * Session and SessionServices Implementation classes .
2009-06-06 06:18:37 +02:00
* * Session and the corresponding Manager are primary Interfaces
* * to control the behaviour of the editing part of the application .
2009-11-07 19:49:29 +01:00
* * All all implementation complexities are hidden behind a " PImpl " .
2009-11-11 06:01:25 +01:00
* *
2009-11-11 05:30:24 +01:00
* * This file contains the implementation level API , it should never
* * be included by client code . Besides the actual SessionImpl , a set
* * of further implementation level services is provided for use by
* * Proc - Layer ' s internals . These additional SessionServices are to be
* * accessed through dedicated headers and interface classes ( typically
* * through static access functions ) , thereby abstracting from the actual
* * session implementation . Within this file , the implementation of these
* * SessionServices is wired up with the SessionImpl object .
2009-11-08 20:13:11 +01:00
* *
2009-11-11 05:30:24 +01:00
* * @ see Session public API
* * @ see session - services . hpp
2009-11-08 20:13:11 +01:00
* * @ see session - service - access - test . cpp for a complete simplified mock session manager
2009-06-06 06:18:37 +02:00
* *
*/
# ifndef MOBJECT_SESSION_SESSIONIMPL_H
# define MOBJECT_SESSION_SESSIONIMPL_H
# include "proc/mobject/session.hpp"
# include "proc/mobject/session/fixture.hpp"
2009-11-06 19:27:53 +01:00
# include "proc/mobject/session/placement-index.hpp"
2009-11-09 07:35:08 +01:00
# include "proc/mobject/session/session-services.hpp"
# include "proc/mobject/session/session-service-fetch.hpp"
# include "proc/mobject/session/session-service-explore-scope.hpp"
# include "proc/mobject/session/session-service-mock-index.hpp"
# include "proc/mobject/session/session-service-defaults.hpp"
2009-11-18 04:23:46 +01:00
# include "proc/mobject/session/placement-index-query-resolver.hpp"
2009-06-06 06:18:37 +02:00
# include <boost/scoped_ptr.hpp>
# include <vector>
namespace mobject {
namespace session {
using std : : vector ;
using boost : : scoped_ptr ;
using std : : tr1 : : shared_ptr ;
2009-11-11 06:01:25 +01:00
2009-06-06 06:18:37 +02:00
/**
* Implementation class for the Session interface
*/
class SessionImpl : public mobject : : Session
{
2010-01-07 08:28:54 +01:00
PlacementIndex pIdx_ ;
2009-06-06 06:18:37 +02:00
PFix fixture ;
2009-11-09 07:35:08 +01:00
2009-06-06 06:18:37 +02:00
2009-11-09 07:35:08 +01:00
scoped_ptr < DefsManager > defaultsManager_ ; ///////////TODO: later, this will be the real defaults manager. Currently this is just never initialised (11/09)
2009-06-06 06:18:37 +02:00
/* ==== Session API ==== */
virtual bool isValid ( ) ;
virtual void add ( PMO & placement ) ;
virtual bool remove ( PMO & placement ) ;
virtual PFix & getFixture ( ) ;
virtual void rebuildFixture ( ) ;
protected : /* == management API === */
2009-11-09 07:35:08 +01:00
SessionImpl ( ) ;
2009-06-06 06:18:37 +02:00
void clear ( ) ;
2009-11-11 05:44:58 +01:00
friend class SessManagerImpl ;
2009-06-06 06:18:37 +02:00
2009-12-11 02:49:12 +01:00
PlacementIndex &
2009-11-11 05:30:24 +01:00
getPlacementIndex ( )
{
2009-12-11 02:49:12 +01:00
ENSURE ( pIdx_ . isValid ( ) ) ;
2009-11-11 05:30:24 +01:00
return pIdx_ ;
}
2009-06-06 06:18:37 +02:00
} ;
2009-11-11 06:01:25 +01:00
/* ===== providing internal services for Proc ===== */
template < class IMPL >
struct ServiceAccessPoint < SessionServiceFetch , IMPL >
: IMPL
{
bool
isRegisteredID ( PMO : : ID const & placementID )
2009-11-11 05:30:24 +01:00
{
2009-12-12 05:03:50 +01:00
return IMPL : : getPlacementIndex ( ) . contains ( placementID ) ; //never throws
2009-11-11 05:30:24 +01:00
}
2009-11-11 06:01:25 +01:00
PMO &
resolveID ( PMO : : ID const & placementID )
{
2009-12-12 05:03:50 +01:00
return IMPL : : getPlacementIndex ( ) . find ( placementID ) ; //may throw
2009-11-11 06:01:25 +01:00
}
} ;
2009-11-09 07:35:08 +01:00
2009-11-18 04:23:46 +01:00
2010-01-19 10:52:15 +01:00
2009-11-11 06:01:25 +01:00
template < class IMPL >
struct ServiceAccessPoint < SessionServiceExploreScope , IMPL >
: IMPL
{
QueryResolver &
2009-11-12 02:15:02 +01:00
getScopeQueryResolver ( )
2009-11-11 06:01:25 +01:00
{
2009-11-18 04:23:46 +01:00
return resolvingWrapper_ ;
2009-11-11 06:01:25 +01:00
}
2009-11-12 02:15:02 +01:00
PlacementMO &
getScopeRoot ( )
{
2009-12-12 05:03:50 +01:00
return IMPL : : getPlacementIndex ( ) . getRoot ( ) ;
2009-11-12 02:15:02 +01:00
}
2009-11-18 04:23:46 +01:00
2010-01-19 10:52:15 +01:00
private :
PlacementIndexQueryResolver resolvingWrapper_ ;
/** indirection to use the \em currently defined
* index access point ( might be a test mock ) */
struct
AccessCurrentIndex
{
IMPL & accessPoint_ ;
PlacementIndex & operator ( ) ( void ) { return accessPoint_ . getPlacementIndex ( ) ; }
AccessCurrentIndex ( IMPL & impl ) : accessPoint_ ( impl ) { }
} ;
2009-11-18 04:23:46 +01:00
protected :
ServiceAccessPoint < SessionServiceExploreScope , IMPL > ( )
2010-01-19 10:52:15 +01:00
: resolvingWrapper_ ( AccessCurrentIndex ( * this ) )
2009-11-18 04:23:46 +01:00
{ }
2009-11-11 06:01:25 +01:00
} ;
2009-11-09 07:35:08 +01:00
2009-11-11 06:01:25 +01:00
2009-11-18 04:23:46 +01:00
2010-01-19 10:52:15 +01:00
2009-11-11 06:01:25 +01:00
template < class IMPL >
struct ServiceAccessPoint < SessionServiceMockIndex , IMPL >
: IMPL
2009-06-06 06:18:37 +02:00
{
2009-12-11 02:49:12 +01:00
PlacementIndex &
2009-11-11 06:01:25 +01:00
getPlacementIndex ( )
{
2009-12-11 02:49:12 +01:00
if ( mockIndex_ & & mockIndex_ - > isValid ( ) )
return * mockIndex_ ;
2009-11-11 06:01:25 +01:00
else
return IMPL : : getPlacementIndex ( ) ;
}
2009-06-06 06:18:37 +02:00
2009-11-11 06:01:25 +01:00
void
2009-12-11 02:49:12 +01:00
reset_PlacementIndex ( PlacementIndex * alternativeIndex = 0 )
2009-11-11 06:01:25 +01:00
{
mockIndex_ = alternativeIndex ;
}
2010-01-07 08:28:54 +01:00
protected :
ServiceAccessPoint < SessionServiceMockIndex , IMPL > ( )
: mockIndex_ ( 0 )
{ }
2009-06-06 06:18:37 +02:00
2009-11-11 06:01:25 +01:00
private :
2009-12-11 02:49:12 +01:00
PlacementIndex * mockIndex_ ;
2009-06-06 06:18:37 +02:00
} ;
2009-11-18 04:23:46 +01:00
2009-11-11 06:01:25 +01:00
template < class IMPL >
struct ServiceAccessPoint < SessionServiceDefaults , IMPL >
: IMPL
// , SessionServiceDefaults
{
////////////////////////////TODO
} ;
class SessManagerImpl ;
/**
* actual configuration of the session implementation compound :
* forming an inheritance chain of all internal SesssionServices
* stacked on top of the SessionImpl class .
* @ note SessionImplAPI is actually an alias to the global Session PImpl
*/
typedef SessionServices < Types < SessionServiceFetch
, SessionServiceExploreScope
, SessionServiceMockIndex
, SessionServiceDefaults
> // List of the APIs to provide
, SessManagerImpl // frontend for access
, SessionImpl // implementation base class
> //
SessionImplAPI ;
2009-06-06 06:18:37 +02:00
} } // namespace mobject::session
# endif