17 #ifndef CYBER_PARAMETER_PARAMETER_H_ 18 #define CYBER_PARAMETER_PARAMETER_H_ 22 #include "cyber/proto/parameter.pb.h" 32 using apollo::cyber::proto::Param;
33 using apollo::cyber::proto::ParamType;
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<
239 template <
typename ValueType>
252 template <
typename ValueType>
264 template <
typename ValueType>
266 const std::string&>::type
276 template <
typename ValueType>
284 template <
typename ValueType>
285 typename std::enable_if<
290 if (!message.ParseFromString(param_.string_value())) {
291 AERROR <<
"The type of parameter \"" << param_.name() <<
"\" is " 292 <<
TypeName() <<
", not " << ValueType::descriptor()->full_name();
297 template <
typename ValueType>
302 if (param_.type() != proto::ParamType::INT) {
303 AERROR <<
"The type of parameter \"" << param_.name() <<
"\" is " 306 return static_cast<ValueType
>(param_.int_value());
309 template <
typename ValueType>
313 if (param_.type() != proto::ParamType::DOUBLE) {
314 AERROR <<
"The type of parameter \"" << param_.name() <<
"\" is " 317 return static_cast<ValueType
>(param_.double_value());
320 template <
typename ValueType>
322 const std::string&>::type
324 if (param_.type() != proto::ParamType::STRING &&
325 param_.type() != proto::ParamType::PROTOBUF) {
326 AERROR <<
"The type of parameter \"" << param_.name() <<
"\" is " 329 return param_.string_value();
332 template <
typename ValueType>
335 if (param_.type() != proto::ParamType::BOOL) {
336 AERROR <<
"The type of parameter \"" << param_.name() <<
"\" is " 339 return param_.bool_value();
361 #endif // CYBER_PARAMETER_PARAMETER_H_ void FromProtoParam(const Param ¶m)
Parse a cyber::proto::Param object to cyber::parameter::Parameter object.
Param ToProtoParam() const
Parse a cyber::parameter::Parameter object to cyber::proto::Param object.
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
A Parameter holds an apollo::cyber::proto::Param, It's more human-readable, you can use basic-value t...
Definition: parameter.h:42
const std::string AsString() const
Get Paramter as a string value.
Definition: parameter.h:356
Parameter()
Empty constructor.
std::enable_if< std::is_base_of< google::protobuf::Message, ValueType >::value, ValueType >::type value() const
Translate paramter value as a protobuf::Message.
Definition: parameter.h:288
std::string TypeName() const
Get Paramter's type name, i.e. INT,DOUBLE,STRING or protobuf message's fullname.
Definition: parameter.h:344
std::string DebugString() const
show debug string
double AsDouble() const
et Paramter as a double value
Definition: parameter.h:354
apollo::cyber::base::std value
#define AERROR
Definition: log.h:44
std::string Descriptor() const
Get Paramter's descriptor, only work on protobuf types.
Definition: parameter.h:346
bool AsBool() const
Get Paramter as a bool value.
Definition: parameter.h:350
int64_t AsInt64() const
Get Paramter as an int64_t value.
Definition: parameter.h:352
ParamType Type() const
Get the cyber:parameter::ParamType of this object.
Definition: parameter.h:342
const std::string Name() const
Get the Parameter name.
Definition: parameter.h:348