cohtml::Binder

Provides binding between C++ and the UI.

#include <Binder.h>

Public Types

Name
enumBindingMode { BM_Value, BM_Scoped, BM_ScopedSafe, BM_ScopedSafeKeyValue, BM_GetTypeInfo}
typedef void(*)(Binder *, void *, size_t)ArrayElementReader
typedef void(*)(Binder *, void *, size_t)ArrayElementBinder
typedef void ()(void *, size_t)ArrayElementGetter
typedef size_t(*)(void *)ArrayLengthGetter

Public Functions

Name
virtual~Binder() =0
Binder()
virtual TypeDescriptionRegisterType(const char * name, void * object)
Register type in the binding.
virtual TypeDescriptionRegisterType(const char * name, const void * object)
Register type in the binding.
virtual voidAddProperty(void * object, const Property & property)
virtual voidAddMethod(const char * name, IEventHandler * method)
virtual voidBeginType()
virtual voidReadType()
virtual TypeInfo *GetTypeInfo() const
virtual voidEndType(void * )
virtual voidBeginEvent(const char * eventName, int arguments) =0
virtual voidEndEvent() =0
virtual voidBeginExposeObject() =0
virtual voidSetAsGlobal(const char * name, void * object) =0
virtual voidEnableSafeDataBinding(bool enable) =0
Enable or disable safe data binding by reference of properties of exposed models. Enabled by default.
virtual boolIsSafeDataBindingEnabled() const =0
virtual voidSetMode(BindingMode mode) =0
virtual Binder::BindingModeGetMode() =0
virtual voidNotifyKeyValuePropertyBindingDone() =0
virtual boolBindObject(TypeInfo * type, void * object) =0
virtual voidTypeName(const char * name) =0
virtual voidPropertyName(const char * name) =0
virtual voidBindUndefined() =0
virtual voidBindNull() =0
virtual voidBind(bool value) =0
virtual voidBind(signed short value) =0
virtual voidBind(unsigned short value) =0
virtual voidBind(signed int value) =0
virtual voidBind(unsigned int value) =0
virtual voidBind(signed long long value) =0
virtual voidBind(unsigned long long value) =0
virtual voidBind(signed long value) =0
virtual voidBind(unsigned long value) =0
virtual voidBind(signed char value) =0
virtual voidBind(unsigned char value) =0
virtual voidBind(float value) =0
virtual voidBind(double value) =0
virtual voidBind(const char * value) =0
virtual voidBind(const wchar_t * value) =0
virtual voidBind(const char16_t * value) =0
virtual voidBind(const char32_t * value) =0
virtual voidBindArray(const int * values, size_t count) =0
virtual voidBindArray(const float * values, size_t count) =0
virtual boolTryBindArrayByRef(void * arr, ArrayElementBinder elementBinder, ArrayElementReader elementReader, ArrayLengthGetter lengthGetter, ArrayElementGetter elementGetter) =0
virtual voidArrayBegin(size_t size) =0
Start exporting an array.
virtual voidArrayEnd() =0
End exporting an array.
virtual voidMapBegin(size_t size) =0
Start exporting a map (object)
virtual voidMapEnd() =0
End exporting a map.
virtual voidOnTypeBegin() =0
virtual voidOnTypeEnd() =0
virtual voidOnReadTypeBegin() =0
virtual voidOnReadTypeEnd() =0
virtual voidSkipValue() =0
virtual voidReadNull() =0
Deprecated Use SkipValue.
virtual voidRead(bool & value) =0
virtual voidRead(signed short & value) =0
virtual voidRead(unsigned short & value) =0
virtual voidRead(signed int & value) =0
virtual voidRead(unsigned int & value) =0
virtual voidRead(signed long long & value) =0
virtual voidRead(unsigned long long & value) =0
virtual voidRead(signed long & value) =0
virtual voidRead(unsigned long & value) =0
virtual voidRead(char & value) =0
virtual voidRead(signed char & value) =0
virtual voidRead(unsigned char & value) =0
virtual voidRead(float & value) =0
virtual voidRead(double & value) =0
virtual voidRead(const char *& buffer, size_t & size) =0
virtual voidRead(const wchar_t *& value, size_t & size) =0
virtual voidRead(const char16_t *& value, size_t & size) =0
virtual voidRead(const char32_t *& value, size_t & size) =0
virtual boolReadProperty(const char * name) =0
virtual boolReadType(const char * name) =0
virtual voidReadAsString(const char *& buffer, size_t & size) =0
Like Read but ensures the value will be read as string.
virtual size_tReadArrayBegin() =0
Start reading an array.
virtual voidReadArrayElement(size_t index) =0
Read element from an array.
virtual voidReadArrayEnd() =0
End reading an array.
virtual size_tReadMapBegin() =0
Start reading a map (object)
virtual voidReadKeyValuePair() =0
Read next key-value pair from a map.
virtual voidReadMapEnd() =0
End reading a map.
virtual ValueTypePeekValueType() =0
Peek the type of the current value.
template <typename T >
PreciseHandle
CreatePreciseHandle(T * instance, const char * propertyName)
Create a handle for updating a specific property of a model.
virtual PreciseHandleCreatePreciseHandle(void * instance, const char * propertyName, const TypeInfo * typeInfo) =0
Create a handle for updating a specific property of a model.
virtual boolUpdatePreciseHandle(void * instance, PreciseHandle propertyHandle) =0
Mark the property defined by handle to be updated on the next SynchronizeModels
virtual voidInstanceMoved(void * oldAddress, void * newAddress) =0
Notify the binding layer that a model has been relocated to a new address.
virtual boolElementUpdated(void * instance, PreciseHandle propertyHandle, size_t index) =0
Mark an element in a collection to be updated.
virtual boolElementAdded(void * instance, PreciseHandle propertyHandle, size_t index) =0
Mark an element as added to the collection.
virtual boolElementRemoved(void * instance, PreciseHandle propertyHandle, size_t index) =0
Mark an element as removed from the collection.

