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);
161 void ParagraphList::assign(iterator beg, iterator end)
164 for (; beg != end; ++beg) {
165 push_back(new Paragraph(*beg, false));
171 void ParagraphList::clear()
175 Paragraph * tmp = parlist->next_;
181 Paragraph * tmp = parlist->next_par_;
189 void ParagraphList::erase(ParagraphList::iterator it)
192 Paragraph * prev = it->previous_;
193 Paragraph * next = it->next_;
201 next->previous_ = prev;
207 Paragraph * prev = it->prev_par_;
208 Paragraph * next = it->next_par_;
211 prev->next_par_ = next;
216 next->prev_par_ = prev;
223 ParagraphList::iterator ParagraphList::begin()
225 return iterator(parlist);
229 ParagraphList::iterator ParagraphList::begin() const
231 return iterator(parlist);
235 ParagraphList::iterator ParagraphList::end()
241 ParagraphList::iterator ParagraphList::end() const
247 Paragraph const & ParagraphList::front() const
253 Paragraph & ParagraphList::front()
259 Paragraph const & ParagraphList::back() const
262 Paragraph * tmp = parlist;
267 Paragraph * tmp = parlist;
268 while (tmp->next_par_)
269 tmp = tmp->next_par_;
275 Paragraph & ParagraphList::back()
278 Paragraph * tmp = parlist;
283 Paragraph * tmp = parlist;
284 while (tmp->next_par_)
285 tmp = tmp->next_par_;
291 void ParagraphList::set(Paragraph * p)
297 void ParagraphList::push_back(Paragraph * p)
305 Paragraph * pos = parlist;
316 Paragraph * pos = parlist;
317 while (pos->next_par_)
318 pos = pos->next_par_;
325 int ParagraphList::size() const
328 // When we switch to a std::container this will be O(1)
329 // instead of O(n). (Lgb)
330 Paragraph * tmp = parlist;
338 // When we switch to a std::container this will be O(1)
339 // instead of O(n). (Lgb)
340 Paragraph * tmp = parlist;
344 tmp = tmp->next_par_;
351 bool ParagraphList::empty() const