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(); });
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.
|
| | 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).
|