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)); \
38 if (value ==
"true") {
40 }
else if (value ==
"false") {
49 return std::atoi(
GetValue().c_str());
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
#define LIBCARLA_THROW_BAD_VALUE_CAST(type)
#define LIBCARLA_THROW_INVALID_VALUE(message)
static void Split(Container &destination, const Range1T &str, const Range2T &separators)
static auto ToLowerCopy(const SequenceT &str)
static void ToLower(WritableRangeT &str)
virtual const std::string & GetValue() const =0
virtual rpc::ActorAttributeType GetType() const =0
T As() const
Cast the value to the given type.
void Set(std::string value)
Set the value of this attribute.
rpc::ActorAttribute _attribute
virtual rpc::ActorAttributeType GetType() const override
auto ActorAttributeValueAccess::As< rpc::ActorAttributeType::String >() const
auto ActorAttributeValueAccess::As< rpc::ActorAttributeType::Bool >() const
auto ActorAttributeValueAccess::As< rpc::ActorAttributeType::RGBColor >() const
auto ActorAttributeValueAccess::As< rpc::ActorAttributeType::Float >() const
auto ActorAttributeValueAccess::As< rpc::ActorAttributeType::Int >() const
This file contains definitions of common data structures used in traffic manager.
static void log_error(Args &&... args)