CARLA
 
载入中...
搜索中...
未找到
GraphParser.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// 这是一个预处理指令,用于保证头文件只被包含一次,避免重复定义等问题
8#pragma once
9
10// 包含 CityAreaDescription 头文件,可能定义了与城市区域描述相关的类、结构体、函数等内容
11#include "CityAreaDescription.h"
12// 包含 GraphTypes 头文件,推测是定义了一些图相关的类型等
13#include "GraphTypes.h"
14// 包含 RoadSegmentDescription 头文件,也许是关于路段描述方面的定义
16
17// 包含标准库中 vector 头文件,用于使用 std::vector 容器
18#include <vector>
19
20// 定义名为 MapGen 的命名空间,里面的类、函数等都在这个命名空间作用域内
21namespace MapGen {
22
23 // 前置声明一个名为 DoublyConnectedEdgeList 的类,
24 // 告诉编译器有这么一个类存在,但具体定义在后面或者其他地方,
25 // 这里先允许使用该类的指针或引用等情况
26 class DoublyConnectedEdgeList;
27
28 // 定义 GraphParser 类,它私有继承自 NonCopyable(可能是禁止拷贝构造和赋值操作的基类)
29 class GraphParser : private NonCopyable
30 {
31 public:
32 // 显式构造函数,接受一个 DoublyConnectedEdgeList 类型的引用作为参数,
33 // 用于初始化该类对象与相关的 DoublyConnectedEdgeList 实例关联起来
34 explicit GraphParser(DoublyConnectedEdgeList &Dcel);
35
36 // 成员函数,用于判断是否存在路段(RoadSegments),
37 // 如果 RoadSegments 容器不为空则返回 true,否则返回 false
38 bool HasRoadSegments() const {
39 return!RoadSegments.empty();
40 }
41
42 // 成员函数,用于判断是否存在城市区域(CityAreas),
43 // 如果 CityAreas 容器不为空则返回 true,否则返回 false
44 bool HasCityAreas() const {
45 return!CityAreas.empty();
46 }
47
48 // 成员函数,返回路段(RoadSegments)的数量,即 RoadSegments 容器的大小
49 size_t RoadSegmentCount() const {
50 return RoadSegments.size();
51 }
52
53 // 成员函数,返回城市区域(CityAreas)的数量,即 CityAreas 容器的大小
54 size_t CityAreaCount() const {
55 return CityAreas.size();
56 }
57
58 // 成员函数,返回指定索引位置 i 处的路段描述(RoadSegmentDescription)的常量引用,
59 // 通过解引用存储在 RoadSegments 容器中对应位置的智能指针来获取
61 return *RoadSegments[i];
62 }
63
64 // 成员函数,返回指定索引位置 i 处的城市区域描述(CityAreaDescription)的常量引用,
65 // 通过解引用存储在 CityAreas 容器中对应位置的智能指针来获取
66 const CityAreaDescription &GetCityAreaAt(size_t i) const {
67 return *CityAreas[i];
68 }
69
70 // 成员函数,从 RoadSegments 容器末尾取出一个路段描述(RoadSegmentDescription)的智能指针,
71 // 先释放容器中最后一个元素(智能指针所管理对象的所有权),然后返回这个智能指针,
72 // 同时容器大小减 1,相当于移除了末尾的元素
73 TUniquePtr<RoadSegmentDescription> PopRoadSegment() {
74 TUniquePtr<RoadSegmentDescription> ptr{RoadSegments.back().Release()};
75 RoadSegments.pop_back();
76 return ptr;
77 }
78
79 // 成员函数,从 CityAreas 容器末尾取出一个城市区域描述(CityAreaDescription)的智能指针,
80 // 先释放容器中最后一个元素(智能指针所管理对象的所有权),然后返回这个智能指针,
81 // 同时容器大小减 1,相当于移除了末尾的元素
82 TUniquePtr<CityAreaDescription> PopCityArea() {
83 TUniquePtr<CityAreaDescription> ptr{CityAreas.back().Release()};
84 CityAreas.pop_back();
85 return ptr;
86 }
87
88 private:
89 // 定义一个类型别名 RoadSegmentList,它表示一个存储 TUniquePtr<RoadSegmentDescription> 类型智能指针的 vector 容器,
90 // 用于管理路段描述的相关对象
91 using RoadSegmentList = std::vector<TUniquePtr<RoadSegmentDescription>>;
92
93 // 定义一个类型别名 CityAreaList,它表示一个存储 TUniquePtr<CityAreaDescription> 类型智能指针的 vector 容器,
94 // 用于管理城市区域描述的相关对象
95 using CityAreaList = std::vector<TUniquePtr<CityAreaDescription>>;
96
97 // 定义一个 RoadSegmentList 类型的私有成员变量 RoadSegments,
98 // 用于存储路段描述相关的智能指针,管理一系列路段相关的数据
100
101 // 定义一个 CityAreaList 类型的私有成员变量 CityAreas,
102 // 用于存储城市区域描述相关的智能指针,管理一系列城市区域相关的数据
104 };
105
106} // namespace MapGen
简单的双连通边链表结构。它只允许添加元素,不允许删除元素。
std::vector< TUniquePtr< RoadSegmentDescription > > RoadSegmentList
Definition GraphParser.h:91
RoadSegmentList RoadSegments
Definition GraphParser.h:99
GraphParser(DoublyConnectedEdgeList &Dcel)
TUniquePtr< RoadSegmentDescription > PopRoadSegment()
Definition GraphParser.h:73
const RoadSegmentDescription & GetRoadSegmentAt(size_t i) const
Definition GraphParser.h:60
bool HasCityAreas() const
Definition GraphParser.h:44
bool HasRoadSegments() const
Definition GraphParser.h:38
std::vector< TUniquePtr< CityAreaDescription > > CityAreaList
Definition GraphParser.h:95
CityAreaList CityAreas
size_t RoadSegmentCount() const
Definition GraphParser.h:49
const CityAreaDescription & GetCityAreaAt(size_t i) const
Definition GraphParser.h:66
TUniquePtr< CityAreaDescription > PopCityArea()
Definition GraphParser.h:82
size_t CityAreaCount() const
Definition GraphParser.h:54