CARLA
ActorList.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 
10 
11 #include <boost/iterator/transform_iterator.hpp>
12 
13 #include <vector>
14 
15 namespace carla {
16 namespace client {
17 
18  class ActorList : public EnableSharedFromThis<ActorList> {
19  private:
20 
21  template <typename It>
22  auto MakeIterator(It it) const {
23  return boost::make_transform_iterator(it, [this](auto &v) {
24  return v.Get(_episode);
25  });
26  }
27 
28  public:
29 
30  /// Find an actor by id.
31  SharedPtr<Actor> Find(ActorId actor_id) const;
32 
33  /// Filters a list of Actor with type id matching @a wildcard_pattern.
34  SharedPtr<ActorList> Filter(const std::string &wildcard_pattern) const;
35 
36  SharedPtr<Actor> operator[](size_t pos) const {
37  return _actors[pos].Get(_episode);
38  }
39 
40  SharedPtr<Actor> at(size_t pos) const {
41  return _actors.at(pos).Get(_episode);
42  }
43 
44  auto begin() const {
45  return MakeIterator(_actors.begin());
46  }
47 
48  auto end() const {
49  return MakeIterator(_actors.end());
50  }
51 
52  bool empty() const {
53  return _actors.empty();
54  }
55 
56  size_t size() const {
57  return _actors.size();
58  }
59 
60  private:
61 
62  friend class World;
63 
64  ActorList(detail::EpisodeProxy episode, std::vector<rpc::Actor> actors);
65 
67 
68  std::vector<detail::ActorVariant> _actors;
69  };
70 
71 } // namespace client
72 } // namespace carla
auto MakeIterator(It it) const
Definition: ActorList.h:22
bool empty() const
Definition: ActorList.h:52
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
size_t size() const
Definition: ActorList.h:56
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
std::vector< detail::ActorVariant > _actors
Definition: ActorList.h:68
SharedPtr< Actor > at(size_t pos) const
Definition: ActorList.h:40
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
SharedPtr< Actor > operator[](size_t pos) const
Definition: ActorList.h:36
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
auto begin() const
Definition: ActorList.h:44