CARLA
 
载入中...
搜索中...
未找到
RoadInfoIterator.h
浏览该文件的文档.
1// Copyright (c) 2019 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
9#include "carla/Debug.h"
11
12#include <iterator>
13#include <memory>
14
15namespace carla {
16namespace road {
17namespace element {
18
19 template <typename T, typename IT>
21 public:
22
23 static_assert(std::is_same<std::unique_ptr<RoadInfo>, typename IT::value_type>::value, "Not compatible.");
24
25 using value_type = T;
26 using difference_type = typename IT::difference_type;
27 using pointer = T *;
28 using reference = T &;
29
30 RoadInfoIterator(IT begin, IT end)
31 : _it(begin),
32 _end(end) {
33 _success = false;
34 for (; !IsAtEnd(); ++_it) {
35 DEBUG_ASSERT((*_it) != nullptr);
36 (*_it)->AcceptVisitor(*this);
37 if (_success) {
38 break;
39 }
40 }
41 }
42
44 _success = false;
45 while (!_success) {
46 ++_it;
47 if (IsAtEnd()) {
48 break;
49 }
50 DEBUG_ASSERT((*_it) != nullptr);
51 (*_it)->AcceptVisitor(*this);
52 }
53 return *this;
54 }
55
57 DEBUG_ASSERT((*_it) != nullptr);
58 return static_cast<T &>(**_it);
59 }
60
62 DEBUG_ASSERT((*_it) != nullptr);
63 return static_cast<T *>(_it->get());
64 }
65
66 bool operator!=(const RoadInfoIterator &rhs) const {
67 return _it != rhs._it;
68 }
69
70 bool operator==(const RoadInfoIterator &rhs) const {
71 return !((*this) != rhs);
72 }
73
74 bool IsAtEnd() const {
75 return _it == _end;
76 }
77
78 private:
79
80 void Visit(T &) {
81 _success = true;
82 }
83
84 IT _it;
85
86 IT _end;
87
89 };
90
91 template <typename T, typename Container>
92 static auto MakeRoadInfoIterator(const Container &c) {
93 auto begin = std::begin(c);
94 auto end = std::end(c);
95 return RoadInfoIterator<T, decltype(begin)>(begin, end);
96 }
97
98 template <typename T, typename IT>
99 static auto MakeRoadInfoIterator(IT begin, IT end) {
100 return RoadInfoIterator<T, decltype(begin)>(begin, end);
101 }
102
103} // namespace element
104} // namespace road
105} // namespace carla
#define DEBUG_ASSERT(predicate)
Definition Debug.h:66
bool operator!=(const RoadInfoIterator &rhs) const
bool operator==(const RoadInfoIterator &rhs) const
typename IT::difference_type difference_type
static auto MakeRoadInfoIterator(const Container &c)
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133