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));
180 void ParagraphList::clear()
184 Paragraph * tmp = parlist->next_;
190 Paragraph * tmp = parlist->next_par_;
198 void ParagraphList::erase(ParagraphList::iterator it)
201 Paragraph * prev = it->previous_;
202 Paragraph * next = it->next_;
210 next->previous_ = prev;
216 Paragraph * prev = it->prev_par_;
217 Paragraph * next = it->next_par_;
220 prev->next_par_ = next;
225 next->prev_par_ = prev;
232 ParagraphList::iterator ParagraphList::begin()
234 return iterator(parlist);
238 ParagraphList::iterator ParagraphList::begin() const
240 return iterator(parlist);
244 ParagraphList::iterator ParagraphList::end()
250 ParagraphList::iterator ParagraphList::end() const
256 Paragraph const & ParagraphList::front() const
262 Paragraph & ParagraphList::front()
268 Paragraph const & ParagraphList::back() const
271 Paragraph * tmp = parlist;
276 Paragraph * tmp = parlist;
277 while (tmp->next_par_)
278 tmp = tmp->next_par_;
284 Paragraph & ParagraphList::back()
287 Paragraph * tmp = parlist;
292 Paragraph * tmp = parlist;
293 while (tmp->next_par_)
294 tmp = tmp->next_par_;
300 void ParagraphList::set(Paragraph * p)
306 void ParagraphList::push_back(Paragraph * p)
314 Paragraph * pos = parlist;
325 Paragraph * pos = parlist;
326 while (pos->next_par_)
327 pos = pos->next_par_;
334 int ParagraphList::size() const
337 // When we switch to a std::container this will be O(1)
338 // instead of O(n). (Lgb)
339 Paragraph * tmp = parlist;
347 // When we switch to a std::container this will be O(1)
348 // instead of O(n). (Lgb)
349 Paragraph * tmp = parlist;
353 tmp = tmp->next_par_;
360 bool ParagraphList::empty() const