aboutsummaryrefslogtreecommitdiff
path: root/paludis/package_dep_spec_properties.cc
blob: 0c003631e8b152a928643c8a44d251530abed4cc (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
/* 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
 */

#include <paludis/package_dep_spec_properties.hh>
#include <paludis/dep_spec.hh>
#include <paludis/util/sequence.hh>

using namespace paludis;

namespace
{
    inline bool check(const bool c, const Tribool w)
    {
        if (w.is_true())
            return c;
        else if (w.is_false())
            return ! c;
        else
            return true;
    }
}

bool
paludis::package_dep_spec_has_properties(const PackageDepSpec & spec, const PackageDepSpecProperties & properties)
{
    bool result(true);

    result = result && check(bool(spec.additional_requirements_ptr()) && ! spec.additional_requirements_ptr()->empty(), properties.has_additional_requirements());
    result = result && check(bool(spec.category_name_part_constraint()), properties.has_category_name_part());
    result = result && check(bool(spec.from_repository_constraint()), properties.has_from_repository());
    result = result && check(bool(spec.all_key_constraints()) && ! spec.all_key_constraints()->empty(), properties.has_key_requirements());
    result = result && check(bool(spec.in_repository_constraint()), properties.has_in_repository());
    result = result && check(bool(spec.installable_to_path_constraint()), properties.has_installable_to_path());
    result = result && check(bool(spec.installable_to_repository_constraint()), properties.has_installable_to_repository());
    result = result && check(bool(spec.installed_at_path_constraint()), properties.has_installed_at_path());
    result = result && check(bool(spec.package_name_constraint()), properties.has_package());
    result = result && check(bool(spec.package_name_part_constraint()), properties.has_package_name_part());
    result = result && check(bool(spec.exact_slot_constraint()), properties.has_exact_slot_requirement());
    result = result && check(bool(spec.any_slot_constraint()), properties.has_any_slot_requirement());
    result = result && check(bool(spec.all_version_constraints()) && ! spec.all_version_constraints()->empty(), properties.has_version_requirements());

    return result;
}