Skip to content

Commit

Permalink
refactor(spa/pod): return enum_value for pod::typeand `pod_prop::…
Browse files Browse the repository at this point in the history
…key`
  • Loading branch information
Curve committed Oct 13, 2024
1 parent ac2c2a1 commit 8c12459
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion include/rohrkabel/spa/pod/pod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ namespace pipewire::spa
[[nodiscard]] std::optional<pod_prop> find_recursive(enum_value<prop>) const;

public:
[[nodiscard]] spa::type type() const;
[[nodiscard]] std::size_t size() const;
[[nodiscard]] enum_value<spa::type> type() const;

public:
template <typename T>
Expand Down
2 changes: 1 addition & 1 deletion include/rohrkabel/spa/pod/prop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<prop> key() const;

public:
[[nodiscard]] raw_type *get() const;
Expand Down
18 changes: 17 additions & 1 deletion include/rohrkabel/utils/enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace pipewire
public:
[[nodiscard]] T get() const
{
return static_Cast<T>(m_value);
return static_cast<T>(m_value);
}

[[nodiscard]] underlying value() const
Expand All @@ -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
10 changes: 5 additions & 5 deletions src/spa/spa.pod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace pipewire::spa

for (auto &&prop : as<pod_object>())
{
if (prop.key() != key.value())
if (prop.key() != key)
{
continue;
}
Expand Down Expand Up @@ -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<spa::type>(m_impl->pod->type);
return m_impl->pod->size;
}

std::size_t pod::size() const
enum_value<spa::type> pod::type() const
{
return m_impl->pod->size;
return m_impl->pod->type;
}

template <>
Expand Down
8 changes: 4 additions & 4 deletions src/spa/spa.pod.prop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<prop> pod_prop::key() const
{
return m_impl->prop->flags;
return m_impl->prop->key;
}

pod_prop::raw_type *pod_prop::get() const
Expand Down

0 comments on commit 8c12459

Please sign in to comment.