CARLA
 
载入中...
搜索中...
未找到
EpisodeProxy.h
浏览该文件的文档.
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
13namespace carla {
14namespace client {
15namespace detail {
16
17 class Simulator;// 前向声明 Simulator 类,表示仿真器类,用于与仿真环境进行交互
18
19 // 定义 EpisodeProxyPointerType 结构体,封装了不同类型的智能指针,用于管理对 Simulator 的引用
20 //定义了三种不同类型的智能指针,用于引用 Simulator 对象。每种指针类型具有不同的生命周期管理策略
22 using Shared = std::shared_ptr<Simulator>;
24 using Weak = std::weak_ptr<Simulator>;
25 };
26
27 /// 在给定情节期间提供对模拟器的访问。
28 /// 情节结束后,对模拟器的任何访问都会引发 std::runtime_error。
29 template <typename PointerT>
31 public:
32
33 // 构造函数,初始化时传入一个 SharedPtrType(SharedPtr 类型的 Simulator 智能指针)
35
36 EpisodeProxyImpl() = default;
37
38 // 构造函数,初始化时传入一个 SharedPtrType
40
41 // 复制构造函数:将另一个 EpisodeProxyImpl<T> 对象的状态复制过来
42 template <typename T>
44 : _episode_id(other._episode_id), // 复制 episode_id
45 _simulator(other._simulator) {}// 复制 simulator 智能指针
46
47 // 返回 episode 的唯一 ID
48 auto GetId() const noexcept {
49 return _episode_id;
50 }
51 // 尝试获取锁,返回一个 SharedPtr(可能为空)
52 SharedPtrType TryLock() const noexcept;
53
54 /// 与 TryLock 相同,但永远不会返回 nullptr。
55 ///
56 /// @throw 如果剧集结束,则发生 std::runtime_error。
57 SharedPtrType Lock() const;
58
59 // 检查当前 episode 是否有效,即 TryLock 是否返回非 nullptr
60 bool IsValid() const noexcept {
61 return TryLock() != nullptr;
62 }
63
64 // 清空当前 EpisodeProxyImpl 的状态
65 void Clear() noexcept;
66
67 private:
68
69 // 友元声明:允许其他模板实例访问该类的私有成员
70 template <typename T>
71 friend class EpisodeProxyImpl;
72
73 uint64_t _episode_id;// 存储当前 episode 的唯一 ID
74
75 PointerT _simulator; // 存储 Simulator 类型的智能指针
76 };
77 // 定义 EpisodeProxy 类型,使用 Strong 类型的智能指针来管理 Simulator
79 // 定义 WeakEpisodeProxy 类型,使用 Weak 类型的智能指针来管理 Simulator
81
82} // namespace detail
83} // namespace client
84} // namespace carla
线程安全的原子智能指针封装类
在给定情节期间提供对模拟器的访问。 情节结束后,对模拟器的任何访问都会引发 std::runtime_error。
EpisodeProxyPointerType::Shared SharedPtrType
SharedPtrType TryLock() const noexcept
EpisodeProxyImpl(EpisodeProxyImpl< T > other)
SharedPtrType Lock() const
与 TryLock 相同,但永远不会返回 nullptr。
EpisodeProxyImpl< EpisodeProxyPointerType::Weak > WeakEpisodeProxy
CARLA模拟器的主命名空间。
Definition Carla.cpp:139
包含CARLA客户端相关类和函数的命名空间。