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:
parent
fb6a9dd2f5
commit
1689ec9100
4 changed files with 186 additions and 0 deletions
30
Userland/Libraries/LibGUI/PropertyDeserializer.h
Normal file
30
Userland/Libraries/LibGUI/PropertyDeserializer.h
Normal 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>();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue