2017-01-28 04:49:09 +08:00
|
|
|
#include "pch.h"
|
2017-04-28 09:08:52 +08:00
|
|
|
|
2016-09-19 11:50:08 +08:00
|
|
|
#include "StatusParagraphs.h"
|
|
|
|
#include "vcpkg_Checks.h"
|
2017-04-11 04:08:47 +08:00
|
|
|
#include <algorithm>
|
2016-09-19 11:50:08 +08:00
|
|
|
|
|
|
|
namespace vcpkg
|
|
|
|
{
|
|
|
|
StatusParagraphs::StatusParagraphs() = default;
|
|
|
|
|
|
|
|
StatusParagraphs::StatusParagraphs(std::vector<std::unique_ptr<StatusParagraph>>&& ps)
|
2017-04-28 09:08:52 +08:00
|
|
|
: paragraphs(std::move(ps)){};
|
2016-09-19 11:50:08 +08:00
|
|
|
|
2017-04-11 04:08:47 +08:00
|
|
|
StatusParagraphs::const_iterator StatusParagraphs::find(const std::string& name, const Triplet& triplet) const
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
return std::find_if(begin(), end(), [&](const std::unique_ptr<StatusParagraph>& pgh) {
|
|
|
|
const PackageSpec& spec = pgh->package.spec;
|
|
|
|
return spec.name() == name && spec.triplet() == triplet;
|
|
|
|
});
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-11 04:08:47 +08:00
|
|
|
StatusParagraphs::iterator StatusParagraphs::find(const std::string& name, const Triplet& triplet)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
return std::find_if(begin(), end(), [&](const std::unique_ptr<StatusParagraph>& pgh) {
|
|
|
|
const PackageSpec& spec = pgh->package.spec;
|
|
|
|
return spec.name() == name && spec.triplet() == triplet;
|
|
|
|
});
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-07-26 12:29:31 +08:00
|
|
|
std::vector<std::unique_ptr<StatusParagraph>*> StatusParagraphs::find_all(const std::string& name,
|
|
|
|
const Triplet& triplet)
|
|
|
|
{
|
|
|
|
std::vector<std::unique_ptr<StatusParagraph>*> spghs;
|
|
|
|
for (auto&& p : *this)
|
|
|
|
{
|
|
|
|
if (p->package.spec.name() == name && p->package.spec.triplet() == triplet)
|
|
|
|
{
|
|
|
|
spghs.emplace_back(&p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return spghs;
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusParagraphs::iterator StatusParagraphs::find(const std::string& name,
|
|
|
|
const Triplet& triplet,
|
|
|
|
const std::string& feature)
|
|
|
|
{
|
|
|
|
return std::find_if(begin(), end(), [&](const std::unique_ptr<StatusParagraph>& pgh) {
|
|
|
|
const PackageSpec& spec = pgh->package.spec;
|
|
|
|
return spec.name() == name && spec.triplet() == triplet && pgh->package.feature == feature;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
StatusParagraphs::const_iterator StatusParagraphs::find_installed(const std::string& name,
|
|
|
|
const Triplet& triplet) const
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-11 04:08:47 +08:00
|
|
|
const const_iterator it = find(name, triplet);
|
2017-04-08 05:25:12 +08:00
|
|
|
if (it != end() && (*it)->want == Want::INSTALL && (*it)->state == InstallState::INSTALLED)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
|
|
|
return end();
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusParagraphs::iterator StatusParagraphs::insert(std::unique_ptr<StatusParagraph> pgh)
|
|
|
|
{
|
2017-03-14 08:38:04 +08:00
|
|
|
Checks::check_exit(VCPKG_LINE_INFO, pgh != nullptr, "Inserted null paragraph");
|
2017-04-04 05:45:00 +08:00
|
|
|
const PackageSpec& spec = pgh->package.spec;
|
2017-07-26 12:29:31 +08:00
|
|
|
auto ptr = find(spec.name(), spec.triplet(), pgh->package.feature);
|
2016-09-19 11:50:08 +08:00
|
|
|
if (ptr == end())
|
|
|
|
{
|
|
|
|
paragraphs.push_back(std::move(pgh));
|
|
|
|
return paragraphs.rbegin();
|
|
|
|
}
|
2016-10-05 06:16:07 +08:00
|
|
|
|
|
|
|
// consume data from provided pgh.
|
|
|
|
**ptr = std::move(*pgh);
|
|
|
|
return ptr;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-13 13:48:52 +08:00
|
|
|
void serialize(const StatusParagraphs& pghs, std::string& out_str)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-13 13:48:52 +08:00
|
|
|
for (auto& pgh : pghs.paragraphs)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-13 13:48:52 +08:00
|
|
|
serialize(*pgh, out_str);
|
|
|
|
out_str.push_back('\n');
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|