Skip to content

Commit 918190c

Browse files
committed
Apply the normal "to_string" pattern in more places.
Extracted from microsoft#1514
1 parent ad7b71c commit 918190c

17 files changed

+108
-100
lines changed

include/vcpkg/base/contractual-constants.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,4 +558,14 @@ namespace vcpkg
558558
inline constexpr StringLiteral AbiTagPostBuildChecks = "post_build_checks";
559559
inline constexpr StringLiteral AbiTagPowershell = "powershell";
560560
inline constexpr StringLiteral AbiTagPublicAbiOverride = "public_abi_override";
561+
562+
inline constexpr StringLiteral StatusDeinstall = "deinstall";
563+
inline constexpr StringLiteral StatusError = "error";
564+
inline constexpr StringLiteral StatusHalfInstalled = "half-installed";
565+
inline constexpr StringLiteral StatusHold = "hold";
566+
inline constexpr StringLiteral StatusInstall = "install";
567+
inline constexpr StringLiteral StatusInstalled = "installed";
568+
inline constexpr StringLiteral StatusNotInstalled = "not-installed";
569+
inline constexpr StringLiteral StatusPurge = "purge";
570+
inline constexpr StringLiteral StatusUnknown = "unknown";
561571
}

include/vcpkg/base/fmt.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ VCPKG_MSVC_WARNING(disable : 6239 4702)
1818
#include <fmt/format.h>
1919
#include <fmt/ranges.h>
2020
VCPKG_MSVC_WARNING(pop)
21+
22+
template<class T>
23+
std::string adapt_to_string(const T& val)
24+
{
25+
std::string result;
26+
val.to_string(result);
27+
return result;
28+
}

include/vcpkg/base/graphs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ namespace vcpkg
1616
struct AdjacencyProvider
1717
{
1818
virtual std::vector<V> adjacency_list(const U& vertex) const = 0;
19-
virtual std::string to_string(const V& vertex) const = 0;
2019
virtual U load_vertex_data(const V& vertex) const = 0;
2120
};
2221

