output_manager_factory.hh

00001 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
00002 
00003 /*
00004  * Copyright (c) 2009 Ciaran McCreesh
00005  *
00006  * This file is part of the Paludis package manager. Paludis is free software;
00007  * you can redistribute it and/or modify it under the terms of the GNU General
00008  * Public License version 2, as published by the Free Software Foundation.
00009  *
00010  * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
00011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00012  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00013  * details.
00014  *
00015  * You should have received a copy of the GNU General Public License along with
00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00017  * Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 #ifndef PALUDIS_GUARD_PALUDIS_OUTPUT_MANAGER_FACTORY_HH
00021 #define PALUDIS_GUARD_PALUDIS_OUTPUT_MANAGER_FACTORY_HH 1
00022 
00023 #include <paludis/output_manager_factory-fwd.hh>
00024 #include <paludis/util/attributes.hh>
00025 #include <paludis/util/private_implementation_pattern.hh>
00026 #include <paludis/util/instantiation_policy.hh>
00027 #include <paludis/util/wrapped_forward_iterator-fwd.hh>
00028 #include <paludis/util/map-fwd.hh>
00029 #include <paludis/output_manager-fwd.hh>
00030 #include <paludis/util/set-fwd.hh>
00031 #include <tr1/functional>
00032 #include <tr1/memory>
00033 
00034 namespace paludis
00035 {
00036     class PALUDIS_VISIBLE OutputManagerFactory :
00037         private PrivateImplementationPattern<OutputManagerFactory>,
00038         public InstantiationPolicy<OutputManagerFactory, instantiation_method::SingletonTag>
00039     {
00040         friend class InstantiationPolicy<OutputManagerFactory, instantiation_method::SingletonTag>;
00041 
00042         private:
00043             OutputManagerFactory();
00044             ~OutputManagerFactory();
00045 
00046         public:
00047             typedef std::tr1::function<std::string (const std::string &)> KeyFunction;
00048 
00049             typedef std::tr1::function<const std::tr1::shared_ptr<OutputManager> (
00050                     const std::string &)> CreateChildFunction;
00051 
00052             typedef std::tr1::function<std::string (
00053                     const std::string & pattern,
00054                     const std::tr1::shared_ptr<const Map<std::string, std::string> > & extra_vars)> ReplaceVarsFunc;
00055 
00056             typedef std::tr1::function<const std::tr1::shared_ptr<OutputManager>(
00057                     const KeyFunction &,
00058                     const CreateChildFunction &,
00059                     const ReplaceVarsFunc &
00060                     )> CreateFunction;
00061 
00062             /**
00063              * Construct a given OutputManager, or throw ConfigurationError.
00064              *
00065              * \param key_function should return the value for a given key. The
00066              * 'handler' key must return a value (e.g. 'standard'), which is used
00067              * to select the return type. Other key names are manager defined,
00068              * but typically include things like 'location' and 'keep_on_success'.
00069              *
00070              * \param create_child_function is used by, for example,
00071              * TeeOutputManager to create child streams. Given a single string,
00072              * this function returns the appropriate child.
00073              *
00074              * \param replace_vars_func should replace '%{vars}' with their
00075              * expanded forms. Variables include 'name', 'action' etc. This is
00076              * used by, for example, FileOutputManager to allow the user to
00077              * specify the output file names.
00078              */
00079             const std::tr1::shared_ptr<OutputManager> create(
00080                     const KeyFunction & key_function,
00081                     const CreateChildFunction & create_child_function,
00082                     const ReplaceVarsFunc & replace_vars_func
00083                     ) const PALUDIS_ATTRIBUTE((warn_unused_result));
00084 
00085             /**
00086              * Add a manager.
00087              *
00088              * \param managers must have at least one value, and no value may be
00089              * specified more than once across all invocations.
00090              *
00091              * \param create_function is used to implement OutputManagerFactory::create.
00092              */
00093             void add_manager(
00094                     const std::tr1::shared_ptr<const Set<std::string> > & managers,
00095                     const CreateFunction & create_function
00096                     );
00097 
00098             struct ConstIteratorTag;
00099             typedef WrappedForwardIterator<ConstIteratorTag, const std::string> ConstIterator;
00100             ConstIterator begin_keys() const PALUDIS_ATTRIBUTE((warn_unused_result));
00101             ConstIterator end_keys() const PALUDIS_ATTRIBUTE((warn_unused_result));
00102     };
00103 
00104 #ifdef PALUDIS_HAVE_EXTERN_TEMPLATE
00105     extern template class PrivateImplementationPattern<OutputManagerFactory>;
00106     extern template class InstantiationPolicy<OutputManagerFactory, instantiation_method::SingletonTag>;
00107 #endif
00108 }
00109 
00110 #endif

Generated on Mon Sep 21 10:36:08 2009 for paludis by  doxygen 1.5.4