CARLA
BlueprintLibrary.cpp
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 
8 
9 #include "carla/Exception.h"
10 
11 #include <algorithm>
12 #include <iterator>
13 
14 namespace carla {
15 namespace 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 
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 
37  auto it = _blueprints.find(key);
38  return it != _blueprints.end() ? &it->second : nullptr;
39  }
40 
42  auto it = _blueprints.find(key);
43  if (it == _blueprints.end()) {
44  using namespace std::string_literals;
45  throw_exception(std::out_of_range("blueprint '"s + key + "' not found"));
46  }
47  return it->second;
48  }
49 
51  if (pos >= size()) {
52  throw_exception(std::out_of_range("index out of range"));
53  }
54  return operator[](pos);
55  }
56 
57 } // namespace client
58 } // namespace carla
std::unordered_map< std::string, ActorBlueprint > map_type
SharedPtr< BlueprintLibrary > Filter(const std::string &wildcard_pattern) const
Filters a list of ActorBlueprint with id or tags matching wildcard_pattern.
void throw_exception(const std::exception &e)
Definition: Carla.cpp:101
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
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:99
const value_type & const_reference
const_pointer Find(const std::string &key) const
const_reference at(const std::string &key) const
Contains all the necessary information for spawning an Actor.
BlueprintLibrary(const std::vector< rpc::ActorDefinition > &blueprints)
const_reference operator[](size_type pos) const