docs
Loading...
Searching...
No Matches
Holders.h
Go to the documentation of this file.
1///
2/// Copyright (C) 2026 Ultralight, Inc. All rights reserved.
3/// A license is required for commercial use. https://ultralig.ht
4///
5#pragma once
7
8#include <memory>
9#include <type_traits>
10
11namespace ultralight {
12namespace dom {
13
14///
15/// Whether or not the DOM API can hold an object through H (ignoring const and references), ie.
16/// ultralight::HolderTraits is specialized for it.
17///
18/// Some DOM calls can take a smart pointer to your object instead of a reference. These are the
19/// listener overloads that take an object and a member function (eg,
20/// Element::addEventListener() and Element::On()) and the data-binding API
21/// (ultralight::dom::data):
22///
23/// ```
24/// auto player = std::make_shared<Player>();
25/// button.addEventListener("click", std::weak_ptr(player), &Player::OnClick);
26/// ```
27///
28/// RefPtr, WeakPtr, std::shared_ptr, std::weak_ptr, and std::unique_ptr work without any setup:
29///
30/// - **An owning pointer keeps your object alive** (RefPtr, std::shared_ptr, or a
31/// std::unique_ptr you move in) for as long as the listener (or binding) exists.
32/// - **A weak pointer doesn't keep it alive** (WeakPtr or std::weak_ptr). The library locks it
33/// for each call and skips each call that comes after your object is destroyed. A data
34/// binding then keeps the values it last published.
35///
36/// To use your engine's own smart pointer, specialize ultralight::HolderTraits for it (see
37/// `<Ultralight/HolderTraits.h>`).
38///
39template <typename H>
41 = requires { typename HolderTraits<std::remove_cvref_t<H>>::element_type; }
42 && (ultralight::detail::HolderHasLock<std::remove_cvref_t<H>>
43 || ultralight::detail::HolderHasGet<std::remove_cvref_t<H>>);
44
45} // namespace dom
46} // namespace ultralight
Whether or not the DOM API can hold an object through H (ignoring const and references),...
Definition Holders.h:41
Direct C++ access to modify page elements and handle events.
Root namespace for every public Ultralight type, function, and enumeration.
Traits template that lets the library hold objects through custom smart pointers.
Definition HolderTraits.h:156