Protected Functions

Name
Binder(const Binder & )
Binder &operator=(const Binder & )

Protected Attributes

Name
BinderImpl *m_Impl

Friends

Name
classTypeDescription

Public Types Documentation

enum BindingMode

EnumeratorValueDescription
BM_Value
BM_ScopedThis mode is set before binding something by value.
BM_ScopedSafeThis mode is set before binding something by reference.
BM_ScopedSafeKeyValueThis mode is set before binding a property of a model by reference and Safe Data Binding is enabled.
BM_GetTypeInfoThis mode is set before binding a key-value property of a model by reference and Safe Data Binding is enabled. This mode is set to generate a TypeInfo.

typedef ArrayElementReader

typedef void(* cohtml::Binder::ArrayElementReader) (Binder *, void *, size_t);

typedef ArrayElementBinder

typedef void(* cohtml::Binder::ArrayElementBinder) (Binder *, void *, size_t);

typedef ArrayElementGetter

typedef void*(* cohtml::Binder::ArrayElementGetter) (void *, size_t);

typedef ArrayLengthGetter

typedef size_t(* cohtml::Binder::ArrayLengthGetter) (void *);

Public Functions Documentation

function ~Binder

virtual ~Binder() =0

function Binder

Binder()

function RegisterType

virtual TypeDescription RegisterType(
    const char * name,
    void * object
)

Register type in the binding.

Parameters:

  • name name for the type
  • object instance of this type

Return: TypeDescription object to be used to describe the properties of object

Warning: The name of the type should be unique for each type. Using duplicated names is undefined behavior

function RegisterType

virtual TypeDescription RegisterType(
    const char * name,
    const void * object
)

Register type in the binding.

Parameters:

  • name name for the type
  • object instance of this type

Return: TypeDescription object to be used to describe the properties of object

Warning: The name of the type should be unique for each type. Using duplicated names is undefined behavior

function AddProperty

virtual void AddProperty(
    void * object,
    const Property & property
)

function AddMethod

virtual void AddMethod(
    const char * name,
    IEventHandler * method
)

function BeginType

virtual void BeginType()

function ReadType

virtual void ReadType()

function GetTypeInfo

virtual TypeInfo * GetTypeInfo() const

function EndType

virtual void EndType(
    void * 
)

function BeginEvent

virtual void BeginEvent(
    const char * eventName,
    int arguments
) =0

function EndEvent

virtual void EndEvent() =0

function BeginExposeObject

virtual void BeginExposeObject() =0

function SetAsGlobal

virtual void SetAsGlobal(
    const char * name,
    void * object
) =0

function EnableSafeDataBinding

virtual void EnableSafeDataBinding(
    bool enable
) =0

