]> git.lyx.org Git - features.git/blob - src/mathed/math_rowst.h
373aff6bcabb8c7c5dd923e7a772b91b954ccbb3
[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 class MathedRowSt : public MathedRowStruct {
67 public:
68         ///
69         explicit MathedRowSt(int n)
70                         : MathedRowStruct(n), next_(0)
71                 {}
72         ///
73         MathedRowSt * next_;
74 };
75
76
77 // The idea is to change this  MathedRowContainer  to mimic the behaviour
78 // of std::list<MathedRowStruct> in several small steps.  In the end it
79 // could be replaced by such a list and MathedRowSt can go as well. 
80  
81 struct MathedRowContainer {
82         ///
83         struct iterator {
84                 ///
85                 iterator() : st_(0) {}
86                 ///
87                 explicit iterator(MathedRowSt * st) : st_(st) {}
88                 ///
89                 explicit iterator(MathedRowContainer * m) : st_(m->data_) {}
90                 /// "better" conversion to bool
91                 operator void *() const { return st_; }
92                 ///
93                 MathedRowStruct & operator*() { Assert(st_); return *st_; }
94                 ///
95                 MathedRowStruct * operator->() { return st_; }
96                 ///
97                 MathedRowStruct const * operator->() const { return st_; }
98                 ///
99                 void operator++() { Assert(st_); st_ = st_->next_; }
100                 ///
101                 bool is_last() const { Assert(st_); return st_->next_ == 0; }
102                 ///
103                 bool operator==(const iterator & it) const { return st_ == it.st_; }
104
105         //private:
106                 ///
107                 MathedRowSt * st_;
108         };
109
110         ///
111         MathedRowContainer() : data_(0) {}
112         ///
113         MathedRowContainer(MathedRowSt * data) : data_(data) {}
114
115         ///
116         iterator begin() { return iterator(this); }
117         ///
118         bool empty() const { return data_ == 0; }
119
120         /// insert 'item' before 'iterator'
121         void insert(iterator const & pos, MathedRowSt const & item) {
122                 MathedRowSt * st = new MathedRowSt(item);
123                 link_before(pos, st);
124         }
125
126         void link_before(iterator const & it, MathedRowSt * r) {
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
138         ///
139         MathedRowSt * data_;
140 };
141
142
143
144 inline
145 string const & MathedRowStruct::getLabel() const
146 {
147         return label_;
148 }
149
150
151 inline
152 bool MathedRowStruct::isNumbered() const
153 {
154         return numbered_;
155 }
156
157
158 inline
159 int MathedRowStruct::getBaseline() const
160 {
161         return y_;
162 }
163
164
165 inline
166 void MathedRowStruct::setBaseline(int b)
167 {
168         y_ = b;
169 }
170
171
172 inline
173 int MathedRowStruct::ascent() const
174 {
175         return asc_;
176 }
177
178
179 inline
180 int MathedRowStruct::descent() const
181 {
182         return desc_;
183 }
184
185
186 inline
187 void MathedRowStruct::ascent(int a)
188 {
189         asc_ = a;
190 }
191
192
193 inline
194 void MathedRowStruct::descent(int d)
195 {
196         desc_ = d;
197 }
198
199
200 inline
201 int MathedRowStruct::getTab(int i) const
202 {
203         return widths_[i];
204 }
205
206
207 inline
208 void MathedRowStruct::setLabel(string const & l)
209 {
210         label_ = l;
211 }
212
213
214 inline
215 void MathedRowStruct::setNumbered(bool nf)
216 {
217         numbered_ = nf;
218 }
219
220
221 inline
222 void MathedRowStruct::setTab(int i, int t)
223 {
224         widths_[i] = t;
225 }
226 #endif