fully delete parameters (#489)
* allow ParameterValue class to be copy constructed with type not-set * actually remove deleted parameters from the map
This commit is contained in:
parent
2a17232ad0
commit
5ab6bde1db
3 changed files with 23 additions and 17 deletions
|
@ -88,27 +88,34 @@ NodeParameters::set_parameters_atomically(
|
|||
}
|
||||
|
||||
for (auto p : parameters) {
|
||||
if (parameters_.find(p.get_name()) == parameters_.end()) {
|
||||
if (p.get_type() != rclcpp::ParameterType::PARAMETER_NOT_SET) {
|
||||
if (p.get_type() == rclcpp::ParameterType::PARAMETER_NOT_SET) {
|
||||
if (parameters_.find(p.get_name()) != parameters_.end()) {
|
||||
// case: parameter was set before, and input is "NOT_SET"
|
||||
// therefore we will erase the parameter from parameters_ later
|
||||
parameter_event->deleted_parameters.push_back(p.to_parameter_msg());
|
||||
}
|
||||
} else {
|
||||
if (parameters_.find(p.get_name()) == parameters_.end()) {
|
||||
// case: parameter not set before, and input is something other than "NOT_SET"
|
||||
parameter_event->new_parameters.push_back(p.to_parameter_msg());
|
||||
} else {
|
||||
// case: parameter was set before, and input is something other than "NOT_SET"
|
||||
parameter_event->changed_parameters.push_back(p.to_parameter_msg());
|
||||
}
|
||||
} else if (p.get_type() != rclcpp::ParameterType::PARAMETER_NOT_SET) {
|
||||
// case: parameter was set before, and input is something other than "NOT_SET"
|
||||
parameter_event->changed_parameters.push_back(p.to_parameter_msg());
|
||||
} else {
|
||||
// case: parameter was set before, and input is "NOT_SET"
|
||||
// therefore we will "unset" the previously set parameter
|
||||
// it is not necessary to erase the parameter from parameters_
|
||||
// because the new value for this key (p.get_name()) will be a
|
||||
// Parameter with type "NOT_SET"
|
||||
parameter_event->deleted_parameters.push_back(p.to_parameter_msg());
|
||||
tmp_map[p.get_name()] = p;
|
||||
}
|
||||
tmp_map[p.get_name()] = p;
|
||||
}
|
||||
// std::map::insert will not overwrite elements, so we'll keep the new
|
||||
// ones and add only those that already exist in the Node's internal map
|
||||
tmp_map.insert(parameters_.begin(), parameters_.end());
|
||||
|
||||
// remove explicitly deleted parameters
|
||||
for (auto p : parameters) {
|
||||
if (p.get_type() == rclcpp::ParameterType::PARAMETER_NOT_SET) {
|
||||
tmp_map.erase(p.get_name());
|
||||
}
|
||||
}
|
||||
|
||||
std::swap(tmp_map, parameters_);
|
||||
|
||||
events_publisher_->publish(parameter_event);
|
||||
|
|
|
@ -126,9 +126,8 @@ ParameterValue::ParameterValue(const rcl_interfaces::msg::ParameterValue & value
|
|||
case PARAMETER_INTEGER_ARRAY:
|
||||
case PARAMETER_DOUBLE_ARRAY:
|
||||
case PARAMETER_STRING_ARRAY:
|
||||
break;
|
||||
case PARAMETER_NOT_SET:
|
||||
throw std::runtime_error("Type from ParameterValue is not set");
|
||||
break;
|
||||
default:
|
||||
// TODO(wjwwood): use custom exception
|
||||
throw std::runtime_error("Unknown type: " + std::to_string(value.type));
|
||||
|
|
|
@ -53,8 +53,8 @@ TEST(TestParameter, not_set_variant) {
|
|||
EXPECT_EQ(rcl_interfaces::msg::ParameterType::PARAMETER_NOT_SET, not_set_param.value.type);
|
||||
|
||||
// From parameter message
|
||||
EXPECT_THROW(rclcpp::Parameter::from_parameter_msg(not_set_param),
|
||||
std::runtime_error);
|
||||
EXPECT_EQ(rclcpp::ParameterType::PARAMETER_NOT_SET,
|
||||
rclcpp::Parameter::from_parameter_msg(not_set_param).get_type());
|
||||
}
|
||||
|
||||
TEST(TestParameter, bool_variant) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue