CatapultServer  v0.5.0.1 (Elephant)
DemuxValidatorBuilder.h
Go to the documentation of this file.
1 
21 #pragma once
23 #include "ValidatorTypes.h"
24 #include <functional>
25 #include <vector>
26 
27 namespace catapult { namespace validators {
28 
30  template<typename... TArgs>
32  private:
33  template<typename TNotification>
34  using NotificationValidatorPointerT = std::unique_ptr<const NotificationValidatorT<TNotification, TArgs...>>;
37 
38  public:
40  template<typename TNotification>
42  if constexpr (!std::is_same_v<model::Notification, TNotification>) {
43  auto predicate = [type = TNotification::Notification_Type](const auto& notification) {
44  return model::AreEqualExcludingChannel(type, notification.Type);
45  };
46  m_builder.add(std::make_unique<ConditionalValidator<TNotification>>(std::move(pValidator), predicate));
47  return *this;
48  } else {
49  m_builder.add(std::move(pValidator));
50  return *this;
51  }
52  }
53 
56  return add<model::Notification>(std::move(pValidator));
57  }
58 
61  return m_builder.build(isSuppressedFailure);
62  }
63 
64  private:
65  template<typename TNotification>
66  class ConditionalValidator : public NotificationValidatorT<model::Notification, TArgs...> {
67  public:
71  : m_pValidator(std::move(pValidator))
73  {}
74 
75  public:
76  const std::string& name() const override {
77  return m_pValidator->name();
78  }
79 
80  ValidationResult validate(const model::Notification& notification, TArgs&&... args) const override {
81  if (!m_predicate(notification))
83 
84  return m_pValidator->validate(static_cast<const TNotification&>(notification), std::forward<TArgs>(args)...);
85  }
86 
87  private:
90  };
91 
92  private:
94  };
95 }}
catapult::validators::DemuxValidatorBuilderT::AggregateValidatorPointer
std::unique_ptr< const AggregateNotificationValidatorT< model::Notification, TArgs... > > AggregateValidatorPointer
Definition: DemuxValidatorBuilder.h:36
catapult::validators::DemuxValidatorBuilderT
A demultiplexing validator builder.
Definition: DemuxValidatorBuilder.h:31
catapult::validators::DemuxValidatorBuilderT::ConditionalValidator
Definition: DemuxValidatorBuilder.h:66
catapult::validators::DemuxValidatorBuilderT::m_builder
AggregateValidatorBuilder< model::Notification, TArgs... > m_builder
Definition: DemuxValidatorBuilder.h:93
catapult::validators::DemuxValidatorBuilderT::ConditionalValidator::validate
ValidationResult validate(const model::Notification &notification, TArgs &&... args) const override
Validates a single notification with contextual information args.
Definition: DemuxValidatorBuilder.h:80
catapult::predicate
std::function< bool(TArgs...)> predicate
A predicate function.
Definition: functions.h:31
catapult::validators::NotificationValidatorT
A strongly typed notification validator.
Definition: NotificationValidator.h:30
catapult::validators::ValidationResult
ValidationResult
Enumeration of all possible validation results.
Definition: ValidationResult.h:51
catapult::validators::Notification
model::AccountAddressNotification Notification
Definition: AddressValidator.cpp:27
catapult::validators::AggregateValidatorBuilder
A strongly typed aggregate notification validator builder.
Definition: AggregateValidatorBuilder.h:31
catapult::validators::DemuxValidatorBuilderT::build
AggregateValidatorPointer build(const ValidationResultPredicate &isSuppressedFailure)
Builds a demultiplexing validator that ignores suppressed failures according to isSuppressedFailure.
Definition: DemuxValidatorBuilder.h:60
catapult::validators::DemuxValidatorBuilderT::NotificationValidatorPredicate
predicate< const model::Notification & > NotificationValidatorPredicate
Definition: DemuxValidatorBuilder.h:35
catapult::validators::DemuxValidatorBuilderT::add
DemuxValidatorBuilderT & add(NotificationValidatorPointerT< model::Notification > &&pValidator)
Adds a validator (pValidator) to the builder that is always invoked.
Definition: DemuxValidatorBuilder.h:55
catapult::validators::AggregateNotificationValidatorT
A strongly typed aggregate notification validator.
Definition: AggregateNotificationValidator.h:29
catapult::validators::DemuxValidatorBuilderT::ConditionalValidator::m_pValidator
NotificationValidatorPointerT< TNotification > m_pValidator
Definition: DemuxValidatorBuilder.h:88
catapult::validators::DemuxValidatorBuilderT::ConditionalValidator::m_predicate
NotificationValidatorPredicate m_predicate
Definition: DemuxValidatorBuilder.h:89
AggregateValidatorBuilder.h
catapult::validators::ValidationResultPredicate
predicate< ValidationResult > ValidationResultPredicate
Validation result predicate.
Definition: ValidatorTypes.h:42
catapult::validators::DemuxValidatorBuilderT::ConditionalValidator::name
const std::string & name() const override
Gets the validator name.
Definition: DemuxValidatorBuilder.h:76
catapult::model::Notification
A basic notification.
Definition: Notifications.h:36
ValidatorTypes.h
catapult::validators::ValidationResult::Success
Validation succeeded.
catapult::validators::DemuxValidatorBuilderT::NotificationValidatorPointerT
std::unique_ptr< const NotificationValidatorT< TNotification, TArgs... > > NotificationValidatorPointerT
Definition: DemuxValidatorBuilder.h:34
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::validators::DemuxValidatorBuilderT::ConditionalValidator::ConditionalValidator
ConditionalValidator(NotificationValidatorPointerT< TNotification > &&pValidator, const NotificationValidatorPredicate &predicate)
Definition: DemuxValidatorBuilder.h:68
catapult::model::AreEqualExcludingChannel
constexpr bool AreEqualExcludingChannel(NotificationType lhs, NotificationType rhs)
Returns true if lhs and rhs have the same source (facility and code).
Definition: NotificationType.h:78
catapult::validators::DemuxValidatorBuilderT::add
DemuxValidatorBuilderT & add(NotificationValidatorPointerT< TNotification > &&pValidator)
Adds a validator (pValidator) to the builder that is invoked only when matching notifications are pro...
Definition: DemuxValidatorBuilder.h:41