]> git.lyx.org Git - lyx.git/blob - src/mathed/math_pos.C
cosmetic fix
[lyx.git] / src / mathed / math_pos.C
1 #include "config.h"
2 #include "math_pos.h"
3 #include "math_inset.h"
4 #include "debug.h"
5 #include "support/LAssert.h"
6 #include "support/LOstream.h"
7
8 using namespace lyx::support;
9
10 CursorPos::CursorPos()
11         : inset_(0), idx_(0), pos_(0)
12 {}
13
14
15 CursorPos::CursorPos(MathInset * p)
16         : inset_(p), idx_(0), pos_(0)
17 {
18         Assert(inset_);
19 }
20
21
22
23 MathArray & CursorPos::cell(MathArray::idx_type idx) const
24 {
25         Assert(inset_);
26         return inset_->cell(idx);
27 }
28
29
30 MathArray & CursorPos::cell() const
31 {
32         Assert(inset_);
33         return inset_->cell(idx_);
34 }
35
36
37 void CursorPos::getPos(int & x, int & y) const
38 {
39         inset_->getPos(idx_, pos_, x, y);
40 }
41
42
43 void CursorPos::setPos(MathArray::pos_type pos)
44 {
45         pos_ = pos;
46 }
47
48
49 std::ostream & operator<<(std::ostream & os, CursorPos const & p)
50 {
51         os << "(par: " << p.inset_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ')';
52         return os;
53 }
54
55
56 bool operator==(CursorPos const & p, CursorPos const & q)
57 {
58         return p.inset_ == q.inset_ && p.idx_ == q.idx_ && p.pos_ == q.pos_;
59 }
60
61
62 bool operator!=(CursorPos const & p, CursorPos const & q)
63 {
64         return p.inset_ != q.inset_ || p.idx_ != q.idx_ || p.pos_ != q.pos_;
65 }
66
67
68 bool operator<(CursorPos const & p, CursorPos const & q)
69 {
70         if (p.inset_ != q.inset_) {
71                 lyxerr << "can't compare cursor and anchor in different insets\n";
72                 return true;
73         }
74         if (p.idx_ != q.idx_)
75                 return p.idx_ < q.idx_;
76         return p.pos_ < q.pos_;
77 }