Kanzi  3.9.7
Kanzi Engine API
kanzi::ManualBinding Class Reference

Manual binding is a one-to-one binding that caches the value that was written to the target. More...

#include <kanzi/core.ui/binding/manual_binding.hpp>

Inheritance diagram for kanzi::ManualBinding:
[legend]

Static Public Member Functions

static ManualBindingSharedPtr create (BindingSourcePtr source)
 Creates a manual binding. More...
 
static ManualBindingSharedPtr create (string_view sourcePath, AbstractPropertyType sourcePropertyType, PropertyField sourceField)
 Creates a manual binding. More...
 

Protected Member Functions

AbstractBindingRuntimeSharedPtr createRuntimeOverride (AbstractBindingSharedPtr binding, BindingLookupContextPtr sourceLookupContext, BindingTargetRuntimePtr targetRuntime) override
 AbstractBinding::createRuntime() implementation. More...
 
 ManualBinding (BindingSourcePtr source)
 Constructor. More...
 
- Protected Member Functions inherited from kanzi::AbstractBinding
 AbstractBinding (BindingSourcePtr source)
 Constructor. More...
 
virtual void addReverseProcessorOverride (BindingProcessorSharedPtr processor)
 Implementation-dependent binding processor add (reverse direction). More...
 
virtual BindingProcessorConstIterator beginReverseProcessorsOverride () const
 Implementation-dependent access to reverse direction binding processors. More...
 
virtual BindingProcessorConstIterator endReverseProcessorsOverride () const
 Implementation-dependent access to reverse direction binding processors. More...
 
virtual void removeReverseProcessorOverride (BindingProcessor &processor)
 Implementation-dependent binding processor remove (reverse direction). More...
 

Additional Inherited Members

- Public Types inherited from kanzi::AbstractBinding
using BindingProcessorConstIterator = BindingProcessorContainer::const_iterator
 Binding processor iterator type. More...
 
using BindingProcessorContainer = vector< BindingProcessorSharedPtr >
 Binding processor container type. More...
 
- Public Member Functions inherited from kanzi::AbstractBinding
void addProcessor (BindingProcessorSharedPtr processor)
 Add a binding processor. More...
 
void addReverseProcessor (BindingProcessorSharedPtr processor)
 Add a binding processor (reverse direction). More...
 
BindingProcessorConstIterator beginProcessors () const
 Gets an iterator to the beginning of binding processors. More...
 
BindingProcessorConstIterator beginReverseProcessors () const
 Gets an iterator to the beginning of reverse direction binding processors. More...
 
AbstractBindingRuntimeSharedPtr createRuntime (AbstractBindingSharedPtr binding, BindingLookupContextPtr sourceLookupContext, BindingTargetRuntimePtr targetRuntime)
 Creates a binding runtime for this binding. More...
 
BindingProcessorConstIterator endProcessors () const
 Gets an iterator to the end of binding processors. More...
 
BindingProcessorConstIterator endReverseProcessors () const
 Gets an iterator to the end of reverse direction binding processors. More...
 
BindingSourcegetSource ()
 Gets the binding source for this binding. More...
 
bool isCreatedFromKZB () const
 Indicates whether the binding is sourced from a KZB? Used to check whether or not to remove the binding during patching. More...
 
void removeProcessor (BindingProcessor &processor)
 Remove a binding processor. More...
 
void removeReverseProcessor (BindingProcessor &processor)
 Remove a binding processor (reverse direction). More...
 
void setCreatedFromKZB (bool flag)
 Sets the created from KZB flag. More...
 
virtual ~AbstractBinding ()=default
 Destructor. More...
 
- Protected Attributes inherited from kanzi::AbstractBinding
bool m_createdFromKZB
 Is the binding sourced from a KZB? This field is used to determine if the binding should be removed during patching. More...
 
BindingProcessorContainer m_processors
 Binding processor (forward direction). More...
 
BindingSourcePtr m_source
 Binding source. More...
 

Detailed Description

Manual binding is a one-to-one binding that caches the value that was written to the target.

Kanzi Engine uses manual bindings internally in triggers and actions.

In a manual binding you can either:

  • Call update to read from source and then write to target
  • Call read and write separately

Creating a manual binding

To create a manual binding, first create a manual binding source:

// Create a manual binding source.

Then create a manual binding:

// Create a manual binding.
ManualBindingSharedPtr manualBinding = ManualBinding::create(kanzi::move(manualSource));
// Set the binding to a node, cast the runtime.
ManualBindingRuntimeSharedPtr manualRuntime = dynamic_pointer_cast<ManualBindingRuntime>(node->setBinding(manualBinding, Node2D::OpacityProperty).getBinding());

You can also use manual bindings with a regular ObjectPropertyBindingSource or DataSourceBindingSource. In that case the only difference to a regular Binding is that manual bindings cache the value within the binding. This is not always desired, because it can alter the lifetime of resources in the case of resource bindings.

Executing bindings manually

You can explicitly run update() on any binding, but it makes most sense when using manual bindings and sources that otherwise do not update automatically.

To execute a binding:

// Run binding update manually.
manualRuntime->update();

With manual bindings, you can split the update into read and write parts. To first read, then write:

// Run read phase of manual runtime.
manualRuntime->read();
// readValue will contain the value read during binding read phase.
Variant readValue = manualRuntime->getCachedValue();
// Run write phase of manual runtime.
manualRuntime->write();

Delayed actions internally first call read and then write.

Since
Kanzi 3.7.0

Constructor & Destructor Documentation

kanzi::ManualBinding::ManualBinding ( BindingSourcePtr  source)
inlineexplicitprotected

Constructor.

Parameters
sourceBinding source.

Member Function Documentation

static ManualBindingSharedPtr kanzi::ManualBinding::create ( BindingSourcePtr  source)
static

Creates a manual binding.

Parameters
sourceBinding source.
Returns
The manual binding.
static ManualBindingSharedPtr kanzi::ManualBinding::create ( string_view  sourcePath,
AbstractPropertyType  sourcePropertyType,
PropertyField  sourceField 
)
static

Creates a manual binding.

Parameters
sourcePathPath to source object.
sourcePropertyTypeSource property type from which to bind.
sourceFieldField of the source property type from which to bind. PropertyFieldWhole for the whole property.
Returns
The manual binding.
AbstractBindingRuntimeSharedPtr kanzi::ManualBinding::createRuntimeOverride ( AbstractBindingSharedPtr  binding,
BindingLookupContextPtr  sourceLookupContext,
BindingTargetRuntimePtr  targetRuntime 
)
overrideprotectedvirtual

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