/usr/include/ktexteditor/cursor.h is in kdelibs5-dev 4:4.8.2-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | /* This file is part of the KDE project
Copyright (C) 2003-2005 Hamish Rodda <rodda@kde.org>
Copyright (C) 2001-2005 Christoph Cullmann <cullmann@kde.org>
Copyright (C) 2002 Christian Couder <christian@kdevelop.org>
Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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 KDELIBS_KTEXTEDITOR_CURSOR_H
#define KDELIBS_KTEXTEDITOR_CURSOR_H
#include <ktexteditor/ktexteditor_export.h>
#include <kdebug.h>
namespace KTextEditor
{
class Document;
class Range;
class SmartCursor;
/**
* \short An object which represents a position in a Document.
*
* A Cursor is a basic class which contains the line() and column() a position
* in a Document. It is very lightweight and maintains no affiliation with a
* particular Document.
*
* If you want additional functionality such as the ability to maintain position
* in a document, see SmartCursor.
*
* \note The Cursor class is designed to be passed via value, while SmartCursor
* and derivatives must be passed via pointer or reference as they maintain a
* connection with their document internally and cannot be copied.
*
* \note Lines and columns start at 0.
*
* \note Think of cursors as having their position at the start of a character,
* not in the middle of one.
*
* \note If a Cursor is associated with a Range the Range will be notified
* whenever the cursor (i.e. start or end position) changes its position.
* Read the class documentation about Range%s for further details.
*
* \sa SmartCursor
*/
class KTEXTEDITOR_EXPORT Cursor
{
friend class Range;
public:
/**
* The default constructor creates a cursor at position (0,0).
*/
Cursor();
/**
* This constructor creates a cursor initialized with \p line
* and \p column.
* \param line line for cursor
* \param column column for cursor
*/
Cursor(int line, int column);
/**
* Copy constructor. Does not copy the owning range, as a range does not
* have any association with copies of its cursors.
*
* \param copy the cursor to copy.
*/
Cursor(const Cursor& copy);
/**
* Virtual destructor.
*/
//Do not remove! Needed for inheritance.
virtual ~Cursor();
/**
* Returns whether the current position of this cursor is a valid position
* (line + column must both be >= 0).
*
* Smart cursors should override this to return whether the cursor is valid
* within the linked document.
*/
virtual bool isValid() const;
/**
* Returns whether this cursor is a SmartCursor.
*/
virtual bool isSmartCursor() const;
/**
* Returns this cursor as a SmartCursor, if it is one.
*/
virtual SmartCursor* toSmartCursor() const;
/**
* Returns an invalid cursor.
*/
static Cursor invalid();
/**
* Returns a cursor representing the start of any document - i.e., line 0, column 0.
*/
static Cursor start();
/**
* \name Position
*
* The following functions provide access to, and manipulation of, the cursor's position.
* \{
*/
/**
* Set the current cursor position to \e position.
*
* \param position new cursor position
*
* \todo add bool to indicate success or not, for smart cursors?
*/
virtual void setPosition(const Cursor& position);
/**
* \overload
*
* Set the cursor position to \e line and \e column.
*
* \param line new cursor line
* \param column new cursor column
*/
void setPosition(int line, int column);
/**
* Retrieve the line on which this cursor is situated.
* \return line number, where 0 is the first line.
*/
virtual int line() const;
/**
* Set the cursor line to \e line.
* \param line new cursor line
*/
virtual void setLine(int line);
/**
* Retrieve the column on which this cursor is situated.
* \return column number, where 0 is the first column.
*/
int column() const;
/**
* Set the cursor column to \e column.
* \param column new cursor column
*/
virtual void setColumn(int column);
/**
* Determine if this cursor is located at the start of a line.
* \return \e true if the cursor is situated at the start of the line, \e false if it isn't.
*/
bool atStartOfLine() const;
/**
* Determine if this cursor is located at the start of a document.
* \return \e true if the cursor is situated at the start of the document, \e false if it isn't.
*/
bool atStartOfDocument() const;
/**
* Get both the line and column of the cursor position.
* \param line will be filled with current cursor line
* \param column will be filled with current cursor column
*/
void position (int &line, int &column) const;
//!\}
/**
* Returns the range that this cursor belongs to, if any.
*/
Range* range() const;
/**
* Assignment operator. Same as setPosition().
* \param cursor the position to assign.
* \return a reference to this cursor
* \see setPosition()
*/
inline Cursor& operator=(const Cursor& cursor)
{ setPosition(cursor); return *this; }
/**
* Addition operator. Takes two cursors and returns their summation.
* \param c1 the first position
* \param c2 the second position
* \return a the summation of the two input cursors
*/
inline friend Cursor operator+(const Cursor& c1, const Cursor& c2)
{ return Cursor(c1.line() + c2.line(), c1.column() + c2.column()); }
/**
* Addition assignment operator. Adds \p c2 to this cursor.
* \param c1 the cursor being added to
* \param c2 the position to add
* \return a reference to the cursor which has just been added to
*/
inline friend Cursor& operator+=(Cursor& c1, const Cursor& c2)
{ c1.setPosition(c1.line() + c2.line(), c1.column() + c2.column()); return c1; }
/**
* Subtraction operator. Takes two cursors and returns the subtraction
* of \p c2 from \p c1.
*
* \param c1 the first position
* \param c2 the second position
* \return a cursor representing the subtraction of \p c2 from \p c1
*/
inline friend Cursor operator-(const Cursor& c1, const Cursor& c2)
{ return Cursor(c1.line() - c2.line(), c1.column() - c2.column()); }
/**
* Subtraction assignment operator. Subtracts \p c2 from \p c1.
* \param c1 the cursor being subtracted from
* \param c2 the position to subtract
* \return a reference to the cursor which has just been subtracted from
*/
inline friend Cursor& operator-=(Cursor& c1, const Cursor& c2)
{ c1.setPosition(c1.line() - c2.line(), c1.column() - c2.column()); return c1; }
/**
* Equality operator.
*
* \note comparison between two invalid cursors is undefined.
* comparison between and invalid and a valid cursor will always be \e false.
*
* \param c1 first cursor to compare
* \param c2 second cursor to compare
* \return \e true, if c1's and c2's line and column are \e equal.
*/
inline friend bool operator==(const Cursor& c1, const Cursor& c2)
{ return c1.line() == c2.line() && c1.column() == c2.column(); }
/**
* Inequality operator.
* \param c1 first cursor to compare
* \param c2 second cursor to compare
* \return \e true, if c1's and c2's line and column are \e not equal.
*/
inline friend bool operator!=(const Cursor& c1, const Cursor& c2)
{ return !(c1 == c2); }
/**
* Greater than operator.
* \param c1 first cursor to compare
* \param c2 second cursor to compare
* \return \e true, if c1's position is greater than c2's position,
* otherwise \e false.
*/
inline friend bool operator>(const Cursor& c1, const Cursor& c2)
{ return c1.line() > c2.line() || (c1.line() == c2.line() && c1.m_column > c2.m_column); }
/**
* Greater than or equal to operator.
* \param c1 first cursor to compare
* \param c2 second cursor to compare
* \return \e true, if c1's position is greater than or equal to c2's
* position, otherwise \e false.
*/
inline friend bool operator>=(const Cursor& c1, const Cursor& c2)
{ return c1.line() > c2.line() || (c1.line() == c2.line() && c1.m_column >= c2.m_column); }
/**
* Less than operator.
* \param c1 first cursor to compare
* \param c2 second cursor to compare
* \return \e true, if c1's position is greater than or equal to c2's
* position, otherwise \e false.
*/
inline friend bool operator<(const Cursor& c1, const Cursor& c2)
{ return !(c1 >= c2); }
/**
* Less than or equal to operator.
* \param c1 first cursor to compare
* \param c2 second cursor to compare
* \return \e true, if c1's position is lesser than or equal to c2's
* position, otherwise \e false.
*/
inline friend bool operator<=(const Cursor& c1, const Cursor& c2)
{ return !(c1 > c2); }
/**
* kDebug() stream operator. Writes this cursor to the debug output in a nicely formatted way.
*/
inline friend QDebug operator<< (QDebug s, const Cursor& cursor) {
if (&cursor)
s.nospace() << "(" << cursor.line() << ", " << cursor.column() << ")";
else
s.nospace() << "(null cursor)";
return s.space();
}
protected:
/**
* \internal
*
* Sets the range that this cursor belongs to.
*
* \param range the range that this cursor is referenced from.
*/
virtual void setRange(Range* range);
/**
* \internal
*
* Notify the owning range, if any, that this cursor has changed directly.
*/
void cursorChangedDirectly(const Cursor& from);
/**
* \internal
*
* Cursor line
*/
int m_line;
/**
* \internal
*
* Cursor column
*/
int m_column;
/**
* \internal
*
* Range which owns this cursor, if any
*/
Range* m_range;
};
}
#endif
// kate: space-indent on; indent-width 2; replace-tabs on;
|