aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include/PackageSpec.h
blob: 57fbefc0af2145e76f995d15aca9823587175353 (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
#pragma once
#include "PackageSpecParseResult.h"
#include "Triplet.h"
#include "vcpkg_expected.h"

namespace vcpkg
{
    struct PackageSpec
    {
        static Expected<PackageSpec> from_string(const std::string& spec_as_string, const Triplet& default_target_triplet);

        static Expected<PackageSpec> from_name_and_triplet(const std::string& name, const Triplet& target_triplet);

        const std::string& name() const;

        const Triplet& target_triplet() const;

        std::string display_name() const;

        std::string dir() const;

        std::string to_string() const;

    private:
        std::string m_name;
        Triplet m_target_triplet;
    };

    std::string to_printf_arg(const PackageSpec& spec);

    bool operator==(const PackageSpec& left, const PackageSpec& right);

    std::ostream& operator<<(std::ostream& os, const PackageSpec& spec);
} //namespace vcpkg

namespace std
{
    template <>
    struct hash<vcpkg::PackageSpec>
    {
        size_t operator()(const vcpkg::PackageSpec& value) const
        {
            size_t hash = 17;
            hash = hash * 31 + std::hash<std::string>()(value.name());
            hash = hash * 31 + std::hash<vcpkg::Triplet>()(value.target_triplet());
            return hash;
        }
    };

    template <>
    struct equal_to<vcpkg::PackageSpec>
    {
        bool operator()(const vcpkg::PackageSpec& left, const vcpkg::PackageSpec& right) const
        {
            return left == right;
        }
    };
} // namespace std