1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:47:35 +00:00

LibGUI: Introduce property deserializers for GML property values

This commit is contained in:
Dan Klishch 2023-11-05 18:44:15 -05:00 committed by Andrew Kaster
parent fb6a9dd2f5
commit 1689ec9100
4 changed files with 186 additions and 0 deletions

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2023, Dan Klishch <danilklishch@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/JsonValue.h>
#include <LibGfx/Forward.h>
namespace GUI {
template<typename T>
struct PropertyDeserializer {
ErrorOr<T> operator()(JsonValue const& value) const;
};
template<Integral T>
requires(!IsSame<T, bool>)
struct PropertyDeserializer<T> {
ErrorOr<T> operator()(JsonValue const& value) const
{
if (!value.is_integer<T>())
return Error::from_string_literal("Value is either not an integer or out of range for requested type");
return value.to_number<T>();
}
};
}