+2003-05-24 Lars Gullik Bjønnes <larsbj@gullik.net>
+
+ * paragraph.h: add NO_STD_LIST define, remove NO_NEXT define.
+
+ * paragraph.C: remove all NO_NEXT node add some NO_STD_LIST parts
+ instead.
+
+ * ParagraphList.h: degenerate to std::list if NO_STD_LIST is not
+ set else use old code.
+
+ * ParagraphList.C: remove all NO_NEXT code and only compile this
+ code of NO_STD_LIST is set.
+
2003-05-23 Alfredo Braunstein <abraunst@libero.it>
* BufferView_pimpl.C:
2003-05-23 Lars Gullik Bjønnes <larsbj@gullik.net>
- * ParagraphList.h (set): remove unused function.
+ * ParagraphList.h (set): remove unused function.
2003-05-23 André Pönitz <poenitz@gmx.net>
#include "paragraph.h"
+#ifdef NO_STD_LIST
+
////////// The ParagraphList::iterator
ParagraphList::iterator::iterator()
ParagraphList::iterator &
ParagraphList::iterator::operator++()
{
-#ifndef NO_NEXT
- ptr = ptr->next_;
-#else
ptr = ptr->next_par_;
-#endif
return *this;
}
ParagraphList::iterator &
ParagraphList::iterator::operator--()
{
-#ifndef NO_NEXT
- ptr = ptr->previous_;
-#else
ptr = ptr->prev_par_;
-#endif
return *this;
}
ParagraphList::iterator
ParagraphList::insert(ParagraphList::iterator it, Paragraph * par)
{
-#ifndef NO_NEXT
- if (it != end()) {
- Paragraph * prev = it->previous_;
- par->next_ = &*it;
- par->previous_ = prev;
- prev->next_ = par;
- it->previous_ = par;
- } else if (parlist == 0) {
- parlist = par;
- } else {
- // Find last par.
- Paragraph * last = parlist;
- while (last->next_)
- last = last->next_;
- last->next_ = par;
- par->previous_ = last;
- }
- return iterator(par);
-#else
if (it != end()) {
Paragraph * prev = it->prev_par_;
par->next_par_ = &*it;
par->prev_par_ = last;
}
return iterator(par);
-#endif
}
Paragraph * first = pl.parlist;
Paragraph * last = first;
-#ifndef NO_NEXT
- while (last->next_)
- last = last->next_;
-
- if (pos == end()) {
- if (parlist == 0) {
- parlist = first;
- } else {
- Paragraph * last_par = &back();
- last_par->next_ = first;
- first->previous_ = last_par;
- }
- } else if (pos == begin()) {
- last->next_ = parlist;
- parlist->previous_ = last;
- parlist = first;
- } else {
- Paragraph * pos_par = &*pos;
- Paragraph * before_pos = pos_par->previous_;
-
- before_pos->next_ = first;
- first->previous_ = before_pos;
- last->next_ = pos_par;
- pos_par->previous_ = last;
- }
- pl.parlist = 0;
-#else
while (last->next_par_)
last = last->next_par_;
pos_par->prev_par_ = last;
}
pl.parlist = 0;
-#endif
}
void ParagraphList::clear()
{
-#ifndef NO_NEXT
- while (parlist) {
- Paragraph * tmp = parlist->next_;
- delete parlist;
- parlist = tmp;
- }
-#else
while (parlist) {
Paragraph * tmp = parlist->next_par_;
delete parlist;
parlist = tmp;
}
-#endif
}
ParagraphList::iterator ParagraphList::erase(ParagraphList::iterator it)
{
-#ifndef NO_NEXT
- Paragraph * prev = it->previous_;
- Paragraph * next = it->next_;
-
- if (prev)
- prev->next_ = next;
- else
- parlist = next;
-
- if (next)
- next->previous_ = prev;
-
- it->previous_ = 0;
- it->next_ = 0;
- delete &*it;
- return next;
-#else
Paragraph * prev = it->prev_par_;
Paragraph * next = it->next_par_;
delete &*it;
return next;
-#endif
}
Paragraph const & ParagraphList::back() const
{
-#ifndef NO_NEXT
- Paragraph * tmp = parlist;
- while (tmp->next_)
- tmp = tmp->next_;
- return *tmp;
-#else
Paragraph * tmp = parlist;
while (tmp->next_par_)
tmp = tmp->next_par_;
return *tmp;
-#endif
}
Paragraph & ParagraphList::back()
{
-#ifndef NO_NEXT
- Paragraph * tmp = parlist;
- while (tmp->next_)
- tmp = tmp->next_;
- return *tmp;
-#else
Paragraph * tmp = parlist;
while (tmp->next_par_)
tmp = tmp->next_par_;
return *tmp;
-#endif
}
void ParagraphList::push_back(Paragraph * p)
{
-#ifndef NO_NEXT
- if (!parlist) {
- parlist = p;
- return;
- }
-
- Paragraph * pos = parlist;
- while (pos->next_)
- pos = pos->next_;
- pos->next_ = p;
- p->previous_ = pos;
-#else
if (!parlist) {
parlist = p;
return;
pos = pos->next_par_;
pos->next_par_ = p;
p->prev_par_ = pos;
-#endif
}
int ParagraphList::size() const
{
-#ifndef NO_NEXT
- // 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_;
- }
- return c;
-#else
// When we switch to a std::container this will be O(1)
// instead of O(n). (Lgb)
Paragraph * tmp = parlist;
tmp = tmp->next_par_;
}
return c;
-#endif
}
{
return parlist == 0;
}
+
+#endif
#ifndef PARAGRAPH_LIST_H
#define PARAGRAPH_LIST_H
-#include <iterator>
-#include <utility>
+#define NO_STD_LIST 1
+
+#ifndef NO_STD_LIST
+
+#include "paragraph.h"
+
+#include <list>
+
+typedef std::list<Paragraph> ParagraphList;
+
+#else
class Paragraph;
+#include <iterator>
+#include <utility>
+
///
class ParagraphList {
public:
bool operator!=(ParagraphList::iterator const & i1,
ParagraphList::iterator const & i2);
+#endif
#endif
Paragraph::Paragraph()
: pimpl_(new Paragraph::Pimpl(this))
{
-#ifndef NO_NEXT
- next_ = 0;
- previous_ = 0;
-#else
+#ifdef NO_STD_LIST
next_par_ = 0;
prev_par_ = 0;
#endif
{
enumdepth = 0;
itemdepth = 0;
-#ifndef NO_NEXT
- next_ = 0;
- previous_ = 0;
-#else
+#ifdef NO_STD_LIST
next_par_ = 0;
prev_par_ = 0;
#endif
// the destructor removes the new paragraph from the list
Paragraph::~Paragraph()
{
-#ifndef NO_NEXT
- if (previous_)
- previous_->next_ = next_;
- if (next_)
- next_->previous_ = previous_;
-#endif
-
delete pimpl_;
//
//lyxerr << "Paragraph::paragraph_id = "
}
-#ifndef NO_NEXT
-void Paragraph::next(Paragraph * p)
-{
- next_ = p;
-}
-
-
-// This function is able to hide closed footnotes.
-Paragraph * Paragraph::next()
-{
- return next_;
-}
-
-
-Paragraph const * Paragraph::next() const
-{
- return next_;
-}
-
-
-void Paragraph::previous(Paragraph * p)
-{
- previous_ = p;
-}
-
-
-// This function is able to hide closed footnotes.
-Paragraph * Paragraph::previous()
-{
- return previous_;
-}
-
-
-// This function is able to hide closed footnotes.
-Paragraph const * Paragraph::previous() const
-{
- return previous_;
-}
-#endif
-
-
void Paragraph::makeSameLayout(Paragraph const & par)
{
layout(par.layout());
// Define this if you want to try out the new storage container for
// paragraphs. (Lgb)
// This is non working and far from finished.
-#define NO_NEXT 1
+#define NO_STD_LIST 1
/// A Paragraph holds all text, attributes and insets in a text paragraph
class Paragraph {
public:
+#ifdef NO_STD_LIST
// Remove this whan ParagraphList transition is over. (Lgb)
friend class ParagraphList;
friend class ParagraphList::iterator;
-
+#endif
///
enum META_KIND {
/// Note that this is 1 right now to avoid
///
InsetBibitem * bibitem(); // ale970302
-#ifndef NO_NEXT
- ///
- void next(Paragraph *);
- /** these function are able to hide closed footnotes
- */
- Paragraph * next();
- ///
- Paragraph const * next() const;
-
- ///
- void previous(Paragraph *);
- ///
- Paragraph * previous();
- ///
- Paragraph const * previous() const;
-#endif
-
/// initialise tracking for this par
void trackChanges(Change::Type = Change::UNCHANGED);
LyXLayout_ptr layout_;
/// if anything uses this we don't want it to.
Paragraph(Paragraph const &);
-#ifndef NO_NEXT
- ///
- Paragraph * next_;
- ///
- Paragraph * previous_;
-#else
+#ifdef NO_STD_LIST
Paragraph * next_par_;
Paragraph * prev_par_;
#endif