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

/*
 * Copyright (c) 2008, 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 <paludis/generator_handler.hh>
#include <paludis/util/set.hh>
#include <paludis/util/sequence.hh>
#include <paludis/util/wrapped_output_iterator.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/name.hh>
#include <paludis/environment.hh>
#include <paludis/package_database.hh>
#include <functional>
#include <algorithm>

using namespace paludis;

GeneratorHandler::~GeneratorHandler()
{
}

std::shared_ptr<const RepositoryNameSet>
AllGeneratorHandlerBase::repositories(
        const Environment * const env) const
{
    using namespace std::placeholders;
    std::shared_ptr<RepositoryNameSet> result(std::make_shared<RepositoryNameSet>());
    std::transform(env->package_database()->begin_repositories(), env->package_database()->end_repositories(),
            result->inserter(), std::bind(&Repository::name, _1));
    return result;
}

std::shared_ptr<const CategoryNamePartSet>
AllGeneratorHandlerBase::categories(
        const Environment * const env,
        const std::shared_ptr<const RepositoryNameSet> & repos) const
{
    std::shared_ptr<CategoryNamePartSet> result(std::make_shared<CategoryNamePartSet>());

    for (RepositoryNameSet::ConstIterator r(repos->begin()), r_end(repos->end()) ;
            r != r_end ; ++r)
    {
        std::shared_ptr<const CategoryNamePartSet> cats(env->package_database()->fetch_repository(*r)->category_names({ }));
        std::copy(cats->begin(), cats->end(), result->inserter());
    }

    return result;
}

std::shared_ptr<const QualifiedPackageNameSet>
AllGeneratorHandlerBase::packages(
        const Environment * const env,
        const std::shared_ptr<const RepositoryNameSet> & repos,
        const std::shared_ptr<const CategoryNamePartSet> & cats) const
{
    std::shared_ptr<QualifiedPackageNameSet> result(std::make_shared<QualifiedPackageNameSet>());

    for (RepositoryNameSet::ConstIterator r(repos->begin()), r_end(repos->end()) ;
            r != r_end ; ++r)
    {
        for (CategoryNamePartSet::ConstIterator c(cats->begin()), c_end(cats->end()) ;
                c != c_end ; ++c)
        {
            std::shared_ptr<const QualifiedPackageNameSet> pkgs(
                    env->package_database()->fetch_repository(*r)->package_names(*c, { }));
            std::copy(pkgs->begin(), pkgs->end(), result->inserter());
        }
    }

    return result;
}

std::shared_ptr<const PackageIDSet>
AllGeneratorHandlerBase::ids(
        const Environment * const env,
        const std::shared_ptr<const RepositoryNameSet> & repos,
        const std::shared_ptr<const QualifiedPackageNameSet> & qpns) const
{
    std::shared_ptr<PackageIDSet> result(std::make_shared<PackageIDSet>());

    for (RepositoryNameSet::ConstIterator r(repos->begin()), r_end(repos->end()) ;
            r != r_end ; ++r)
    {
        for (QualifiedPackageNameSet::ConstIterator q(qpns->begin()), q_end(qpns->end()) ;
                q != q_end ; ++q)
        {
            std::shared_ptr<const PackageIDSequence> i(
                    env->package_database()->fetch_repository(*r)->package_ids(*q, { }));
            std::copy(i->begin(), i->end(), result->inserter());
        }
    }

    return result;
}