replace most &dquot;...&dquot; by <...>
[lyx.git] / src / cursor_slice.C
blobf891844e196547906fa8ac0d54d414290325c0ab
1 /**
2  * \file cursor_slice.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Matthias Ettrich
8  * \author André Pönitz
9  * \author Jürgen Vigna
10  *
11  * Full author contact details are available in file CREDITS.
12  */
14 #include <config.h>
16 #include "cursor_slice.h"
17 #include "debug.h"
18 #include "lyxtext.h"
19 #include "paragraph.h"
21 #include "mathed/math_inset.h"
22 #include "mathed/math_data.h"
24 #include "insets/updatableinset.h"
27 #include <boost/assert.hpp>
29 using std::endl;
32 CursorSlice::CursorSlice()
33         : inset_(0), idx_(0), par_(0), pos_(0), boundary_(false)
37 CursorSlice::CursorSlice(InsetBase & p)
38         : inset_(&p), idx_(0), par_(0), pos_(0), boundary_(false)
40         BOOST_ASSERT(inset_);
44 size_t CursorSlice::nargs() const
46         BOOST_ASSERT(inset_);
47         return inset_->nargs();
51 size_t CursorSlice::nrows() const
53         BOOST_ASSERT(inset_);
54         return inset_->nrows();
58 size_t CursorSlice::ncols() const
60         BOOST_ASSERT(inset_);
61         return inset_->ncols();
65 CursorSlice::pos_type CursorSlice::lastpos() const
67         BOOST_ASSERT(inset_);
68         return inset_->asMathInset() ? cell().size() : paragraph().size();
72 CursorSlice::row_type CursorSlice::row() const
74         BOOST_ASSERT(asMathInset());
75         return asMathInset()->row(idx_);
79 CursorSlice::col_type CursorSlice::col() const
81         BOOST_ASSERT(asMathInset());
82         return asMathInset()->col(idx_);
86 MathInset * CursorSlice::asMathInset() const
88         BOOST_ASSERT(inset_);
89         return inset_->asMathInset();
93 UpdatableInset * CursorSlice::asUpdatableInset() const
95         BOOST_ASSERT(inset_);
96         return inset_->asUpdatableInset();
100 MathArray & CursorSlice::cell() const
102         BOOST_ASSERT(asMathInset());
103         return asMathInset()->cell(idx_);
107 LyXText * CursorSlice::text() const
109         BOOST_ASSERT(inset_);
110         return inset_->getText(idx_);
114 Paragraph & CursorSlice::paragraph()
116         // access to the main lyx text must be handled in the cursor
117         BOOST_ASSERT(text());
118         return text()->getPar(par_);
122 Paragraph const & CursorSlice::paragraph() const
124         // access to the main lyx text must be handled in the cursor
125         BOOST_ASSERT(text());
126         return text()->getPar(par_);
130 bool operator==(CursorSlice const & p, CursorSlice const & q)
132         return &p.inset() == &q.inset()
133                && p.idx() == q.idx()
134                && p.par() == q.par()
135                && p.pos() == q.pos();
139 bool operator!=(CursorSlice const & p, CursorSlice const & q)
141         return &p.inset() != &q.inset()
142                || p.idx() != q.idx()
143                || p.par() != q.par()
144                || p.pos() != q.pos();
148 bool operator<(CursorSlice const & p, CursorSlice const & q)
150         if (&p.inset() != &q.inset()) {
151                 lyxerr << "can't compare cursor and anchor in different insets\n"
152                        << "p: " << p << '\n' << "q: " << q << endl;
153                 BOOST_ASSERT(false);
154         }
155         if (p.idx() != q.idx())
156                 return p.idx() < q.idx();
157         if (p.par() != q.par())
158                 return p.par() < q.par();
159         return p.pos() < q.pos();
163 bool operator>(CursorSlice const & p, CursorSlice const & q)
165         return q < p;
169 bool operator<=(CursorSlice const & p, CursorSlice const & q)
171         return !(q < p);
175 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
177         return os
178            << "inset: " << &item.inset()
179 //         << " text: " << item.text()
180            << " idx: " << item.idx()
181            << " par: " << item.par()
182            << " pos: " << item.pos()
183 //         << " x: " << item.inset().x()
184 //         << " y: " << item.inset().y()