3 #include "ParagraphList.h"
7 ////////// The ParagraphList::iterator
9 ParagraphList::iterator::iterator()
14 ParagraphList::iterator::iterator(Paragraph * p)
19 ParagraphList::iterator::reference
20 ParagraphList::iterator::operator*()
26 ParagraphList::iterator::pointer
27 ParagraphList::iterator::operator->()
33 ParagraphList::iterator &
34 ParagraphList::iterator::operator++()
45 ParagraphList::iterator
46 ParagraphList::iterator::operator++(int)
54 ParagraphList::iterator &
55 ParagraphList::iterator::operator--()
66 ParagraphList::iterator
67 ParagraphList::iterator::operator--(int)
75 bool operator==(ParagraphList::iterator const & i1,
76 ParagraphList::iterator const & i2)
78 return &(*const_cast<ParagraphList::iterator&>(i1))
79 == &(*const_cast<ParagraphList::iterator&>(i2));
83 bool operator!=(ParagraphList::iterator const & i1,
84 ParagraphList::iterator const & i2)
90 ////////// The ParagraphList proper
93 ParagraphList::ParagraphList()
98 ParagraphList::ParagraphList(ParagraphList const & pl)
102 ParagraphList::iterator it = pl.begin();
103 ParagraphList::iterator end = pl.end();
104 for (; it != end; ++it) {
105 push_back(new Paragraph(*it, false));
110 ParagraphList & ParagraphList::operator=(ParagraphList const & rhs)
112 ParagraphList tmp(rhs);
113 std::swap(parlist, tmp.parlist);
118 ParagraphList::iterator
119 ParagraphList::insert(ParagraphList::iterator it, Paragraph * par)
123 Paragraph * prev = it->previous_;
125 par->previous_ = prev;
128 } else if (parlist == 0) {
132 Paragraph * last = parlist;
136 par->previous_ = last;
138 return iterator(par);
141 Paragraph * prev = it->prev_par_;
142 par->next_par_ = &*it;
143 par->prev_par_ = prev;
144 prev->next_par_ = par;
146 } else if (parlist == 0) {
150 Paragraph * last = parlist;
151 while (last->next_par_)
152 last = last->next_par_;
153 last->next_par_ = par;
154 par->prev_par_ = last;
156 return iterator(par);
162 void ParagraphList::insert(iterator pos, iterator beg, iterator end)
164 for (; beg != end; ++beg) {
165 insert(pos, new Paragraph(*beg, false));
170 void ParagraphList::assign(iterator beg, iterator end)
173 for (; beg != end; ++beg) {
174 push_back(new Paragraph(*beg, false));
179 void ParagraphList::splice(iterator pos, ParagraphList & pl)
184 Paragraph * first = pl.parlist;
185 Paragraph * last = first;
194 Paragraph * last_par = &back();
195 last_par->next_ = first;
196 first->previous_ = last_par;
198 } else if (pos == begin()) {
199 last->next_ = parlist;
200 parlist->previous_ = last;
203 Paragraph * pos_par = &*pos;
204 Paragraph * before_pos = pos_par->previous_;
206 before_pos->next_ = first;
207 first->previous_ = before_pos;
208 last->next_ = pos_par;
209 pos_par->previous_ = last;
213 while (last->next_par_)
214 last = last->next_par_;
220 Paragraph * last_par = &back();
221 last_par->next_par_ = first;
222 first->prev_par_ = last_par;
224 } else if (pos == begin()) {
225 last->next_par_ = parlist;
226 parlist->prev_par_ = last;
229 Paragraph * pos_par = &*pos;
230 Paragraph * before_pos = pos_par->prev_par_;
232 before_pos->next_par_ = first;
233 first->prev_par_ = before_pos;
234 last->next_par_ = pos_par;
235 pos_par->prev_par_ = last;
242 void ParagraphList::clear()
246 Paragraph * tmp = parlist->next_;
252 Paragraph * tmp = parlist->next_par_;
260 ParagraphList::iterator ParagraphList::erase(ParagraphList::iterator it)
263 Paragraph * prev = it->previous_;
264 Paragraph * next = it->next_;
272 next->previous_ = prev;
279 Paragraph * prev = it->prev_par_;
280 Paragraph * next = it->next_par_;
283 prev->next_par_ = next;
288 next->prev_par_ = prev;
296 ParagraphList::iterator ParagraphList::erase(ParagraphList::iterator first,
297 ParagraphList::iterator last)
299 while (first != last) {
306 ParagraphList::iterator ParagraphList::begin()
308 return iterator(parlist);
312 ParagraphList::iterator ParagraphList::begin() const
314 return iterator(parlist);
318 ParagraphList::iterator ParagraphList::end()
324 ParagraphList::iterator ParagraphList::end() const
330 Paragraph const & ParagraphList::front() const
336 Paragraph & ParagraphList::front()
342 Paragraph const & ParagraphList::back() const
345 Paragraph * tmp = parlist;
350 Paragraph * tmp = parlist;
351 while (tmp->next_par_)
352 tmp = tmp->next_par_;
358 Paragraph & ParagraphList::back()
361 Paragraph * tmp = parlist;
366 Paragraph * tmp = parlist;
367 while (tmp->next_par_)
368 tmp = tmp->next_par_;
374 void ParagraphList::set(Paragraph * p)
380 void ParagraphList::push_back(Paragraph * p)
388 Paragraph * pos = parlist;
399 Paragraph * pos = parlist;
400 while (pos->next_par_)
401 pos = pos->next_par_;
408 int ParagraphList::size() const
411 // When we switch to a std::container this will be O(1)
412 // instead of O(n). (Lgb)
413 Paragraph * tmp = parlist;
421 // When we switch to a std::container this will be O(1)
422 // instead of O(n). (Lgb)
423 Paragraph * tmp = parlist;
427 tmp = tmp->next_par_;
434 bool ParagraphList::empty() const