17#ifndef CYBER_PARAMETER_PARAMETER_H_
18#define CYBER_PARAMETER_PARAMETER_H_
22#include "cyber/proto/parameter.pb.h"
59 explicit Parameter(
const std::string& name);
67 Parameter(
const std::string& name,
const bool bool_value);
75 Parameter(
const std::string& name,
const int int_value);
83 Parameter(
const std::string& name,
const int64_t int_value);
91 Parameter(
const std::string& name,
const float float_value);
99 Parameter(
const std::string& name,
const double double_value);
107 Parameter(
const std::string& name,
const std::string& string_value);
115 Parameter(
const std::string& name,
const char* string_value);
125 Parameter(
const std::string& name,
const std::string& msg_str,
126 const std::string& full_name,
const std::string& proto_desc);
135 Parameter(
const std::string& name,
const google::protobuf::Message& msg);
157 inline ParamType
Type()
const;
165 inline std::string
TypeName()
const;
179 inline const std::string
Name()
const;
187 inline bool AsBool()
const;
194 inline int64_t
AsInt64()
const;
208 inline const std::string
AsString()
const;
225 template <
typename ValueType>
226 typename std::enable_if<
227 std::is_base_of<google::protobuf::Message, ValueType>::value,
239 template <
typename ValueType>
240 typename std::enable_if<std::is_integral<ValueType>::value &&
241 !std::is_same<ValueType, bool>::value,
252 template <
typename ValueType>
253 typename std::enable_if<std::is_floating_point<ValueType>::value,
264 template <
typename ValueType>
265 typename std::enable_if<std::is_convertible<ValueType, std::string>::value,
266 const std::string&>::type
276 template <
typename ValueType>
277 typename std::enable_if<std::is_same<ValueType, bool>::value,
bool>::type
284template <
typename ValueType>
285typename std::enable_if<
286 std::is_base_of<google::protobuf::Message, ValueType>::value,
290 if (!message.ParseFromString(param_.string_value())) {
291 AERROR <<
"The type of parameter \"" << param_.
name() <<
"\" is "
292 <<
TypeName() <<
", not " << ValueType::descriptor()->full_name();
297template <
typename ValueType>
298typename std::enable_if<std::is_integral<ValueType>::value &&
299 !std::is_same<ValueType, bool>::value,
303 AERROR <<
"The type of parameter \"" << param_.
name() <<
"\" is "
306 return static_cast<ValueType
>(param_.int_value());
309template <
typename ValueType>
310typename std::enable_if<std::is_floating_point<ValueType>::value,
314 AERROR <<
"The type of parameter \"" << param_.
name() <<
"\" is "
317 return static_cast<ValueType
>(param_.double_value());
320template <
typename ValueType>
321typename std::enable_if<std::is_convertible<ValueType, std::string>::value,
322 const std::string&>::type
326 AERROR <<
"The type of parameter \"" << param_.
name() <<
"\" is "
329 return param_.string_value();
332template <
typename ValueType>
333typename std::enable_if<std::is_same<ValueType, bool>::value,
bool>::type
336 AERROR <<
"The type of parameter \"" << param_.
name() <<
"\" is "
339 return param_.bool_value();
A Parameter holds an apollo::cyber::proto::Param, It's more human-readable, you can use basic-value t...
std::enable_if< std::is_floating_point< ValueType >::value, ValueType >::type value() const
std::enable_if< std::is_base_of< google::protobuf::Message, ValueType >::value, ValueType >::type value() const
std::string TypeName() const
Get Paramter's type name, i.e.
void FromProtoParam(const Param ¶m)
Parse a cyber::proto::Param object to cyber::parameter::Parameter object
Parameter()
Empty constructor
double AsDouble() const
et Paramter as a double value
std::enable_if< std::is_integral< ValueType >::value &&!std::is_same< ValueType, bool >::value, ValueType >::type value() const
std::string DebugString() const
show debug string
std::enable_if< std::is_convertible< ValueType, std::string >::value, conststd::string & >::type value() const
int64_t AsInt64() const
Get Paramter as an int64_t value
ParamType Type() const
Get the cyber:parameter::ParamType of this object
std::string Descriptor() const
Get Paramter's descriptor, only work on protobuf types
bool AsBool() const
Get Paramter as a bool value
const std::string AsString() const
Get Paramter as a string value
Param ToProtoParam() const
Parse a cyber::parameter::Parameter object to cyber::proto::Param object
const std::string Name() const
Get the Parameter name
optional string type_name
optional bytes proto_desc