1/*
2 SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: MIT
5*/
6
7#ifndef KSYNTAXHIGHLIGHTING_STATE_H
8#define KSYNTAXHIGHLIGHTING_STATE_H
9
10#include "ksyntaxhighlighting_export.h"
11
12#include <QExplicitlySharedDataPointer>
13#include <QHash>
14
15namespace KSyntaxHighlighting
16{
17class State;
18class StateData;
19
20KSYNTAXHIGHLIGHTING_EXPORT std::size_t qHash(const State &state, std::size_t seed = 0);
21
22/*!
23 * \class KSyntaxHighlighting::State
24 * \inheaderfile KSyntaxHighlighting/State
25 * \inmodule KSyntaxHighlighting
26 *
27 * \brief Opaque handle to the state of the highlighting engine.
28 *
29 * This needs to be fed into AbstractHighlighter for every line of text
30 * and allows concrete highlighter implementations to store state per
31 * line for fast re-highlighting of specific lines (e.g. during editing).
32 *
33 * \since 5.28
34 */
35class KSYNTAXHIGHLIGHTING_EXPORT State
36{
37public:
38 /*! Creates an initial state, ie. what should be used for the first line
39 * in a document.
40 */
41 State();
42 State(State &&other) noexcept;
43 State(const State &other) noexcept;
44 ~State();
45 State &operator=(State &&rhs) noexcept;
46 State &operator=(const State &rhs) noexcept;
47
48 /*! Compares two states for equality.
49 * For two equal states and identical text input, AbstractHighlighter
50 * guarantees to produce equal results. This can be used to only
51 * re-highlight as many lines as necessary during editing.
52 */
53 bool operator==(const State &other) const;
54 /*! Compares two states for inequality.
55 * This is the opposite of operator==().
56 */
57 bool operator!=(const State &other) const;
58
59 /*!
60 * Returns whether or not indentation-based folding is enabled in this state.
61 * When using a Definition with indentation-based folding, use
62 * this method to check if indentation-based folding has been
63 * suspended in the current line.
64 *
65 * \sa Definition::indentationBasedFoldingEnabled()
66 */
67 bool indentationBasedFoldingEnabled() const;
68
69private:
70 friend class StateData;
71 friend KSYNTAXHIGHLIGHTING_EXPORT std::size_t qHash(const State &, std::size_t);
72 QExplicitlySharedDataPointer<StateData> d;
73};
74}
75
76QT_BEGIN_NAMESPACE
77Q_DECLARE_TYPEINFO(KSyntaxHighlighting::State, Q_RELOCATABLE_TYPE);
78QT_END_NAMESPACE
79
80#endif // KSYNTAXHIGHLIGHTING_STATE_H
81

source code of syntax-highlighting/src/lib/state.h