diff --git a/src/desktop/types/OverridableVar.hpp b/src/desktop/types/OverridableVar.hpp index 9ecfc890..538346c7 100644 --- a/src/desktop/types/OverridableVar.hpp +++ b/src/desktop/types/OverridableVar.hpp @@ -3,7 +3,8 @@ #include #include #include -#include +#include +#include #include "../../config/ConfigValue.hpp" namespace Desktop::Types { @@ -25,6 +26,8 @@ namespace Desktop::Types { PRIORITY_WORKSPACE_RULE, PRIORITY_WINDOW_RULE, PRIORITY_SET_PROP, + + PRIORITY_END, }; template @@ -56,11 +59,11 @@ namespace Desktop::Types { if (this == &other) return *this; - for (auto const& value : other.m_values) { + for (size_t i = 0; i < PRIORITY_END; ++i) { if constexpr (Extended && !std::is_same_v) - m_values[value.first] = clampOptional(value.second, m_minValue, m_maxValue); + m_values[i] = clampOptional(*other.m_values[i], m_minValue, m_maxValue); else - m_values[value.first] = value.second; + m_values[i] = other.m_values[i]; } return *this; @@ -71,18 +74,19 @@ namespace Desktop::Types { } void unset(eOverridePriority priority) { - m_values.erase(priority); + m_values[priority] = std::nullopt; } bool hasValue() const { - return !m_values.empty(); + return std::ranges::any_of(m_values, [](const auto& e) { return e.has_value(); }); } T value() const { - if (!m_values.empty()) - return std::prev(m_values.end())->second; - else - throw std::bad_optional_access(); + for (const auto& v : m_values | std::ranges::views::reverse) { + if (v) + return *v; + } + throw std::bad_optional_access(); } T valueOr(T const& other) const { @@ -115,10 +119,12 @@ namespace Desktop::Types { } eOverridePriority getPriority() const { - if (!m_values.empty()) - return std::prev(m_values.end())->first; - else - throw std::bad_optional_access(); + for (int i = PRIORITY_END - 1; i >= 0; --i) { + if (m_values[i]) + return sc(i); + } + + throw std::bad_optional_access(); } void increment(T const& other, eOverridePriority priority) { @@ -143,11 +149,11 @@ namespace Desktop::Types { } private: - std::map m_values; - std::optional m_defaultValue; // used for toggling, so required for bool - std::optional m_minValue; - std::optional m_maxValue; - std::any m_configValue; // only there for select variables + std::array, PRIORITY_END> m_values; + std::optional m_defaultValue; // used for toggling, so required for bool + std::optional m_minValue; + std::optional m_maxValue; + std::any m_configValue; // only there for select variables }; } \ No newline at end of file