File indexing completed on 2024-05-12 15:50:04

0001 /*
0002     SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: MIT
0005 */
0006 
0007 #ifndef KSYNTAXHIGHLIGHTING_FOLDINGREGION_H
0008 #define KSYNTAXHIGHLIGHTING_FOLDINGREGION_H
0009 
0010 #include "ksyntaxhighlighting_export.h"
0011 
0012 #include <QTypeInfo>
0013 
0014 namespace KSyntaxHighlighting
0015 {
0016 /** Represents a begin or end of a folding region.
0017  *  @since 5.28 */
0018 class KSYNTAXHIGHLIGHTING_EXPORT FoldingRegion
0019 {
0020 public:
0021     /**
0022      * Defines whether a FoldingRegion starts or ends a folding region.
0023      */
0024     enum Type {
0025         //! Used internally as indicator for invalid FoldingRegion%s.
0026         None,
0027         //! Indicates the start of a FoldingRegion.
0028         Begin,
0029         //! Indicates the end of a FoldingRegion.
0030         End
0031     };
0032 
0033     /**
0034      * Constructs an invalid folding region, meaning that isValid() returns @e false.
0035      * To obtain valid instances, see AbstractHighlighter::applyFolding().
0036      */
0037     FoldingRegion();
0038 
0039     /** Compares two FoldingRegion instances for equality. */
0040     bool operator==(const FoldingRegion &other) const;
0041 
0042     /**
0043      * Returns @c true if this is a valid folding region.
0044      * A valid FoldingRegion is defined by a type() other than Type::None.
0045      *
0046      * @note The FoldingRegion%s passed in AbstractHighlighter::applyFolding()
0047      *       are always valid.
0048      */
0049     bool isValid() const;
0050 
0051     /**
0052      * Returns a unique identifier for this folding region.
0053      *
0054      * As example, the C/C++ highlighter starts and ends a folding region for
0055      * scopes, e.g.:
0056      * \code
0057      * void foo() {     // '{' starts a folding region
0058      *     if (bar()) { // '{' starts a (nested) folding region
0059      *     }            // '}' ends the (nested) folding region
0060      * }                // '}' ends the outer folding region
0061      * \endcode
0062      * In this example, all braces '{' and '}' have the same id(), meaning that
0063      * if you want to find the matching closing region for the first opening
0064      * brace, you need to do kind of a reference counting to find the correct
0065      * closing brace.
0066      */
0067     quint16 id() const;
0068 
0069     /**
0070      * Returns whether this is the begin or end of a region.
0071      *
0072      * @note The FoldingRegion%s passed in AbstractHighlighter::applyFolding()
0073      *       are always valid, i.e. either Type::Begin or Type::End.
0074      */
0075     Type type() const;
0076 
0077 private:
0078     friend class Rule;
0079     KSYNTAXHIGHLIGHTING_NO_EXPORT FoldingRegion(Type type, quint16 id);
0080 
0081     quint16 m_type : 2;
0082     quint16 m_id : 14;
0083 };
0084 
0085 }
0086 
0087 QT_BEGIN_NAMESPACE
0088 Q_DECLARE_TYPEINFO(KSyntaxHighlighting::FoldingRegion, Q_PRIMITIVE_TYPE);
0089 QT_END_NAMESPACE
0090 
0091 #endif