CARLA
LibCarla/source/carla/rpc/ActorAttribute.h
Go to the documentation of this file.
1 // Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #pragma once
8 
9 #include "carla/MsgPack.h"
11 #include "carla/rpc/String.h"
12 
13 #include <vector>
14 
16 
17 #ifdef LIBCARLA_INCLUDED_FROM_UE4
21 #endif // LIBCARLA_INCLUDED_FROM_UE4
22 
23 namespace carla {
24 namespace rpc {
25 
27  public:
28 
29  ActorAttribute() = default;
30 
31  std::string id;
32 
34 
35  std::string value;
36 
37  std::vector<std::string> recommended_values;
38 
39  bool is_modifiable = true;
40 
42 
43 #ifdef LIBCARLA_INCLUDED_FROM_UE4
44 
45  ActorAttribute(const FActorAttribute &Attribute)
46  : id(FromFString(Attribute.Id)),
47  type(static_cast<ActorAttributeType>(Attribute.Type)),
48  value(FromFString(Attribute.Value)),
49  is_modifiable(false) {}
50 
51  ActorAttribute(const FActorVariation &Variation)
52  : id(FromFString(Variation.Id)),
53  type(static_cast<ActorAttributeType>(Variation.Type)),
54  is_modifiable(true),
56  recommended_values.reserve(Variation.RecommendedValues.Num());
57  for (const auto &Item : Variation.RecommendedValues) {
58  recommended_values.push_back(FromFString(Item));
59  }
60  if (!recommended_values.empty()) {
61  value = recommended_values[0u];
62  }
63  }
64 
65 #endif // LIBCARLA_INCLUDED_FROM_UE4
66 
67  MSGPACK_DEFINE_ARRAY(id, type, value, recommended_values, is_modifiable, restrict_to_recommended);
68  };
69 
71  public:
72 
73  ActorAttributeValue() = default;
74 
76  : id(attribute.id),
77  type(attribute.type),
78  value(attribute.value) {}
79 
80  std::string id;
81 
83 
84  std::string value;
85 
86 #ifdef LIBCARLA_INCLUDED_FROM_UE4
87 
88  ActorAttributeValue(const FActorAttribute &Attribute)
89  : ActorAttributeValue(ActorAttribute(Attribute)) {}
90 
91  operator FActorAttribute() const {
92  FActorAttribute Attribute;
93  Attribute.Id = ToFString(id);
94  Attribute.Type = static_cast<EActorAttributeType>(type);
95  Attribute.Value = ToFString(value);
96  return Attribute;
97  }
98 
99 #endif // LIBCARLA_INCLUDED_FROM_UE4
100 
101  MSGPACK_DEFINE_ARRAY(id, type, value);
102  };
103 
104 } // namespace rpc
105 } // namespace carla
EActorAttributeType
List of valid types for actor attributes.
MSGPACK_DEFINE_ARRAY(id, type, value, recommended_values, is_modifiable, restrict_to_recommended)
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
An actor attribute, may be an intrinsic (non-modifiable) attribute of the actor or an user-defined ac...
MSGPACK_ADD_ENUM(carla::rpc::ActorAttributeType)