CARLA
 
载入中...
搜索中...
未找到
ActorBlueprint.cpp
浏览该文件的文档.
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
8
9#include "carla/Exception.h"
10#include "carla/StringUtil.h"
11
12#include <algorithm>
13
14namespace carla {
15namespace client {
16
17 template <typename Map, typename Container>
18 static void FillMap(Map &destination, Container &source) {
19 destination.reserve(source.size());
20 for (auto &item : source) {
21 auto id = item.id;
22 destination.emplace(id, std::move(item));
23 }
24 }
25
27 : _uid(definition.uid),
28 _id(std::move(definition.id)) {
29 StringUtil::Split(_tags, definition.tags, ",");
30 FillMap(_attributes, definition.attributes);
31 }
32
33 bool ActorBlueprint::MatchTags(const std::string &wildcard_pattern) const {
34 return
35 StringUtil::Match(_id, wildcard_pattern) ||
36 std::any_of(_tags.begin(), _tags.end(), [&](const auto &tag) {
37 return StringUtil::Match(tag, wildcard_pattern);
38 });
39 }
40
41 const ActorAttribute &ActorBlueprint::GetAttribute(const std::string &id) const {
42 auto it = _attributes.find(id);
43 if (it == _attributes.end()) {
44 using namespace std::string_literals;
45 throw_exception(std::out_of_range("attribute '"s + id + "' not found"));
46 }
47 return it->second;
48 }
49
50 void ActorBlueprint::SetAttribute(const std::string &id, std::string value) {
51 const_cast<ActorAttribute &>(GetAttribute(id)).Set(std::move(value));
52 }
53
55 rpc::ActorDescription description;
56 description.uid = _uid;
57 description.id = _id;
58 description.attributes.reserve(_attributes.size());
59 for (const auto &attribute : *this) {
60 description.attributes.push_back(attribute);
61 }
62 return description;
63 }
64
65} // namespace client
66} // namespace carla
static bool Match(const char *str, const char *wildcard_pattern)
Match str with the Unix shell-style wildcard_pattern.
static void Split(Container &destination, const Range1T &str, const Range2T &separators)
Definition StringUtil.h:66
rpc::ActorDescription MakeActorDescription() const
std::unordered_map< std::string, ActorAttribute > _attributes
const ActorAttribute & GetAttribute(const std::string &id) const
std::unordered_set< std::string > _tags
ActorBlueprint(rpc::ActorDefinition actor_definition)
bool MatchTags(const std::string &wildcard_pattern) const
Test if any of the flags matches wildcard_pattern.
void SetAttribute(const std::string &id, std::string value)
Set the value of the attribute given by id.
static void FillMap(Map &destination, Container &source)
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133
void throw_exception(const std::exception &e)
Definition Carla.cpp:135