]> git.lyx.org Git - lyx.git/blob - src/mathed/math_pos.C
Standardise the header blurb in mathed.
[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 #include "support/LOstream.h"
18
19 using namespace lyx::support;
20
21 using std::endl;
22
23
24 CursorPos::CursorPos()
25         : inset_(0), idx_(0), pos_(0)
26 {}
27
28
29 CursorPos::CursorPos(MathInset * p)
30         : inset_(p), idx_(0), pos_(0)
31 {
32         Assert(inset_);
33 }
34
35
36
37 MathArray & CursorPos::cell(MathArray::idx_type idx) const
38 {
39         Assert(inset_);
40         return inset_->cell(idx);
41 }
42
43
44 MathArray & CursorPos::cell() const
45 {
46         Assert(inset_);
47         return inset_->cell(idx_);
48 }
49
50
51 void CursorPos::getPos(int & x, int & y) const
52 {
53         inset_->getPos(idx_, pos_, x, y);
54 }
55
56
57 void CursorPos::setPos(MathArray::pos_type pos)
58 {
59         pos_ = pos;
60 }
61
62
63 std::ostream & operator<<(std::ostream & os, CursorPos const & p)
64 {
65         os << "(par: " << p.inset_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ')';
66         return os;
67 }
68
69
70 bool operator==(CursorPos const & p, CursorPos const & q)
71 {
72         return p.inset_ == q.inset_ && p.idx_ == q.idx_ && p.pos_ == q.pos_;
73 }
74
75
76 bool operator!=(CursorPos const & p, CursorPos const & q)
77 {
78         return p.inset_ != q.inset_ || p.idx_ != q.idx_ || p.pos_ != q.pos_;
79 }
80
81
82 bool operator<(CursorPos const & p, CursorPos const & q)
83 {
84         if (p.inset_ != q.inset_) {
85                 lyxerr << "can't compare cursor and anchor in different insets"
86                        << endl;
87                 return true;
88         }
89         if (p.idx_ != q.idx_)
90                 return p.idx_ < q.idx_;
91         return p.pos_ < q.pos_;
92 }