]> git.lyx.org Git - lyx.git/blob - src/mathed/math_rowst.h
mathed47.diff
[lyx.git] / src / mathed / math_rowst.h
1 // -*- C++ -*-
2 #ifndef MATH_ROWST_H
3 #define MATH_ROWST_H
4
5 #include <vector>
6 #include "support/LAssert.h"
7
8 /** The physical structure of a row and aditional information is stored here.
9     It allows to manage the extra info independently of the paragraph data.  
10     Only used for multiline paragraphs.
11  */
12
13 class MathedRowStruct
14 {
15 public:
16         ///
17         typedef std::vector<int> Widths;
18         
19         ///
20         explicit
21         MathedRowStruct(int n)
22                 : asc_(0), desc_(0), y_(0), widths_(n + 1, 0),
23                   numbered_(true)
24                 {}
25         ///
26         string const & getLabel() const;
27         ///
28         bool isNumbered() const;
29         ///
30         int  getBaseline() const;
31         ///
32         void setBaseline(int b);
33         ///
34         int ascent() const;
35         ///
36         int descent() const;
37         ///
38         void ascent(int a);
39         ///
40         void descent(int d);
41         ///
42         int  getTab(int i) const;
43         /// 
44         void setLabel(string const & l);
45         ///
46         void setNumbered(bool nf);
47         ///
48         void setTab(int i, int t);
49         ///
50         friend class MathedRowSt;
51 protected:
52         /// Vericals 
53         int asc_;
54         ///
55         int desc_;
56         ///
57         int y_;
58         /// widths 
59         Widths widths_;
60         /// 
61         string label_;
62         ///
63         bool numbered_;
64 };
65
66 class MathedRowSt : public MathedRowStruct {
67 public:
68         ///
69         explicit MathedRowSt(int n)
70                         : MathedRowStruct(n), next_(0)
71                 {}
72         /// Should be const but...
73         MathedRowSt * getNext() const;
74         /// ...we couldn't use this.
75         void setNext(MathedRowSt * n);
76 //private:
77         ///
78         MathedRowSt * next_;
79 };
80
81
82 // The idea is to change this  MathedRowContainer  to mimic the behaviour
83 // of std::list<MathedRowStruct> in several small steps.  In the end it
84 // could be replaced by such a list and MathedRowSt can go as well. 
85  
86 struct MathedRowContainer {
87         ///
88         struct iterator {
89                 ///
90                 iterator() : st_(0) {}
91                 ///
92                 explicit iterator(MathedRowSt * st) : st_(st) {}
93                 /// "better" conversion to bool
94                 explicit iterator(MathedRowContainer * m) : st_(m->data_) {}
95                 /// "better" conversion to bool
96                 operator void *() const { return st_; }
97                 ///
98                 MathedRowStruct & operator*() { Assert(st_); return *st_; }
99                 ///
100                 MathedRowStruct * operator->() { return st_; }
101                 ///
102                 MathedRowStruct const * operator->() const { return st_; }
103                 ///
104                 void operator++() { Assert(st_); st_ = st_->next_; }
105                 ///
106                 bool is_last() const { Assert(st_); return st_->next_ == 0; }
107                 ///
108                 bool operator==(const iterator & it) const { return st_ == it.st_; }
109
110         //private:
111                 ///
112                 MathedRowSt * st_;
113         };
114
115         ///
116         MathedRowContainer() : data_(0) {}
117         ///
118         MathedRowContainer(MathedRowSt * data) : data_(data) {}
119
120         ///
121         iterator begin() { return iterator(this); }
122         ///
123         bool empty() const { return data_ == 0; }
124
125         ///
126         MathedRowSt * data_;
127 };
128
129
130
131 inline
132 MathedRowSt * MathedRowSt::getNext() const
133 {
134         return next_;
135 }
136
137
138 inline
139 void MathedRowSt::setNext(MathedRowSt * n)
140 {
141         next_ = n;
142 }
143
144
145 inline
146 string const & MathedRowStruct::getLabel() const
147 {
148         return label_;
149 }
150
151
152 inline
153 bool MathedRowStruct::isNumbered() const
154 {
155         return numbered_;
156 }
157
158
159 inline
160 int MathedRowStruct::getBaseline() const
161 {
162         return y_;
163 }
164
165
166 inline
167 void MathedRowStruct::setBaseline(int b)
168 {
169         y_ = b;
170 }
171
172
173 inline
174 int MathedRowStruct::ascent() const
175 {
176         return asc_;
177 }
178
179
180 inline
181 int MathedRowStruct::descent() const
182 {
183         return desc_;
184 }
185
186
187 inline
188 void MathedRowStruct::ascent(int a)
189 {
190         asc_ = a;
191 }
192
193
194 inline
195 void MathedRowStruct::descent(int d)
196 {
197         desc_ = d;
198 }
199
200
201 inline
202 int MathedRowStruct::getTab(int i) const
203 {
204         return widths_[i];
205 }
206
207
208 inline
209 void MathedRowStruct::setLabel(string const & l)
210 {
211         label_ = l;
212 }
213
214
215 inline
216 void MathedRowStruct::setNumbered(bool nf)
217 {
218         numbered_ = nf;
219 }
220
221
222 inline
223 void MathedRowStruct::setTab(int i, int t)
224 {
225         widths_[i] = t;
226 }
227 #endif