CatapultServer  v0.5.0.1 (Elephant)
FunctionalNotificationValidator.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "NotificationValidator.h"
23 #include <functional>
24 
25 namespace catapult { namespace validators {
26 
28  template<typename TNotification, typename... TArgs>
29  class FunctionalNotificationValidatorT : public NotificationValidatorT<TNotification, TArgs...> {
30  private:
31  using FunctionType = std::function<ValidationResult (const TNotification&, TArgs&&...)>;
32 
33  public:
35  explicit FunctionalNotificationValidatorT(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  ValidationResult validate(const TNotification& notification, TArgs&&... args) const override {
46  return m_func(notification, std::forward<TArgs>(args)...);
47  }
48 
49  private:
50  std::string m_name;
52  };
53 }}
NotificationValidator.h
catapult::validators::FunctionalNotificationValidatorT
Notification validator that wraps a function.
Definition: FunctionalNotificationValidator.h:29
catapult::validators::FunctionalNotificationValidatorT::m_func
FunctionType m_func
Definition: FunctionalNotificationValidator.h:51
catapult::validators::NotificationValidatorT
A strongly typed notification validator.
Definition: NotificationValidator.h:30
catapult::validators::FunctionalNotificationValidatorT::validate
ValidationResult validate(const TNotification &notification, TArgs &&... args) const override
Validates a single notification with contextual information args.
Definition: FunctionalNotificationValidator.h:45
catapult::validators::ValidationResult
ValidationResult
Enumeration of all possible validation results.
Definition: ValidationResult.h:51
catapult::validators::FunctionalNotificationValidatorT::m_name
std::string m_name
Definition: FunctionalNotificationValidator.h:50
catapult::validators::FunctionalNotificationValidatorT::name
const std::string & name() const override
Gets the validator name.
Definition: FunctionalNotificationValidator.h:41
catapult::validators::FunctionalNotificationValidatorT::FunctionType
std::function< ValidationResult(const TNotification &, TArgs &&...)> FunctionType
Definition: FunctionalNotificationValidator.h:31
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::validators::FunctionalNotificationValidatorT::FunctionalNotificationValidatorT
FunctionalNotificationValidatorT(const std::string &name, const FunctionType &func)
Creates a functional notification validator around func with name.
Definition: FunctionalNotificationValidator.h:35