31#ifndef BERTINI_DETAIL_OBSERVER_HPP
32#define BERTINI_DETAIL_OBSERVER_HPP
39#include <boost/fusion/adapted/std_tuple.hpp>
41#include <boost/fusion/algorithm/iteration/for_each.hpp>
42#include <boost/fusion/include/for_each.hpp>
68 { BOOST_TYPE_INDEX_REGISTER_CLASS
115 template<
class ObservedT>
117 { BOOST_TYPE_INDEX_REGISTER_CLASS
121 std::type_index
ObservedKind()
const override {
return typeid(ObservedT); }
137 template<
class ObservedT,
template<
class>
class... ObserverTypes>
139 { BOOST_TYPE_INDEX_REGISTER_CLASS
153 using namespace boost::fusion;
159 auto f = [&e,&keep](
auto &obs) {
199 template<
class Derived,
class ObservedT,
class... ConcreteEvents>
201 { BOOST_TYPE_INDEX_REGISTER_CLASS
205 return { std::type_index(
typeid(ConcreteEvents))... };
211 bool matched =
false;
213 (TryDispatch<ConcreteEvents>(e, result, matched), ...);
225 if (
auto p =
dynamic_cast<const Ev*
>(&e))
228 result =
static_cast<Derived*
>(
this)->OnEvent(*p);
Strawman Event type, enabling polymorphism.
Definition events.hpp:57
Strawman base class for Observer objects.
Definition observer.hpp:68
virtual std::type_index ObservedKind() const
The type this observer expects to observe.
Definition observer.hpp:103
virtual ObserveResult Observe(AnyEvent const &e)=0
Observe the observable object being observed.
virtual std::vector< std::type_index > SubscribedEventTypes() const
Declares which event types this observer wants to receive.
Definition observer.hpp:93
virtual ~AnyObserver()=default
A class which can glob together observer types into a new, single observer type.
Definition observer.hpp:139
std::tuple< ObserverTypes< ObservedT >... > observers_
The held sub-observers, one per observer type.
Definition observer.hpp:167
ObserveResult Observe(AnyEvent const &e) override
Observe override which calls the overrides for the types you glued together.
Definition observer.hpp:151
virtual ~MultiObserver()=default
Actual observer type, which you should derive from to extract custom information from observable type...
Definition observer.hpp:117
virtual ~Observer()=default
std::type_index ObservedKind() const override
The type this observer expects to observe.
Definition observer.hpp:121
CRTP base that turns an observer into a set of typed Observe() overloads.
Definition observer.hpp:201
virtual ~TypedObserver()=default
ObserveResult Observe(AnyEvent const &e) override
Observe the observable object being observed.
Definition observer.hpp:208
std::vector< std::type_index > SubscribedEventTypes() const override
Declares which event types this observer wants to receive.
Definition observer.hpp:203
Contains the detail/events base types.
Definition algorithm_builder.hpp:36
ObserveResult
The result an observer returns from Observe(), telling the observable whether to keep sending it even...
Definition observer.hpp:59
@ Unsubscribe
Definition observer.hpp:59
@ KeepObserving
Definition observer.hpp:59