Enable or disable safe data binding by reference of properties of exposed models. Enabled by default.

Parameters:

  • enable

Warning: Changing this setting doesn’t affect already exposed properties

function IsSafeDataBindingEnabled

virtual bool IsSafeDataBindingEnabled() const =0

function SetMode

virtual void SetMode(
    BindingMode mode
) =0

function GetMode

virtual Binder::BindingMode GetMode() =0

function NotifyKeyValuePropertyBindingDone

virtual void NotifyKeyValuePropertyBindingDone() =0

function BindObject

virtual bool BindObject(
    TypeInfo * type,
    void * object
) =0

function TypeName

virtual void TypeName(
    const char * name
) =0

function PropertyName

virtual void PropertyName(
    const char * name
) =0

function BindUndefined

virtual void BindUndefined() =0

function BindNull

virtual void BindNull() =0

function Bind

virtual void Bind(
    bool value
) =0

function Bind

virtual void Bind(
    signed short value
) =0

function Bind

virtual void Bind(
    unsigned short value
) =0

function Bind

virtual void Bind(
    signed int value
) =0

function Bind

virtual void Bind(
    unsigned int value
) =0

function Bind

virtual void Bind(
    signed long long value
) =0

function Bind

virtual void Bind(
    unsigned long long value
) =0

function Bind

virtual void Bind(
    signed long value
) =0

function Bind

virtual void Bind(
    unsigned long value
) =0

function Bind

virtual void Bind(
    signed char value
) =0

function Bind

virtual void Bind(
    unsigned char value
) =0

function Bind

virtual void Bind(
    float value
) =0

function Bind

virtual void Bind(
    double value
) =0

function Bind

virtual void Bind(
    const char * value
) =0

function Bind

virtual void Bind(
    const wchar_t * value
) =0

function Bind

virtual void Bind(
    const char16_t * value
) =0

function Bind

virtual void Bind(
    const char32_t * value
) =0

function BindArray

virtual void BindArray(
    const int * values,
    size_t count
) =0

function BindArray

virtual void BindArray(
    const float * values,
    size_t count
) =0

function TryBindArrayByRef

virtual bool TryBindArrayByRef(
    void * arr,
    ArrayElementBinder elementBinder,
    ArrayElementReader elementReader,
    ArrayLengthGetter lengthGetter,
    ArrayElementGetter elementGetter
) =0

function ArrayBegin

virtual void ArrayBegin(
    size_t size
) =0

Start exporting an array.

Parameters:

  • size size of the array

function ArrayEnd

virtual void ArrayEnd() =0

End exporting an array.

function MapBegin

virtual void MapBegin(
    size_t size
) =0

Start exporting a map (object)

Parameters:

  • size size of the map

Note: Every exported type that uses MapBegin() and MapEnd in its bind function, such as maps, pairs, etc, should wrap the call to CoherentBind with CoherentBindKeyValueProperty(). You can check Map.h, UnorderedMap.h and Pair.h for example.

function MapEnd

virtual void MapEnd() =0

End exporting a map.

function OnTypeBegin

virtual void OnTypeBegin() =0

function OnTypeEnd

virtual void OnTypeEnd() =0

function OnReadTypeBegin

virtual void OnReadTypeBegin() =0

function OnReadTypeEnd

virtual void OnReadTypeEnd() =0

function SkipValue

virtual void SkipValue() =0

function ReadNull

virtual void ReadNull() =0

Deprecated Use SkipValue.

function Read

virtual void Read(
    bool & value
) =0

function Read

virtual void Read(
    signed short & value
) =0

function Read

virtual void Read(
    unsigned short & value
) =0

function Read

virtual void Read(
    signed int & value
) =0

function Read

virtual void Read(
    unsigned int & value
) =0

function Read

virtual void Read(
    signed long long & value
) =0

function Read

virtual void Read(
    unsigned long long & value
) =0

function Read

virtual void Read(
    signed long & value
) =0

function Read

virtual void Read(
    unsigned long & value
) =0

function Read

virtual void Read(
    char & value
) =0

function Read

virtual void Read(
    signed char & value
) =0

function Read

virtual void Read(
    unsigned char & value
) =0

function Read

virtual void Read(
    float & value
) =0

function Read

virtual void Read(
    double & value
) =0

function Read

virtual void Read(
    const char *& buffer,
    size_t & size
) =0

