| 1 | /* |
|---|---|
| 2 | SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org> |
| 3 | |
| 4 | SPDX-License-Identifier: MIT |
| 5 | */ |
| 6 | |
| 7 | #include "foldingregion.h" |
| 8 | |
| 9 | using namespace KSyntaxHighlighting; |
| 10 | |
| 11 | static_assert(sizeof(FoldingRegion) == sizeof(int), "FoldingRegion is size-sensitive to frequent use in KTextEditor!"); |
| 12 | |
| 13 | FoldingRegion::FoldingRegion() = default; |
| 14 | |
| 15 | FoldingRegion::FoldingRegion(Type type, int id) |
| 16 | : m_idWithType((type == End) ? -id : id) |
| 17 | { |
| 18 | } |
| 19 | |
| 20 | bool FoldingRegion::operator==(const FoldingRegion &other) const |
| 21 | { |
| 22 | return m_idWithType == other.m_idWithType; |
| 23 | } |
| 24 | |
| 25 | bool FoldingRegion::isValid() const |
| 26 | { |
| 27 | return m_idWithType != 0; |
| 28 | } |
| 29 | |
| 30 | int FoldingRegion::id() const |
| 31 | { |
| 32 | return (m_idWithType < 0) ? -m_idWithType : m_idWithType; |
| 33 | } |
| 34 | |
| 35 | FoldingRegion::Type FoldingRegion::type() const |
| 36 | { |
| 37 | if (isValid()) { |
| 38 | return (m_idWithType < 0) ? End : Begin; |
| 39 | } |
| 40 | return None; |
| 41 | } |
| 42 | |
| 43 | FoldingRegion FoldingRegion::sibling() const |
| 44 | { |
| 45 | return isValid() ? FoldingRegion(type() ? End : Begin, id()) : FoldingRegion(); |
| 46 | } |
| 47 |
