docs
Loading...
Searching...
No Matches
BindingGuard

#include <Ultralight/js/API.h>

Overview

A binding tied to a C++ object's lifetime.

When an armed guard is destroyed, it removes the binding at its path (see API::Unbind()), so a feature can keep a binding for exactly as long as its owner lives:

api.Bind("debug.dump", [] { DumpState(); });
js::BindingGuard dump_guard(api, "debug.dump");
// ~dump_guard removes debug.dump (pages see the removal at their next navigation).
A binding tied to a C++ object's lifetime.
Definition API.h:1210

The guard keeps its own reference to the API, so it stays safe to destroy after the js::API that created it. It doesn't own the API, so destroying the js::API still detaches it. The guard removes by path: if you bind something else at the path later, the guard removes that.

Note
Destroying or move-assigning over an armed guard removes the binding, so it follows the registration thread rules (see the js::API class overview): once the API is attached, do it on the Renderer's thread. To give up a guard on another thread, call Release().
Note
operator bool only says whether the guard is armed. It never reflects whether the binding or any page still exists.

Public Member Functions

 BindingGuard ()=default
 Create an unarmed guard (removes nothing).
 BindingGuard (const API &api, const char *path)
 Create an armed guard that removes the binding at path when destroyed.
 ~BindingGuard ()
 Destructor (removes the binding if the guard is armed).
 BindingGuard (BindingGuard &&other) noexcept
 Move constructor (other becomes unarmed).
BindingGuard & operator= (BindingGuard &&other) noexcept
 Move assignment (removes the current binding first if armed, and other becomes unarmed).
 BindingGuard (const BindingGuard &)=delete
BindingGuard & operator= (const BindingGuard &)=delete
void Release ()
 Disarm the guard without removing the binding (it stays until you unbind it or the API is destroyed).
 operator bool () const
 Whether or not the guard is armed (holds a path to remove).

Constructor & Destructor Documentation

◆ BindingGuard() [1/4]

BindingGuard ( )
default

Create an unarmed guard (removes nothing).

◆ BindingGuard() [2/4]

BindingGuard ( const API & api,
const char * path )
inline

Create an armed guard that removes the binding at path when destroyed.

Parameters
apiThe API the binding belongs to (an empty API gives an unarmed guard).
pathThe binding's path relative to the root, as you bound it.

◆ ~BindingGuard()

~BindingGuard ( )
inline

Destructor (removes the binding if the guard is armed).

◆ BindingGuard() [3/4]

BindingGuard ( BindingGuard && other)
inlinenoexcept

Move constructor (other becomes unarmed).

◆ BindingGuard() [4/4]

BindingGuard ( const BindingGuard & )
delete

Member Function Documentation

◆ operator bool()

operator bool ( ) const
inlineexplicit

Whether or not the guard is armed (holds a path to remove).

◆ operator=() [1/2]

BindingGuard & operator= ( BindingGuard && other)
inlinenoexcept

Move assignment (removes the current binding first if armed, and other becomes unarmed).

◆ operator=() [2/2]

BindingGuard & operator= ( const BindingGuard & )
delete

◆ Release()

void Release ( )
inline

Disarm the guard without removing the binding (it stays until you unbind it or the API is destroyed).

Safe to call from any thread.


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