2002-08-12 00:15:19 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "ParagraphList.h"
|
|
|
|
|
|
|
|
#include "paragraph.h"
|
|
|
|
|
|
|
|
////////// The ParagraphList::iterator
|
|
|
|
|
|
|
|
ParagraphList::iterator::iterator()
|
|
|
|
: ptr(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
ParagraphList::iterator::iterator(Paragraph * p)
|
|
|
|
: ptr(p)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
ParagraphList::iterator::reference
|
|
|
|
ParagraphList::iterator::operator*()
|
|
|
|
{
|
|
|
|
return *ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ParagraphList::iterator::pointer
|
|
|
|
ParagraphList::iterator::operator->()
|
|
|
|
{
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ParagraphList::iterator &
|
|
|
|
ParagraphList::iterator::operator++()
|
|
|
|
{
|
2003-04-15 19:18:24 +00:00
|
|
|
#ifndef NO_NEXT
|
2003-04-02 21:19:35 +00:00
|
|
|
ptr = ptr->next_;
|
2003-04-15 19:18:24 +00:00
|
|
|
#else
|
|
|
|
ptr = ptr->next_par_;
|
|
|
|
#endif
|
2002-08-12 00:15:19 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ParagraphList::iterator
|
|
|
|
ParagraphList::iterator::operator++(int)
|
|
|
|
{
|
|
|
|
iterator tmp = *this;
|
|
|
|
++*this;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ParagraphList::iterator &
|
|
|
|
ParagraphList::iterator::operator--()
|
|
|
|
{
|
2003-04-15 19:18:24 +00:00
|
|
|
#ifndef NO_NEXT
|
2003-04-02 21:19:35 +00:00
|
|
|
ptr = ptr->previous_;
|
2003-04-15 19:18:24 +00:00
|
|
|
#else
|
|
|
|
ptr = ptr->prev_par_;
|
|
|
|
#endif
|
2002-08-12 00:15:19 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ParagraphList::iterator
|
|
|
|
ParagraphList::iterator::operator--(int)
|
|
|
|
{
|
|
|
|
iterator tmp = *this;
|
|
|
|
--*this;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool operator==(ParagraphList::iterator const & i1,
|
2002-08-14 18:40:10 +00:00
|
|
|
ParagraphList::iterator const & i2)
|
2002-08-12 00:15:19 +00:00
|
|
|
{
|
2002-08-13 17:43:40 +00:00
|
|
|
return &(*const_cast<ParagraphList::iterator&>(i1))
|
|
|
|
== &(*const_cast<ParagraphList::iterator&>(i2));
|
2002-08-12 00:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool operator!=(ParagraphList::iterator const & i1,
|
2002-08-14 18:40:10 +00:00
|
|
|
ParagraphList::iterator const & i2)
|
2002-08-12 00:15:19 +00:00
|
|
|
{
|
|
|
|
return !(i1 == i2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////// The ParagraphList proper
|
|
|
|
ParagraphList::ParagraphList()
|
|
|
|
: parlist(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2003-03-04 21:40:36 +00:00
|
|
|
ParagraphList::iterator
|
|
|
|
ParagraphList::insert(ParagraphList::iterator it, Paragraph * par)
|
|
|
|
{
|
2003-04-15 19:18:24 +00:00
|
|
|
#ifndef NO_NEXT
|
2003-03-05 09:41:49 +00:00
|
|
|
if (it != end()) {
|
2003-04-02 21:19:35 +00:00
|
|
|
Paragraph * prev = it->previous_;
|
|
|
|
par->next_ = &*it;
|
|
|
|
par->previous_ = prev;
|
|
|
|
prev->next_ = par;
|
|
|
|
it->previous_ = par;
|
2003-03-06 21:01:04 +00:00
|
|
|
} else if (parlist == 0) {
|
|
|
|
parlist = par;
|
2003-03-05 09:41:49 +00:00
|
|
|
} else {
|
|
|
|
// Find last par.
|
|
|
|
Paragraph * last = parlist;
|
2003-04-02 21:19:35 +00:00
|
|
|
while (last->next_)
|
|
|
|
last = last->next_;
|
|
|
|
last->next_ = par;
|
|
|
|
par->previous_ = last;
|
2003-03-05 09:41:49 +00:00
|
|
|
}
|
2003-03-04 21:40:36 +00:00
|
|
|
return iterator(par);
|
2003-04-15 19:18:24 +00:00
|
|
|
#else
|
|
|
|
if (it != end()) {
|
|
|
|
Paragraph * prev = it->prev_par_;
|
|
|
|
par->next_par_ = &*it;
|
|
|
|
par->prev_par_ = prev;
|
|
|
|
prev->next_par_ = par;
|
|
|
|
it->prev_ par_= par;
|
|
|
|
} else if (parlist == 0) {
|
|
|
|
parlist = par;
|
|
|
|
} else {
|
|
|
|
// Find last par.
|
|
|
|
Paragraph * last = parlist;
|
|
|
|
while (last->next_par_)
|
|
|
|
last = last->next_par_;
|
|
|
|
last->next_par_ = par;
|
|
|
|
par->prev_par_ = last;
|
|
|
|
}
|
|
|
|
return iterator(par);
|
|
|
|
#endif
|
2003-03-04 21:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-12 00:15:19 +00:00
|
|
|
void ParagraphList::clear()
|
|
|
|
{
|
2003-04-15 19:18:24 +00:00
|
|
|
#ifndef NO_NEXT
|
2002-08-12 00:15:19 +00:00
|
|
|
while (parlist) {
|
2003-04-02 21:19:35 +00:00
|
|
|
Paragraph * tmp = parlist->next_;
|
2002-08-12 00:15:19 +00:00
|
|
|
delete parlist;
|
|
|
|
parlist = tmp;
|
|
|
|
}
|
2003-04-15 19:18:24 +00:00
|
|
|
#else
|
|
|
|
while (parlist) {
|
|
|
|
Paragraph * tmp = parlist->next_par_;
|
|
|
|
delete parlist;
|
|
|
|
parlist = tmp;
|
|
|
|
}
|
|
|
|
#endif
|
2002-08-12 00:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-04 20:45:02 +00:00
|
|
|
void ParagraphList::erase(ParagraphList::iterator it)
|
|
|
|
{
|
2003-04-15 19:18:24 +00:00
|
|
|
#ifndef NO_NEXT
|
2003-04-02 21:19:35 +00:00
|
|
|
Paragraph * prev = it->previous_;
|
|
|
|
Paragraph * next = it->next_;
|
2003-03-04 20:45:02 +00:00
|
|
|
|
2003-03-05 09:41:49 +00:00
|
|
|
if (prev)
|
2003-04-02 21:19:35 +00:00
|
|
|
prev->next_ = next;
|
2003-03-26 10:59:22 +00:00
|
|
|
else
|
|
|
|
parlist = next;
|
|
|
|
|
2003-03-05 09:41:49 +00:00
|
|
|
if (next)
|
2003-04-02 21:19:35 +00:00
|
|
|
next->previous_ = prev;
|
2003-03-04 20:45:02 +00:00
|
|
|
|
2003-04-16 00:02:38 +00:00
|
|
|
it->previous_ = 0;
|
|
|
|
it->next_ = 0;
|
2003-03-04 20:45:02 +00:00
|
|
|
delete &*it;
|
2003-04-15 19:18:24 +00:00
|
|
|
#else
|
|
|
|
Paragraph * prev = it->prev_par_;
|
|
|
|
Paragraph * next = it->next_par_;
|
|
|
|
|
|
|
|
if (prev)
|
|
|
|
prev->next_par_ = next;
|
|
|
|
else
|
|
|
|
parlist = next;
|
|
|
|
|
|
|
|
if (next)
|
|
|
|
next->prev_par_ = prev;
|
|
|
|
|
|
|
|
delete &*it;
|
|
|
|
#endif
|
2003-03-04 20:45:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-14 18:40:10 +00:00
|
|
|
ParagraphList::iterator ParagraphList::begin()
|
2002-08-12 00:15:19 +00:00
|
|
|
{
|
|
|
|
return iterator(parlist);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ParagraphList::iterator ParagraphList::begin() const
|
|
|
|
{
|
|
|
|
return iterator(parlist);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ParagraphList::iterator ParagraphList::end()
|
|
|
|
{
|
|
|
|
return iterator();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ParagraphList::iterator ParagraphList::end() const
|
|
|
|
{
|
|
|
|
return iterator();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-06 21:01:04 +00:00
|
|
|
Paragraph const & ParagraphList::front() const
|
|
|
|
{
|
|
|
|
return *parlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Paragraph & ParagraphList::front()
|
|
|
|
{
|
|
|
|
return *parlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Paragraph const & ParagraphList::back() const
|
|
|
|
{
|
2003-04-15 19:18:24 +00:00
|
|
|
#ifndef NO_NEXT
|
2003-03-06 21:01:04 +00:00
|
|
|
Paragraph * tmp = parlist;
|
2003-04-02 21:19:35 +00:00
|
|
|
while (tmp->next_)
|
|
|
|
tmp = tmp->next_;
|
2003-03-06 21:01:04 +00:00
|
|
|
return *tmp;
|
2003-04-15 19:18:24 +00:00
|
|
|
#else
|
|
|
|
Paragraph * tmp = parlist;
|
|
|
|
while (tmp->next_par_)
|
|
|
|
tmp = tmp->next_par_;
|
|
|
|
return *tmp;
|
|
|
|
#endif
|
2003-03-06 21:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Paragraph & ParagraphList::back()
|
|
|
|
{
|
2003-04-15 19:18:24 +00:00
|
|
|
#ifndef NO_NEXT
|
2003-03-06 21:01:04 +00:00
|
|
|
Paragraph * tmp = parlist;
|
2003-04-02 21:19:35 +00:00
|
|
|
while (tmp->next_)
|
|
|
|
tmp = tmp->next_;
|
2003-03-06 21:01:04 +00:00
|
|
|
return *tmp;
|
2003-04-15 19:18:24 +00:00
|
|
|
#else
|
|
|
|
Paragraph * tmp = parlist;
|
|
|
|
while (tmp->next_par_)
|
|
|
|
tmp = tmp->next_par_;
|
|
|
|
return *tmp;
|
|
|
|
#endif
|
2003-03-06 21:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-12 00:15:19 +00:00
|
|
|
void ParagraphList::set(Paragraph * p)
|
|
|
|
{
|
|
|
|
parlist = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-13 17:43:40 +00:00
|
|
|
void ParagraphList::push_back(Paragraph * p)
|
|
|
|
{
|
2003-04-15 19:18:24 +00:00
|
|
|
#ifndef NO_NEXT
|
2002-08-13 17:43:40 +00:00
|
|
|
if (!parlist) {
|
|
|
|
parlist = p;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Paragraph * pos = parlist;
|
2003-04-02 21:19:35 +00:00
|
|
|
while (pos->next_)
|
|
|
|
pos = pos->next_;
|
|
|
|
pos->next_ = p;
|
|
|
|
p->previous_ = pos;
|
2003-04-15 19:18:24 +00:00
|
|
|
#else
|
|
|
|
if (!parlist) {
|
|
|
|
parlist = p;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Paragraph * pos = parlist;
|
|
|
|
while (pos->next_par_)
|
|
|
|
pos = pos->next_par_;
|
|
|
|
pos->next_par_ = p;
|
|
|
|
p->prev_par_ = pos;
|
|
|
|
#endif
|
2002-08-13 17:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-12 00:15:19 +00:00
|
|
|
int ParagraphList::size() const
|
|
|
|
{
|
2003-04-15 19:18:24 +00:00
|
|
|
#ifndef NO_NEXT
|
2002-08-12 00:15:19 +00:00
|
|
|
// When we switch to a std::container this will be O(1)
|
|
|
|
// instead of O(n). (Lgb)
|
|
|
|
Paragraph * tmp = parlist;
|
|
|
|
int c = 0;
|
|
|
|
while (tmp) {
|
|
|
|
++c;
|
2003-04-02 21:19:35 +00:00
|
|
|
tmp = tmp->next_;
|
2002-08-12 00:15:19 +00:00
|
|
|
}
|
|
|
|
return c;
|
2003-04-15 19:18:24 +00:00
|
|
|
#else
|
|
|
|
// When we switch to a std::container this will be O(1)
|
|
|
|
// instead of O(n). (Lgb)
|
|
|
|
Paragraph * tmp = parlist;
|
|
|
|
int c = 0;
|
|
|
|
while (tmp) {
|
|
|
|
++c;
|
|
|
|
tmp = tmp->next_par_;
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
#endif
|
2002-08-12 00:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ParagraphList::empty() const
|
|
|
|
{
|
|
|
|
return parlist == 0;
|
|
|
|
}
|