hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
validation_error_helpers.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_VALIDATION_ERROR_HELPERS_HPP
7 #define IROHA_VALIDATION_ERROR_HELPERS_HPP
8 
9 #include <optional>
11 
12 namespace shared_model {
13  namespace validation {
14 
17  public:
22  std::optional<ValidationError> getValidationError(
23  const ReasonName &name) &&;
24 
30  template <typename NameProvider>
31  std::optional<ValidationError> getValidationErrorWithGeneratedName(
32  NameProvider &&name_provider) && {
33  if (optional_error_) {
34  optional_error_->name = std::forward<NameProvider>(name_provider)();
35  }
36  return std::move(optional_error_);
37  }
38 
41 
44 
47  std::optional<ReasonType> optional_reason);
48 
51  std::optional<ValidationError> optional_error);
52 
53  private:
54  ValidationError &getOrCreateValidationError();
55 
56  std::optional<ValidationError> optional_error_;
57  };
58 
59  std::optional<ValidationError> operator|(
60  std::optional<ValidationError> oe1, std::optional<ValidationError> oe2);
61 
71  std::optional<ValidationError> aggregateErrors(
72  const ReasonName &name,
73  std::vector<std::optional<ReasonType>> optional_reasons,
74  std::vector<std::optional<ValidationError>> optional_child_errors);
75 
76  } // namespace validation
77 } // namespace shared_model
78 
79 #endif
ValidationErrorCreator & addChildError(ValidationError error)
Add a child error.
Definition: validation_error_helpers.cpp:28
Represents a validation error.
Definition: validation_error.hpp:19
std::optional< ValidationError > getValidationErrorWithGeneratedName(NameProvider &&name_provider) &&
Definition: validation_error_helpers.hpp:31
std::optional< ValidationError > aggregateErrors(const ReasonName &name, std::vector< std::optional< ReasonType >> optional_reasons, std::vector< std::optional< ValidationError >> optional_child_errors)
Definition: validation_error_helpers.cpp:57
std::string ReasonType
Definition: validation_error.hpp:15
ValidationErrorCreator & addReason(ReasonType reason)
Add a reason to error.
Definition: validation_error_helpers.cpp:23
std::optional< ValidationError > getValidationError(const ReasonName &name) &&
Definition: validation_error_helpers.cpp:15
std::optional< ValidationError > operator|(std::optional< ValidationError > oe1, std::optional< ValidationError > oe2)
Definition: validation_error_helpers.cpp:71
Helper class for ValidationError creation.
Definition: validation_error_helpers.hpp:16
std::string ReasonName
Definition: validation_error.hpp:16
Definition: command_executor.hpp:12
ValidationErrorCreator & operator|=(std::optional< ReasonType > optional_reason)
Add a reason, if any.
Definition: validation_error_helpers.cpp:34