/* vim: set sw=4 sts=4 et foldmethod=syntax : */ /* * Copyright (c) 2009, 2010, 2011 Ciaran McCreesh * * This file is part of the Paludis package manager. Paludis is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * Paludis 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., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace paludis; namespace paludis { namespace n { typedef Name create_function; } } namespace { struct Funcs { NamedValue create_function; }; typedef std::unordered_map Keys; const Funcs & fetch(const Keys & keys, const std::string & key) { if (key.empty()) throw ConfigurationError("Key 'handler' not specified when creating an output manager"); Keys::const_iterator i(keys.find(key)); if (i == keys.end()) throw ConfigurationError("Format '" + key + "' not supported when creating an output manager (known formats are { " + join(first_iterator(keys.begin()), first_iterator(keys.end()), ", ") + " })"); return i->second; } } namespace paludis { template <> struct Imp { Keys keys; std::list dl_opened; }; template <> struct WrappedForwardIteratorTraits { typedef FirstIteratorTypes::Type UnderlyingIterator; }; } OutputManagerFactory::OutputManagerFactory() : _imp() { /* we might want to make this plugin loadable at some point */ add_manager(BufferOutputManager::factory_managers(), BufferOutputManager::factory_create); add_manager(CommandOutputManager::factory_managers(), CommandOutputManager::factory_create); add_manager(FileOutputManager::factory_managers(), FileOutputManager::factory_create); add_manager(FormatMessagesOutputManager::factory_managers(), FormatMessagesOutputManager::factory_create); add_manager(ForwardAtFinishOutputManager::factory_managers(), ForwardAtFinishOutputManager::factory_create); add_manager(StandardOutputManager::factory_managers(), StandardOutputManager::factory_create); add_manager(TeeOutputManager::factory_managers(), TeeOutputManager::factory_create); } OutputManagerFactory::~OutputManagerFactory() { } const std::shared_ptr OutputManagerFactory::create( const KeyFunction & key_function, const CreateChildFunction & create_child_function, const ReplaceVarsFunc & replace_vars_func ) const { Context context("When creating output manager:"); return fetch(_imp->keys, key_function("handler")).create_function()(key_function, create_child_function, replace_vars_func); } OutputManagerFactory::ConstIterator OutputManagerFactory::begin_keys() const { return ConstIterator(first_iterator(_imp->keys.begin())); } OutputManagerFactory::ConstIterator OutputManagerFactory::end_keys() const { return ConstIterator(first_iterator(_imp->keys.end())); } void OutputManagerFactory::add_manager( const std::shared_ptr > & formats, const CreateFunction & create_function ) { for (Set::ConstIterator f(formats->begin()), f_end(formats->end()) ; f != f_end ; ++f) { if (! _imp->keys.insert(std::make_pair(*f, make_named_values( n::create_function() = create_function ))).second) throw ConfigurationError("Handler for output manager format '" + stringify(*f) + "' already exists"); } } namespace paludis { template class Pimp; template class Singleton; template class WrappedForwardIterator; }