Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
forward-pointer-iterator.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Inkscape::Util::ForwardPointerIterator - wraps a simple pointer
4 * with various strategies
5 * to determine sequence
6 *
7 * Authors:
8 * MenTaLguY <mental@rydia.net>
9 *
10 * Copyright (C) 2004 MenTaLguY
11 *
12 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
13 */
14
15#ifndef SEEN_INKSCAPE_UTIL_FORWARD_POINTER_ITERATOR_H
16#define SEEN_INKSCAPE_UTIL_FORWARD_POINTER_ITERATOR_H
17
18#include <iterator>
19#include <cstddef>
20#include "util/reference.h"
21
22namespace Inkscape {
23
24namespace Util {
25
26template <typename BaseType, typename Strategy>
27class ForwardPointerIterator;
28
29template <typename BaseType, typename Strategy>
30class ForwardPointerIterator<BaseType const, Strategy> {
31public:
32 typedef std::forward_iterator_tag iterator_category;
34 typedef std::ptrdiff_t difference_type;
38
40
43
44 operator pointer() const { return _p; }
45 reference operator*() const { return *_p; }
46 pointer operator->() const { return _p; }
47
48 bool operator==(Self const &other) const {
49 return _p == other._p;
50 }
51 bool operator!=(Self const &other) const {
52 return _p != other._p;
53 }
54
56 _p = Strategy::next(_p);
57 return *this;
58 }
60 Self old(*this);
61 operator++();
62 return old;
63 }
64
65 operator bool() const { return _p != nullptr; }
66
67private:
69};
70
71template <typename BaseType, typename Strategy>
73: public ForwardPointerIterator<BaseType const, Strategy>
74{
75public:
80
83
86
87 operator pointer() const {
88 return const_cast<pointer>(Ancestor::operator->());
89 }
91 return const_cast<reference>(Ancestor::operator*());
92 }
94 return const_cast<pointer>(Ancestor::operator->());
95 }
96
99 return *this;
100 }
102 Self old(*this);
103 operator++();
104 return old;
105 }
106};
107
108}
109
110}
111
112#endif
113/*
114 Local Variables:
115 mode:c++
116 c-file-style:"stroustrup"
117 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
118 indent-tabs-mode:nil
119 fill-column:99
120 End:
121*/
122// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
ForwardPointerIterator< BaseType const, Strategy > Ancestor
Traits::Reference< BaseType >::Pointer pointer
Traits::Reference< BaseType >::RValue const_reference
Traits::Reference< BaseType >::LValue reference
Traits::Reference< BaseType >::LValue value_type
ForwardPointerIterator< BaseType, Strategy > Self
Miscellaneous supporting code.
Definition document.h:93
Helper class to stream background task notifications as a series of messages.