From c216426908d9a13292cbe336e7b132c153ccb6a4 Mon Sep 17 00:00:00 2001 From: Simon Giraudot Date: Thu, 29 Oct 2020 15:16:44 +0100 Subject: [PATCH] Add missing file --- .../include/CGAL/Subiterator.h | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 Principal_component_analysis/include/CGAL/Subiterator.h diff --git a/Principal_component_analysis/include/CGAL/Subiterator.h b/Principal_component_analysis/include/CGAL/Subiterator.h new file mode 100644 index 00000000000..fbadd1980c2 --- /dev/null +++ b/Principal_component_analysis/include/CGAL/Subiterator.h @@ -0,0 +1,99 @@ +// Copyright (c) 2020 GeometryFactory (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Simon Giraudot +// + +#ifndef CGAL_PCA_SUBITERATOR_H +#define CGAL_PCA_SUBITERATOR_H + +#include + +namespace CGAL +{ + +template +class Subiterator + : public boost::iterator_facade, + ValueType, + std::input_iterator_tag> +{ +public: + using Self = Subiterator; + using Facade = boost::iterator_facade; + + using Input_type = typename std::iterator_traits::value_type; + using Output_type = ValueType; + + using Converter = std::function; + +private: + + Converter m_converter; + std::size_t m_next_index; + InputIterator m_base; + mutable Output_type m_current; + +public: + + Subiterator() { } + + Subiterator(InputIterator begin, const Converter& converter) + : m_converter(converter), m_next_index(0), m_base(begin) + { } + + Subiterator(InputIterator end) + : m_next_index(0), m_base(end) + { } + +private: + + friend class boost::iterator_core_access; + + void increment() + { + ++ m_next_index; + if (m_next_index == Size) + { + ++ m_base; + m_next_index = 0; + } + } + + bool equal(const Self& other) const + { + return this->m_base == other.m_base && this->m_next_index == other.m_next_index; + } + + Output_type& dereference() const + { + m_current = m_converter (*m_base, m_next_index); + return const_cast(m_current); + } +}; + +template +Subiterator +make_subiterator (InputIterator begin, + const typename Subiterator::Converter& converter) +{ + return Subiterator(begin, converter); +} + +template +Subiterator +make_subiterator (InputIterator end) +{ + return Subiterator(end); +} + + +} // namespace CGAL + +#endif // CGAL_PCA_SUBITERATOR_H