File indexing completed on 2024-05-12 04:02:18

0001 /*
0002     SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: MIT
0005 */
0006 
0007 #include "foldingregion.h"
0008 
0009 using namespace KSyntaxHighlighting;
0010 
0011 static_assert(sizeof(FoldingRegion) == sizeof(int), "FoldingRegion is size-sensitive to frequent use in KTextEditor!");
0012 
0013 FoldingRegion::FoldingRegion() = default;
0014 
0015 FoldingRegion::FoldingRegion(Type type, int id)
0016     : m_idWithType((type == End) ? -id : id)
0017 {
0018 }
0019 
0020 bool FoldingRegion::operator==(const FoldingRegion &other) const
0021 {
0022     return m_idWithType == other.m_idWithType;
0023 }
0024 
0025 bool FoldingRegion::isValid() const
0026 {
0027     return m_idWithType != 0;
0028 }
0029 
0030 int FoldingRegion::id() const
0031 {
0032     return (m_idWithType < 0) ? -m_idWithType : m_idWithType;
0033 }
0034 
0035 FoldingRegion::Type FoldingRegion::type() const
0036 {
0037     if (isValid()) {
0038         return (m_idWithType < 0) ? End : Begin;
0039     }
0040     return None;
0041 }
0042 
0043 FoldingRegion FoldingRegion::sibling() const
0044 {
0045     return isValid() ? FoldingRegion(type() ? End : Begin, id()) : FoldingRegion();
0046 }