diff options
Diffstat (limited to 'src/lib/corelib/tools/codelocation.cpp')
-rw-r--r-- | src/lib/corelib/tools/codelocation.cpp | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/src/lib/corelib/tools/codelocation.cpp b/src/lib/corelib/tools/codelocation.cpp index ebfd5edc6..f04041e14 100644 --- a/src/lib/corelib/tools/codelocation.cpp +++ b/src/lib/corelib/tools/codelocation.cpp @@ -87,8 +87,9 @@ CodeLocation::CodeLocation(const QString &aFilePath, int aLine, int aColumn, boo } CodeLocation::CodeLocation(const CodeLocation &other) = default; - +CodeLocation::CodeLocation(CodeLocation &&other) noexcept = default; CodeLocation &CodeLocation::operator=(const CodeLocation &other) = default; +CodeLocation &CodeLocation::operator=(CodeLocation &&other) noexcept = default; CodeLocation::~CodeLocation() = default; @@ -181,4 +182,44 @@ bool operator<(const CodeLocation &cl1, const CodeLocation &cl2) return cl1.toString() < cl2.toString(); } +void CodePosition::load(Internal::PersistentPool &pool) { pool.load(m_line, m_column); } +void CodePosition::store(Internal::PersistentPool &pool) const { pool.store(m_line, m_column); } + +bool operator==(const CodePosition &pos1, const CodePosition &pos2) +{ + return pos1.line() == pos2.line() && pos1.column() == pos2.column(); +} +bool operator!=(const CodePosition &pos1, const CodePosition &pos2) { return !(pos1 == pos2); } + +bool operator<(const CodePosition &pos1, const CodePosition &pos2) +{ + const int lineDiff = pos1.line() - pos2.line(); + if (lineDiff < 0) + return true; + if (lineDiff > 0) + return false; + return pos1.column() < pos2.column(); +} +bool operator>(const CodePosition &pos1, const CodePosition &pos2) { return pos2 < pos1; } +bool operator<=(const CodePosition &pos1, const CodePosition &pos2) { return !(pos1 > pos2); } +bool operator>=(const CodePosition &pos1, const CodePosition &pos2) { return !(pos1 < pos2); } + +CodeRange::CodeRange(const CodePosition &start, const CodePosition &end) + : m_start(start), m_end(end) {} + +void CodeRange::load(Internal::PersistentPool &pool) { pool.load(m_start, m_end); } +void CodeRange::store(Internal::PersistentPool &pool) const { pool.store(m_start, m_end); } + +bool CodeRange::contains(const CodePosition &pos) const +{ + return start() <= pos && end() > pos; +} + +bool operator==(const CodeRange &r1, const CodeRange &r2) +{ + return r1.start() == r2.start() && r1.end() == r2.end(); +} +bool operator!=(const CodeRange &r1, const CodeRange &r2) { return !(r1 == r2); } +bool operator<(const CodeRange &r1, const CodeRange &r2) { return r1.start() < r2.start(); } + } // namespace qbs |