From 8c1245997cece47c2e7ba9baadc9731b5aea64c5 Mon Sep 17 00:00:00 2001 From: Curve Date: Sun, 13 Oct 2024 16:20:10 +0200 Subject: [PATCH] refactor(spa/pod): return `enum_value` for `pod::type`and `pod_prop::key` --- include/rohrkabel/spa/pod/pod.hpp | 2 +- include/rohrkabel/spa/pod/prop.hpp | 2 +- include/rohrkabel/utils/enum.hpp | 18 +++++++++++++++++- src/spa/spa.pod.cpp | 10 +++++----- src/spa/spa.pod.prop.cpp | 8 ++++---- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/include/rohrkabel/spa/pod/pod.hpp b/include/rohrkabel/spa/pod/pod.hpp index d0a4f67..e3332b1 100644 --- a/include/rohrkabel/spa/pod/pod.hpp +++ b/include/rohrkabel/spa/pod/pod.hpp @@ -65,8 +65,8 @@ namespace pipewire::spa [[nodiscard]] std::optional find_recursive(enum_value) const; public: - [[nodiscard]] spa::type type() const; [[nodiscard]] std::size_t size() const; + [[nodiscard]] enum_value type() const; public: template diff --git a/include/rohrkabel/spa/pod/prop.hpp b/include/rohrkabel/spa/pod/prop.hpp index 368c39d..9ff5f88 100644 --- a/include/rohrkabel/spa/pod/prop.hpp +++ b/include/rohrkabel/spa/pod/prop.hpp @@ -33,8 +33,8 @@ namespace pipewire::spa public: [[nodiscard]] pod value() const; - [[nodiscard]] std::uint32_t key() const; [[nodiscard]] std::uint32_t flags() const; + [[nodiscard]] enum_value key() const; public: [[nodiscard]] raw_type *get() const; diff --git a/include/rohrkabel/utils/enum.hpp b/include/rohrkabel/utils/enum.hpp index cfd13e6..bd0ff78 100644 --- a/include/rohrkabel/utils/enum.hpp +++ b/include/rohrkabel/utils/enum.hpp @@ -20,7 +20,7 @@ namespace pipewire public: [[nodiscard]] T get() const { - return static_Cast(m_value); + return static_cast(m_value); } [[nodiscard]] underlying value() const @@ -38,5 +38,21 @@ namespace pipewire { return value(); } + + public: + bool operator==(const enum_value &other) const + { + return m_value == other.m_value; + } + + bool operator==(const underlying &other) const + { + return m_value == other; + } + + bool operator==(const T &other) const + { + return get() == other; + } }; } // namespace pipewire diff --git a/src/spa/spa.pod.cpp b/src/spa/spa.pod.cpp index d8fed63..71b09f6 100644 --- a/src/spa/spa.pod.cpp +++ b/src/spa/spa.pod.cpp @@ -66,7 +66,7 @@ namespace pipewire::spa for (auto &&prop : as()) { - if (prop.key() != key.value()) + if (prop.key() != key) { continue; } @@ -111,14 +111,14 @@ namespace pipewire::spa return find_recursive(*this, find_recursive); } - spa::type pod::type() const + std::size_t pod::size() const { - return static_cast(m_impl->pod->type); + return m_impl->pod->size; } - std::size_t pod::size() const + enum_value pod::type() const { - return m_impl->pod->size; + return m_impl->pod->type; } template <> diff --git a/src/spa/spa.pod.prop.cpp b/src/spa/spa.pod.prop.cpp index 88c1a43..b3458c3 100644 --- a/src/spa/spa.pod.prop.cpp +++ b/src/spa/spa.pod.prop.cpp @@ -31,14 +31,14 @@ namespace pipewire::spa return pod::view(&m_impl->prop->value); } - std::uint32_t pod_prop::key() const + std::uint32_t pod_prop::flags() const { - return m_impl->prop->key; + return m_impl->prop->flags; } - std::uint32_t pod_prop::flags() const + enum_value pod_prop::key() const { - return m_impl->prop->flags; + return m_impl->prop->key; } pod_prop::raw_type *pod_prop::get() const