aboutsummaryrefslogtreecommitdiff
path: root/paludis/output_manager_factory.hh
blob: 189dfe735aae5fae8f74adcdcdb2d96c2f27289b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* 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
 */

#ifndef PALUDIS_GUARD_PALUDIS_OUTPUT_MANAGER_FACTORY_HH
#define PALUDIS_GUARD_PALUDIS_OUTPUT_MANAGER_FACTORY_HH 1

#include <paludis/output_manager_factory-fwd.hh>
#include <paludis/output_manager-fwd.hh>
#include <paludis/util/attributes.hh>
#include <paludis/util/map-fwd.hh>
#include <paludis/util/pimp.hh>
#include <paludis/util/set-fwd.hh>
#include <paludis/util/singleton.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <functional>
#include <memory>

namespace paludis
{
    extern template class PALUDIS_VISIBLE Singleton<OutputManagerFactory>;

    class PALUDIS_VISIBLE OutputManagerFactory :
        public Singleton<OutputManagerFactory>
    {
        friend class Singleton<OutputManagerFactory>;

        private:
            Pimp<OutputManagerFactory> _imp;

            OutputManagerFactory();
            ~OutputManagerFactory();

        public:
            typedef std::function<std::string (const std::string &)> KeyFunction;

            typedef std::function<const std::shared_ptr<OutputManager> (
                    const std::string &)> CreateChildFunction;

            typedef std::function<std::string (
                    const std::string & pattern,
                    const std::shared_ptr<const Map<std::string, std::string> > & extra_vars)> ReplaceVarsFunc;

            typedef std::function<const std::shared_ptr<OutputManager>(
                    const KeyFunction &,
                    const CreateChildFunction &,
                    const ReplaceVarsFunc &
                    )> CreateFunction;

            /**
             * Construct a given OutputManager, or throw ConfigurationError.
             *
             * \param key_function should return the value for a given key. The
             * 'handler' key must return a value (e.g. 'standard'), which is used
             * to select the return type. Other key names are manager defined,
             * but typically include things like 'location' and 'keep_on_success'.
             *
             * \param create_child_function is used by, for example,
             * TeeOutputManager to create child streams. Given a single string,
             * this function returns the appropriate child.
             *
             * \param replace_vars_func should replace '%{vars}' with their
             * expanded forms. Variables include 'name', 'action' etc. This is
             * used by, for example, FileOutputManager to allow the user to
             * specify the output file names.
             */
            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));

            /**
             * Add a manager.
             *
             * \param managers must have at least one value, and no value may be
             * specified more than once across all invocations.
             *
             * \param create_function is used to implement OutputManagerFactory::create.
             */
            void add_manager(
                    const std::shared_ptr<const Set<std::string> > & managers,
                    const CreateFunction & create_function
                    );

            struct ConstIteratorTag;
            typedef WrappedForwardIterator<ConstIteratorTag, const std::string> ConstIterator;
            ConstIterator begin_keys() const PALUDIS_ATTRIBUTE((warn_unused_result));
            ConstIterator end_keys() const PALUDIS_ATTRIBUTE((warn_unused_result));
    };

    extern template class Pimp<OutputManagerFactory>;
    extern template class PALUDIS_VISIBLE WrappedForwardIterator<OutputManagerFactory::ConstIteratorTag, const std::string>;
}

#endif