lumiera_/src/proc/mobject/session/defsmanager.cpp

166 lines
4.7 KiB
C++
Raw Normal View History

/*
DefsManager - access to preconfigured default objects and definitions
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 02139, USA.
* *****************************************************/
#include "proc/mobject/session/defsmanager.hpp"
2008-02-29 18:58:29 +01:00
#include "proc/mobject/session/defsregistry.hpp"
#include "common/configrules.hpp"
#include "common/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 mobject
{
namespace session
{
using std::tr1::shared_ptr;
2008-02-29 18:58:29 +01:00
/** initialize the most basic internal defaults. */
DefsManager::DefsManager () throw()
: defsRegistry(new DefsRegistry)
{
TODO ("setup basic defaults of the session");
}
2008-02-29 18:58:29 +01:00
template<class TAR>
2008-02-29 18:58:29 +01:00
shared_ptr<TAR>
DefsManager::search (const Query<TAR>& capabilities)
{
shared_ptr<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"
}
2008-02-29 18:58:29 +01:00
template<class TAR>
shared_ptr<TAR>
DefsManager::create (const Query<TAR>& capabilities)
{
2008-02-29 18:58:29 +01:00
shared_ptr<TAR> res;
QueryHandler<TAR>& typeHandler = ConfigRules::instance();
typeHandler.resolve (res, capabilities);
if (res)
defsRegistry->put (res, capabilities);
2008-02-29 18:58:29 +01:00
return res;
}
2008-02-29 18:58:29 +01:00
template<class TAR>
bool
2008-02-29 18:58:29 +01:00
DefsManager::define (const shared_ptr<TAR>& defaultObj, const Query<TAR>& capabilities)
{
2008-02-29 18:58:29 +01:00
shared_ptr<TAR> candidate (defaultObj);
QueryHandler<TAR>& typeHandler = ConfigRules::instance();
typeHandler.resolve (candidate, capabilities);
if (!candidate)
return false;
else
return defsRegistry->put (candidate, capabilities);
}
2008-02-29 18:58:29 +01:00
template<class TAR>
bool
2008-02-29 18:58:29 +01:00
DefsManager::forget (const shared_ptr<TAR>& defaultObj)
{
return defsRegistry->forget (defaultObj);
}
template<class TAR>
shared_ptr<TAR>
DefsManager::operator() (const Query<TAR>& capabilities)
{
2008-02-29 18:58:29 +01:00
shared_ptr<TAR> res (search (capabilities));
if (res)
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;
}
2008-02-29 18:58:29 +01:00
} // namespace mobject::session
} // namespace mobject
/***************************************************************/
/* 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"
2008-04-07 03:19:24 +02:00
#include "proc/asset/track.hpp"
#include "proc/mobject/session/track.hpp"
2008-02-29 18:58:29 +01:00
namespace mobject
{
namespace session
{
using asset::Pipe;
using asset::PPipe;
using asset::ProcPatt;
using asset::PProcPatt;
2008-04-07 03:19:24 +02:00
using mobject::session::Track;
using mobject::session::TrackAsset;
using mobject::session::PTrack;
using mobject::session::PTrackAsset;
2008-02-29 18:58:29 +01:00
2008-04-07 03:19:24 +02:00
template PPipe DefsManager::operator() (const Query<Pipe>&);
template PProcPatt DefsManager::operator() (const Query<const ProcPatt>&);
template PTrack DefsManager::operator() (const Query<Track>&);
template PTrackAsset DefsManager::operator() (const Query<TrackAsset>&);
2008-02-29 18:58:29 +01:00
template bool DefsManager::define (const PPipe&, const Query<Pipe>&);
template bool DefsManager::forget (const PPipe&);
} // namespace mobject::session
} // namespace mobject