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
19 #endif // LIBCARLA_INCLUDED_FROM_UE4
20 
21 namespace carla {
22 namespace rpc {
23 
25  public:
26 
27  ActorAttribute() = default;
28 
29  std::string id;
30 
32 
33  std::string value;
34 
35  std::vector<std::string> recommended_values;
36 
37  bool is_modifiable = true;
38 
40 
41 #ifdef LIBCARLA_INCLUDED_FROM_UE4
42 
43  ActorAttribute(const FActorAttribute &Attribute)
44  : id(FromFString(Attribute.Id)),
45  type(static_cast<ActorAttributeType>(Attribute.Type)),
46  value(FromFString(Attribute.Value)),
47  is_modifiable(false) {}
48 
49  ActorAttribute(const FActorVariation &Variation)
50  : id(FromFString(Variation.Id)),
51  type(static_cast<ActorAttributeType>(Variation.Type)),
52  is_modifiable(true),
54  recommended_values.reserve(Variation.RecommendedValues.Num());
55  for (const auto &Item : Variation.RecommendedValues) {
56  recommended_values.push_back(FromFString(Item));
57  }
58  if (!recommended_values.empty()) {
59  value = recommended_values[0u];
60  }
61  }
62 
63 #endif // LIBCARLA_INCLUDED_FROM_UE4
64 
65  MSGPACK_DEFINE_ARRAY(id, type, value, recommended_values, is_modifiable, restrict_to_recommended);
66  };
67 
69  public:
70 
71  ActorAttributeValue() = default;
72 
74  : id(attribute.id),
75  type(attribute.type),
76  value(attribute.value) {}
77 
78  std::string id;
79 
81 
82  std::string value;
83 
84 #ifdef LIBCARLA_INCLUDED_FROM_UE4
85 
86  ActorAttributeValue(const FActorAttribute &Attribute)
87  : ActorAttributeValue(ActorAttribute(Attribute)) {}
88 
89  operator FActorAttribute() const {
90  FActorAttribute Attribute;
91  Attribute.Id = ToFString(id);
92  Attribute.Type = static_cast<EActorAttributeType>(type);
93  Attribute.Value = ToFString(value);
94  return Attribute;
95  }
96 
97 #endif // LIBCARLA_INCLUDED_FROM_UE4
98 
99  MSGPACK_DEFINE_ARRAY(id, type, value);
100  };
101 
102 } // namespace rpc
103 } // 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:99
An actor attribute, may be an intrinsic (non-modifiable) attribute of the actor or an user-defined ac...
MSGPACK_ADD_ENUM(carla::rpc::ActorAttributeType)