aboutsummaryrefslogtreecommitdiff
path: root/paludis/environments/paludis/output_managers.cc
blob: b5d29d87ff66b14c4ba8e7059a6ab0c2d784f244 (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
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2009 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 <paludis/environments/paludis/output_managers.hh>
#include <paludis/environments/paludis/bashable_conf.hh>
#include <paludis/environments/paludis/paludis_config.hh>
#include <paludis/environments/paludis/paludis_environment.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/config_file.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/map.hh>
#include <paludis/util/strip.hh>
#include <paludis/output_manager_factory.hh>
#include <tr1/unordered_map>

using namespace paludis;
using namespace paludis::paludis_environment;

namespace
{
    typedef std::tr1::unordered_map<std::string, std::tr1::shared_ptr<const KeyValueConfigFile> > Store;

    std::string from_kv(const std::tr1::shared_ptr<const KeyValueConfigFile> & m,
            const std::string & k)
    {
        return m->get(k);
    }
}

namespace paludis
{
    template<>
    struct Implementation<OutputManagers>
    {
        Store store;
    };
}

OutputManagers::OutputManagers(const PaludisEnvironment * const) :
    PrivateImplementationPattern<OutputManagers>(new Implementation<OutputManagers>)
{
}

OutputManagers::~OutputManagers()
{
}

void
OutputManagers::add(const FSEntry & filename)
{
    Context context("When adding source '" + stringify(filename) + "' as an output manager file:");

    std::tr1::shared_ptr<KeyValueConfigFile> f(make_bashable_kv_conf(filename));
    if (! f)
        return;

    std::string manager(filename.basename());
    manager = strip_trailing_string(manager, ".conf");
    manager = strip_trailing_string(manager, ".bash");

    _imp->store[manager] = f;
}

const std::tr1::shared_ptr<OutputManager>
OutputManagers::create_named_output_manager(const std::string & s) const
{
    Context context("When creating output manager named '" + s + "':");

    Store::const_iterator i(_imp->store.find(s));
    if (i == _imp->store.end())
        throw PaludisConfigError("No output manager named '" + s + "' exists");

    return OutputManagerFactory::get_instance()->create(
            std::tr1::bind(&from_kv, i->second, std::tr1::placeholders::_1),
            std::tr1::bind(&OutputManagers::create_named_output_manager, this, std::tr1::placeholders::_1)
            );
}

template class PrivateImplementationPattern<paludis_environment::OutputManagers>;