mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-24 06:01:02 +00:00
Support afd endpoint serialization
This commit is contained in:
@@ -9,6 +9,9 @@
|
||||
#include <functional>
|
||||
#include <typeindex>
|
||||
|
||||
void serialize();
|
||||
void deserialize();
|
||||
|
||||
namespace utils
|
||||
{
|
||||
class buffer_serializer;
|
||||
@@ -57,6 +60,18 @@ namespace utils
|
||||
: std::true_type
|
||||
{
|
||||
};
|
||||
|
||||
template <typename, typename = void>
|
||||
struct has_construct_function : std::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct has_construct_function<T, std::void_t<decltype(T::construct(
|
||||
std::declval<buffer_deserializer&>()))>>
|
||||
: std::bool_constant<std::is_same_v<decltype(T::construct(std::declval<buffer_deserializer&>())), T>>
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
class buffer_deserializer
|
||||
@@ -291,7 +306,11 @@ namespace utils
|
||||
template <typename T>
|
||||
T construct_object()
|
||||
{
|
||||
if constexpr (std::is_default_constructible_v<T>)
|
||||
if constexpr (detail::has_construct_function<T>::value)
|
||||
{
|
||||
return T::construct(*this);
|
||||
}
|
||||
else if constexpr (std::is_default_constructible_v<T>)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user