]> git.lyx.org Git - lyx.git/blob - src/mathed/math_pos.C
Finish the task of removing all cruft from the header files.
[lyx.git] / src / mathed / math_pos.C
1 /**
2  * \file math_pos.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "math_pos.h"
14 #include "math_inset.h"
15 #include "debug.h"
16 #include "support/LAssert.h"
17
18 using namespace lyx::support;
19
20 using std::endl;
21
22
23 CursorPos::CursorPos()
24         : inset_(0), idx_(0), pos_(0)
25 {}
26
27
28 CursorPos::CursorPos(MathInset * p)
29         : inset_(p), idx_(0), pos_(0)
30 {
31         Assert(inset_);
32 }
33
34
35
36 MathArray & CursorPos::cell(MathArray::idx_type idx) const
37 {
38         Assert(inset_);
39         return inset_->cell(idx);
40 }
41
42
43 MathArray & CursorPos::cell() const
44 {
45         Assert(inset_);
46         return inset_->cell(idx_);
47 }
48
49
50 void CursorPos::getPos(int & x, int & y) const
51 {
52         inset_->getPos(idx_, pos_, x, y);
53 }
54
55
56 void CursorPos::setPos(MathArray::pos_type pos)
57 {
58         pos_ = pos;
59 }
60
61
62 std::ostream & operator<<(std::ostream & os, CursorPos const & p)
63 {
64         os << "(par: " << p.inset_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ')';
65         return os;
66 }
67
68
69 bool operator==(CursorPos const & p, CursorPos const & q)
70 {
71         return p.inset_ == q.inset_ && p.idx_ == q.idx_ && p.pos_ == q.pos_;
72 }
73
74
75 bool operator!=(CursorPos const & p, CursorPos const & q)
76 {
77         return p.inset_ != q.inset_ || p.idx_ != q.idx_ || p.pos_ != q.pos_;
78 }
79
80
81 bool operator<(CursorPos const & p, CursorPos const & q)
82 {
83         if (p.inset_ != q.inset_) {
84                 lyxerr << "can't compare cursor and anchor in different insets"
85                        << endl;
86                 return true;
87         }
88         if (p.idx_ != q.idx_)
89                 return p.idx_ < q.idx_;
90         return p.pos_ < q.pos_;
91 }