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 void ParagraphList::erase(ParagraphList::iterator it)
263 Paragraph * prev = it->previous_;
264 Paragraph * next = it->next_;
272 next->previous_ = prev;
278 Paragraph * prev = it->prev_par_;
279 Paragraph * next = it->next_par_;
282 prev->next_par_ = next;
287 next->prev_par_ = prev;
294 ParagraphList::iterator ParagraphList::begin()
296 return iterator(parlist);
300 ParagraphList::iterator ParagraphList::begin() const
302 return iterator(parlist);
306 ParagraphList::iterator ParagraphList::end()
312 ParagraphList::iterator ParagraphList::end() const
318 Paragraph const & ParagraphList::front() const
324 Paragraph & ParagraphList::front()
330 Paragraph const & ParagraphList::back() const
333 Paragraph * tmp = parlist;
338 Paragraph * tmp = parlist;
339 while (tmp->next_par_)
340 tmp = tmp->next_par_;
346 Paragraph & ParagraphList::back()
349 Paragraph * tmp = parlist;
354 Paragraph * tmp = parlist;
355 while (tmp->next_par_)
356 tmp = tmp->next_par_;
362 void ParagraphList::set(Paragraph * p)
368 void ParagraphList::push_back(Paragraph * p)
376 Paragraph * pos = parlist;
387 Paragraph * pos = parlist;
388 while (pos->next_par_)
389 pos = pos->next_par_;
396 int ParagraphList::size() const
399 // When we switch to a std::container this will be O(1)
400 // instead of O(n). (Lgb)
401 Paragraph * tmp = parlist;
409 // When we switch to a std::container this will be O(1)
410 // instead of O(n). (Lgb)
411 Paragraph * tmp = parlist;
415 tmp = tmp->next_par_;
422 bool ParagraphList::empty() const