From ccca198c1b1730b0241911cb56dc8e3504958b2a Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Sun, 18 Sep 2016 20:50:08 -0700 Subject: Initial commit --- toolsrc/src/StatusParagraphs.cpp | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 toolsrc/src/StatusParagraphs.cpp (limited to 'toolsrc/src/StatusParagraphs.cpp') diff --git a/toolsrc/src/StatusParagraphs.cpp b/toolsrc/src/StatusParagraphs.cpp new file mode 100644 index 000000000..463e3e3b8 --- /dev/null +++ b/toolsrc/src/StatusParagraphs.cpp @@ -0,0 +1,67 @@ +#include "StatusParagraphs.h" +#include +#include "vcpkg_Checks.h" + +namespace vcpkg +{ + StatusParagraphs::StatusParagraphs() = default; + + StatusParagraphs::StatusParagraphs(std::vector>&& 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 auto& pgh) + { + return pgh->package.name == name && pgh->package.target_triplet == target_triplet; + }); + } + + StatusParagraphs::iterator StatusParagraphs::find(const std::string& name, const triplet& target_triplet) + { + return std::find_if(begin(), end(), [&](const auto& pgh) + { + return pgh->package.name == name && pgh->package.target_triplet == target_triplet; + }); + } + + StatusParagraphs::iterator StatusParagraphs::find_installed(const std::string& name, const triplet& target_triplet) + { + auto it = find(name, target_triplet); + if (it != end() && (*it)->want == want_t::install) + { + return it; + } + + return end(); + } + + StatusParagraphs::iterator StatusParagraphs::insert(std::unique_ptr pgh) + { + Checks::check_throw(pgh != nullptr, "Inserted null paragraph"); + auto ptr = find(pgh->package.name, pgh->package.target_triplet); + if (ptr == end()) + { + paragraphs.push_back(std::move(pgh)); + return paragraphs.rbegin(); + } + else + { + // 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; + } +} -- cgit v1.2.3