/* DefsManager - access to preconfigured default objects and definitions Copyright (C) Lumiera.org 2008, Hermann Vosseler 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" #include "proc/mobject/session/defsregistry.hpp" #include "common/configrules.hpp" #include "common/error.hpp" #include using boost::format; using asset::Query; using lumiera::ConfigRules; using lumiera::query::QueryHandler; using lumiera::query::LUMIERA_ERROR_CAPABILITY_QUERY; namespace mobject { namespace session { using std::tr1::shared_ptr; namespace // Implementation details { DefsRegistry& defaultsRegistry; //////////////////TODO } /** initialize the most basic internal defaults. */ DefsManager::DefsManager () throw() { TODO ("setup basic defaults of the session"); } template shared_ptr DefsManager::search (const Query& capabilities) { defaultsRegistry.get (capabilities); } template shared_ptr DefsManager::create (const Query& capabilities) { shared_ptr res; QueryHandler& typeHandler = ConfigRules::instance(); typeHandler.resolve (res, capabilities); if (res) defaultsRegistry.put (res, capabilities); return res; } template bool DefsManager::define (const shared_ptr& defaultObj, const Query& capabilities) { shared_ptr candidate (defaultObj); QueryHandler& typeHandler = ConfigRules::instance(); typeHandler.resolve (candidate, capabilities); if (!candidate) return false; else return defaultsRegistry.put (candidate, capabilities); } template bool DefsManager::forget (const shared_ptr& defaultObj) { defaultsRegistry.forget (defaultObj); } template shared_ptr DefsManager::operator() (const Query& capabilities) { shared_ptr 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; } } // namespace mobject::session } // namespace mobject /***************************************************************/ /* explicit template instantiations for querying various Types */ /***************************************************************/ #include "proc/asset/procpatt.hpp" #include "proc/asset/pipe.hpp" namespace mobject { namespace session { using asset::Pipe; using asset::PPipe; using asset::ProcPatt; using asset::PProcPatt; template PPipe DefsManager::operator() (const Query&); template PProcPatt DefsManager::operator() (const Query&); template bool DefsManager::define (const PPipe&, const Query&); template bool DefsManager::forget (const PPipe&); } // namespace mobject::session } // namespace mobject