CatapultServer  v0.5.0.1 (Elephant)
AggregateObserverBuilder.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "ObserverTypes.h"
24 #include <vector>
25 
26 namespace catapult { namespace observers {
27 
29  template<typename TNotification>
31  private:
33  using NotificationObserverPointerVector = std::vector<NotificationObserverPointer>;
34 
35  public:
38  m_observers.push_back(std::move(pObserver));
39  return *this;
40  }
41 
44  return std::make_unique<DefaultAggregateNotificationObserver>(std::move(m_observers));
45  }
46 
47  private:
49  public:
51  : m_observers(std::move(observers))
52  , m_name(utils::ReduceNames(utils::ExtractNames(m_observers)))
53  {}
54 
55  public:
56  const std::string& name() const override {
57  return m_name;
58  }
59 
60  std::vector<std::string> names() const override {
62  }
63 
64  void notify(const TNotification& notification, ObserverContext& context) const override {
65  if (NotifyMode::Commit == context.Mode)
66  notifyAll(m_observers.cbegin(), m_observers.cend(), notification, context);
67  else
68  notifyAll(m_observers.crbegin(), m_observers.crend(), notification, context);
69  }
70 
71  private:
72  template<typename TIter>
73  void notifyAll(TIter begin, TIter end, const TNotification& notification, ObserverContext& context) const {
74  for (auto iter = begin; end != iter; ++iter)
75  (*iter)->notify(notification, context);
76  }
77 
78  private:
80  std::string m_name;
81  };
82 
83  private:
85  };
86 }}
catapult::observers::AggregateObserverBuilder::DefaultAggregateNotificationObserver::notifyAll
void notifyAll(TIter begin, TIter end, const TNotification &notification, ObserverContext &context) const
Definition: AggregateObserverBuilder.h:73
catapult::utils::ExtractNames
std::vector< std::string > ExtractNames(const TNamedObjects &namedObjects)
Extracts all names from namedObjects.
Definition: NamedObject.h:46
catapult::observers::ObserverContext
Context passed to all the observers.
Definition: ObserverContext.h:78
catapult::observers::AggregateObserverBuilder::DefaultAggregateNotificationObserver
Definition: AggregateObserverBuilder.h:48
catapult::observers::AggregateObserverBuilder::m_observers
NotificationObserverPointerVector m_observers
Definition: AggregateObserverBuilder.h:84
ObserverTypes.h
catapult::observers::AggregateObserverBuilder::add
AggregateObserverBuilder & add(NotificationObserverPointer &&pObserver)
Adds pObserver to the builder and allows chaining.
Definition: AggregateObserverBuilder.h:37
catapult::utils::ReduceNames
std::string ReduceNames(const std::vector< std::string > &names)
Reduces names into a single string.
Definition: NamedObject.h:56
catapult::observers::AggregateObserverBuilder::build
AggregateNotificationObserverPointerT< TNotification > build()
Builds a strongly typed notification observer.
Definition: AggregateObserverBuilder.h:43
catapult::observers::AggregateObserverBuilder::DefaultAggregateNotificationObserver::names
std::vector< std::string > names() const override
Gets the names of all sub observers.
Definition: AggregateObserverBuilder.h:60
catapult::observers::AggregateObserverBuilder
A strongly typed aggregate notification observer builder.
Definition: AggregateObserverBuilder.h:30
catapult::observers::AggregateObserverBuilder::DefaultAggregateNotificationObserver::name
const std::string & name() const override
Gets the observer name.
Definition: AggregateObserverBuilder.h:56
catapult::observers::AggregateNotificationObserverPointerT
std::unique_ptr< const AggregateNotificationObserverT< TNotification > > AggregateNotificationObserverPointerT
An aggregate notification observer (unique) pointer.
Definition: ObserverTypes.h:41
catapult::observers::AggregateObserverBuilder::DefaultAggregateNotificationObserver::notify
void notify(const TNotification &notification, ObserverContext &context) const override
Notifies the observer with a notification to process and an observer context.
Definition: AggregateObserverBuilder.h:64
NamedObject.h
catapult::observers::AggregateObserverBuilder::DefaultAggregateNotificationObserver::m_name
std::string m_name
Definition: AggregateObserverBuilder.h:80
catapult::observers::AggregateObserverBuilder< catapult::model::Notification >::NotificationObserverPointer
NotificationObserverPointerT< catapult::model::Notification > NotificationObserverPointer
Definition: AggregateObserverBuilder.h:32
catapult::observers::ObserverContext::Mode
const NotifyMode Mode
Notification mode.
Definition: ObserverContext.h:95
catapult::observers::NotificationObserverPointerT
std::unique_ptr< const NotificationObserverT< TNotification > > NotificationObserverPointerT
A notification observer (unique) pointer.
Definition: ObserverTypes.h:34
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::observers::AggregateNotificationObserverT
A strongly typed aggregate notification observer.
Definition: AggregateNotificationObserver.h:29
catapult::observers::AggregateObserverBuilder< catapult::model::Notification >::NotificationObserverPointerVector
std::vector< NotificationObserverPointer > NotificationObserverPointerVector
Definition: AggregateObserverBuilder.h:33
catapult::observers::AggregateObserverBuilder::DefaultAggregateNotificationObserver::DefaultAggregateNotificationObserver
DefaultAggregateNotificationObserver(NotificationObserverPointerVector &&observers)
Definition: AggregateObserverBuilder.h:50
catapult::observers::AggregateObserverBuilder::DefaultAggregateNotificationObserver::m_observers
NotificationObserverPointerVector m_observers
Definition: AggregateObserverBuilder.h:79