From b8a0721e7d9efaa6b55798af1b090f3eb7deeb62 Mon Sep 17 00:00:00 2001 From: SimonCROS Date: Sat, 15 Nov 2025 19:48:37 +0100 Subject: [PATCH] Use the flat_multimap --- src/CMakeLists.txt | 1 - src/Components/UserInterface.cpp | 2 +- src/Components/UserInterface.h | 4 +- src/Utility/VectorMultiMap.h | 82 -------------------------------- 4 files changed, 3 insertions(+), 86 deletions(-) delete mode 100644 src/Utility/VectorMultiMap.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 425a4c7..968c27c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -58,7 +58,6 @@ add_executable(HumanGL Utility/EnumHelpers.h Utility/StridedIterator.h - Utility/VectorMultiMap.h InterfaceBlocks/DisplayInterfaceBlock.cpp InterfaceBlocks/DisplayInterfaceBlock.h diff --git a/src/Components/UserInterface.cpp b/src/Components/UserInterface.cpp index a248ad0..dddebb9 100644 --- a/src/Components/UserInterface.cpp +++ b/src/Components/UserInterface.cpp @@ -26,7 +26,7 @@ auto UserInterface::onUpdate(Engine& engine) -> void uint16_t index = 0; for (const auto& entry : m_blocks) { - entry.value->onDrawUI(index, engine, *this); + entry.second->onDrawUI(index, engine, *this); if (index < m_blocks.size() - 1) InterfaceBlock::addSeparator(); ++index; diff --git a/src/Components/UserInterface.h b/src/Components/UserInterface.h index 285bd07..c7f021a 100644 --- a/src/Components/UserInterface.h +++ b/src/Components/UserInterface.h @@ -6,10 +6,10 @@ #define USERINTERFACE_H #include +#include #include "Engine/Engine.h" #include "Engine/EngineComponent.h" -#include "Utility/VectorMultiMap.h" class MeshRenderer; @@ -49,7 +49,7 @@ class UserInterface : public EngineComponent std::string m_name; ImguiWindowData m_windowData; - VectorMultiMap> m_blocks; + std::flat_multimap> m_blocks; public: explicit UserInterface(Object& object, const std::string_view& name = "default interface", const ImguiWindowData& windowData = {}); diff --git a/src/Utility/VectorMultiMap.h b/src/Utility/VectorMultiMap.h deleted file mode 100644 index f89430d..0000000 --- a/src/Utility/VectorMultiMap.h +++ /dev/null @@ -1,82 +0,0 @@ -// -// Created by Simon Cros on 08/02/2025. -// - -#ifndef VECTORMULTIMAP_H -#define VECTORMULTIMAP_H - -#include -#include - -template -class VectorMultiMap -{ -public: - struct Entry - { - Key key; - Value value; - - bool operator<(const Entry& other) const - { - return key < other.key; - } - - bool operator<(const Key& other) const - { - return key < other; - } - }; - - using Container = std::vector; - using Iterator = typename Container::iterator; - using ConstIterator = typename Container::const_iterator; - - auto insert(const Key& key, const Value& value) -> Iterator - { - Entry entry{key, value}; - auto it = std::lower_bound(m_data.begin(), m_data.end(), entry); - return m_data.insert(it, entry); - } - - template - requires std::constructible_from - auto emplace(const Key& key, Args&&... args) -> Iterator - { - auto it = std::lower_bound(m_data.begin(), m_data.end(), key); - return m_data.emplace(it, key, std::forward(args)...); - } - - [[nodiscard]] auto equal_range(const Key& key) -> std::pair - { - return std::equal_range(m_data.begin(), m_data.end(), key); - } - - [[nodiscard]] auto equal_range(const Key& key) const -> std::pair - { - return std::equal_range(m_data.begin(), m_data.end(), key); - } - - auto erase(const Key& key) -> void - { - auto range = equal_range(key); - m_data.erase(range.first, range.second); - } - - auto erase(const ConstIterator& it) -> void - { - m_data.erase(it); - } - - [[nodiscard]] auto size() -> typename Container::size_type { return m_data.size(); } - - [[nodiscard]] auto begin() -> Iterator { return m_data.begin(); } - [[nodiscard]] auto end() -> Iterator { return m_data.end(); } - [[nodiscard]] auto begin() const -> ConstIterator { return m_data.begin(); } - [[nodiscard]] auto end() const -> ConstIterator { return m_data.end(); } - -private: - Container m_data{}; -}; - -#endif //VECTORMULTIMAP_H