diff --git a/language/editor/simplecursor.h b/language/editor/simplecursor.h index 9bec17e758..b2ac0af06f 100644 --- a/language/editor/simplecursor.h +++ b/language/editor/simplecursor.h @@ -1,101 +1,102 @@ /* This file is part of KDevelop Copyright 2007 David Nolden This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef SIMPLECURSOR_H #define SIMPLECURSOR_H #include #include "../languageexport.h" namespace KDevelop { /** * Represents a cursor (line-number and column-number) within a text document. Generally this is * a more efficient version of KTextEditor::Cursor. * In KDevelop, this object is used when referencing the most current document revision * (the document in its current version) */ class KDEVPLATFORMLANGUAGE_EXPORT SimpleCursor { public: int line, column; SimpleCursor() : line(0), column(0) { } SimpleCursor(int _line, int _column) : line(_line), column(_column) { } static SimpleCursor invalid() { return SimpleCursor(-1, -1); } explicit SimpleCursor(const KTextEditor::Cursor& cursor) : line(cursor.line()), column(cursor.column()) { } bool isValid() const { return line != -1 || column != -1; } bool operator<(const SimpleCursor& rhs) const { return line < rhs.line || (line == rhs.line && column < rhs.column); } bool operator<=(const SimpleCursor& rhs) const { return line < rhs.line || (line == rhs.line && column <= rhs.column); } bool operator>(const SimpleCursor& rhs) const { return line > rhs.line || (line == rhs.line && column > rhs.column); } bool operator>=(const SimpleCursor& rhs) const { return line > rhs.line || (line == rhs.line && column >= rhs.column); } bool operator ==(const SimpleCursor& rhs) const { return line == rhs.line && column == rhs.column; } bool operator !=(const SimpleCursor& rhs) const { return !(*this == rhs); } KTextEditor::Cursor textCursor() const { return KTextEditor::Cursor(line, column); } SimpleCursor operator +(const SimpleCursor& rhs) const { return SimpleCursor(line + rhs.line, column + rhs.column); } /** * kDebug() stream operator. Writes this cursor to the debug output in a nicely formatted way. */ inline friend QDebug operator<< (QDebug s, const SimpleCursor& cursor) { s.nospace() << "(" << cursor.line << ", " << cursor.column << ")"; return s.space(); } }; -} inline uint qHash(const KDevelop::SimpleCursor& cursor) { return cursor.line * 53 + cursor.column * 47; } +} // namespace KDevelop + #endif diff --git a/language/editor/simplerange.h b/language/editor/simplerange.h index a096caf182..a5d0544e77 100644 --- a/language/editor/simplerange.h +++ b/language/editor/simplerange.h @@ -1,105 +1,106 @@ /* This file is part of KDevelop Copyright 2007 David Nolden This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef SIMPLERANGE_H #define SIMPLERANGE_H #include #include "../languageexport.h" #include "simplecursor.h" /** * Represents a range (start- and end-cursor) within a text document. Generally this is * a more efficient version of KTextEditor::Range. * In KDevelop, this object is used when referencing the most current document revision * (the document in its current version) */ namespace KDevelop { class KDEVPLATFORMLANGUAGE_EXPORT SimpleRange { public: SimpleCursor start, end; SimpleRange(const SimpleCursor& _start, const SimpleCursor& _end) : start(_start), end(_end) { } SimpleRange(const SimpleCursor& _start, int length) : start(_start), end(_start.line, _start.column + length) { } SimpleRange() { } SimpleRange(const KTextEditor::Range& range) : start(range.start()), end(range.end()) { } SimpleRange(int sLine, int sCol, int eLine, int eCol) : start(sLine, sCol), end(eLine, eCol) { } static SimpleRange invalid() { return SimpleRange(-1, -1, -1, -1); } bool isValid() const { return start.column != -1 || start.line != -1 || end.column != -1 || end.line != -1; } bool isEmpty() const { return start == end; } bool contains(const SimpleCursor& position) const { return position >= start && position < end; } bool contains(const SimpleRange& range) const { return range.start >= start && range.end <= end; } bool operator ==( const SimpleRange& rhs ) const { return start == rhs.start && end == rhs.end; } bool operator !=( const SimpleRange& rhs ) const { return !(*this == rhs); } bool operator <( const SimpleRange& rhs ) const { return start < rhs.start; } KTextEditor::Range textRange() const { return KTextEditor::Range( KTextEditor::Cursor(start.line, start.column), KTextEditor::Cursor(end.line, end.column) ); } /** * kDebug() stream operator. Writes this range to the debug output in a nicely formatted way. */ inline friend QDebug operator<< (QDebug s, const SimpleRange& range) { s.nospace() << '[' << range.start << ", " << range.end << ']'; return s.space(); } }; -} inline uint qHash(const KDevelop::SimpleRange& range) { return qHash(range.start) + qHash(range.end)*41; } +} // namespace KDevelop + #endif