vcpkg/toolsrc/include/PackageSpec.h

96 lines
2.8 KiB
C
Raw Normal View History

2016-09-19 11:50:08 +08:00
#pragma once
#include "PackageSpecParseResult.h"
2017-04-04 06:02:45 +08:00
#include "Triplet.h"
2017-04-01 07:33:10 +08:00
#include "vcpkg_expected.h"
2016-09-19 11:50:08 +08:00
namespace vcpkg
{
2017-08-19 11:32:35 +08:00
struct ParsedSpecifier
{
std::string name;
std::vector<std::string> features;
std::string triplet;
static ExpectedT<ParsedSpecifier, PackageSpecParseResult> from_string(const std::string& input);
};
2017-04-04 05:45:00 +08:00
struct PackageSpec
2016-09-19 11:50:08 +08:00
{
2017-06-06 06:58:47 +08:00
static ExpectedT<PackageSpec, PackageSpecParseResult> from_name_and_triplet(const std::string& name,
const Triplet& triplet);
const std::string& name() const;
const Triplet& triplet() const;
2016-09-19 11:50:08 +08:00
std::string dir() const;
std::string to_string() const;
private:
std::string m_name;
Triplet m_triplet;
2016-09-19 11:50:08 +08:00
};
struct FeatureSpec
{
FeatureSpec(const PackageSpec& spec, const std::string& feature) : m_spec(spec), m_feature(feature) {}
const std::string& name() const { return m_spec.name(); }
const std::string& feature() const { return m_feature; }
const Triplet& triplet() const { return m_spec.triplet(); }
const PackageSpec& spec() const { return m_spec; }
std::string to_string() const;
static std::vector<FeatureSpec> from_strings_and_triplet(const std::vector<std::string>& depends,
const Triplet& t);
private:
PackageSpec m_spec;
std::string m_feature;
};
struct FullPackageSpec
{
PackageSpec package_spec;
std::vector<std::string> features;
2017-07-20 05:29:28 +08:00
static std::vector<FeatureSpec> to_feature_specs(const std::vector<FullPackageSpec>& specs);
2017-07-20 05:29:28 +08:00
static ExpectedT<FullPackageSpec, PackageSpecParseResult> from_string(const std::string& spec_as_string,
const Triplet& default_triplet);
};
struct Features
{
std::string name;
std::vector<std::string> features;
static ExpectedT<Features, PackageSpecParseResult> from_string(const std::string& input);
};
2017-04-04 05:45:00 +08:00
bool operator==(const PackageSpec& left, const PackageSpec& right);
2017-04-13 13:36:44 +08:00
bool operator!=(const PackageSpec& left, const PackageSpec& right);
}
2016-09-19 11:50:08 +08:00
template<>
struct std::hash<vcpkg::PackageSpec>
2016-09-19 11:50:08 +08:00
{
size_t operator()(const vcpkg::PackageSpec& value) const
2016-09-19 11:50:08 +08:00
{
size_t hash = 17;
hash = hash * 31 + std::hash<std::string>()(value.name());
hash = hash * 31 + std::hash<vcpkg::Triplet>()(value.triplet());
return hash;
}
};
template<>
struct std::equal_to<vcpkg::PackageSpec>
{
bool operator()(const vcpkg::PackageSpec& left, const vcpkg::PackageSpec& right) const { return left == right; }
};