-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exception type should be moved to in rclcpp/exceptions.hpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in bea1335
}; | ||
|
||
/// Indicate the parameter type does not match the expected type. | ||
class ParameterTypeException : public std::exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't get to finish a thorough review but these are some comments from what I got to
@@ -49,7 +49,7 @@ | |||
* - rclcpp::Node::describe_parameters() | |||
* - rclcpp::Node::list_parameters() | |||
* - rclcpp::Node::register_param_change_callback() | |||
* - rclcpp::parameter::ParameterVariant | |||
* - rclcpp::Parameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add parameter_value.hpp
below too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in 18555dc
rclcpp/include/rclcpp/parameter.hpp
Outdated
from_parameter(const rcl_interfaces::msg::Parameter & parameter); | ||
|
||
RCLCPP_PUBLIC | ||
rcl_interfaces::msg::Parameter | ||
to_parameter(); | ||
to_parameter() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
ParameterVariant
toParameter
. I can split it into smaller PRs if need be.Changes
ParameterVariant
toParameter
rclcpp::parameter
namespace (as was done for other namespaces in Remove e.g.node::
namespaces and namespace escalation #416)ParameterValue
class.ParameterTypeException
instead ofstd::runtime_error
when there is a type mismatchParameter::get_parameter_value()
toParameter::get_value_message()
const
toParameter::to_parameter()