CARLA
EpisodeProxy.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"
11 
12 #include <exception>
13 
14 namespace carla {
15 namespace client {
16 namespace detail {
17 
19  return ptr.load();
20  }
21 
23  return ptr.lock();
24  }
25 
26  template <typename T>
28  : _episode_id(simulator != nullptr ? simulator->GetCurrentEpisodeId() : 0u),
29  _simulator(std::move(simulator)) {}
30 
31  template <typename T>
33  auto ptr = Load(_simulator);
34  const bool is_valid = (ptr != nullptr) && (_episode_id == ptr->GetCurrentEpisodeId());
35  return is_valid ? ptr : nullptr;
36  }
37 
38  template <typename T>
40  auto ptr = Load(_simulator);
41  if (ptr == nullptr) {
42  throw_exception(std::runtime_error(
43  "trying to operate on a destroyed actor; an actor's function "
44  "was called, but the actor is already destroyed."));
45  }
46  return ptr;
47  }
48 
49  template <typename T>
50  void EpisodeProxyImpl<T>::Clear() noexcept {
51  _simulator.reset();
52  }
53 
55 
57 
58 } // namespace detail
59 } // namespace client
60 } // namespace carla
std::shared_ptr< T > load() const noexcept
void throw_exception(const std::exception &e)
Definition: Carla.cpp:135
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
static EpisodeProxyPointerType::Shared Load(EpisodeProxyPointerType::Strong ptr)
static EpisodeProxyPointerType::Shared Load(EpisodeProxyPointerType::Weak ptr)
A very simple atomic shared ptr with release-acquire memory order.
Provides access to the Simulator during a given episode.
Definition: EpisodeProxy.h:28