]> git.lyx.org Git - features.git/blob - src/mathed/math_rowst.h
488967e4faa4b7f1461a11847b45f76ce511d2bc
[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         iterator begin() { return iterator(this); }
121         ///
122         bool empty() const { return data_ == 0; }
123
124         /// insert 'item' before 'iterator'
125         void insert(iterator const & it, MathedRowSt const & item) {
126                 MathedRowSt * r = new MathedRowSt(item);
127                 if (data_ == it.st_)
128                         data_ = r;
129                 else {
130                         MathedRowSt * pos = data_;
131                         if (pos->next_ == it.st_)
132                                 pos->next_ = r;
133                 }
134                 r->next_  = it.st_;
135         }
136                         
137         /// insert 'item' after 'iterator'
138         void insert_after(iterator & it, MathedRowSt const & item) {
139                 MathedRowSt * r = new MathedRowSt(item);
140                 if (it) {
141                         r->next_ = it.st_->next_;
142                         it.st_->next_ = r;
143                 } else {
144                         it.st_ = r;
145                         r->next_ = 0;
146                 }
147         }
148
149         ///
150         MathedRowSt * data_;
151
152 private:
153         // currently unimplemented just to make sure it's not used
154         MathedRowContainer(MathedRowContainer const &); // unimplemented
155         void operator=(MathedRowContainer const &); // unimplemented
156 };
157
158
159
160 inline
161 string const & MathedRowStruct::getLabel() const
162 {
163         return label_;
164 }
165
166
167 inline
168 bool MathedRowStruct::isNumbered() const
169 {
170         return numbered_;
171 }
172
173
174 inline
175 int MathedRowStruct::getBaseline() const
176 {
177         return y_;
178 }
179
180
181 inline
182 void MathedRowStruct::setBaseline(int b)
183 {
184         y_ = b;
185 }
186
187
188 inline
189 int MathedRowStruct::ascent() const
190 {
191         return asc_;
192 }
193
194
195 inline
196 int MathedRowStruct::descent() const
197 {
198         return desc_;
199 }
200
201
202 inline
203 void MathedRowStruct::ascent(int a)
204 {
205         asc_ = a;
206 }
207
208
209 inline
210 void MathedRowStruct::descent(int d)
211 {
212         desc_ = d;
213 }
214
215
216 inline
217 int MathedRowStruct::getTab(int i) const
218 {
219         return widths_[i];
220 }
221
222
223 inline
224 void MathedRowStruct::setLabel(string const & l)
225 {
226         label_ = l;
227 }
228
229
230 inline
231 void MathedRowStruct::setNumbered(bool nf)
232 {
233         numbered_ = nf;
234 }
235
236
237 inline
238 void MathedRowStruct::setTab(int i, int t)
239 {
240         widths_[i] = t;
241 }
242 #endif