Use enum value to return appropriate values for get_value<>

This commit is contained in:
Esteve Fernandez 2015-05-04 14:34:38 -07:00
parent db0e117c72
commit d82aa219d3

View file

@ -100,11 +100,6 @@ public:
value_.parameter_type = rcl_interfaces::ParameterType::PARAMETER_BYTES; 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 ParameterType get_type() const {return static_cast<ParameterType>(value_.parameter_type); }
inline std::string get_name() const & {return name_; } inline std::string get_name() const & {return name_; }
@ -114,13 +109,9 @@ public:
return value_; return value_;
} }
private: template<ParameterType type>
std::string name_; typename std::enable_if<type == ParameterType::PARAMETER_INTEGER, int64_t>::type
rcl_interfaces::ParameterValue value_; get_value() const
};
template<>
inline int64_t ParameterVariant::get_value() const
{ {
if (value_.parameter_type != rcl_interfaces::ParameterType::PARAMETER_INTEGER) { if (value_.parameter_type != rcl_interfaces::ParameterType::PARAMETER_INTEGER) {
// TODO: use custom exception // TODO: use custom exception
@ -128,8 +119,9 @@ inline int64_t ParameterVariant::get_value() const
} }
return value_.integer_value; return value_.integer_value;
} }
template<> template<ParameterType type>
inline double ParameterVariant::get_value() const typename std::enable_if<type == ParameterType::PARAMETER_DOUBLE, double>::type
get_value() const
{ {
if (value_.parameter_type != rcl_interfaces::ParameterType::PARAMETER_DOUBLE) { if (value_.parameter_type != rcl_interfaces::ParameterType::PARAMETER_DOUBLE) {
// TODO: use custom exception // TODO: use custom exception
@ -137,8 +129,9 @@ inline double ParameterVariant::get_value() const
} }
return value_.double_value; return value_.double_value;
} }
template<> template<ParameterType type>
inline std::string ParameterVariant::get_value() const typename std::enable_if<type == ParameterType::PARAMETER_STRING, const std::string &>::type
get_value() const
{ {
if (value_.parameter_type != rcl_interfaces::ParameterType::PARAMETER_STRING) { if (value_.parameter_type != rcl_interfaces::ParameterType::PARAMETER_STRING) {
// TODO: use custom exception // TODO: use custom exception
@ -146,8 +139,9 @@ inline std::string ParameterVariant::get_value() const
} }
return value_.string_value; return value_.string_value;
} }
template<> template<ParameterType type>
inline bool ParameterVariant::get_value() const typename std::enable_if<type == ParameterType::PARAMETER_BOOL, bool>::type
get_value() const
{ {
if (value_.parameter_type != rcl_interfaces::ParameterType::PARAMETER_BOOL) { if (value_.parameter_type != rcl_interfaces::ParameterType::PARAMETER_BOOL) {
// TODO: use custom exception // TODO: use custom exception
@ -155,8 +149,9 @@ inline bool ParameterVariant::get_value() const
} }
return value_.bool_value; return value_.bool_value;
} }
template<> template<ParameterType type>
inline std::vector<uint8_t> ParameterVariant::get_value() const 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) { if (value_.parameter_type != rcl_interfaces::ParameterType::PARAMETER_BYTES) {
// TODO: use custom exception // TODO: use custom exception
@ -165,6 +160,11 @@ inline std::vector<uint8_t> ParameterVariant::get_value() const
return value_.bytes_value; return value_.bytes_value;
} }
private:
std::string name_;
rcl_interfaces::ParameterValue value_;
};
class AsyncParametersClient class AsyncParametersClient
{ {