include/vcpkg/binaryparagraph.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
namespace vcpkg
1010
{
11-
/// <summary>
12-
/// Built package metadata
13-
/// </summary>
11+
// metadata for a package in the 'packages' tree
1412
struct BinaryParagraph
1513
{
1614
BinaryParagraph() = default;

include/vcpkg/statusparagraph.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313

1414
namespace vcpkg
1515
{
16-
/// <summary>
17-
/// Installed package metadata
18-
/// </summary>
16+
17+
// metadata for a package's representation in the 'installed' tree
1918
struct StatusParagraph
2019
{
2120
StatusParagraph() noexcept;
@@ -30,14 +29,12 @@ namespace vcpkg
3029

3130
void serialize(const StatusParagraph& pgh, std::string& out_str);
3231

33-
std::string to_string(InstallState f);
34-
35-
std::string to_string(Want f);
32+
StringLiteral to_string_literal(InstallState f);
33+
StringLiteral to_string_literal(Want f);
3634

3735
struct InstalledPackageView
3836
{
39-
InstalledPackageView() noexcept : core(nullptr) { }
40-
37+
InstalledPackageView() = default;
4138
InstalledPackageView(const StatusParagraph* c, std::vector<const StatusParagraph*>&& fs)
4239
: core(c), features(std::move(fs))
4340
{
@@ -51,11 +48,14 @@ namespace vcpkg
5148

5249
std::vector<StatusParagraph> all_status_paragraphs() const;
5350

54-
const StatusParagraph* core;
51+
const StatusParagraph* core = nullptr;
5552
std::vector<const StatusParagraph*> features;
5653
};
5754

5855
Json::Value serialize_ipv(const InstalledPackageView& ipv,
5956
const InstalledPaths& installed,
6057
const ReadOnlyFilesystem& fs);
6158
}
59+
60+
VCPKG_FORMAT_WITH_TO_STRING_LITERAL_NONMEMBER(vcpkg::InstallState);
61+
VCPKG_FORMAT_WITH_TO_STRING_LITERAL_NONMEMBER(vcpkg::Want);

include/vcpkg/versions.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ namespace vcpkg
4848
VersionDiff(const Version& left, const Version& right);
4949

5050
std::string to_string() const;
51+
void to_string(std::string& out) const;
5152
};
5253

5354
struct VersionMapLess
@@ -85,6 +86,7 @@ namespace vcpkg
8586
VersionSpec(const std::string& port_name, const std::string& version_string, int port_version);
8687

8788
std::string to_string() const;
89+
void to_string(std::string& out) const;
8890

8991
friend bool operator==(const VersionSpec& lhs, const VersionSpec& rhs);
9092
friend bool operator!=(const VersionSpec& lhs, const VersionSpec& rhs);
@@ -97,7 +99,7 @@ namespace vcpkg
9799

98100
struct DotVersion
99101
{
100-
DotVersion() { } // intentionally disable making this type an aggregate
102+
DotVersion() noexcept { } // intentionally disable making this type an aggregate
101103

102104
std::string original_string;
103105
std::string version_string;
@@ -122,7 +124,7 @@ namespace vcpkg
122124

123125
struct DateVersion
124126
{
125-
DateVersion() { } // intentionally disable making this type an aggregate
127+
DateVersion() noexcept { } // intentionally disable making this type an aggregate
126128

127129
std::string original_string;
128130
std::string version_string;

src/vcpkg/binaryparagraph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ namespace vcpkg
284284
return fmt::format(
285285
"\nspec: \"{}\"\nversion: \"{}\"\nport_version: {}\ndescription: [\"{}\"]\nmaintainers: [\"{}\"]\nfeature: "
286286
"\"{}\"\ndefault_features: [\"{}\"]\ndependencies: [\"{}\"]\nabi: \"{}\"",
287-
paragraph.spec.to_string(),
287+
paragraph.spec,
288288
paragraph.version.text,
289289
paragraph.version.port_version,
290290
Strings::join(join_str, paragraph.description),

src/vcpkg/commands.ci.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ namespace
5252
(void)filesystem.create_directory(target_path, VCPKG_LINE_INFO);
5353
if (children.empty())
5454
{
55-
std::string message =
56-
"There are no build logs for " + spec.to_string() +
57-
" build.\n"
58-
"This is usually because the build failed early and outside of a task that is logged.\n"
59-
"See the console output logs from vcpkg for more information on the failure.\n";
55+
auto message =
56+
fmt::format("There are no build logs for {} build.\n"
57+
"This is usually because the build failed early and outside of a task that is logged.\n"
58+
"See the console output logs from vcpkg for more information on the failure.\n",
59+
spec);
6060
filesystem.write_contents(std::move(target_path) / "readme.log", message, VCPKG_LINE_INFO);
6161
}
6262
else

src/vcpkg/commands.export.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,7 @@ namespace
472472
Checks::unreachable(VCPKG_LINE_INFO);
473473
}
474474

475-
const std::string display_name = action.spec.to_string();
476-
msg::println(msgExportingPackage, msg::package_name = display_name);
475+
msg::println(msgExportingPackage, msg::package_name = action.spec);
477476

478477
const BinaryParagraph& binary_paragraph = action.core_paragraph().value_or_exit(VCPKG_LINE_INFO);
479478

src/vcpkg/commands.list.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,20 @@ namespace
1717
Json::Object obj;
1818
for (const StatusParagraph* status_paragraph : installed_packages)
1919
{
20-
auto current_spec = status_paragraph->package.spec;
21-
if (obj.contains(current_spec.to_string()))
20+
const auto& current_spec = status_paragraph->package.spec;
21+
const auto current_spec_string = current_spec.to_string();
22+
if (obj.contains(current_spec_string))
2223
{
2324
if (status_paragraph->package.is_feature())
2425
{
25-
Json::Value* value_obj = obj.get(current_spec.to_string());
26+
Json::Value* value_obj = obj.get(current_spec_string);
2627
auto& feature_list = value_obj->object(VCPKG_LINE_INFO)[JsonIdFeatures].array(VCPKG_LINE_INFO);
2728
feature_list.push_back(Json::Value::string(status_paragraph->package.feature));
2829
}
2930
}
3031
else
3132
{
32-
Json::Object& library_obj = obj.insert(current_spec.to_string(), Json::Object());
33+
Json::Object& library_obj = obj.insert(current_spec_string, Json::Object());
3334
library_obj.insert(JsonIdPackageUnderscoreName, Json::Value::string(current_spec.name()));
3435
library_obj.insert(JsonIdTriplet, Json::Value::string(current_spec.triplet().to_string()));
3536
library_obj.insert(JsonIdVersion, Json::Value::string(status_paragraph->package.version.text));

0 commit comments

Comments
 (0)