In the middle of multithreading parsers.

This commit is contained in:
zy4n
2025-03-30 22:38:06 +02:00
parent d18b40a7fc
commit 144126ee7a
80 changed files with 2904 additions and 1450 deletions

View File

@@ -0,0 +1,104 @@
#pragma once
#include <unordered_map>
#include <filesystem>
#include <ranges>
#include <vector>
template<typename ID>
class file_id_lookup
{
public:
using container_type = std::unordered_map<std::filesystem::path, ID>;
using key_type = typename container_type::key_type;
using mapped_type = typename container_type::mapped_type;
using value_type = typename container_type::value_type;
using size_type = typename container_type::size_type;
using difference_type = typename container_type::difference_type;
using hasher = typename container_type::hasher;
using key_equal = typename container_type::key_equal;
using allocator_type = typename container_type::allocator_type;
using reference = typename container_type::reference;
using const_reference = typename container_type::const_reference;
using pointer = typename container_type::pointer;
using const_pointer = typename container_type::const_pointer;
using iterator = typename container_type::iterator;
using const_iterator = typename container_type::const_iterator;
using local_iterator = typename container_type::local_iterator;
using const_local_iterator = typename container_type::const_local_iterator;
using node_type = typename container_type::node_type;
using insert_return_type = typename container_type::insert_return_type;
[[nodiscard]] iterator begin() noexcept { return m_container.begin(); }
[[nodiscard]] const_iterator begin() const noexcept { return m_container.begin(); }
[[nodiscard]] const_iterator cbegin() const noexcept { return m_container.cbegin(); }
[[nodiscard]] iterator end() noexcept { return m_container.end(); }
[[nodiscard]] const_iterator end() const noexcept { return m_container.end(); }
[[nodiscard]] const_iterator cend() const noexcept { return m_container.cend(); }
[[nodiscard]] bool empty() const noexcept { return m_container.empty(); }
[[nodiscard]] size_type size() const noexcept { return m_container.size(); }
[[nodiscard]] size_type max_size() const noexcept { return m_container.max_size(); }
void by_extension(
const std::string_view extension,
std::vector<const_pointer>& dst
) const {
std::ranges::copy(
m_container |
std::views::filter(
[&](const value_type& entry)
{
return entry.first.extension() == extension;
}
) |
std::views::transform(
[&](const value_type& entry)
{
return &entry;
}
),
std::back_inserter(dst)
);
}
std::pair<iterator, bool> try_emplace(const key_type& path)
{
auto it = m_container.find(path);
const auto is_new = it == m_container.end();
if (not is_new)
{
it = m_container.emplace_hint(it, path, ID::next());
}
return { it, is_new };
}
[[nodiscard]] bool contains(const key_type& key) const { return m_container.contains(key); }
[[nodiscard]] size_type count(const key_type& key) const { return m_container.count(key); }
[[nodiscard]] iterator find(const key_type& key) { return m_container.find(key); }
[[nodiscard]] const_iterator find(const key_type& key) const { return m_container.find(key); }
iterator erase(iterator pos) { return m_container.erase(pos); }
iterator erase(const_iterator pos) { return m_container.erase(pos); }
iterator erase(const_iterator first, const_iterator last) { return m_container.erase(first, last); }
size_type erase(const key_type& key) { return m_container.erase(key); }
void clear() noexcept { m_container.clear(); }
private:
static auto extension_filter(const std::string_view& extension)
{
return std::views::filter(
[extension](const key_type& path)
{
return path.extension() == extension;
}
);
}
container_type m_container;
};