diff options
Diffstat (limited to 'toolsrc/include')
| -rw-r--r-- | toolsrc/include/ImmutableSortedVector.h | 73 | ||||
| -rw-r--r-- | toolsrc/include/Paragraphs.h | 10 | ||||
| -rw-r--r-- | toolsrc/include/SortedVector.h | 55 | ||||
| -rw-r--r-- | toolsrc/include/vcpkglib.h | 4 |
4 files changed, 63 insertions, 79 deletions
diff --git a/toolsrc/include/ImmutableSortedVector.h b/toolsrc/include/ImmutableSortedVector.h deleted file mode 100644 index 0756068eb..000000000 --- a/toolsrc/include/ImmutableSortedVector.h +++ /dev/null @@ -1,73 +0,0 @@ -#pragma once - -#include <vector> -#include <algorithm> - -// Add more forwarding functions to the delegate std::vector as needed. -namespace vcpkg -{ - template <class T> - class ImmutableSortedVector - { - typedef typename std::vector<T>::size_type size_type; - - public: - static ImmutableSortedVector<T> create(std::vector<T> vector) - { - ImmutableSortedVector out; - out.delegate = std::move(vector); - if (!std::is_sorted(out.delegate.cbegin(), out.delegate.cend())) - { - std::sort(out.delegate.begin(), out.delegate.end()); - } - - return out; - } - - template <class Compare> - static ImmutableSortedVector<T> create(std::vector<T> vector, Compare comp) - { - ImmutableSortedVector<T> out; - out.delegate = std::move(vector); - if (!std::is_sorted(out.delegate.cbegin(), out.delegate.cend(), comp)) - { - std::sort(out.delegate.begin(), out.delegate.end(), comp); - } - - return out; - } - - typename std::vector<T>::const_iterator begin() const - { - return this->delegate.cbegin(); - } - - typename std::vector<T>::const_iterator end() const - { - return this->delegate.cend(); - } - - typename std::vector<T>::const_iterator cbegin() const - { - return this->delegate.cbegin(); - } - - typename std::vector<T>::const_iterator cend() const - { - return this->delegate.cend(); - } - - bool empty() const - { - return this->delegate.empty(); - } - - size_type size() const - { - return this->delegate.size(); - } - - private: - std::vector<T> delegate; - }; -} diff --git a/toolsrc/include/Paragraphs.h b/toolsrc/include/Paragraphs.h index 39880192c..26f81ffad 100644 --- a/toolsrc/include/Paragraphs.h +++ b/toolsrc/include/Paragraphs.h @@ -9,10 +9,12 @@ namespace vcpkg::Paragraphs { - expected<std::unordered_map<std::string, std::string>> get_single_paragraph(const fs::path& control_path); - expected<std::vector<std::unordered_map<std::string, std::string>>> get_paragraphs(const fs::path& control_path); - expected<std::unordered_map<std::string, std::string>> parse_single_paragraph(const std::string& str); - expected<std::vector<std::unordered_map<std::string, std::string>>> parse_paragraphs(const std::string& str); + using ParagraphDataMap = std::unordered_map<std::string, std::string>; + + expected<ParagraphDataMap> get_single_paragraph(const fs::path& control_path); + expected<std::vector<ParagraphDataMap>> get_paragraphs(const fs::path& control_path); + expected<ParagraphDataMap> parse_single_paragraph(const std::string& str); + expected<std::vector<ParagraphDataMap>> parse_paragraphs(const std::string& str); expected<SourceParagraph> try_load_port(const fs::path& control_path); diff --git a/toolsrc/include/SortedVector.h b/toolsrc/include/SortedVector.h new file mode 100644 index 000000000..d11c3544a --- /dev/null +++ b/toolsrc/include/SortedVector.h @@ -0,0 +1,55 @@ +#pragma once + +#include <vector> +#include <algorithm> + +// Add more forwarding functions to the m_data std::vector as needed. +namespace vcpkg +{ + template <class T> + class SortedVector + { + public: + using size_type = typename std::vector<T>::size_type; + using iterator = typename std::vector<T>::const_iterator; + + explicit SortedVector<T>(std::vector<T> v) : m_data(std::move(v)) + { + if (!std::is_sorted(m_data.begin(), m_data.end())) + { + std::sort(m_data.begin(), m_data.end()); + } + } + template <class Compare> + SortedVector<T>(std::vector<T> v, Compare comp) : m_data(std::move(v)) + { + if (!std::is_sorted(m_data.cbegin(), m_data.cend(), comp)) + { + std::sort(m_data.begin(), m_data.end(), comp); + } + } + + iterator begin() const + { + return this->m_data.cbegin(); + } + + iterator end() const + { + return this->m_data.cend(); + } + + bool empty() const + { + return this->m_data.empty(); + } + + size_type size() const + { + return this->m_data.size(); + } + + private: + std::vector<T> m_data; + }; +} diff --git a/toolsrc/include/vcpkglib.h b/toolsrc/include/vcpkglib.h index b589c1617..bab1c28a1 100644 --- a/toolsrc/include/vcpkglib.h +++ b/toolsrc/include/vcpkglib.h @@ -2,7 +2,7 @@ #include "StatusParagraphs.h" #include "vcpkg_paths.h" -#include "ImmutableSortedVector.h" +#include "SortedVector.h" namespace vcpkg { @@ -15,7 +15,7 @@ namespace vcpkg struct StatusParagraph_and_associated_files { StatusParagraph pgh; - ImmutableSortedVector<std::string> files; + SortedVector<std::string> files; }; std::vector<StatusParagraph*> get_installed_ports(const StatusParagraphs& status_db); |
