CARLA
ActorList.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/StringUtil.h"
11 
12 #include <iterator>
13 
14 namespace carla {
15 namespace client {
16 
18  detail::EpisodeProxy episode,
19  std::vector<rpc::Actor> actors)
20  : _episode(std::move(episode)),
21  _actors(std::make_move_iterator(actors.begin()), std::make_move_iterator(actors.end())) {}
22 
23  SharedPtr<Actor> ActorList::Find(const ActorId actor_id) const {
24  for (auto &actor : _actors) {
25  if (actor_id == actor.GetId()) {
26  return actor.Get(_episode);
27  }
28  }
29  return nullptr;
30  }
31 
32  SharedPtr<ActorList> ActorList::Filter(const std::string &wildcard_pattern) const {
33  SharedPtr<ActorList> filtered (new ActorList(_episode, {}));
34  for (auto &&actor : _actors) {
35  if (StringUtil::Match(actor.GetTypeId(), wildcard_pattern)) {
36  filtered->_actors.push_back(actor);
37  }
38  }
39  return filtered;
40  }
41 
42 } // namespace client
43 } // namespace carla
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
std::vector< detail::ActorVariant > _actors
Definition: ActorList.h:68
static bool Match(const char *str, const char *wildcard_pattern)
Match str with the Unix shell-style wildcard_pattern.
Definition: StringUtil.cpp:17
carla::ActorId ActorId
SharedPtr< Actor > Find(ActorId actor_id) const
Find an actor by id.
Definition: ActorList.cpp:23
detail::EpisodeProxy _episode
Definition: ActorList.h:66
ActorList(detail::EpisodeProxy episode, std::vector< rpc::Actor > actors)
Definition: ActorList.cpp:17
SharedPtr< ActorList > Filter(const std::string &wildcard_pattern) const
Filters a list of Actor with type id matching wildcard_pattern.
Definition: ActorList.cpp:32