blob: 9a440fbb8977b48aa9114d9b91bcfb49622124b0 (
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
59
60
61
62
63
64
65
66
67
68
|
#include "pch.h"
#include "StatusParagraphs.h"
#include "vcpkg_Checks.h"
namespace vcpkg
{
StatusParagraphs::StatusParagraphs() = default;
StatusParagraphs::StatusParagraphs(std::vector<std::unique_ptr<StatusParagraph>>&& ps)
: paragraphs(std::move(ps))
{
};
StatusParagraphs::const_iterator StatusParagraphs::find(const std::string& name, const triplet& target_triplet) const
{
return std::find_if(begin(), end(), [&](const std::unique_ptr<StatusParagraph>& pgh)
{
const package_spec& spec = pgh->package.spec;
return spec.name() == name && spec.target_triplet() == target_triplet;
});
}
StatusParagraphs::iterator StatusParagraphs::find(const std::string& name, const triplet& target_triplet)
{
return std::find_if(begin(), end(), [&](const std::unique_ptr<StatusParagraph>& pgh)
{
const package_spec& spec = pgh->package.spec;
return spec.name() == name && spec.target_triplet() == target_triplet;
});
}
StatusParagraphs::const_iterator StatusParagraphs::find_installed(const std::string& name, const triplet& target_triplet) const
{
const const_iterator it = find(name, target_triplet);
if (it != end() && (*it)->want == want_t::install)
{
return it;
}
return end();
}
StatusParagraphs::iterator StatusParagraphs::insert(std::unique_ptr<StatusParagraph> pgh)
{
Checks::check_exit(pgh != nullptr, "Inserted null paragraph");
const package_spec& spec = pgh->package.spec;
auto ptr = find(spec.name(), spec.target_triplet());
if (ptr == end())
{
paragraphs.push_back(std::move(pgh));
return paragraphs.rbegin();
}
// consume data from provided pgh.
**ptr = std::move(*pgh);
return ptr;
}
std::ostream& vcpkg::operator<<(std::ostream& os, const StatusParagraphs& l)
{
for (auto& pgh : l.paragraphs)
{
os << *pgh;
os << "\n";
}
return os;
}
}
|