Byte array parameter rename (#428)

* rename bytes_value to byte_values

* adapt enum to new names

* rename byte_values to byte_array_values

* linters
This commit is contained in:
Mikael Arguedas 2018-01-26 15:03:22 -08:00 committed by GitHub
parent e08c80052a
commit e4b5c0bbb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 14 deletions

View file

@ -38,7 +38,7 @@ enum ParameterType
PARAMETER_INTEGER = rcl_interfaces::msg::ParameterType::PARAMETER_INTEGER, PARAMETER_INTEGER = rcl_interfaces::msg::ParameterType::PARAMETER_INTEGER,
PARAMETER_DOUBLE = rcl_interfaces::msg::ParameterType::PARAMETER_DOUBLE, PARAMETER_DOUBLE = rcl_interfaces::msg::ParameterType::PARAMETER_DOUBLE,
PARAMETER_STRING = rcl_interfaces::msg::ParameterType::PARAMETER_STRING, PARAMETER_STRING = rcl_interfaces::msg::ParameterType::PARAMETER_STRING,
PARAMETER_BYTES = rcl_interfaces::msg::ParameterType::PARAMETER_BYTES, PARAMETER_BYTE_ARRAY = rcl_interfaces::msg::ParameterType::PARAMETER_BYTE_ARRAY,
}; };
// Structure to store an arbitrary parameter with templated get/set methods // Structure to store an arbitrary parameter with templated get/set methods
@ -62,7 +62,9 @@ public:
RCLCPP_PUBLIC RCLCPP_PUBLIC
explicit ParameterVariant(const std::string & name, const char * string_value); explicit ParameterVariant(const std::string & name, const char * string_value);
RCLCPP_PUBLIC RCLCPP_PUBLIC
explicit ParameterVariant(const std::string & name, const std::vector<uint8_t> & bytes_value); explicit ParameterVariant(
const std::string & name,
const std::vector<uint8_t> & byte_array_value);
RCLCPP_PUBLIC RCLCPP_PUBLIC
ParameterType ParameterType
@ -128,14 +130,14 @@ public:
template<ParameterType type> template<ParameterType type>
typename std::enable_if< typename std::enable_if<
type == ParameterType::PARAMETER_BYTES, const std::vector<uint8_t> &>::type type == ParameterType::PARAMETER_BYTE_ARRAY, const std::vector<uint8_t> &>::type
get_value() const get_value() const
{ {
if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_BYTES) { if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_BYTE_ARRAY) {
// TODO(wjwwood): use custom exception // TODO(wjwwood): use custom exception
throw std::runtime_error("Invalid type"); throw std::runtime_error("Invalid type");
} }
return value_.bytes_value; return value_.byte_array_value;
} }
// The following get_value() variants allow the use of primitive types // The following get_value() variants allow the use of primitive types
@ -175,7 +177,7 @@ public:
type, const std::vector<uint8_t> &>::value, const std::vector<uint8_t> &>::type type, const std::vector<uint8_t> &>::value, const std::vector<uint8_t> &>::type
get_value() const get_value() const
{ {
return get_value<ParameterType::PARAMETER_BYTES>(); return get_value<ParameterType::PARAMETER_BYTE_ARRAY>();
} }
RCLCPP_PUBLIC RCLCPP_PUBLIC

View file

@ -76,11 +76,11 @@ ParameterVariant::ParameterVariant(const std::string & name, const char * string
{} {}
ParameterVariant::ParameterVariant( ParameterVariant::ParameterVariant(
const std::string & name, const std::vector<uint8_t> & bytes_value) const std::string & name, const std::vector<uint8_t> & byte_array_value)
: name_(name) : name_(name)
{ {
value_.bytes_value = bytes_value; value_.byte_array_value = byte_array_value;
value_.type = rcl_interfaces::msg::ParameterType::PARAMETER_BYTES; value_.type = rcl_interfaces::msg::ParameterType::PARAMETER_BYTE_ARRAY;
} }
ParameterType ParameterType
@ -101,7 +101,7 @@ ParameterVariant::get_type_name() const
return "double"; return "double";
case rclcpp::parameter::ParameterType::PARAMETER_STRING: case rclcpp::parameter::ParameterType::PARAMETER_STRING:
return "string"; return "string";
case rclcpp::parameter::ParameterType::PARAMETER_BYTES: case rclcpp::parameter::ParameterType::PARAMETER_BYTE_ARRAY:
return "bytes"; return "bytes";
case rclcpp::parameter::ParameterType::PARAMETER_NOT_SET: case rclcpp::parameter::ParameterType::PARAMETER_NOT_SET:
return "not set"; return "not set";
@ -152,7 +152,7 @@ ParameterVariant::as_bool() const
const std::vector<uint8_t> & const std::vector<uint8_t> &
ParameterVariant::as_bytes() const ParameterVariant::as_bytes() const
{ {
return get_value<ParameterType::PARAMETER_BYTES>(); return get_value<ParameterType::PARAMETER_BYTE_ARRAY>();
} }
ParameterVariant ParameterVariant
@ -167,8 +167,8 @@ ParameterVariant::from_parameter(const rcl_interfaces::msg::Parameter & paramete
return ParameterVariant(parameter.name, parameter.value.double_value); return ParameterVariant(parameter.name, parameter.value.double_value);
case PARAMETER_STRING: case PARAMETER_STRING:
return ParameterVariant(parameter.name, parameter.value.string_value); return ParameterVariant(parameter.name, parameter.value.string_value);
case PARAMETER_BYTES: case PARAMETER_BYTE_ARRAY:
return ParameterVariant(parameter.name, parameter.value.bytes_value); return ParameterVariant(parameter.name, parameter.value.byte_array_value);
case PARAMETER_NOT_SET: case PARAMETER_NOT_SET:
throw std::runtime_error("Type from ParameterValue is not set"); throw std::runtime_error("Type from ParameterValue is not set");
default: default:
@ -201,7 +201,7 @@ ParameterVariant::value_to_string() const
return std::to_string(as_double()); return std::to_string(as_double());
case rclcpp::parameter::ParameterType::PARAMETER_STRING: case rclcpp::parameter::ParameterType::PARAMETER_STRING:
return as_string(); return as_string();
case rclcpp::parameter::ParameterType::PARAMETER_BYTES: case rclcpp::parameter::ParameterType::PARAMETER_BYTE_ARRAY:
{ {
std::stringstream bytes; std::stringstream bytes;
bool first_byte = true; bool first_byte = true;