CARLA
 
载入中...
搜索中...
未找到
BlueprintLibrary.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
11#include <algorithm>
12#include <iterator>
13
14namespace carla {
15namespace client {
16
18 const std::vector<rpc::ActorDefinition> &blueprints) {
19 _blueprints.reserve(blueprints.size());
20 for (auto &definition : blueprints) {
21 _blueprints.emplace(definition.id, ActorBlueprint{definition});
22 }
23 }
24
25 SharedPtr<BlueprintLibrary> BlueprintLibrary::Filter(
26 const std::string &wildcard_pattern) const {
27 map_type result;
28 for (auto &pair : _blueprints) {
29 if (pair.second.MatchTags(wildcard_pattern)) {
30 result.emplace(pair);
31 }
32 }
34 }
35
36 SharedPtr<BlueprintLibrary> BlueprintLibrary::FilterByAttribute(
37 const std::string &name, const std::string& value) const {
38 map_type result;
39
40 for (auto &pair : _blueprints) {
41 if (!pair.second.ContainsAttribute(name))
42 continue;
43 const ActorAttribute &Attribute = pair.second.GetAttribute(name);
44 const std::vector<std::string> &Values = Attribute.GetRecommendedValues();
45 if (Values.empty())
46 {
47 const std::string &AttributeValue = Attribute.GetValue();
48 if (value == AttributeValue)
49 result.emplace(pair);
50 }
51 else
52 {
53 for (const std::string &Value : Values)
54 {
55 if (Value == value)
56 {
57 result.emplace(pair);
58 break;
59 }
60 }
61 }
62
63 }
65 }
66
67 BlueprintLibrary::const_pointer BlueprintLibrary::Find(const std::string &key) const {
68 auto it = _blueprints.find(key);
69 return it != _blueprints.end() ? &it->second : nullptr;
70 }
71
72 BlueprintLibrary::const_reference BlueprintLibrary::at(const std::string &key) const {
73 auto it = _blueprints.find(key);
74 if (it == _blueprints.end()) {
75 using namespace std::string_literals;
76 throw_exception(std::out_of_range("blueprint '"s + key + "' not found"));
77 }
78 return it->second;
79 }
80
81 BlueprintLibrary::const_reference BlueprintLibrary::at(size_type pos) const {
82 if (pos >= size()) {
83 throw_exception(std::out_of_range("index out of range"));
84 }
85 return operator[](pos);
86 }
87
88} // namespace client
89} // namespace carla
virtual const std::string & GetValue() const override
const std::vector< std::string > & GetRecommendedValues() const
Contains all the necessary information for spawning an Actor.
std::unordered_map< std::string, ActorBlueprint > map_type
BlueprintLibrary(const std::vector< rpc::ActorDefinition > &blueprints)
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
boost::shared_ptr< T > SharedPtr
Use this SharedPtr (boost::shared_ptr) to keep compatibility with boost::python, but it would be nice...
Definition Memory.h:20