summaryrefslogtreecommitdiffstats
path: root/src/util/forward-pointer-iterator.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
commitcca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch)
tree146f39ded1c938019e1ed42d30923c2ac9e86789 /src/util/forward-pointer-iterator.h
parentInitial commit. (diff)
downloadinkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.tar.xz
inkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.zip
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/util/forward-pointer-iterator.h')
-rw-r--r--src/util/forward-pointer-iterator.h122
1 files changed, 122 insertions, 0 deletions
diff --git a/src/util/forward-pointer-iterator.h b/src/util/forward-pointer-iterator.h
new file mode 100644
index 0000000..9fe3bb8
--- /dev/null
+++ b/src/util/forward-pointer-iterator.h
@@ -0,0 +1,122 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Inkscape::Util::ForwardPointerIterator - wraps a simple pointer
+ * with various strategies
+ * to determine sequence
+ *
+ * Authors:
+ * MenTaLguY <mental@rydia.net>
+ *
+ * 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 <iterator>
+#include <cstddef>
+#include "util/reference.h"
+
+namespace Inkscape {
+
+namespace Util {
+
+template <typename BaseType, typename Strategy>
+class ForwardPointerIterator;
+
+template <typename BaseType, typename Strategy>
+class ForwardPointerIterator<BaseType const, Strategy> {
+public:
+ typedef std::forward_iterator_tag iterator_category;
+ typedef typename Traits::Reference<BaseType const>::LValue value_type;
+ typedef std::ptrdiff_t difference_type;
+ typedef typename Traits::Reference<BaseType const>::LValue reference;
+ typedef typename Traits::Reference<BaseType const>::RValue const_reference;
+ typedef typename Traits::Reference<BaseType const>::Pointer pointer;
+
+ typedef ForwardPointerIterator<BaseType const, Strategy> 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 <typename BaseType, typename Strategy>
+class ForwardPointerIterator
+: public ForwardPointerIterator<BaseType const, Strategy>
+{
+public:
+ typedef typename Traits::Reference<BaseType>::LValue value_type;
+ typedef typename Traits::Reference<BaseType>::LValue reference;
+ typedef typename Traits::Reference<BaseType>::RValue const_reference;
+ typedef typename Traits::Reference<BaseType>::Pointer pointer;
+
+ typedef ForwardPointerIterator<BaseType const, Strategy> Ancestor;
+ typedef ForwardPointerIterator<BaseType, Strategy> Self;
+
+ ForwardPointerIterator() : Ancestor() {}
+ ForwardPointerIterator(pointer p) : Ancestor(p) {}
+
+ operator pointer() const {
+ return const_cast<pointer>(Ancestor::operator->());
+ }
+ reference operator*() const {
+ return const_cast<reference>(Ancestor::operator*());
+ }
+ pointer operator->() const {
+ return const_cast<pointer>(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 :