LUMIERA.clone/src/proc/mobject/session/defs-manager.cpp

175 lines
4.7 KiB
C++
Raw Normal View History

/*
DefsManager - access to preconfigured default objects and definitions
2010-12-17 23:28:49 +01:00
Copyright (C) Lumiera.org
2008, Hermann Vosseler <Ichthyostega@web.de>
2010-12-17 23:28:49 +01:00
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
2010-12-17 23:28:49 +01:00
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.
2010-12-17 23:28:49 +01:00
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.
2010-12-17 23:28:49 +01:00
* *****************************************************/
#include "proc/mobject/session/defs-manager.hpp"
#include "proc/mobject/session/defs-registry.hpp"
#include "common/configrules.hpp"
2008-12-27 00:53:35 +01:00
#include "lib/error.hpp"
#include <boost/format.hpp>
using boost::format;
using lumiera::ConfigRules;
using lumiera::query::QueryHandler;
using lumiera::query::LUMIERA_ERROR_CAPABILITY_QUERY;
2008-02-29 18:58:29 +01:00
namespace proc {
namespace mobject {
namespace session {
/** initialise the most basic internal defaults. */
DefsManager::DefsManager () throw()
: defsRegistry(new DefsRegistry)
{
TODO ("setup basic defaults of the session");
}
/** @internal causes boost::checked_delete from \c scoped_ptr<DefsRegistry>
* to be placed here, where the declaration of DefsRegistry is available.*/
DefsManager::~DefsManager() {}
template<class TAR>
P<TAR>
DefsManager::search (const Query<TAR>& capabilities)
{
P<TAR> res;
QueryHandler<TAR>& typeHandler = ConfigRules::instance();
for (DefsRegistry::Iter<TAR> i = defsRegistry->candidates(capabilities);
res = *i ; ++i )
{
typeHandler.resolve (res, capabilities);
if (res)
return res;
}
return res; // "no solution found"
}
template<class TAR>
P<TAR>
DefsManager::create (const Query<TAR>& capabilities)
{
P<TAR> res;
QueryHandler<TAR>& typeHandler = ConfigRules::instance();
typeHandler.resolve (res, capabilities);
if (res)
defsRegistry->put (res, capabilities);
return res;
}
template<class TAR>
bool
DefsManager::define (const P<TAR>& defaultObj, const Query<TAR>& capabilities)
{
P<TAR> candidate (defaultObj);
QueryHandler<TAR>& typeHandler = ConfigRules::instance();
typeHandler.resolve (candidate, capabilities);
if (!candidate)
return false;
else
return defsRegistry->put (candidate, capabilities);
}
template<class TAR>
bool
DefsManager::forget (const P<TAR>& defaultObj)
{
return defsRegistry->forget (defaultObj);
}
template<class TAR>
P<TAR>
DefsManager::operator() (const Query<TAR>& capabilities)
{
P<TAR> res (search (capabilities));
if (res)
2008-02-29 18:58:29 +01:00
return res;
else
res = create (capabilities); // not yet known as default, create new
if (!res)
throw lumiera::error::Config ( str(format("The following Query could not be resolved: %s.")
% capabilities.asKey())
, LUMIERA_ERROR_CAPABILITY_QUERY );
else
return res;
}
}}} // namespace mobject::session
2008-02-29 18:58:29 +01:00
/***************************************************************/
/* explicit template instantiations for querying various Types */
/***************************************************************/
2008-02-29 18:58:29 +01:00
#include "proc/asset/procpatt.hpp"
#include "proc/asset/pipe.hpp"
#include "proc/asset/timeline.hpp"
#include "proc/asset/sequence.hpp"
2008-04-07 03:19:24 +02:00
#include "proc/mobject/session/track.hpp"
2008-02-29 18:58:29 +01:00
namespace proc {
2009-01-05 16:17:17 +01:00
namespace mobject {
namespace session {
using asset::Pipe;
using asset::PPipe;
using asset::ProcPatt;
using asset::PProcPatt;
using asset::Timeline;
using asset::PTimeline;
using asset::Sequence;
using asset::PSequence;
using mobject::session::Track;
using mobject::session::PTrack;
2010-10-24 06:50:00 +02:00
template PPipe DefsManager::operator() (Query<Pipe> const&);
template PProcPatt DefsManager::operator() (Query<const ProcPatt> const&);
template PTrack DefsManager::operator() (Query<Track> const&);
template PTimeline DefsManager::operator() (Query<Timeline> const&);
template PSequence DefsManager::operator() (Query<Sequence> const&);
template bool DefsManager::define (PPipe const&, Query<Pipe> const&);
template bool DefsManager::forget (PPipe const&);
}}} // namespace proc::mobject::session