docs
Loading...
Searching...
No Matches
Snapshot< T >

#include <Ultralight/dom/data/Model.h>

Overview

template<typename T>
class ultralight::dom::data::Snapshot< T >

Read-only access to the synchronized values of a described type.

Snapshot lets you inspect the field values and CSS variables recorded for a described type without touching the underlying C++ instance. Calling Get() with an entry name returns its current synchronized value.

This schema uses a validator to check an edited bid against another field on the page:

struct Shop {
int64_t gold = 500;
int64_t bid = 0;
static constexpr auto schema = dd::Schema(
dd::Field("gold", &Shop::gold),
dd::Field("bid", &Shop::bid, dd::Editable,
dd::Validate([](int64_t bid, auto s) -> std::optional<int64_t> {
if (bid > s.template Get<"gold">())
return std::nullopt; // can't bid more than you have
return bid;
})));
};
static constexpr const auto & schema()
Get the type's schema.
Definition Model.h:83
auto Get() const
Get the value of a field or Var by name.
Definition Model.h:104

Receiving a Snapshot

The library passes a Snapshot to functions that inspect page state:

  • A validator receives a Snapshot through its second parameter on the Renderer's thread. It provides the values the page currently shows, letting you inspect related fields before accepting an edit.
  • A type's static Sync function receives a dom::data::Model, which inherits from Snapshot. Calling Get() returns the last synced values, including any fields that call has already synced, so you can compare against native data and skip unchanged fields (see dom::data::Model).
See also
dom::data::Model, dom::data::Validate()
Inheritance diagram for Snapshot< T >:
Model< T >

Public Types

using described_type = T

Static Public Member Functions

static constexpr const auto & schema ()
 Get the type's schema.

Public Member Functions

template<ultralight::detail::FixedString Name>
auto Get () const
 Get the value of a field or Var by name.

Protected Member Functions

template<ValueKind K>
auto ReadSlot (uint32_t slot) const

Static Protected Member Functions

template<ultralight::detail::FixedString Name>
static consteval size_t IndexOfChecked ()

Protected Attributes

detail::RecordOps * ops_

Member Typedef Documentation

◆ described_type

template<typename T>
using described_type = T

Member Function Documentation

◆ Get()

template<typename T>
template<ultralight::detail::FixedString Name>
auto Get ( ) const
inline

Get the value of a field or Var by name.

A misspelled name is a compile error. So is an object, a list, or an action (they have no single value).

Returns
Returns the value as a bool, int64_t, double, String, StyleValue, or Color. Integer fields read as int64_t and floating-point fields as double. String fields read as a String, and so do enum fields (as the enumerator's name).
Note
Most fields compare directly with the value in your object (eg, s.rev != m.Get<"rev">()). A std::string, enum, or StyleValue field can't be compared that way, so gate on an integer revision counter instead.

◆ IndexOfChecked()

template<typename T>
template<ultralight::detail::FixedString Name>
consteval size_t IndexOfChecked ( )
inlinestaticconstevalprotected

◆ ReadSlot()

template<typename T>
template<ValueKind K>
auto ReadSlot ( uint32_t slot) const
inlineprotected

◆ schema()

template<typename T>
constexpr const auto & schema ( )
inlinestaticconstexpr

Get the type's schema.

Member Data Documentation

◆ ops_

template<typename T>
detail::RecordOps* ops_
protected

The documentation for this class was generated from the following file: