CARLA
 
载入中...
搜索中...
未找到
EpisodeProxy.cpp
浏览该文件的文档.
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
14namespace carla {
15namespace client {
16namespace detail {
17
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>
51 _simulator.reset();
52 }
53
55
58} // namespace detail
59} // namespace client
60} // namespace carla
A very simple atomic shared ptr with release-acquire memory order.
std::shared_ptr< T > load() const noexcept
Provides access to the Simulator during a given episode.
EpisodeProxyPointerType::Shared SharedPtrType
SharedPtrType TryLock() const noexcept
SharedPtrType Lock() const
Same as TryLock but never return nullptr.
static EpisodeProxyPointerType::Shared Load(EpisodeProxyPointerType::Strong ptr)
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133
void throw_exception(const std::exception &e)
Definition Carla.cpp:135