16 #define LIBCARLA_THROW_INVALID_VALUE(message) throw_exception(InvalidAttributeValue(GetId() + ": " + message)); 17 #define LIBCARLA_THROW_BAD_VALUE_CAST(type) \ 18 if (GetType() != rpc::ActorAttributeType:: type) { \ 19 throw_exception(BadAttributeCast(GetId() + ": bad attribute cast: cannot convert to " #type)); \ 35 bool ActorAttributeValueAccess::As<bool>()
const {
38 if (value ==
"true") {
40 }
else if (value ==
"false") {
47 int ActorAttributeValueAccess::As<int>()
const {
49 return std::atoi(
GetValue().c_str());
53 float ActorAttributeValueAccess::As<float>()
const {
55 double x = std::atof(
GetValue().c_str());
56 if ((x > std::numeric_limits<float>::max()) ||
57 (x < std::numeric_limits<float>::lowest())) {
60 return static_cast<float>(x);
64 std::string ActorAttributeValueAccess::As<std::string>()
const {
73 std::vector<std::string> channels;
75 if (channels.size() != 3u) {
80 auto to_int = [
this](
const std::string &str) {
81 int i = std::atoi(str.c_str());
82 if (i > std::numeric_limits<uint8_t>::max()) {
85 return static_cast<uint8_t
>(i);
88 return {to_int(channels[0u]), to_int(channels[1u]), to_int(channels[2u])};
103 #undef LIBCARLA_THROW_BAD_VALUE_CAST 104 #undef LIBCARLA_THROW_INVALID_VALUE void Set(std::string value)
Set the value of this attribute.
static auto ToLowerCopy(const SequenceT &str)
#define LIBCARLA_THROW_BAD_VALUE_CAST(type)
static void log_error(Args &&... args)
This file contains definitions of common data structures used in traffic manager. ...
virtual rpc::ActorAttributeType GetType() const override
virtual const std::string & GetValue() const override
#define LIBCARLA_THROW_INVALID_VALUE(message)
static void Split(Container &destination, const Range1T &str, const Range2T &separators)
static void ToLower(WritableRangeT &str)
rpc::ActorAttribute _attribute