// SPDX-License-Identifier: GPL-2.0-or-later /* * Inkscape::Util::ForwardPointerIterator - wraps a simple pointer * with various strategies * to determine sequence * * Authors: * MenTaLguY * * Copyright (C) 2004 MenTaLguY * * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ #ifndef SEEN_INKSCAPE_UTIL_FORWARD_POINTER_ITERATOR_H #define SEEN_INKSCAPE_UTIL_FORWARD_POINTER_ITERATOR_H #include #include #include "util/reference.h" namespace Inkscape { namespace Util { template class ForwardPointerIterator; template class ForwardPointerIterator { public: typedef std::forward_iterator_tag iterator_category; typedef typename Traits::Reference::LValue value_type; typedef std::ptrdiff_t difference_type; typedef typename Traits::Reference::LValue reference; typedef typename Traits::Reference::RValue const_reference; typedef typename Traits::Reference::Pointer pointer; typedef ForwardPointerIterator Self; ForwardPointerIterator() = default; ForwardPointerIterator(pointer p) : _p(p) {} operator pointer() const { return _p; } reference operator*() const { return *_p; } pointer operator->() const { return _p; } bool operator==(Self const &other) const { return _p == other._p; } bool operator!=(Self const &other) const { return _p != other._p; } Self &operator++() { _p = Strategy::next(_p); return *this; } Self operator++(int) { Self old(*this); operator++(); return old; } operator bool() const { return _p != nullptr; } private: pointer _p; }; template class ForwardPointerIterator : public ForwardPointerIterator { public: typedef typename Traits::Reference::LValue value_type; typedef typename Traits::Reference::LValue reference; typedef typename Traits::Reference::RValue const_reference; typedef typename Traits::Reference::Pointer pointer; typedef ForwardPointerIterator Ancestor; typedef ForwardPointerIterator Self; ForwardPointerIterator() : Ancestor() {} ForwardPointerIterator(pointer p) : Ancestor(p) {} operator pointer() const { return const_cast(Ancestor::operator->()); } reference operator*() const { return const_cast(Ancestor::operator*()); } pointer operator->() const { return const_cast(Ancestor::operator->()); } Self &operator++() { Ancestor::operator++(); return *this; } Self operator++(int) { Self old(*this); operator++(); return old; } }; } } #endif /* Local Variables: mode:c++ c-file-style:"stroustrup" c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) indent-tabs-mode:nil fill-column:99 End: */ // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :