Use enum value to return appropriate values for get_value<>
This commit is contained in:
parent
db0e117c72
commit
d82aa219d3
1 changed files with 51 additions and 51 deletions
|
@ -100,11 +100,6 @@ public:
|
|||
value_.parameter_type = rcl_interfaces::ParameterType::PARAMETER_BYTES;
|
||||
}
|
||||
|
||||
/* Templated getter */
|
||||
template<typename T>
|
||||
T
|
||||
get_value() const;
|
||||
|
||||
inline ParameterType get_type() const {return static_cast<ParameterType>(value_.parameter_type); }
|
||||
|
||||
inline std::string get_name() const & {return name_; }
|
||||
|
@ -114,13 +109,9 @@ public:
|
|||
return value_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
rcl_interfaces::ParameterValue value_;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline int64_t ParameterVariant::get_value() const
|
||||
template<ParameterType type>
|
||||
typename std::enable_if<type == ParameterType::PARAMETER_INTEGER, int64_t>::type
|
||||
get_value() const
|
||||
{
|
||||
if (value_.parameter_type != rcl_interfaces::ParameterType::PARAMETER_INTEGER) {
|
||||
// TODO: use custom exception
|
||||
|
@ -128,8 +119,9 @@ inline int64_t ParameterVariant::get_value() const
|
|||
}
|
||||
return value_.integer_value;
|
||||
}
|
||||
template<>
|
||||
inline double ParameterVariant::get_value() const
|
||||
template<ParameterType type>
|
||||
typename std::enable_if<type == ParameterType::PARAMETER_DOUBLE, double>::type
|
||||
get_value() const
|
||||
{
|
||||
if (value_.parameter_type != rcl_interfaces::ParameterType::PARAMETER_DOUBLE) {
|
||||
// TODO: use custom exception
|
||||
|
@ -137,8 +129,9 @@ inline double ParameterVariant::get_value() const
|
|||
}
|
||||
return value_.double_value;
|
||||
}
|
||||
template<>
|
||||
inline std::string ParameterVariant::get_value() const
|
||||
template<ParameterType type>
|
||||
typename std::enable_if<type == ParameterType::PARAMETER_STRING, const std::string &>::type
|
||||
get_value() const
|
||||
{
|
||||
if (value_.parameter_type != rcl_interfaces::ParameterType::PARAMETER_STRING) {
|
||||
// TODO: use custom exception
|
||||
|
@ -146,8 +139,9 @@ inline std::string ParameterVariant::get_value() const
|
|||
}
|
||||
return value_.string_value;
|
||||
}
|
||||
template<>
|
||||
inline bool ParameterVariant::get_value() const
|
||||
template<ParameterType type>
|
||||
typename std::enable_if<type == ParameterType::PARAMETER_BOOL, bool>::type
|
||||
get_value() const
|
||||
{
|
||||
if (value_.parameter_type != rcl_interfaces::ParameterType::PARAMETER_BOOL) {
|
||||
// TODO: use custom exception
|
||||
|
@ -155,8 +149,9 @@ inline bool ParameterVariant::get_value() const
|
|||
}
|
||||
return value_.bool_value;
|
||||
}
|
||||
template<>
|
||||
inline std::vector<uint8_t> ParameterVariant::get_value() const
|
||||
template<ParameterType type>
|
||||
typename std::enable_if<type == ParameterType::PARAMETER_BYTES, std::vector<uint8_t>>::type
|
||||
get_value() const
|
||||
{
|
||||
if (value_.parameter_type != rcl_interfaces::ParameterType::PARAMETER_BYTES) {
|
||||
// TODO: use custom exception
|
||||
|
@ -165,6 +160,11 @@ inline std::vector<uint8_t> ParameterVariant::get_value() const
|
|||
return value_.bytes_value;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
rcl_interfaces::ParameterValue value_;
|
||||
};
|
||||
|
||||
class AsyncParametersClient
|
||||
{
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue