1/*
2 SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: MIT
5*/
6
7#ifndef KSYNTAXHIGHLIGHTING_FOLDINGREGION_H
8#define KSYNTAXHIGHLIGHTING_FOLDINGREGION_H
9
10#include "ksyntaxhighlighting_export.h"
11
12#include <QTypeInfo>
13
14namespace KSyntaxHighlighting
15{
16/** Represents a begin or end of a folding region.
17 * @since 5.28 */
18class KSYNTAXHIGHLIGHTING_EXPORT FoldingRegion
19{
20public:
21 /**
22 * Defines whether a FoldingRegion starts or ends a folding region.
23 */
24 enum Type {
25 //! Used internally as indicator for an invalid FoldingRegion.
26 None,
27 //! Indicates the start of a FoldingRegion.
28 Begin,
29 //! Indicates the end of a FoldingRegion.
30 End
31 };
32
33 /**
34 * Constructs an invalid folding region, meaning that isValid() returns @e false.
35 * To obtain valid instances, see AbstractHighlighter::applyFolding().
36 */
37 FoldingRegion();
38
39 /** Compares two FoldingRegion instances for equality. */
40 bool operator==(const FoldingRegion &other) const;
41
42 /**
43 * Returns @c true if this is a valid folding region.
44 * A valid FoldingRegion is defined by a type() other than Type::None.
45 *
46 * @note The FoldingRegion%s passed in AbstractHighlighter::applyFolding()
47 * are always valid.
48 */
49 bool isValid() const;
50
51 /**
52 * Returns a unique identifier for this folding region.
53 *
54 * As example, the C/C++ highlighter starts and ends a folding region for
55 * scopes, e.g.:
56 * \code
57 * void foo() { // '{' starts a folding region
58 * if (bar()) { // '{' starts a (nested) folding region
59 * } // '}' ends the (nested) folding region
60 * } // '}' ends the outer folding region
61 * \endcode
62 * In this example, all braces '{' and '}' have the same id(), meaning that
63 * if you want to find the matching closing region for the first opening
64 * brace, you need to do kind of a reference counting to find the correct
65 * closing brace.
66 */
67 int id() const;
68
69 /**
70 * Returns whether this is the begin or end of a region.
71 *
72 * @note The FoldingRegion%s passed in AbstractHighlighter::applyFolding()
73 * are always valid, i.e. either Type::Begin or Type::End.
74 */
75 Type type() const;
76
77 /**
78 * Returns the matching start or end region.
79 *
80 * @note Will return invalid region for an invalid region.
81 *
82 * @since 6.0
83 */
84 FoldingRegion sibling() const;
85
86private:
87 friend class Rule;
88 KSYNTAXHIGHLIGHTING_NO_EXPORT FoldingRegion(Type type, int id);
89
90 // 0 is invalid, positive begin, negative end
91 int m_idWithType = 0;
92};
93
94}
95
96QT_BEGIN_NAMESPACE
97Q_DECLARE_TYPEINFO(KSyntaxHighlighting::FoldingRegion, Q_PRIMITIVE_TYPE);
98QT_END_NAMESPACE
99
100#endif
101

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