mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-21 10:05:32 +00:00
AK+LibIPC: Make all enums codable
If an enum has a supported underlying type we can provide encoding and decoding for the enum as well.
This commit is contained in:
parent
60f84f3154
commit
e42484bb65
|
@ -26,6 +26,9 @@ concept Signed = IsSigned<T>;
|
|||
template<typename T>
|
||||
concept Unsigned = IsUnsigned<T>;
|
||||
|
||||
template<typename T>
|
||||
concept Enum = IsEnum<T>;
|
||||
|
||||
template<typename T, typename U>
|
||||
concept SameAs = IsSame<T, U>;
|
||||
|
||||
|
@ -52,6 +55,7 @@ concept IteratorFunction = requires(Func func, Args... args)
|
|||
}
|
||||
|
||||
using AK::Concepts::Arithmetic;
|
||||
using AK::Concepts::Enum;
|
||||
using AK::Concepts::FloatingPoint;
|
||||
using AK::Concepts::Integral;
|
||||
using AK::Concepts::IteratorFunction;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Concepts.h>
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/NumericLimits.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
|
@ -66,6 +67,17 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
template<Enum T>
|
||||
bool decode(T& enum_value)
|
||||
{
|
||||
UnderlyingType<T> inner_value;
|
||||
if (!decode(inner_value))
|
||||
return false;
|
||||
|
||||
enum_value = T(inner_value);
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool decode(T& value)
|
||||
{
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Concepts.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <LibIPC/Forward.h>
|
||||
#include <LibIPC/Message.h>
|
||||
|
||||
|
@ -62,6 +64,13 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
template<Enum T>
|
||||
Encoder& operator<<(T const& enum_value)
|
||||
{
|
||||
*this << AK::to_underlying(enum_value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Encoder& operator<<(const T& value)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue