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

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