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 
14 namespace KSyntaxHighlighting
15 {
16 class StateData;
17 
18 /** Opaque handle to the state of the highlighting engine.
19  *  This needs to be fed into AbstractHighlighter for every line of text
20  *  and allows concrete highlighter implementations to store state per
21  *  line for fast re-highlighting of specific lines (e.g. during editing).
22  *
23  *  @since 5.28
24  */
25 class KSYNTAXHIGHLIGHTING_EXPORT State
26 {
27 public:
28     /** Creates an initial state, ie. what should be used for the first line
29      *  in a document.
30      */
31     State();
32     State(const State &other);
33     ~State();
34     State &operator=(const State &rhs);
35 
36     /** Compares two states for equality.
37      *  For two equal states and identical text input, AbstractHighlighter
38      *  guarantees to produce equal results. This can be used to only
39      *  re-highlight as many lines as necessary during editing.
40      */
41     bool operator==(const State &other) const;
42     /** Compares two states for inequality.
43      *  This is the opposite of operator==().
44      */
45     bool operator!=(const State &other) const;
46 
47     /**
48      * Returns whether or not indentation-based folding is enabled in this state.
49      * When using a Definition with indentation-based folding, use
50      * this method to check if indentation-based folding has been
51      * suspended in the current line.
52      *
53      * @see Definition::indentationBasedFoldingEnabled()
54      */
55     bool indentationBasedFoldingEnabled() const;
56 
57 private:
58     friend class StateData;
59     QExplicitlySharedDataPointer<StateData> d;
60 };
61 
62 }
63 
64 QT_BEGIN_NAMESPACE
65 Q_DECLARE_TYPEINFO(KSyntaxHighlighting::State, Q_MOVABLE_TYPE);
66 QT_END_NAMESPACE
67 
68 #endif // KSYNTAXHIGHLIGHTING_STATE_H
69