From 19ce185c93687cb90a7f0f52da51e42da7b1b685 Mon Sep 17 00:00:00 2001 From: nsubiron Date: Wed, 27 Mar 2019 14:14:18 +0100 Subject: [PATCH] Move RoadInfoIterator to its own header --- LibCarla/source/carla/road/InformationSet.h | 5 +- .../carla/road/element/RoadInfoIterator.h | 105 ++++++++++++++++++ .../carla/road/element/RoadInfoVisitor.h | 89 --------------- 3 files changed, 107 insertions(+), 92 deletions(-) create mode 100644 LibCarla/source/carla/road/element/RoadInfoIterator.h diff --git a/LibCarla/source/carla/road/InformationSet.h b/LibCarla/source/carla/road/InformationSet.h index e6e823b0c..fc314244b 100644 --- a/LibCarla/source/carla/road/InformationSet.h +++ b/LibCarla/source/carla/road/InformationSet.h @@ -6,10 +6,10 @@ #pragma once +#include "carla/NonCopyable.h" #include "carla/road/RoadElementSet.h" #include "carla/road/element/RoadInfo.h" -#include "carla/road/element/RoadInfoVisitor.h" -#include "carla/NonCopyable.h" +#include "carla/road/element/RoadInfoIterator.h" #include #include @@ -47,7 +47,6 @@ namespace road { private: RoadElementSet> _road_set; - }; } // road diff --git a/LibCarla/source/carla/road/element/RoadInfoIterator.h b/LibCarla/source/carla/road/element/RoadInfoIterator.h new file mode 100644 index 000000000..254722eb6 --- /dev/null +++ b/LibCarla/source/carla/road/element/RoadInfoIterator.h @@ -0,0 +1,105 @@ +// Copyright (c) 2019 Computer Vision Center (CVC) at the Universitat Autonoma +// de Barcelona (UAB). +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#pragma once + +#include "carla/Debug.h" +#include "carla/road/element/RoadInfoVisitor.h" + +#include +#include + +namespace carla { +namespace road { +namespace element { + + template + class RoadInfoIterator : private RoadInfoVisitor { + public: + + static_assert(std::is_same, typename IT::value_type>::value, "Not compatible."); + + using value_type = T; + using difference_type = typename IT::difference_type; + using pointer = T *; + using reference = T &; + + RoadInfoIterator(IT begin, IT end) + : _it(begin), + _end(end) { + _success = false; + for (; !IsAtEnd(); ++_it) { + DEBUG_ASSERT((*_it) != nullptr); + (*_it)->AcceptVisitor(*this); + if (_success) { + break; + } + } + } + + RoadInfoIterator &operator++() { + _success = false; + while (!_success) { + ++_it; + if (IsAtEnd()) { + break; + } + DEBUG_ASSERT((*_it) != nullptr); + (*_it)->AcceptVisitor(*this); + } + return *this; + } + + reference operator*() const { + DEBUG_ASSERT((*_it) != nullptr); + return static_cast(**_it); + } + + pointer operator->() const { + DEBUG_ASSERT((*_it) != nullptr); + return static_cast(_it->get()); + } + + bool operator!=(const RoadInfoIterator &rhs) const { + return _it != rhs._it; + } + + bool operator==(const RoadInfoIterator &rhs) const { + return !((*this) != rhs); + } + + bool IsAtEnd() const { + return _it == _end; + } + + private: + + void Visit(T &) { + _success = true; + } + + IT _it; + + IT _end; + + bool _success; + }; + + template + static auto MakeRoadInfoIterator(const Container &c) { + auto begin = std::begin(c); + auto end = std::end(c); + return RoadInfoIterator(begin, end); + } + + template + static auto MakeRoadInfoIterator(IT begin, IT end) { + return RoadInfoIterator(begin, end); + } + +} // namespace element +} // namespace road +} // namespace carla diff --git a/LibCarla/source/carla/road/element/RoadInfoVisitor.h b/LibCarla/source/carla/road/element/RoadInfoVisitor.h index 54a65fda7..3cb8a4ec9 100644 --- a/LibCarla/source/carla/road/element/RoadInfoVisitor.h +++ b/LibCarla/source/carla/road/element/RoadInfoVisitor.h @@ -6,11 +6,6 @@ #pragma once -#include "carla/Debug.h" - -#include -#include - namespace carla { namespace road { namespace element { @@ -50,90 +45,6 @@ namespace element { virtual void Visit(RoadInfoSpeed &) {} }; - template - class RoadInfoIterator : private RoadInfoVisitor { - public: - - static_assert(std::is_same, typename IT::value_type>::value, "Not compatible."); - - using value_type = T; - using difference_type = typename IT::difference_type; - using pointer = T *; - using reference = T &; - - RoadInfoIterator(IT begin, IT end) - : _it(begin), - _end(end) { - _success = false; - for (; !IsAtEnd(); ++_it) { - DEBUG_ASSERT((*_it) != nullptr); - (*_it)->AcceptVisitor(*this); - if (_success) { - break; - } - } - } - - RoadInfoIterator &operator++() { - _success = false; - while (!_success) { - ++_it; - if (IsAtEnd()) { - break; - } - DEBUG_ASSERT((*_it) != nullptr); - (*_it)->AcceptVisitor(*this); - } - return *this; - } - - reference operator*() const { - DEBUG_ASSERT((*_it) != nullptr); - return static_cast(**_it); - } - - pointer operator->() const { - DEBUG_ASSERT((*_it) != nullptr); - return static_cast(_it->get()); - } - - bool operator!=(const RoadInfoIterator &rhs) const { - return _it != rhs._it; - } - - bool operator==(const RoadInfoIterator &rhs) const { - return !((*this) != rhs); - } - - bool IsAtEnd() const { - return _it == _end; - } - - private: - - void Visit(T &) { - _success = true; - } - - IT _it; - - IT _end; - - bool _success; - }; - - template - static auto MakeRoadInfoIterator(const Container &c) { - auto begin = std::begin(c); - auto end = std::end(c); - return RoadInfoIterator(begin, end); - } - - template - static auto MakeRoadInfoIterator(IT begin, IT end) { - return RoadInfoIterator(begin, end); - } - } // namespace element } // namespace road } // namespace carla