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// 静态函数,用于加载强指针类型的 EpisodeProxyPointerType
21// 静态函数,用于加载弱指针类型的 EpisodeProxyPointerType
23 return ptr.lock();
24 }
25// 模板类 EpisodeProxyImpl 的实现,用于处理强指针类型和弱指针类型的 EpisodeProxyPointerType
26 template <typename T>
28 : _episode_id(simulator != nullptr ? simulator->GetCurrentEpisodeId() : 0u),
29 _simulator(std::move(simulator)) {}
30// 尝试锁定 EpisodeProxyImpl,返回共享指针,如果当前指针有效则返回非空指针,否则返回空指针
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// 锁定 EpisodeProxyImpl,如果模拟器指针为空则抛出异常,否则返回共享指针
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// 清除 EpisodeProxyImpl 的模拟器指针
49 template <typename T>
51 _simulator.reset();
52 }
53// 实例化模板类 EpisodeProxyImpl 分别用于强指针类型和弱指针类型
55
58} // namespace detail
59} // namespace client
60} // namespace carla
线程安全的原子智能指针封装类
std::shared_ptr< T > load() const noexcept
原子加载当前指针值
在给定情节期间提供对模拟器的访问。 情节结束后,对模拟器的任何访问都会引发 std::runtime_error。
EpisodeProxyPointerType::Shared SharedPtrType
SharedPtrType TryLock() const noexcept
SharedPtrType Lock() const
与 TryLock 相同,但永远不会返回 nullptr。
static EpisodeProxyPointerType::Shared Load(EpisodeProxyPointerType::Strong ptr)
CARLA模拟器的主命名空间。
Definition Carla.cpp:139
void throw_exception(const std::exception &e)
Definition Carla.cpp:142
包含CARLA客户端相关类和函数的命名空间。