2008-01-14 01:01:11 +01:00
|
|
|
/*
|
|
|
|
|
DefsManager - access to preconfigured default objects and definitions
|
|
|
|
|
|
2008-03-10 08:38:59 +01:00
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Hermann Vosseler <Ichthyostega@web.de>
|
2008-01-14 01:01:11 +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
|
|
|
|
|
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"
|
2008-12-18 08:54:33 +01:00
|
|
|
#include "common/configrules.hpp"
|
2008-12-27 00:53:35 +01:00
|
|
|
#include "lib/error.hpp"
|
2008-01-28 06:05:46 +01:00
|
|
|
|
|
|
|
|
#include <boost/format.hpp>
|
|
|
|
|
|
|
|
|
|
using boost::format;
|
2008-01-14 01:01:11 +01:00
|
|
|
|
2008-03-10 08:38:59 +01:00
|
|
|
using lumiera::ConfigRules;
|
|
|
|
|
using lumiera::query::QueryHandler;
|
|
|
|
|
using lumiera::query::LUMIERA_ERROR_CAPABILITY_QUERY;
|
2008-01-14 01:01:11 +01:00
|
|
|
|
2008-02-29 18:58:29 +01:00
|
|
|
|
2008-09-10 04:42:09 +02:00
|
|
|
namespace mobject {
|
|
|
|
|
namespace session {
|
|
|
|
|
|
2008-05-19 08:46:19 +02:00
|
|
|
using lumiera::P;
|
2008-01-14 01:01:11 +01:00
|
|
|
|
2008-02-29 18:58:29 +01:00
|
|
|
|
|
|
|
|
|
2009-01-05 16:17:17 +01:00
|
|
|
/** initialise the most basic internal defaults. */
|
2008-01-14 01:01:11 +01:00
|
|
|
DefsManager::DefsManager () throw()
|
2008-03-31 03:21:28 +02:00
|
|
|
: defsRegistry(new DefsRegistry)
|
2008-01-14 01:01:11 +01:00
|
|
|
{
|
2008-02-10 17:23:16 +01:00
|
|
|
TODO ("setup basic defaults of the session");
|
2008-01-14 01:01:11 +01:00
|
|
|
}
|
2008-02-29 18:58:29 +01:00
|
|
|
|
|
|
|
|
|
2008-09-09 06:16:42 +02:00
|
|
|
|
|
|
|
|
/** @internal causes boost::checked_delete from \c scoped_ptr<DefsRegistry>
|
|
|
|
|
* to be placed here, where the declaration of DefsRegistry is available.*/
|
|
|
|
|
DefsManager::~DefsManager() {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-02-29 04:27:24 +01:00
|
|
|
template<class TAR>
|
2008-05-19 08:46:19 +02:00
|
|
|
P<TAR>
|
2008-02-29 04:27:24 +01:00
|
|
|
DefsManager::search (const Query<TAR>& capabilities)
|
|
|
|
|
{
|
2008-05-19 08:46:19 +02:00
|
|
|
P<TAR> res;
|
2008-03-31 03:21:28 +02:00
|
|
|
QueryHandler<TAR>& typeHandler = ConfigRules::instance();
|
|
|
|
|
for (DefsRegistry::Iter<TAR> i = defsRegistry->candidates(capabilities);
|
2008-04-07 08:03:22 +02:00
|
|
|
res = *i ; ++i )
|
2008-03-31 03:21:28 +02:00
|
|
|
{
|
|
|
|
|
typeHandler.resolve (res, capabilities);
|
|
|
|
|
if (res)
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
return res; // "no solution found"
|
2008-02-29 04:27:24 +01:00
|
|
|
}
|
|
|
|
|
|
2008-02-29 18:58:29 +01:00
|
|
|
|
2008-02-29 04:27:24 +01:00
|
|
|
template<class TAR>
|
2008-05-19 08:46:19 +02:00
|
|
|
P<TAR>
|
2008-02-29 04:27:24 +01:00
|
|
|
DefsManager::create (const Query<TAR>& capabilities)
|
|
|
|
|
{
|
2008-05-19 08:46:19 +02:00
|
|
|
P<TAR> res;
|
2008-02-29 18:58:29 +01:00
|
|
|
QueryHandler<TAR>& typeHandler = ConfigRules::instance();
|
|
|
|
|
typeHandler.resolve (res, capabilities);
|
|
|
|
|
if (res)
|
2008-03-31 03:21:28 +02:00
|
|
|
defsRegistry->put (res, capabilities);
|
2008-02-29 18:58:29 +01:00
|
|
|
return res;
|
2008-02-29 04:27:24 +01:00
|
|
|
}
|
|
|
|
|
|
2008-02-29 18:58:29 +01:00
|
|
|
|
2008-02-29 04:27:24 +01:00
|
|
|
template<class TAR>
|
|
|
|
|
bool
|
2008-05-19 08:46:19 +02:00
|
|
|
DefsManager::define (const P<TAR>& defaultObj, const Query<TAR>& capabilities)
|
2008-02-29 04:27:24 +01:00
|
|
|
{
|
2008-05-19 08:46:19 +02:00
|
|
|
P<TAR> candidate (defaultObj);
|
2008-02-29 18:58:29 +01:00
|
|
|
QueryHandler<TAR>& typeHandler = ConfigRules::instance();
|
|
|
|
|
typeHandler.resolve (candidate, capabilities);
|
|
|
|
|
if (!candidate)
|
|
|
|
|
return false;
|
|
|
|
|
else
|
2008-03-31 03:21:28 +02:00
|
|
|
return defsRegistry->put (candidate, capabilities);
|
2008-02-29 04:27:24 +01:00
|
|
|
}
|
2008-02-29 18:58:29 +01:00
|
|
|
|
|
|
|
|
|
2008-02-29 04:27:24 +01:00
|
|
|
template<class TAR>
|
|
|
|
|
bool
|
2008-05-19 08:46:19 +02:00
|
|
|
DefsManager::forget (const P<TAR>& defaultObj)
|
2008-02-29 04:27:24 +01:00
|
|
|
{
|
2008-03-31 03:21:28 +02:00
|
|
|
return defsRegistry->forget (defaultObj);
|
2008-02-29 04:27:24 +01:00
|
|
|
}
|
|
|
|
|
|
2008-01-28 06:05:46 +01:00
|
|
|
|
|
|
|
|
template<class TAR>
|
2008-05-19 08:46:19 +02:00
|
|
|
P<TAR>
|
2008-01-28 06:05:46 +01:00
|
|
|
DefsManager::operator() (const Query<TAR>& capabilities)
|
2008-01-14 01:01:11 +01:00
|
|
|
{
|
2008-05-19 08:46:19 +02:00
|
|
|
P<TAR> res (search (capabilities));
|
2008-02-29 18:58:29 +01:00
|
|
|
if (res)
|
|
|
|
|
return res;
|
|
|
|
|
else
|
|
|
|
|
res = create (capabilities); // not yet known as default, create new
|
2008-01-28 06:05:46 +01:00
|
|
|
|
|
|
|
|
if (!res)
|
2008-03-10 08:38:59 +01:00
|
|
|
throw lumiera::error::Config ( str(format("The following Query could not be resolved: %s.")
|
|
|
|
|
% capabilities.asKey())
|
|
|
|
|
, LUMIERA_ERROR_CAPABILITY_QUERY );
|
2008-01-28 06:05:46 +01:00
|
|
|
else
|
|
|
|
|
return res;
|
2008-01-27 23:40:45 +01:00
|
|
|
}
|
|
|
|
|
|
2008-02-29 18:58:29 +01:00
|
|
|
} // namespace mobject::session
|
|
|
|
|
|
|
|
|
|
} // namespace mobject
|
2008-03-31 03:21:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-01-28 06:05:46 +01:00
|
|
|
/***************************************************************/
|
|
|
|
|
/* explicit template instantiations for querying various Types */
|
|
|
|
|
/***************************************************************/
|
2008-01-27 23:40:45 +01:00
|
|
|
|
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
|
|
|
|
2009-01-05 16:17:17 +01:00
|
|
|
namespace mobject {
|
|
|
|
|
namespace session {
|
|
|
|
|
|
|
|
|
|
|
2008-02-29 18:58:29 +01:00
|
|
|
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&);
|
2009-01-05 16:17:17 +01:00
|
|
|
|
|
|
|
|
|
2008-01-14 01:01:11 +01:00
|
|
|
} // namespace mobject::session
|
|
|
|
|
|
|
|
|
|
} // namespace mobject
|
2008-01-28 06:05:46 +01:00
|
|
|
|