CARLA
EpisodeProxy.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 <cstdint>
12 
13 namespace carla {
14 namespace client {
15 namespace detail {
16 
17  class Simulator;
18 
20  using Shared = std::shared_ptr<Simulator>;
22  using Weak = std::weak_ptr<Simulator>;
23  };
24 
25  /// Provides access to the Simulator during a given episode. After the episode
26  /// is ended any access to the simulator throws an std::runtime_error.
27  template <typename PointerT>
29  public:
30 
32 
33  EpisodeProxyImpl() = default;
34 
36 
37  template <typename T>
39  : _episode_id(other._episode_id),
40  _simulator(other._simulator) {}
41 
42  auto GetId() const noexcept {
43  return _episode_id;
44  }
45 
46  SharedPtrType TryLock() const noexcept;
47 
48  /// Same as TryLock but never return nullptr.
49  ///
50  /// @throw std::runtime_error if episode is gone.
51  SharedPtrType Lock() const;
52 
53  bool IsValid() const noexcept {
54  return TryLock() != nullptr;
55  }
56 
57  void Clear() noexcept;
58 
59  private:
60 
61  template <typename T>
62  friend class EpisodeProxyImpl;
63 
64  uint64_t _episode_id;
65 
66  PointerT _simulator;
67  };
68 
70 
72 
73 } // namespace detail
74 } // namespace client
75 } // namespace carla
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:99
A very simple atomic shared ptr with release-acquire memory order.
Provides access to the Simulator during a given episode.
Definition: EpisodeProxy.h:28
EpisodeProxyImpl< EpisodeProxyPointerType::Weak > WeakEpisodeProxy
Definition: EpisodeProxy.h:71
EpisodeProxyImpl(EpisodeProxyImpl< T > other)
Definition: EpisodeProxy.h:38