Add the RowList files

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6582 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2003-03-26 11:04:29 +00:00
parent a6c7b5bc14
commit 336be5b8f5
3 changed files with 322 additions and 0 deletions

View File

@ -77,6 +77,8 @@ lyx_SOURCES = \
ParagraphParameters.h \
ParameterStruct.h \
PrinterParams.h \
RowList.C \
RowList.h \
ShareContainer.h \
Spacing.C \
Spacing.h \

230
src/RowList.C Normal file
View File

@ -0,0 +1,230 @@
#include <config.h>
#include "RowList.h"
#include "lyxrow.h"
////////// The RowList::iterator
RowList::iterator::iterator()
: ptr(0)
{}
RowList::iterator::iterator(Row * p)
: ptr(p)
{}
RowList::iterator::reference
RowList::iterator::operator*()
{
return *ptr;
}
RowList::iterator::pointer
RowList::iterator::operator->()
{
return ptr;
}
RowList::iterator &
RowList::iterator::operator++()
{
ptr = ptr->next();
return *this;
}
RowList::iterator
RowList::iterator::operator++(int)
{
iterator tmp = *this;
++*this;
return tmp;
}
RowList::iterator &
RowList::iterator::operator--()
{
ptr = ptr->previous();
return *this;
}
RowList::iterator
RowList::iterator::operator--(int)
{
iterator tmp = *this;
--*this;
return tmp;
}
bool operator==(RowList::iterator const & i1,
RowList::iterator const & i2)
{
return &(*const_cast<RowList::iterator&>(i1))
== &(*const_cast<RowList::iterator&>(i2));
}
bool operator!=(RowList::iterator const & i1,
RowList::iterator const & i2)
{
return !(i1 == i2);
}
////////// The RowList proper
RowList::RowList()
: rowlist(0)
{}
RowList::iterator
RowList::insert(RowList::iterator it, Row * row)
{
if (it != end()) {
Row * prev = it->previous();
row->next(&*it);
row->previous(prev);
prev->next(row);
it->previous(row);
} else if (rowlist == 0) {
rowlist = row;
} else {
// Find last par.
Row * last = rowlist;
while (last->next())
last = last->next();
last->next(row);
row->previous(last);
}
return iterator(row);
}
void RowList::clear()
{
while (rowlist) {
Row * tmp = rowlist->next();
delete rowlist;
rowlist = tmp;
}
}
void RowList::erase(RowList::iterator it)
{
Row * prev = it->previous();
Row * next = it->next();
if (prev)
prev->next(next);
else
rowlist = next;
if (next)
next->previous(prev);
delete &*it;
}
RowList::iterator RowList::begin()
{
return iterator(rowlist);
}
RowList::iterator RowList::begin() const
{
return iterator(rowlist);
}
RowList::iterator RowList::end()
{
return iterator();
}
RowList::iterator RowList::end() const
{
return iterator();
}
Row const & RowList::front() const
{
return *rowlist;
}
Row & RowList::front()
{
return *rowlist;
}
Row const & RowList::back() const
{
Row * tmp = rowlist;
while (tmp->next())
tmp = tmp->next();
return *tmp;
}
Row & RowList::back()
{
Row * tmp = rowlist;
while (tmp->next())
tmp = tmp->next();
return *tmp;
}
void RowList::set(Row * p)
{
rowlist = p;
}
void RowList::push_back(Row * p)
{
if (!rowlist) {
rowlist = p;
return;
}
Row * pos = rowlist;
while (pos->next())
pos = pos->next();
pos->next(p);
p->previous(pos);
}
int RowList::size() const
{
// When we switch to a std::container this will be O(1)
// instead of O(n). (Lgb)
Row * tmp = rowlist;
int c = 0;
while (tmp) {
++c;
tmp = tmp->next();
}
return c;
}
bool RowList::empty() const
{
return rowlist == 0;
}

90
src/RowList.h Normal file
View File

@ -0,0 +1,90 @@
// -*- C++ -*-
#ifndef ROW_LIST_H
#define ROW_LIST_H
#include <iterator>
class Row;
///
class RowList {
public:
///
class iterator {
public:
///
typedef std::bidirectional_iterator_tag iterator_category;
///
typedef Row * value_type;
///
typedef ptrdiff_t difference_type;
///
typedef Row * pointer;
///
typedef Row & reference;
///
iterator();
///
iterator(value_type);
///
reference operator*();
///
pointer operator->();
///
iterator & operator++();
///
iterator operator++(int);
///
iterator & operator--();
///
iterator operator--(int);
private:
///
Row * ptr;
};
///
RowList();
///
iterator insert(iterator it, Row * row);
///
void clear();
///
void erase(iterator it);
///
iterator begin();
///
iterator begin() const;
///
iterator end();
///
iterator end() const;
///
void set(Row *);
///
void push_back(Row *);
///
Row const & front() const;
///
Row & front();
///
Row const & back() const;
///
Row & back();
///
int size() const;
///
bool empty() const;
private:
///
Row * rowlist;
};
///
bool operator==(RowList::iterator const & i1,
RowList::iterator const & i2);
///
bool operator!=(RowList::iterator const & i1,
RowList::iterator const & i2);
#endif