CatapultServer  v0.5.0.1 (Elephant)
FunctionalNotificationObserver.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "NotificationObserver.h"
23 #include "catapult/functions.h"
24 
25 namespace catapult { namespace observers {
26 
28  template<typename TNotification>
30  private:
32 
33  public:
35  explicit FunctionalNotificationObserverT(const std::string& name, const FunctionType& func)
36  : m_name(name)
37  , m_func(func)
38  {}
39 
40  public:
41  const std::string& name() const override {
42  return m_name;
43  }
44 
45  void notify(const TNotification& notification, ObserverContext& context) const override {
46  return m_func(notification, context);
47  }
48 
49  private:
50  std::string m_name;
52  };
53 }}
catapult::observers::FunctionalNotificationObserverT::FunctionalNotificationObserverT
FunctionalNotificationObserverT(const std::string &name, const FunctionType &func)
Creates a functional notification observer around func with name.
Definition: FunctionalNotificationObserver.h:35
NotificationObserver.h
catapult::observers::ObserverContext
Context passed to all the observers.
Definition: ObserverContext.h:78
functions.h
catapult::observers::FunctionalNotificationObserverT
A notification observer implementation that wraps a function.
Definition: FunctionalNotificationObserver.h:29
catapult::observers::NotificationObserverT
A strongly typed notification observer.
Definition: NotificationObserver.h:29
catapult::observers::FunctionalNotificationObserverT::m_func
FunctionType m_func
Definition: FunctionalNotificationObserver.h:51
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::observers::FunctionalNotificationObserverT::notify
void notify(const TNotification &notification, ObserverContext &context) const override
Notifies the observer with a notification to process and an observer context.
Definition: FunctionalNotificationObserver.h:45
catapult::observers::FunctionalNotificationObserverT::name
const std::string & name() const override
Gets the observer name.
Definition: FunctionalNotificationObserver.h:41
catapult::consumer
std::function< void(TArgs...)> consumer
A consumer function.
Definition: functions.h:35
catapult::observers::FunctionalNotificationObserverT::m_name
std::string m_name
Definition: FunctionalNotificationObserver.h:50
catapult::observers::FunctionalNotificationObserverT::FunctionType
consumer< const TNotification &, ObserverContext & > FunctionType
Definition: FunctionalNotificationObserver.h:31