diff options
author | Timothy <timmot@users.noreply.github.com> | 2021-07-04 14:44:34 +1000 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-07-04 13:48:20 +0430 |
commit | e42484bb656187229c6902c572f406be0fd637cf (patch) | |
tree | 4b3bc69d30074696deda297d73b4cb48801b637b /Userland/Libraries/LibIPC/Decoder.h | |
parent | 60f84f3154300ecf85f118f837d01d8f918eaa46 (diff) | |
download | serenity-e42484bb656187229c6902c572f406be0fd637cf.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibIPC/Decoder.h')
-rw-r--r-- | Userland/Libraries/LibIPC/Decoder.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Userland/Libraries/LibIPC/Decoder.h b/Userland/Libraries/LibIPC/Decoder.h index 7a288f8448..84f066ae22 100644 --- a/Userland/Libraries/LibIPC/Decoder.h +++ b/Userland/Libraries/LibIPC/Decoder.h @@ -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) { |