2017-01-28 04:49:09 +08:00
|
|
|
#include "pch.h"
|
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>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <algorithm>
|
2016-09-19 11:50:08 +08:00
|
|
|
|
|
|
|
namespace vcpkg
|
|
|
|
{
|
|
|
|
StatusParagraphs::StatusParagraphs() = default;
|
|
|
|
|
|
|
|
StatusParagraphs::StatusParagraphs(std::vector<std::unique_ptr<StatusParagraph>>&& ps)
|
|
|
|
: paragraphs(std::move(ps))
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
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
|
|
|
{
|
2016-10-05 06:10:04 +08:00
|
|
|
return std::find_if(begin(), end(), [&](const std::unique_ptr<StatusParagraph>& pgh)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-04 05:45:00 +08:00
|
|
|
const PackageSpec& spec = pgh->package.spec;
|
2017-04-11 04:08:47 +08:00
|
|
|
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
|
|
|
{
|
2016-10-05 06:10:04 +08:00
|
|
|
return std::find_if(begin(), end(), [&](const std::unique_ptr<StatusParagraph>& pgh)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-04 05:45:00 +08:00
|
|
|
const PackageSpec& spec = pgh->package.spec;
|
2017-04-11 04:08:47 +08:00
|
|
|
return spec.name() == name && spec.triplet() == triplet;
|
2016-09-19 11:50:08 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-04-11 04:08:47 +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-04-11 04:03:34 +08:00
|
|
|
auto ptr = find(spec.name(), spec.triplet());
|
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
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream& vcpkg::operator<<(std::ostream& os, const StatusParagraphs& l)
|
|
|
|
{
|
|
|
|
for (auto& pgh : l.paragraphs)
|
|
|
|
{
|
|
|
|
os << *pgh;
|
|
|
|
os << "\n";
|
|
|
|
}
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
}
|