Split ParameterVariant into Parameter and ParameterValue#481
Split ParameterVariant into Parameter and ParameterValue#481
Conversation
Test expects ParameterTypeException
|
CI (f002629) |
|
If there was context around this change on another PR, could you link to it please? |
|
@dhood context in #477. Reason behind splitting NodeParameters::create_parameter(std::string name, ParameterType type, ParameterValue default_value = ParameterValue())There are other options with some drawbacks
Admittedly these drawbacks are all pretty minor. Subjectively splitting the classes feels nicer to me because it matches |
| }; | ||
|
|
||
| /// Indicate the parameter type does not match the expected type. | ||
| class ParameterTypeException : public std::exception |
There was a problem hiding this comment.
exception type should be moved to in rclcpp/exceptions.hpp
There was a problem hiding this comment.
I support this. Though I've gone back and forth on putting the exceptions all in one place versus in files where they might be used. You still need something like rclcpp/exceptions.hpp for exceptions which are used all over the place.
There was a problem hiding this comment.
After discussing it offline a289f63 makes ParameterTypeException inherit from std::runtime_error but continue to live in this file so it's constructor can continue to use ParameterType.
wjwwood
left a comment
There was a problem hiding this comment.
lgtm, other than some style comments. No blockers.
rclcpp/include/rclcpp/parameter.hpp
Outdated
| typename std::enable_if<std::is_convertible<type, std::string>::value, const std::string &>::type | ||
| /// Get value of parameter using rclcpp::ParameterType as template argument. | ||
| template<ParameterType ParamT> | ||
| decltype(ParameterValue().get<ParamT>()) |
There was a problem hiding this comment.
This is a bit clunky, is it possible to use auto for the return type? or to improve it with something in the ParameterValue class? So that you could do something like ParameterValue::type<ParamT>::type?
Would just decltype(ParameterValue::get<ParamT>) work?
Or decltype(auto) (http://en.cppreference.com/w/cpp/language/auto)?
I would try one of the alternatives, but I don't have these branches setup locally.
There was a problem hiding this comment.
The rules for auto don't seem to allow for only some of the functions return references. decltype(auto) works! f8646d0
| public: | ||
| /// Construct an instance. | ||
| /// \param[in] expected the expected parameter type. | ||
| /// \param[in] actual the actual parameter type. |
There was a problem hiding this comment.
nitpick: the rest of the code uses:
/// Brief on one line.
/**
* absolutely anything else...
*/
code...
You might want to use this style in the future for consistency.
| }; | ||
|
|
||
| /// Indicate the parameter type does not match the expected type. | ||
| class ParameterTypeException : public std::exception |
There was a problem hiding this comment.
I support this. Though I've gone back and forth on putting the exceptions all in one place versus in files where they might be used. You still need something like rclcpp/exceptions.hpp for exceptions which are used all over the place.
dhood
left a comment
There was a problem hiding this comment.
I didn't get to finish a thorough review but these are some comments from what I got to
| * - rclcpp::Node::list_parameters() | ||
| * - rclcpp::Node::register_param_change_callback() | ||
| * - rclcpp::parameter::ParameterVariant | ||
| * - rclcpp::Parameter |
There was a problem hiding this comment.
could you add parameter_value.hpp below too
rclcpp/include/rclcpp/parameter.hpp
Outdated
| RCLCPP_PUBLIC | ||
| rcl_interfaces::msg::Parameter | ||
| to_parameter(); | ||
| to_parameter() const; |
There was a problem hiding this comment.
IMO the name of this function ought to be renamed now. Parameter.to_parameter is confusing to me. Maybe to_rcl_parameter and from_rcl_parameter above?
There was a problem hiding this comment.
I'm wondering if xxx_rcl_parameter isn't specific enough now that ros2/rcl#235 added rcl_params_t. What do you think of xxx_parameter_message()?
There was a problem hiding this comment.
yeah, or xx_parameter_msg (might be more natural when writing a line like this) but I don't have a strong preference either way: whatever fits better with our existing naming scheme
There was a problem hiding this comment.
to_parameter_msg() and from_parameter_msg() in
22d89b9
Also changed ParameterValue::get_message() to to_value_msg() to match.
4c071ae to
22d89b9
Compare
|
CI looks good. @wjwwood Would you mind checking if the changes since your review look ok? https://github.com/ros2/rclcpp/pull/481/files/f0026290fe8cdddc8aa5e3966c13a139f401c51f..22d89b9ba05bbfb38b389fb120ee31e76034f65b |
|
@sloretz FYI: follow up PR at ros2/navigation#28 |
In progress while CI runs
This PR looks large, but most of the changed lines in this PR are due to renaming
ParameterVarianttoParameter. I can split it into smaller PRs if need be.Changes
ParameterVarianttoParameterrclcpp::parameternamespace (as was done for other namespaces in Remove e.g.node::namespaces and namespace escalation #416)ParameterValueclass.ParameterTypeExceptioninstead ofstd::runtime_errorwhen there is a type mismatchParameter::get_parameter_value()toParameter::get_value_message()consttoParameter::to_parameter()