32#include "Bmi_Adapter.hpp"
33#include "JSONProperty.hpp"
34#include <nonstd/expected.hpp>
39using nonstd::expected;
40using nonstd::make_unexpected;
68 return "Error(Uninitialized Model)::" +
message;
70 return "Warning(Unsupported Protocol)::" +
message;
72 return "Error(Integration)::" +
message;
74 return "Error(Protocol)::" +
message;
76 return "Warning(Protocol)::" +
message;
78 return "Unknown Error: " +
message;
90 const char*
what() const noexcept
override {
104 const std::string&
id;
107using ModelPtr = std::shared_ptr<models::bmi::Bmi_Adapter>;
131 switch (err.error_code()) {
139 std::cerr << err.to_string() << std::endl;
140 return make_unexpected<ProtocolError>(
ProtocolError(std::move(err)));
144 assert(
false &&
"Unreachable code reached in error_or_warning");
164 -> expected<void, ProtocolError> = 0;
198 -> expected<void, ProtocolError> = 0;
Definition protocol.hpp:110
virtual bool is_supported() const =0
Whether the protocol is supported by the model.
virtual nsel_NODISCARD expected< void, ProtocolError > check_support(const ModelPtr &model)=0
Check if the BMI protocol is supported by the model.
virtual auto initialize(const ModelPtr &model, const Properties &properties) -> expected< void, ProtocolError >=0
Initialize the BMI protocol from a set of key/value properties.
virtual ~NgenBmiProtocol()=default
Abstract interface for a generic BMI protocol.
static auto error_or_warning(const ProtocolError &err) -> expected< void, ProtocolError >
Handle a ProtocolError by either throwing it or logging it as a warning.
Definition protocol.hpp:129
virtual nsel_NODISCARD auto run(const ModelPtr &model, const Context &ctx) const -> expected< void, ProtocolError >=0
Run the BMI protocol against the given model.
Definition protocols.hpp:45
Definition protocol.hpp:50
std::string message
Definition protocol.hpp:97
const char * what() const noexcept override
Definition protocol.hpp:90
Error err
Definition protocol.hpp:96
auto error_code() const -> const Error &
Definition protocol.hpp:82
ProtocolError & operator=(ProtocolError &&other) noexcept=default
ProtocolError(Error err, const std::string &message="")
Definition protocol.hpp:54
ProtocolError(const ProtocolError &other)=default
ProtocolError & operator=(const ProtocolError &other)=default
auto get_message() const -> const std::string &
Definition protocol.hpp:86
ProtocolError(ProtocolError &&other) noexcept=default
auto to_string() const -> std::string
Definition protocol.hpp:65
std::map< std::string, JSONProperty > PropertyMap
Shorthand for a mapping between strings and properties.
Definition JSONProperty.hpp:21
Definition deserialization.hpp:40
std::shared_ptr< models::bmi::Bmi_Adapter > ModelPtr
Definition protocol.hpp:107
geojson::PropertyMap Properties
Definition protocol.hpp:108
Error
Definition protocol.hpp:42
Definition AbstractCLibBmiAdapter.hpp:6
Definition protocol.hpp:100
const std::string & id
Definition protocol.hpp:104
const std::string & timestamp
Definition protocol.hpp:103
const int total_steps
Definition protocol.hpp:102
const int current_time_step
Definition protocol.hpp:101