paludis Version 3.0.2
The one true package mangler
output_manager_factory.hh
1/* vim: set sw=4 sts=4 et foldmethod=syntax : */
2
3/*
4 * Copyright (c) 2009, 2010, 2011 Ciaran McCreesh
5 *
6 * This file is part of the Paludis package manager. Paludis is free software;
7 * you can redistribute it and/or modify it under the terms of the GNU General
8 * Public License version 2, as published by the Free Software Foundation.
9 *
10 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 * Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#ifndef PALUDIS_GUARD_PALUDIS_OUTPUT_MANAGER_FACTORY_HH
21#define PALUDIS_GUARD_PALUDIS_OUTPUT_MANAGER_FACTORY_HH 1
22
23#include <paludis/output_manager_factory-fwd.hh>
24#include <paludis/output_manager-fwd.hh>
27#include <paludis/util/pimp.hh>
30#include <paludis/util/wrapped_forward_iterator.hh>
31#include <functional>
32#include <memory>
33
34namespace paludis
35{
37
38 class PALUDIS_VISIBLE OutputManagerFactory :
39 public Singleton<OutputManagerFactory>
40 {
41 friend class Singleton<OutputManagerFactory>;
42
43 private:
45
46 OutputManagerFactory();
47 ~OutputManagerFactory();
48
49 public:
50 typedef std::function<std::string (const std::string &)> KeyFunction;
51
52 typedef std::function<const std::shared_ptr<OutputManager> (
53 const std::string &)> CreateChildFunction;
54
55 typedef std::function<std::string (
56 const std::string & pattern,
57 const std::shared_ptr<const Map<std::string, std::string> > & extra_vars)> ReplaceVarsFunc;
58
59 typedef std::function<const std::shared_ptr<OutputManager>(
60 const KeyFunction &,
61 const CreateChildFunction &,
62 const ReplaceVarsFunc &
63 )> CreateFunction;
64
65 /**
66 * Construct a given OutputManager, or throw ConfigurationError.
67 *
68 * \param key_function should return the value for a given key. The
69 * 'handler' key must return a value (e.g. 'standard'), which is used
70 * to select the return type. Other key names are manager defined,
71 * but typically include things like 'location' and 'keep_on_success'.
72 *
73 * \param create_child_function is used by, for example,
74 * TeeOutputManager to create child streams. Given a single string,
75 * this function returns the appropriate child.
76 *
77 * \param replace_vars_func should replace '%{vars}' with their
78 * expanded forms. Variables include 'name', 'action' etc. This is
79 * used by, for example, FileOutputManager to allow the user to
80 * specify the output file names.
81 */
82 const std::shared_ptr<OutputManager> create(
83 const KeyFunction & key_function,
84 const CreateChildFunction & create_child_function,
85 const ReplaceVarsFunc & replace_vars_func
86 ) const PALUDIS_ATTRIBUTE((warn_unused_result));
87
88 /**
89 * Add a manager.
90 *
91 * \param managers must have at least one value, and no value may be
92 * specified more than once across all invocations.
93 *
94 * \param create_function is used to implement OutputManagerFactory::create.
95 */
97 const std::shared_ptr<const Set<std::string> > & managers,
98 const CreateFunction & create_function
99 );
100
101 struct ConstIteratorTag;
103 ConstIterator begin_keys() const PALUDIS_ATTRIBUTE((warn_unused_result));
104 ConstIterator end_keys() const PALUDIS_ATTRIBUTE((warn_unused_result));
105 };
106
107 extern template class Pimp<OutputManagerFactory>;
108 extern template class PALUDIS_VISIBLE WrappedForwardIterator<OutputManagerFactory::ConstIteratorTag, const std::string>;
109}
110
111#endif
Definition map.hh:53
void add_manager(const std::shared_ptr< const Set< std::string > > &managers, const CreateFunction &create_function)
const std::shared_ptr< OutputManager > create(const KeyFunction &key_function, const CreateChildFunction &create_child_function, const ReplaceVarsFunc &replace_vars_func) const PALUDIS_ATTRIBUTE((warn_unused_result))
Definition pimp.hh:52
Definition set.hh:51
Definition singleton.hh:45
Definition wrapped_forward_iterator.hh:42
#define PALUDIS_ATTRIBUTE(x)
Definition attributes.hh:53
#define PALUDIS_VISIBLE
Definition attributes.hh:59
Definition about_metadata-fwd.hh:24