point.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (C) 2003 Mooffie <mooffie@typo.co.il>
  2. //
  3. // This program is free software; you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation; either version 2 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  16. #ifndef BDE_POINT_H
  17. #define BDE_POINT_H
  18. // struct Point represents a point in the EditBox buffer. It consists of a
  19. // paragraph number and a character index within this paragraphs. The cursor
  20. // itself is of type Point.
  21. struct Point {
  22. int para;
  23. idx_t pos;
  24. Point(int para, idx_t pos) {
  25. this->para = para;
  26. this->pos = pos;
  27. }
  28. Point() {
  29. zero();
  30. }
  31. void zero() {
  32. para = 0;
  33. pos = 0;
  34. }
  35. void swap(Point &p) {
  36. Point tmp = p;
  37. p = *this;
  38. *this = tmp;
  39. }
  40. bool operator< (const Point &p) const {
  41. return para < p.para || (para == p.para && pos < p.pos);
  42. }
  43. bool operator== (const Point &p) const {
  44. return para == p.para && pos == p.pos;
  45. }
  46. bool operator> (const Point &p) const {
  47. return !(*this == p || *this < p);
  48. }
  49. };
  50. #endif