Flip Reference

DocumentObserverDynamic Class Reference

Declared in

flip/DocumentObserverDynamic.h

template <class T>   class DocumentObserverDynamic;

flip::DocumentObserverDynamic allows to attach an observer to the document after the document was created.

flip::DocumentObserver has a lifetime longer than the document : it needs to be constructed before the document is constructed, and needs to be destroyed after the document is destroyed.

flip::DocumentObserverDynamic is exactly the inverse : it is constructed anytime after a document is constructed, and is destroyed anytime before the document is destroyed.

A flip::DocumentObserverDynamic takes a document as a parameter, and a document can have any number of dynamic observers at the same time.

Important: flip::DocumentObserverDynamics can and will be called in any order. If you need to order observers, then use composition.

Template Parameters

T

The root class to observer. T must inherit from flip::Object

Member Functions Synopsys

Constructor

Constructs the DocumentObserverDynamic

Member Functions

Constructor

template <class F> DocumentObserverDynamic (Document & document, F f);

Constructs the dynamic document observer, passing the document to observe as well as a callable matching the signature void (T &), typically a lambda function.

Example:

using Observer = flip::DocumentObserverDynamic <MyRootClass>;
Observer observer {document, [](MyRootClass & root){
   if (root.changed ())
   {
      // ...
   }
}};