/usr/include/ktexteditor/range.h is in kdelibs5-dev 4:4.8.4-4+deb7u1.
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 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | /* 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_RANGE_H
#define KDELIBS_KTEXTEDITOR_RANGE_H
#include <ktexteditor/ktexteditor_export.h>
#include <ktexteditor/cursor.h>
namespace KTextEditor
{
class SmartRange;
/**
* \short An object representing a section of text, from one Cursor to another.
*
* A Range is a basic class which represents a range of text with two Cursors,
* from a start() position to an end() position.
*
* For simplicity and convenience, ranges always maintain their start position to
* be before or equal to their end position. Attempting to set either the
* start or end of the range beyond the respective end or start will result in
* both values being set to the specified position. In the constructor, the
* start and end will be swapped if necessary.
*
* If you want additional functionality such as the ability to maintain position
* in a document, see SmartRange.
*
* \sa SmartRange
*
* \author Hamish Rodda \<rodda@kde.org\>
*/
class KTEXTEDITOR_EXPORT Range
{
friend class Cursor;
public:
/**
* Default constructor. Creates a valid range from position (0, 0) to
* position (0, 0).
*/
Range();
/**
* Constructor which creates a range from \e start to \e end.
* If start is after end, they will be swapped.
*
* \param start start position
* \param end end position
*/
Range(const Cursor& start, const Cursor& end);
/**
* Constructor which creates a single-line range from \p start,
* extending \p width characters along the same line.
*
* \param start start position
* \param width width of this range in columns along the same line
*/
Range(const Cursor& start, int width);
/**
* Constructor which creates a range from \p start, to \p endLine, \p endColumn.
*
* \param start start position
* \param endLine end line
* \param endColumn end column
*/
Range(const Cursor& start, int endLine, int endColumn);
/**
* Constructor which creates a range from \e startLine, \e startColumn to \e endLine, \e endColumn.
*
* \param startLine start line
* \param startColumn start column
* \param endLine end line
* \param endColumn end column
*/
Range(int startLine, int startColumn, int endLine, int endColumn);
/**
* Copy constructor.
*
* \param copy the range from which to copy the start and end position.
*/
Range(const Range& copy);
/**
* Virtual destructor.
*/
//Do not remove! Needed for inheritance.
virtual ~Range();
/**
* Validity check. In the base class, returns true unless the range starts before (0,0).
*/
virtual bool isValid() const;
/**
* Returns an invalid range.
*/
static Range invalid();
/**
* Returns whether this range is a SmartRange.
*/
virtual bool isSmartRange() const;
/**
* Returns this range as a SmartRange, if it is one.
*/
virtual SmartRange* toSmartRange() const;
/**
* \name Position
*
* The following functions provide access to, and manipulation of, the range's position.
* \{
*/
/**
* Get the start position of this range. This will always be <= end().
*
* This non-const function allows direct manipulation of the start position,
* while still retaining notification support.
*
* If start is set to a position after end, end will be moved to the
* same position as start, as ranges are not allowed to have
* start() > end().
*
* \note If you want to change both start() and end() simultaneously,
* you should use setRange(), for several reasons:
* \li otherwise, the rule preventing start() > end() may alter your intended change
* \li any notifications needed will be performed multiple times for no benefit
*
* \returns a reference to the start position of this range.
*/
Cursor& start();
/**
* Get the start position of this range. This will always be <= end().
*
* \returns a const reference to the start position of this range.
*
* \internal this function is virtual to allow for covariant return of SmartCursor%s.
*/
const Cursor& start() const;
/**
* Get the end position of this range. This will always be >= start().
*
* This non-const function allows direct manipulation of the end position,
* while still retaining notification support.
*
* If end is set to a position before start, start will be moved to the
* same position as end, as ranges are not allowed to have
* start() > end().
*
* \note If you want to change both start() and end() simultaneously,
* you should use setRange(), for several reasons:
* \li otherwise, the rule preventing start() > end() may alter your intended change
* \li any notifications needed will be performed multiple times for no benefit
*
* \returns a reference to the end position of this range.
*
* \internal this function is virtual to allow for covariant return of SmartCursor%s.
*/
Cursor& end();
/**
* Get the end position of this range. This will always be >= start().
*
* \returns a const reference to the end position of this range.
*
* \internal this function is virtual to allow for covariant return of SmartCursor%s.
*/
const Cursor& end() const;
/**
* Convenience function. Set the start and end lines to \p line.
*
* \param line the line number to assign to start() and end()
*/
void setBothLines(int line);
/**
* Convenience function. Set the start and end columns to \p column.
*
* \param column the column number to assign to start() and end()
*/
void setBothColumns(int column);
/**
* Set the start and end cursors to \e range.start() and \e range.end() respectively.
*
* \param range range to assign to this range
*/
virtual void setRange(const Range& range);
/**
* \overload
* \n \n
* Set the start and end cursors to \e start and \e end respectively.
*
* \note If \e start is after \e end, they will be reversed.
*
* \param start start cursor
* \param end end cursor
*/
void setRange(const Cursor& start, const Cursor& end);
/**
* Expand this range if necessary to contain \p range.
*
* \param range range which this range should contain
*
* \return \e true if expansion occurred, \e false otherwise
*/
virtual bool expandToRange(const Range& range);
/**
* Confine this range if necessary to fit within \p range.
*
* \param range range which should contain this range
*
* \return \e true if confinement occurred, \e false otherwise
*/
virtual bool confineToRange(const Range& range);
/**
* Check whether this range is wholly contained within one line, ie. if
* the start() and end() positions are on the same line.
*
* \return \e true if both the start and end positions are on the same
* line, otherwise \e false
*/
bool onSingleLine() const;
/**
* Returns the number of lines separating the start() and end() positions.
*
* \return the number of lines separating the start() and end() positions;
* 0 if the start and end lines are the same.
*/
int numberOfLines() const;
/**
* Returns the number of columns separating the start() and end() positions.
*
* \return the number of columns separating the start() and end() positions;
* 0 if the start and end columns are the same.
*/
int columnWidth() const;
/**
* Returns true if this range contains no characters, ie. the start() and
* end() positions are the same.
*
* \returns \e true if the range contains no characters, otherwise \e false
*/
bool isEmpty() const;
//BEGIN comparison functions
/**
* \}
*
* \name Comparison
*
* The following functions perform checks against this range in comparison
* to other lines, columns, cursors, and ranges.
* \{
*/
/**
* Check whether the this range wholly encompasses \e range.
*
* \param range range to check
*
* \return \e true, if this range contains \e range, otherwise \e false
*/
bool contains(const Range& range) const;
/**
* Check to see if \p cursor is contained within this range, ie >= start() and \< end().
*
* \param cursor the position to test for containment
*
* \return \e true if the cursor is contained within this range, otherwise \e false.
*/
bool contains(const Cursor& cursor) const;
/**
* Returns true if this range wholly encompasses \p line.
*
* \param line line to check
*
* \return \e true if the line is wholly encompassed by this range, otherwise \e false.
*/
bool containsLine(int line) const;
/**
* Check whether the range contains \e column.
*
* \param column column to check
*
* \return \e true if the range contains \e column, otherwise \e false
*/
bool containsColumn(int column) const;
/**
* Check whether the this range overlaps with \e range.
*
* \param range range to check against
*
* \return \e true, if this range overlaps with \e range, otherwise \e false
*/
bool overlaps(const Range& range) const;
/**
* Check whether the range overlaps at least part of \e line.
*
* \param line line to check
*
* \return \e true, if the range overlaps at least part of \e line, otherwise \e false
*/
bool overlapsLine(int line) const;
/**
* Check to see if this range overlaps \p column; that is, if \p column is
* between start().column() and end().column(). This function is most likely
* to be useful in relation to block text editing.
*
* \param column the column to test
*
* \return \e true if the column is between the range's starting and ending
* columns, otherwise \e false.
*/
bool overlapsColumn(int column) const;
/**
* Determine where \p cursor is positioned in relationship to this range.
* Equivalency (a return value of 0) is returned when \p cursor is \e contained
* within the range, not when \e overlapped - i.e., \p cursor may be on a
* line which is also partially occupied by this range, but the position
* may not be eqivalent. For overlap checking, use positionRelativeToLine().
*
* \param cursor position to check
*
* \return \e -1 if before, \e +1 if after, and \e 0 if \p cursor is contained within the range.
*
* \see positionRelativeToLine()
*/
int positionRelativeToCursor(const Cursor& cursor) const;
/**
* Determine where \p line is positioned in relationship to this range.
* Equivalency (a return value of 0) is returned when \p line is \e overlapped
* within the range, not when \e contained - i.e., this range may not cover an entire line,
* but \p line's position will still be eqivalent. For containment checking, use positionRelativeToCursor().
*
* \param line line to check
*
* \return \e -1 if before, \e +1 if after, and \e 0 if \p line is overlapped by this range.
*
* \see positionRelativeToCursor()
*/
int positionRelativeToLine(int line) const;
/**
* Check whether \p cursor is located at either of the start() or end()
* boundaries.
*
* \param cursor cursor to check
*
* \return \e true if the cursor is equal to \p start() or \p end(),
* otherwise \e false.
*/
bool boundaryAtCursor(const Cursor& cursor) const;
/**
* Check whether \p line is on the same line as either of the start() or
* end() boundaries.
*
* \param line line to check
*
* \return \e true if \p line is on the same line as either of the
* boundaries, otherwise \e false
*/
bool boundaryOnLine(int line) const;
/**
* Check whether \p column is on the same column as either of the start()
* or end() boundaries.
*
* \param column column to check
*
* \return \e true if \p column is on the same column as either of the
* boundaries, otherwise \e false
*/
bool boundaryOnColumn(int column) const;
//!\}
//END
/**
* Intersects this range with another, returning the shared area of
* the two ranges.
*
* \param range other range to intersect with this
*
* \return the intersection of this range and the supplied \a range.
*/
Range intersect(const Range& range) const;
/**
* Returns the smallest range which encompasses this range and the
* supplied \a range.
*
* \param range other range to encompass
*
* \return the smallest range which contains this range and the supplied \a range.
*/
Range encompass(const Range& range) const;
/**
* Assignment operator. Same as setRange().
*
* \param rhs range to assign to this range.
*
* \return a reference to this range, after assignment has occurred.
*
* \see setRange()
*/
inline Range& operator=(const Range& rhs)
{ setRange(rhs); return *this; }
/**
* Addition operator. Takes two ranges and returns their summation.
*
* \param r1 the first range
* \param r2 the second range
*
* \return a the summation of the two input ranges
*/
inline friend Range operator+(const Range& r1, const Range& r2)
{ return Range(r1.start() + r2.start(), r1.end() + r2.end()); }
/**
* Addition assignment operator. Adds \p r2 to this range.
*
* \param r1 the first range
* \param r2 the second range
*
* \return a reference to the cursor which has just been added to
*/
inline friend Range& operator+=(Range& r1, const Range& r2)
{ r1.setRange(r1.start() + r2.start(), r1.end() + r2.end()); return r1; }
/**
* Subtraction operator. Takes two ranges and returns the subtraction
* of \p r2 from \p r1.
*
* \param r1 the first range
* \param r2 the second range
*
* \return a range representing the subtraction of \p r2 from \p r1
*/
inline friend Range operator-(const Range& r1, const Range& r2)
{ return Range(r1.start() - r2.start(), r1.end() - r2.end()); }
/**
* Subtraction assignment operator. Subtracts \p r2 from \p r1.
*
* \param r1 the first range
* \param r2 the second range
*
* \return a reference to the range which has just been subtracted from
*/
inline friend Range& operator-=(Range& r1, const Range& r2)
{ r1.setRange(r1.start() - r2.start(), r1.end() - r2.end()); return r1; }
/**
* Intersects \a r1 and \a r2.
*
* \param r1 the first range
* \param r2 the second range
*
* \return the intersected range, invalid() if there is no overlap
*/
inline friend Range operator&(const Range& r1, const Range& r2)
{ return r1.intersect(r2); }
/**
* Intersects \a r1 with \a r2 and assigns the result to \a r1.
*
* \param r1 the range to assign the intersection to
* \param r2 the range to intersect \a r1 with
*
* \return a reference to this range, after the intersection has taken place
*/
inline friend Range& operator&=(Range& r1, const Range& r2)
{ r1.setRange(r1.intersect(r2)); return r1; }
/**
* Equality operator.
*
* \param r1 first range to compare
* \param r2 second range to compare
*
* \return \e true if \e r1 and \e r2 equal, otherwise \e false
*/
inline friend bool operator==(const Range& r1, const Range& r2)
{ return r1.start() == r2.start() && r1.end() == r2.end(); }
/**
* Inequality operator.
*
* \param r1 first range to compare
* \param r2 second range to compare
*
* \return \e true if \e r1 and \e r2 do \e not equal, otherwise \e false
*/
inline friend bool operator!=(const Range& r1, const Range& r2)
{ return r1.start() != r2.start() || r1.end() != r2.end(); }
/**
* Greater than operator. Looks only at the position of the two ranges,
* does not consider their size.
*
* \param r1 first range to compare
* \param r2 second range to compare
*
* \return \e true if \e r1 starts after where \e r2 ends, otherwise \e false
*/
inline friend bool operator>(const Range& r1, const Range& r2)
{ return r1.start() > r2.end(); }
/**
* Less than operator. Looks only at the position of the two ranges,
* does not consider their size.
*
* \param r1 first range to compare
* \param r2 second range to compare
*
* \return \e true if \e r1 ends before \e r2 begins, otherwise \e false
*/
inline friend bool operator<(const Range& r1, const Range& r2)
{ return r1.end() < r2.start(); }
/**
* kDebug() stream operator. Writes this range to the debug output in a nicely formatted way.
*/
inline friend QDebug operator<< (QDebug s, const Range& range) {
if (&range)
s << "[" << range.start() << " -> " << range.end() << "]";
else
s << "(null range)";
return s;
}
protected:
/**
* Constructor for advanced cursor types.
* Creates a range from \e start to \e end.
* Takes ownership of \e start and \e end.
*
* \param start the start cursor.
* \param end the end cursor.
*/
Range(Cursor* start, Cursor* end);
/**
* Notify this range that one or both of the cursors' position has changed directly.
*
* \param cursor the cursor that changed. If 0L, both cursors have changed.
* \param from the previous position of this range
*
* \internal
*/
virtual void rangeChanged(Cursor* cursor, const Range& from);
/**
* This range's start cursor pointer.
*
* \internal
*/
Cursor* m_start;
/**
* This range's end cursor pointer.
*
* \internal
*/
Cursor* m_end;
};
}
#endif
// kate: space-indent on; indent-width 2; replace-tabs on;
|