]> git.lyx.org Git - lyx.git/blob - src/mathed/math_iterator.h
Jean-Marc's fix for wrong descent
[lyx.git] / src / mathed / math_iterator.h
1 // -*- C++ -*-
2 #ifndef MATH_ITERATOR_H
3 #define MATH_ITERATOR_H
4
5
6 #include "math_pos.h"
7 #include <vector>
8
9 // this is used for traversing math insets
10
11 class MathIterator : private std::vector<MathCursorPos> {
12 public:
13         // re-use inherited stuff
14         typedef std::vector<MathCursorPos> base_type;
15         using base_type::clear;
16         using base_type::size;
17         using base_type::push_back;
18         using base_type::pop_back;
19         using base_type::back;
20         using base_type::begin;
21         using base_type::end;
22         using base_type::erase;
23         using base_type::operator[];
24         using base_type::size_type;
25         using base_type::difference_type;
26         using base_type::const_iterator;
27         friend bool operator!=(MathIterator const &, MathIterator const &);
28         friend bool operator==(MathIterator const &, MathIterator const &);
29
30         /// default constructor
31         MathIterator();
32         /// start with given inset
33         explicit MathIterator(MathInset * p);
34         ///
35         MathCursorPos const & operator*() const;
36         ///
37         MathCursorPos const & operator->() const;
38         /// move on one step
39         void operator++();
40         /// move on several steps
41         void jump(difference_type);
42         /// read access to top most inset
43         MathInset const * par() const;
44         /// read access to top most inset
45         MathInset * par();
46         /// helper for iend
47         void goEnd();
48         /// read access to top most item
49         MathArray const & cell() const;
50         /// is this a non-end position
51         bool normal() const;
52         /// shrinks to at most i levels
53         void shrink(size_type i);
54
55 private:
56         /// own level down
57         void push(MathInset *);
58         /// own level up
59         void pop();
60 };
61
62 ///
63 bool operator==(MathIterator const &, MathIterator const &);
64 ///
65 bool operator!=(MathIterator const &, MathIterator const &);
66
67 ///
68 MathIterator ibegin(MathInset * p);
69 ///
70 MathIterator iend(MathInset * p);
71
72 #endif