3 #include "ParagraphList.h"
9 ////////// The ParagraphList::iterator
11 ParagraphList::iterator::iterator()
16 ParagraphList::iterator::iterator(Paragraph * p)
21 ParagraphList::iterator::reference
22 ParagraphList::iterator::operator*()
28 ParagraphList::iterator::pointer
29 ParagraphList::iterator::operator->()
35 ParagraphList::iterator &
36 ParagraphList::iterator::operator++()
43 ParagraphList::iterator
44 ParagraphList::iterator::operator++(int)
52 ParagraphList::iterator &
53 ParagraphList::iterator::operator--()
60 ParagraphList::iterator
61 ParagraphList::iterator::operator--(int)
69 bool operator==(ParagraphList::iterator const & i1,
70 ParagraphList::iterator const & i2)
72 return &(*const_cast<ParagraphList::iterator&>(i1))
73 == &(*const_cast<ParagraphList::iterator&>(i2));
77 bool operator!=(ParagraphList::iterator const & i1,
78 ParagraphList::iterator const & i2)
83 ////////// The ParagraphList::const_iterator
85 ParagraphList::const_iterator::const_iterator()
90 ParagraphList::const_iterator::const_iterator(Paragraph * p)
95 ParagraphList::const_iterator::const_reference
96 ParagraphList::const_iterator::operator*()
102 ParagraphList::const_iterator::const_pointer
103 ParagraphList::const_iterator::operator->()
109 ParagraphList::const_iterator &
110 ParagraphList::const_iterator::operator++()
112 ptr = ptr->next_par_;
117 ParagraphList::const_iterator
118 ParagraphList::const_iterator::operator++(int)
120 const_iterator tmp = *this;
126 ParagraphList::const_iterator &
127 ParagraphList::const_iterator::operator--()
129 ptr = ptr->prev_par_;
134 ParagraphList::const_iterator
135 ParagraphList::const_iterator::operator--(int)
137 const_iterator tmp = *this;
143 bool operator==(ParagraphList::const_iterator const & i1,
144 ParagraphList::const_iterator const & i2)
146 return &(*const_cast<ParagraphList::const_iterator&>(i1))
147 == &(*const_cast<ParagraphList::const_iterator&>(i2));
151 bool operator!=(ParagraphList::const_iterator const & i1,
152 ParagraphList::const_iterator const & i2)
158 ////////// The ParagraphList proper
161 ParagraphList::ParagraphList()
166 ParagraphList::ParagraphList(ParagraphList const & pl)
170 ParagraphList::const_iterator it = pl.begin();
171 ParagraphList::const_iterator end = pl.end();
172 for (; it != end; ++it) {
178 ParagraphList & ParagraphList::operator=(ParagraphList const & rhs)
180 ParagraphList tmp(rhs);
181 std::swap(parlist, tmp.parlist);
186 ParagraphList::iterator
187 ParagraphList::insert(ParagraphList::iterator it, Paragraph const & p)
189 Paragraph * par = new Paragraph(p);
192 Paragraph * prev = it->prev_par_;
193 par->next_par_ = &*it;
194 par->prev_par_ = prev;
195 prev->next_par_ = par;
197 } else if (parlist == 0) {
201 Paragraph * last = parlist;
202 while (last->next_par_)
203 last = last->next_par_;
204 last->next_par_ = par;
205 par->prev_par_ = last;
207 return iterator(par);
212 void ParagraphList::insert(iterator pos, iterator beg, iterator end)
214 for (; beg != end; ++beg) {
220 void ParagraphList::assign(iterator beg, iterator end)
223 for (; beg != end; ++beg) {
229 void ParagraphList::splice(iterator pos, ParagraphList & pl)
234 Paragraph * first = pl.parlist;
235 Paragraph * last = first;
236 while (last->next_par_)
237 last = last->next_par_;
243 Paragraph * last_par = &back();
244 last_par->next_par_ = first;
245 first->prev_par_ = last_par;
247 } else if (pos == begin()) {
248 last->next_par_ = parlist;
249 parlist->prev_par_ = last;
252 Paragraph * pos_par = &*pos;
253 Paragraph * before_pos = pos_par->prev_par_;
255 before_pos->next_par_ = first;
256 first->prev_par_ = before_pos;
257 last->next_par_ = pos_par;
258 pos_par->prev_par_ = last;
264 void ParagraphList::clear()
267 Paragraph * tmp = parlist->next_par_;
274 ParagraphList::iterator ParagraphList::erase(ParagraphList::iterator it)
276 Paragraph * prev = it->prev_par_;
277 Paragraph * next = it->next_par_;
280 prev->next_par_ = next;
285 next->prev_par_ = prev;
292 ParagraphList::iterator ParagraphList::erase(ParagraphList::iterator first,
293 ParagraphList::iterator last)
295 while (first != last) {
302 ParagraphList::iterator ParagraphList::begin()
304 return iterator(parlist);
308 ParagraphList::const_iterator ParagraphList::begin() const
310 return const_iterator(parlist);
314 ParagraphList::iterator ParagraphList::end()
320 ParagraphList::const_iterator ParagraphList::end() const
322 return const_iterator();
326 Paragraph const & ParagraphList::front() const
332 Paragraph & ParagraphList::front()
338 Paragraph const & ParagraphList::back() const
340 Paragraph * tmp = parlist;
341 while (tmp->next_par_)
342 tmp = tmp->next_par_;
347 Paragraph & ParagraphList::back()
349 Paragraph * tmp = parlist;
350 while (tmp->next_par_)
351 tmp = tmp->next_par_;
356 void ParagraphList::push_back(Paragraph const & pr)
358 Paragraph * p = new Paragraph(pr);
365 Paragraph * pos = parlist;
366 while (pos->next_par_)
367 pos = pos->next_par_;
373 int ParagraphList::size() const
375 // When we switch to a std::container this will be O(1)
376 // instead of O(n). (Lgb)
377 Paragraph * tmp = parlist;
381 tmp = tmp->next_par_;
387 bool ParagraphList::empty() const