9#include <Ultralight/dom/data/detail/EnumReflection.h>
59 static constexpr long long min = 0;
60 static constexpr long long max = 63;
69template <
typename T,
typename =
void>
70struct BuiltinValueTraits {};
73struct BuiltinValueTraits<bool> {
74 static constexpr ValueKind kind = ValueKind::Bool;
75 static constexpr bool ToSlot(
bool value) {
return value; }
80struct BuiltinValueTraits<T,
81 std::enable_if_t<std::is_integral_v<T> && !std::is_same_v<T, bool>>> {
82 static constexpr ValueKind kind = ValueKind::Int64;
83 static constexpr int64_t ToSlot(T value) {
return static_cast<int64_t
>(value); }
88struct BuiltinValueTraits<T, std::enable_if_t<std::is_floating_point_v<T>>> {
89 static constexpr ValueKind kind = ValueKind::Double;
90 static constexpr double ToSlot(T value) {
return static_cast<double>(value); }
94struct BuiltinValueTraits<
String> {
95 static constexpr ValueKind kind = ValueKind::String;
96 static const String& ToSlot(
const String& value) {
return value; }
100struct BuiltinValueTraits<std::string> {
101 static constexpr ValueKind kind = ValueKind::String;
102 static String ToSlot(
const std::string& value) {
103 return String(value.data(), value.size());
108struct BuiltinValueTraits<std::string_view> {
109 static constexpr ValueKind kind = ValueKind::String;
110 static String ToSlot(std::string_view value) {
return String(value.data(), value.size()); }
114struct BuiltinValueTraits<const char*> {
115 static constexpr ValueKind kind = ValueKind::String;
116 static String ToSlot(
const char* value) {
return String(value ? value :
""); }
122struct BuiltinValueTraits<char*> : BuiltinValueTraits<const char*> {};
126 static constexpr ValueKind kind = ValueKind::StyleValue;
127 static const StyleValue& ToSlot(
const StyleValue& value) {
return value; }
131struct BuiltinValueTraits<
Color> {
132 static constexpr ValueKind kind = ValueKind::Color;
133 static const Color& ToSlot(
const Color& value) {
return value; }
136#if ULTRALIGHT_REFLECTION
142struct BuiltinValueTraits<E, std::enable_if_t<std::is_enum_v<E>>> {
143 static constexpr ValueKind kind = ValueKind::String;
144 static String ToSlot(E value) {
145 const long long raw =
static_cast<long long>(value);
146 const std::string_view name = detail::EnumInfo<E>::NameOf(raw);
148 return String(name.data(), name.size());
150 const int length = snprintf(buffer,
sizeof(buffer),
"%lld", raw);
151 return String(buffer, length > 0 ?
static_cast<size_t>(length) : 0);
247template <
typename T,
typename =
void>
An RGBA color value in a certain color space (with CSS parsing helpers).
Definition Color.h:69
Unicode string container with conversions for UTF-8, UTF-16, and UTF-32.
Definition String.h:31
Whether or not T binds as a leaf value (ignoring const, volatile, and references),...
Definition ValueTraits.h:255
Whether or not P can be an action's payload without a payload struct (ignoring const,...
Definition ValueTraits.h:268
Definition StringSTL.h:166
Data-binding API that connects native C++ data to HTML and CSS markup.
Definition ActionInfo.h:13
ValueKind
The kinds of value a schema entry holds.
Definition ValueTraits.h:27
@ String
UTF-8 text (from strings and enums).
Definition ValueTraits.h:31
@ Object
A nested object (no value of its own).
Definition ValueTraits.h:34
@ StyleValue
A CSS number with a unit (see dom::StyleValue).
Definition ValueTraits.h:32
@ Bool
A boolean.
Definition ValueTraits.h:28
@ Color
A color (see ultralight::Color).
Definition ValueTraits.h:33
@ Double
A double-precision float (from any floating-point type).
Definition ValueTraits.h:30
@ Int64
A signed 64-bit integer (from any integer type).
Definition ValueTraits.h:29
consteval ActionToken< Payload > Action(const char *name, Tags... tags)
Declare an action (a request the page sends to your code).
Definition Schema.h:688
consteval auto List(const char *name, A accessor, KeyPtr key, Tags... tags)
Declare a keyed list.
Definition Schema.h:615
Direct C++ access to modify page elements and handle events.
Root namespace for every public Ultralight type, function, and enumeration.
A numeric CSS value and its unit.
Definition StyleValue.h:147
The range of values searched for an enum's enumerator names.
Definition ValueTraits.h:58
static constexpr long long max
The highest value searched (inclusive).
Definition ValueTraits.h:60
static constexpr long long min
The lowest value searched (inclusive).
Definition ValueTraits.h:59
Conversion rules that expose a C++ type as a primitive value in data bindings.
Definition ValueTraits.h:248