Skip to content

Commit

Permalink
Add exception for reading wrong message input port
Browse files Browse the repository at this point in the history
Also fix compile warnings in examples
  • Loading branch information
rhysgoldstein committed Dec 16, 2020
1 parent ad069a2 commit 7402d35
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/examples/research/realtime/realtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void realtime::interaction_phase()
}
}
else if (isdigit(input_ch)) {
int64 input_int = input_ch - '0';
int64 input_int = int64(input_ch) - '0';
if (input_int == 0) {
t_syn_rate_ = 0;
}
Expand Down Expand Up @@ -125,8 +125,8 @@ void realtime::print_frame(distance x)
int64 ball_chars = (flight_chars < 48 ? 1 : 0);
int64 animation_padding = 48 - flight_chars - ball_chars;
auto animation_str = std::string(flight_chars, '-') +
std::string(ball_chars, '0') +
std::string(animation_padding, ' ') + "|";
std::string(ball_chars, '0') +
std::string(animation_padding, ' ') + "|";
auto t_str = (string_builder() << t_).str();
int64 t_padding = std::max(int64(0), int64(12 - t_str.length()));
t_str = std::string(t_padding, ' ') + t_str;
Expand Down
2 changes: 1 addition & 1 deletion src/examples/test_systems/data/data_structures_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ inline duration data_structures_node::unplanned_event(duration elapsed_dt)
sv_vector_vector_duration[0][0] *= 1.1;
sv_map_duration_float64[987654321_s] = -10;
sv_set_pair_float64_string.emplace(9.7, "nine point seven");
*sv_rate_ptr = 1/0_s;
*sv_rate_ptr = (1/1_ys).fixed_at(yocto);
ostringstream_var << "received;";

print("ostringstream_var.str() = " + ostringstream_var.str());
Expand Down
5 changes: 5 additions & 0 deletions src/sydevs/systems/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ const T& port<message, input, T>::value() const
throw std::logic_error("Attempt to get value on message input port (" + this->port_name() + ") " +
"of node (" + full_node_name + ") outside of unplanned event");
}
if (const_cast<node_interface&>(this->external_interface()).message_input_port_index() != this->port_index()) {
const auto& full_node_name = const_cast<node_interface&>(this->external_interface()).full_name();
throw std::logic_error("Attempt to get value on message input port (" + this->port_name() + ") " +
"of node (" + full_node_name + "), which was not the port that received the message.");
}
const auto& val = const_cast<node_interface&>(this->external_interface()).message_input_port_value(this->port_index());
return const_cast<const T&>(val.template dereference<T>());
}
Expand Down

0 comments on commit 7402d35

Please sign in to comment.