]> git.lyx.org Git - features.git/blob - src/mathed/math_rowst.h
mathed50.diff
[features.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
67 class MathedRowContainer;
68
69 class MathedRowSt : public MathedRowStruct {
70 public:
71         ///
72         explicit MathedRowSt(int n)
73                         : MathedRowStruct(n), next_(0)
74                 {}
75 //private:
76         ///
77         MathedRowSt * next_;
78         ///
79         friend class MathedRowContainer;
80 };
81
82
83 // The idea is to change this  MathedRowContainer  to mimic the behaviour
84 // of std::list<MathedRowStruct> in several small steps.  In the end it
85 // could be replaced by such a list and MathedRowSt can go as well. 
86  
87 struct MathedRowContainer {
88         ///
89         struct iterator {
90                 ///
91                 iterator() : st_(0) {}
92                 ///
93                 explicit iterator(MathedRowSt * st) : st_(st) {}
94                 ///
95                 explicit iterator(MathedRowContainer * m) : st_(m->data_) {}
96                 /// "better" conversion to bool
97                 operator void *() const { return st_; }
98                 ///
99                 MathedRowStruct & operator*() { Assert(st_); return *st_; }
100                 ///
101                 MathedRowStruct * operator->() { return st_; }
102                 ///
103                 MathedRowStruct const * operator->() const { return st_; }
104                 ///
105                 void operator++() { Assert(st_); st_ = st_->next_; }
106                 ///
107                 bool is_last() const { Assert(st_); return st_->next_ == 0; }
108                 ///
109                 bool operator==(const iterator & it) const { return st_ == it.st_; }
110
111         //private:
112                 ///
113                 MathedRowSt * st_;
114         };
115
116         ///
117         MathedRowContainer() : data_(0) {}
118
119         ///
120         MathedRowContainer(MathedRowContainer const & c) : data_(0) {
121                 if (!c.empty()) {
122                         MathedRowSt * ro = 0;
123                         MathedRowSt * mrow = c.data_;
124
125                         while (mrow) {
126                                 MathedRowSt * r = new MathedRowSt(*mrow);
127                                 if (!ro) 
128                                         data_ = r;
129                                 else
130                                         ro->next_ = r;
131                                 mrow = mrow->next_;
132                                 ro = r;
133                         }
134                 }
135         }
136
137                 
138         ~MathedRowContainer() {
139                 MathedRowSt * r = data_;
140                 while (r) {
141                         MathedRowSt * q = r->next_;
142                         delete r;
143                         r = q;
144                 }
145         }
146
147         ///
148         iterator begin() { return iterator(this); }
149         ///
150         bool empty() const { return data_ == 0; }
151
152         /// insert 'item' before 'iterator'
153         void insert(iterator const & it, MathedRowSt const & item) {
154                 MathedRowSt * r = new MathedRowSt(item);
155                 if (data_ == it.st_)
156                         data_ = r;
157                 else {
158                         MathedRowSt * pos = data_;
159                         if (pos->next_ == it.st_)
160                                 pos->next_ = r;
161                 }
162                 r->next_  = it.st_;
163         }
164                         
165         /// insert 'item' after 'iterator'
166         void insert_after(iterator & it, MathedRowSt const & item) {
167                 MathedRowSt * r = new MathedRowSt(item);
168                 if (it) {
169                         r->next_ = it.st_->next_;
170                         it.st_->next_ = r;
171                 } else {
172                         it.st_ = r;
173                         r->next_ = 0;
174                 }
175         }
176
177         ///
178         MathedRowSt * data_;
179
180 private:
181         // currently unimplemented just to make sure it's not used
182         void operator=(MathedRowContainer const &); // unimplemented
183 };
184
185
186
187 inline
188 string const & MathedRowStruct::getLabel() const
189 {
190         return label_;
191 }
192
193
194 inline
195 bool MathedRowStruct::isNumbered() const
196 {
197         return numbered_;
198 }
199
200
201 inline
202 int MathedRowStruct::getBaseline() const
203 {
204         return y_;
205 }
206
207
208 inline
209 void MathedRowStruct::setBaseline(int b)
210 {
211         y_ = b;
212 }
213
214
215 inline
216 int MathedRowStruct::ascent() const
217 {
218         return asc_;
219 }
220
221
222 inline
223 int MathedRowStruct::descent() const
224 {
225         return desc_;
226 }
227
228
229 inline
230 void MathedRowStruct::ascent(int a)
231 {
232         asc_ = a;
233 }
234
235
236 inline
237 void MathedRowStruct::descent(int d)
238 {
239         desc_ = d;
240 }
241
242
243 inline
244 int MathedRowStruct::getTab(int i) const
245 {
246         return widths_[i];
247 }
248
249
250 inline
251 void MathedRowStruct::setLabel(string const & l)
252 {
253         label_ = l;
254 }
255
256
257 inline
258 void MathedRowStruct::setNumbered(bool nf)
259 {
260         numbered_ = nf;
261 }
262
263
264 inline
265 void MathedRowStruct::setTab(int i, int t)
266 {
267         widths_[i] = t;
268 }
269 #endif