]> git.lyx.org Git - features.git/blob - src/mathed/math_rowst.h
mathed58.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         MathedRowStruct()
21                 : asc_(0), desc_(0), y_(0), numbered_(true)
22                 {}
23         ///
24         string const & getLabel() const;
25         ///
26         bool isNumbered() const;
27         ///
28         int  getBaseline() const;
29         ///
30         void setBaseline(int b);
31         ///
32         int ascent() const;
33         ///
34         int descent() const;
35         ///
36         void ascent(int a);
37         ///
38         void descent(int d);
39         ///
40         int  getTab(unsigned int i) const;
41         /// 
42         void setLabel(string const & l);
43         ///
44         void setNumbered(bool nf);
45         ///
46         void setTab(unsigned int i, int t);
47 protected:
48         /// verticals 
49         int asc_;
50         ///
51         int desc_;
52         ///
53         int y_;
54         /// widths 
55         Widths widths_;
56         /// 
57         string label_;
58         ///
59         bool numbered_;
60 };
61
62
63  
64 class MathedRowContainer {
65 private:
66         ///
67         struct iterator {
68                 ///
69                 iterator() : st_(0), pos_(0) {}
70                 ///
71                 explicit iterator(MathedRowContainer * m) : st_(m), pos_(0) {}
72                 /// "better" conversion to bool, static_cast doens't help?
73                 operator void *() const
74                         { return (void *)(st_ && pos_ < st_->data_.size()); }
75                 ///
76                 MathedRowStruct & operator*() { Assert(st_); return st_->data_[pos_]; }
77                 ///
78                 MathedRowStruct * operator->() { Assert(st_); return &st_->data_[pos_]; }
79                 ///
80                 MathedRowStruct const * operator->() const { Assert(st_); return &st_->data_[pos_]; }
81                 ///
82                 void operator++() { Assert(st_); ++pos_; }
83                 ///
84                 bool is_last() const { Assert(st_); return pos_ == st_->data_.size() - 1; }
85                 ///
86                 bool operator==(const iterator & it) const
87                         { return st_ == it.st_ && pos_ == it.pos_; }
88
89         //private:
90                 ///
91                 friend class MathedRowContainer;
92
93                 /// pointer to the container to which we belong
94                 MathedRowContainer * st_;
95                 /// position in this container, e.g. row number
96                 unsigned int pos_;
97         };
98
99 public:
100         /// 
101         iterator begin() { return iterator(this); }
102         ///
103         bool empty() const { return data_.size() == 0; }
104
105         /// insert item before 'it'
106         void insert(iterator const & it) {
107                 Assert(it.st_ == this);
108                 data_.insert(data_.begin() + it.pos_, MathedRowStruct());
109         }
110                         
111         /// erase item pointed to by 'it'
112         void erase(iterator & it) {
113                 Assert(it.st_ == this);
114                 data_.erase(data_.begin() + it.pos_);
115         }
116
117         /// access to last item
118         MathedRowStruct & back() {
119                 Assert(data_.size());
120                 return data_.back();
121         }
122         
123         /// append empty element
124         void push_back() {
125                 data_.push_back(MathedRowStruct());
126         }
127         
128
129         ///
130         std::vector<MathedRowStruct> data_;
131
132 private:
133         // currently unimplemented just to make sure it's not used
134         void operator=(MathedRowContainer const &); // unimplemented
135 };
136
137
138
139 inline
140 string const & MathedRowStruct::getLabel() const
141 {
142         return label_;
143 }
144
145
146 inline
147 bool MathedRowStruct::isNumbered() const
148 {
149         return numbered_;
150 }
151
152
153 inline
154 int MathedRowStruct::getBaseline() const
155 {
156         return y_;
157 }
158
159
160 inline
161 void MathedRowStruct::setBaseline(int b)
162 {
163         y_ = b;
164 }
165
166
167 inline
168 int MathedRowStruct::ascent() const
169 {
170         return asc_;
171 }
172
173
174 inline
175 int MathedRowStruct::descent() const
176 {
177         return desc_;
178 }
179
180
181 inline
182 void MathedRowStruct::ascent(int a)
183 {
184         asc_ = a;
185 }
186
187
188 inline
189 void MathedRowStruct::descent(int d)
190 {
191         desc_ = d;
192 }
193
194
195 inline
196 int MathedRowStruct::getTab(unsigned int i) const
197 {
198         return i < widths_.size() ? widths_[i] : 0;
199 }
200
201
202 inline
203 void MathedRowStruct::setLabel(string const & l)
204 {
205         label_ = l;
206 }
207
208
209 inline
210 void MathedRowStruct::setNumbered(bool nf)
211 {
212         numbered_ = nf;
213 }
214
215
216 inline
217 void MathedRowStruct::setTab(unsigned int i, int t)
218 {
219         if (i >= widths_.size())
220                 widths_.resize(i + 2);  
221         widths_[i] = t;
222 }
223 #endif