function Read

virtual void Read(
    const wchar_t *& value,
    size_t & size
) =0

function Read

virtual void Read(
    const char16_t *& value,
    size_t & size
) =0

function Read

virtual void Read(
    const char32_t *& value,
    size_t & size
) =0

function ReadProperty

virtual bool ReadProperty(
    const char * name
) =0

function ReadType

virtual bool ReadType(
    const char * name
) =0

function ReadAsString

virtual void ReadAsString(
    const char *& buffer,
    size_t & size
) =0

Like Read but ensures the value will be read as string.

function ReadArrayBegin

virtual size_t ReadArrayBegin() =0

Start reading an array.

Return: the size of the array

function ReadArrayElement

virtual void ReadArrayElement(
    size_t index
) =0

Read element from an array.

Parameters:

  • index the index of the element in the array

function ReadArrayEnd

virtual void ReadArrayEnd() =0

End reading an array.

function ReadMapBegin

virtual size_t ReadMapBegin() =0

Start reading a map (object)

Return: the size of the map

function ReadKeyValuePair

virtual void ReadKeyValuePair() =0

Read next key-value pair from a map.

function ReadMapEnd

virtual void ReadMapEnd() =0

End reading a map.

function PeekValueType

virtual ValueType PeekValueType() =0

Peek the type of the current value.

Return: the type of the current value

function CreatePreciseHandle

template <typename T >
inline PreciseHandle CreatePreciseHandle(
    T * instance,
    const char * propertyName
)

Create a handle for updating a specific property of a model.

Parameters:

  • instance the model instance that will be updated with this handle
  • propertyName the name of the property to be updated with this handle. Must match the name given when exposing the model.

Return: handle that can be used to update this property on this instace or different instances of the same type

Note: To be able to use the same handle on different instances their runtime types must be the same

function CreatePreciseHandle

virtual PreciseHandle CreatePreciseHandle(
    void * instance,
    const char * propertyName,
    const TypeInfo * typeInfo
) =0

Create a handle for updating a specific property of a model.

Parameters:

  • instance the model instance that will be updated with this handle
  • propertyName the name of the property to be updated with this handle. Must match the name given when exposing the model.
  • typeInfo the TypeInfo that describes the properties of instance

Return: handle that can be used to update this property on this instace or different instances of the same type

Note: To be able to use the same handle on different instances their runtime types must be the same

function UpdatePreciseHandle

virtual bool UpdatePreciseHandle(
    void * instance,
    PreciseHandle propertyHandle
) =0

Mark the property defined by handle to be updated on the next SynchronizeModels

Parameters:

  • instance the model whose property has to be updated
  • propertyHandle the handle for the property to be updated

Return: true if any data-binding expressions have been marked for update

function InstanceMoved

virtual void InstanceMoved(
    void * oldAddress,
    void * newAddress
) =0

Notify the binding layer that a model has been relocated to a new address.

Parameters:

  • oldAddress the old address of the model
  • newAddress the new address of the model

Note: does nothing if old_address and new_address are the same

function ElementUpdated

virtual bool ElementUpdated(
    void * instance,
    PreciseHandle propertyHandle,
    size_t index
) =0

Mark an element in a collection to be updated.

Parameters:

  • instance the model that contains the collection
  • propertyHandle the handle for the collection to be updated
  • index index of the updated element

Return: true if any data-binding expressions have been marked for update

function ElementAdded

virtual bool ElementAdded(
    void * instance,
    PreciseHandle propertyHandle,
    size_t index
) =0

Mark an element as added to the collection.

Parameters:

  • instance the model that contains the collection
  • propertyHandle the handle for the collection to be updated
  • index index of the added element

Return: true if any data-binding expressions have been marked for update

function ElementRemoved

virtual bool ElementRemoved(
    void * instance,
    PreciseHandle propertyHandle,
    size_t index
) =0

Mark an element as removed from the collection.

Parameters:

  • instance the model that contains the collection
  • propertyHandle the handle for the collection to be updated
  • index index of the removed element

Return: true if any data-binding expressions have been marked for update

Protected Functions Documentation

function Binder

Binder(
    const Binder & 
)

function operator=

Binder & operator=(
    const Binder & 
)

Protected Attributes Documentation

variable m_Impl

BinderImpl * m_Impl;

Friends

friend TypeDescription

friend class TypeDescription;