File indexing completed on 2024-05-12 04:02:20

0001 /*
0002     SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: MIT
0005 */
0006 
0007 #ifndef KSYNTAXHIGHLIGHTING_STATE_H
0008 #define KSYNTAXHIGHLIGHTING_STATE_H
0009 
0010 #include "ksyntaxhighlighting_export.h"
0011 
0012 #include <QExplicitlySharedDataPointer>
0013 #include <QHash>
0014 
0015 namespace KSyntaxHighlighting
0016 {
0017 class State;
0018 class StateData;
0019 
0020 KSYNTAXHIGHLIGHTING_EXPORT std::size_t qHash(const State &state, std::size_t seed = 0);
0021 
0022 /** Opaque handle to the state of the highlighting engine.
0023  *  This needs to be fed into AbstractHighlighter for every line of text
0024  *  and allows concrete highlighter implementations to store state per
0025  *  line for fast re-highlighting of specific lines (e.g. during editing).
0026  *
0027  *  @since 5.28
0028  */
0029 class KSYNTAXHIGHLIGHTING_EXPORT State
0030 {
0031 public:
0032     /** Creates an initial state, ie. what should be used for the first line
0033      *  in a document.
0034      */
0035     State();
0036     State(State &&other) noexcept;
0037     State(const State &other) noexcept;
0038     ~State();
0039     State &operator=(State &&rhs) noexcept;
0040     State &operator=(const State &rhs) noexcept;
0041 
0042     /** Compares two states for equality.
0043      *  For two equal states and identical text input, AbstractHighlighter
0044      *  guarantees to produce equal results. This can be used to only
0045      *  re-highlight as many lines as necessary during editing.
0046      */
0047     bool operator==(const State &other) const;
0048     /** Compares two states for inequality.
0049      *  This is the opposite of operator==().
0050      */
0051     bool operator!=(const State &other) const;
0052 
0053     /**
0054      * Returns whether or not indentation-based folding is enabled in this state.
0055      * When using a Definition with indentation-based folding, use
0056      * this method to check if indentation-based folding has been
0057      * suspended in the current line.
0058      *
0059      * @see Definition::indentationBasedFoldingEnabled()
0060      */
0061     bool indentationBasedFoldingEnabled() const;
0062 
0063 private:
0064     friend class StateData;
0065     friend std::size_t qHash(const State &, std::size_t);
0066     QExplicitlySharedDataPointer<StateData> d;
0067 };
0068 }
0069 
0070 QT_BEGIN_NAMESPACE
0071 Q_DECLARE_TYPEINFO(KSyntaxHighlighting::State, Q_RELOCATABLE_TYPE);
0072 QT_END_NAMESPACE
0073 
0074 #endif // KSYNTAXHIGHLIGHTING_STATE_H