|
Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
|
CRTP base that turns an observer into a set of typed Observe() overloads. More...
#include <observer.hpp>
Public Member Functions | |
| std::vector< std::type_index > | SubscribedEventTypes () const override |
| Declares which event types this observer wants to receive. | |
| ObserveResult | Observe (AnyEvent const &e) override |
| Observe the observable object being observed. | |
| virtual | ~TypedObserver ()=default |
| std::type_index | ObservedKind () const override |
| The type this observer expects to observe. | |
CRTP base that turns an observer into a set of typed Observe() overloads.
Instead of writing one Observe(AnyEvent const&) body full of dynamic_casts (and a matching hand-written SubscribedEventTypes()), derive from this and provide one ObserveResult OnEvent(ConcreteEvent const&) overload per event you care about. This helper:
The per-event handler is named OnEvent (not an Observe overload) so it does not hide the Observe(AnyEvent const&) virtual – keeping Observe the single dispatch entry point and avoiding -Woverloaded-virtual noise.
The downcast stays a dynamic_cast (so the dispatch semantics are identical to the old hand-written observers), but it now lives in exactly one place rather than being copy-pasted into every observer body.
| Derived | The concrete observer (CRTP). |
| ObservedT | The observed type (so this is still an Observer<ObservedT>). |
| ConcreteEvents | The exact event types to subscribe to, e.g. TrackingStarted<EmitterT>. Derived must provide an ObserveResult OnEvent(E const&) overload for each one. |
|
virtualdefault |
|
inlineoverridevirtual |
Observe the observable object being observed.
This is probably in response to NotifyObservers.
This virtual function must be overridden by actual observers, defining how they observe the observable they are observing, probably filtering events and doing something specific for different ones.
| e | The event which was emitted by the observed object. |
Implements bertini::AnyObserver.
|
inlineoverridevirtualinherited |
The type this observer expects to observe.
Used by Observable::AddObserver to reject attaching an observer to an incompatible observable (which would otherwise silently never fire). The default is typeid(void), a wildcard meaning "attach me anywhere"; Observer<ObservedT> reports typeid(ObservedT).
Reimplemented from bertini::AnyObserver.
|
inlineoverridevirtual |
Declares which event types this observer wants to receive.
Return a non-empty vector to opt into type-indexed dispatch: the observable will only call Observe() for events whose dynamic type exactly matches one of the returned type_index values. Return an empty vector (the default) to receive every event — this is the correct choice for observers that handle many or all event types, and is the automatic behavior for Python-defined observers.
Reimplemented from bertini::AnyObserver.