Observables Implementation

内容表

关于

An implementation of an interface that declares an observable must implement the behaviour of the observable. The observable must be initiated, freed and invoked.

Implementation

To implement basic observable functionality an implementation must include a maxon::ObserverObjectClass object with MAXON_COMPONENT() .

The observable declared with MAXON_OBSERVABLE() is available as a member variable with the defined name and a "_" prefix.

// This example shows an implementation of an interface. // It implements also an observable that is invoked when the function Ping() is called.
class ObserveMeImpl : public maxon::Component <ObserveMeImpl, ObserveMeInterface> { // use ObserverObjectClass to implement basic observer functionality MAXON_COMPONENT ( NORMAL , maxon::ObserverObjectClass);
public : // implement observable MAXON_OBSERVABLE_IMPL (ObservablePing); maxon::Result<void> InitComponent() { iferr_scope ; _count = 0;

// init observable _ObservablePing.Init( self , maxon::Id ( "ObservablePing" )) iferr_return ; return maxon::OK ; } void FreeComponent() { // free observable _ObservablePing.Free(); } MAXON_METHOD void Ping() { // increment ++_count;

// notify subscribers iferr (_ObservablePing.Notify(_count)) { DiagnosticOutput ( "Observable error: @" , err); } } private : maxon::Int32 _count; };

The observable must be implemented using MAXON_OBSERVABLE_IMPL() .

ObservableBaseInterface

Observables are based on maxon::ObservableBaseInterface :

Subscriber notification:

Observers are handled with:

延伸阅读

maxon::ComponentWithBase
定义: objectbase.h:2472
MAXON_COMPONENT
#define MAXON_COMPONENT(KIND,...)
定义: objectbase.h:2036
maxon::OK
return OK
定义: apibase.h:2532
maxon::Id
定义: apibaseid.h:250
iferr_return
#define iferr_return
定义: resultbase.h:1434
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
定义: debugdiagnostics.h:166
maxon::Result< void >
MAXON_METHOD
#define MAXON_METHOD
定义: interfacebase.h:855
maxon::Int32
int32_t Int32
32 bit signed integer datatype.
定义: apibase.h:172
iferr_scope
#define iferr_scope
定义: resultbase.h:1343
SCULPTBRUSHMODE::NORMAL
@ NORMAL
Samples the surface as the user moves over it the SculptObject and returns a new hit point and normal...
iferr
#define iferr(...)
定义: errorbase.h:380
MAXON_OBSERVABLE_IMPL
#define MAXON_OBSERVABLE_IMPL(NAME,...)
定义: observable.h:255

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1