The InsetList

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4933 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2002-08-11 15:03:52 +00:00
parent c10a113cd8
commit 260c7f3187
16 changed files with 470 additions and 276 deletions

View File

@ -191,19 +191,20 @@ bool BufferView::removeAutoInsets()
}
}
Paragraph::inset_iterator pit = par->inset_iterator_begin();
Paragraph::inset_iterator pend = par->inset_iterator_end();
InsetList::iterator pit = par->insetlist.begin();
InsetList::iterator pend = par->insetlist.end();
while (pit != pend) {
if (pit->autoDelete()) {
if (pit.getInset()->autoDelete()) {
removed = true;
pos_type const pos = pit.getPos();
par->erase(pos);
// We just invalidated par's inset iterators so
// we get the next valid iterator position
pit = par->InsetIterator(pos);
pit = par->insetlist.insetIterator(pos);
// and ensure we have a valid end iterator.
pend = par->inset_iterator_end();
pend = par->insetlist.end();
if (cursor_par == par) {
// update the saved cursor position
@ -523,20 +524,20 @@ bool BufferView::lockInset(UpdatableInset * inset)
// Then do a deep look of the inset and lock the right one
Paragraph * par = buffer()->paragraph;
int const id = inset->id();
while(par) {
Paragraph::inset_iterator it =
par->inset_iterator_begin();
Paragraph::inset_iterator const end =
par->inset_iterator_end();
while (par) {
InsetList::iterator it =
par->insetlist.begin();
InsetList::iterator const end =
par->insetlist.end();
for (; it != end; ++it) {
if ((*it) == inset) {
if (it.getInset() == inset) {
text->setCursorIntern(this, par, it.getPos());
theLockingInset(inset);
return true;
}
if ((*it)->getInsetFromID(id)) {
if (it.getInset()->getInsetFromID(id)) {
text->setCursorIntern(this, par, it.getPos());
(*it)->edit(this);
it.getInset()->edit(this);
return theLockingInset()->lockInsetInInset(this, inset);
}
}
@ -656,10 +657,10 @@ bool BufferView::ChangeInsets(Inset::Code code,
it != end; ++it) {
Paragraph * par = *it;
bool changed_inset = false;
for (Paragraph::inset_iterator it2 = par->inset_iterator_begin();
it2 != par->inset_iterator_end(); ++it2) {
if ((*it2)->lyxCode() == code) {
InsetCommand * inset = static_cast<InsetCommand *>(*it2);
for (InsetList::iterator it2 = par->insetlist.begin();
it2 != par->insetlist.end(); ++it2) {
if (it2.getInset()->lyxCode() == code) {
InsetCommand * inset = static_cast<InsetCommand *>(it2.getInset());
if (inset->getContents() == from) {
inset->setContents(to);
changed_inset = true;

View File

@ -1,3 +1,30 @@
2002-08-11 Lars Gullik Bjønnes <larsbj@gullik.net>
* insets/insettext.C: InsetList changes
* graphics/GraphicsSupport.C (operator()): InsetList changes
* toc.C (getTocList): InsetList changes
* paragraph_pimpl.[Ch]: InsetList changes
* paragraph.[Ch]: InsetList changes
* buffer.C (inset_iterator): InsetList changes
(setParagraph): ditto
* buffer.h (inset_iterator): ditto
* iterators.C (operator++): ditto
* iterators.h: ditto
* Makefile.am (lyx_SOURCES): add InsetList.C and InsetList.h
* InsetList.[Ch]: new files, most InsetList handling moved out of
paragraph.C.
* BufferView2.C (removeAutoInsets): InsetList changes
(lockInset): ditto
(ChangeInsets): ditto
2002-08-10 Lars Gullik Bjønnes <larsbj@gullik.net>
* paragraph_pimpl.h (empty): new function

242
src/InsetList.C Normal file
View File

@ -0,0 +1,242 @@
#include <config.h>
#include "InsetList.h"
#include "debug.h"
#include "insets/inset.h"
#include <algorithm>
using lyx::pos_type;
using std::lower_bound;
using std::upper_bound;
using std::endl;
namespace {
struct MatchIt {
/// used by lower_bound and upper_bound
inline
int operator()(InsetList::InsetTable const & a,
InsetList::InsetTable const & b) const {
return a.pos < b.pos;
}
};
}
InsetList::iterator::iterator(InsetList::List::iterator const & iter)
: it(iter)
{}
InsetList::iterator & InsetList::iterator::operator++()
{
++it;
return *this;
}
InsetList::iterator InsetList::iterator::operator++(int)
{
iterator tmp = *this;
++*this;
return tmp;
}
pos_type InsetList::iterator::getPos() const
{
return it->pos;
}
Inset * InsetList::iterator::getInset() const
{
return it->inset;
}
void InsetList::iterator::setInset(Inset * inset)
{
it->inset = inset;
}
InsetList::~InsetList()
{
// If we begin storing a shared_ptr in the List
// this code can be removed. (Lgb)
List::iterator it = list.begin();
List::iterator end = list.end();
for (; it != end; ++it) {
delete it->inset;
}
}
InsetList::iterator InsetList::begin()
{
return iterator(list.begin());
}
InsetList::iterator InsetList::end()
{
return iterator(list.end());
}
InsetList::iterator InsetList::begin() const
{
return iterator(const_cast<InsetList*>(this)->list.begin());
}
InsetList::iterator InsetList::end() const
{
return iterator(const_cast<InsetList*>(this)->list.end());
}
InsetList::iterator
InsetList::insetIterator(pos_type pos)
{
InsetTable search_elem(pos, 0);
List::iterator it = lower_bound(list.begin(),
list.end(),
search_elem, MatchIt());
return iterator(it);
}
void InsetList::insert(Inset * inset, lyx::pos_type pos)
{
InsetTable search_elem(pos, 0);
List::iterator it = lower_bound(list.begin(),
list.end(),
search_elem, MatchIt());
if (it != list.end() && it->pos == pos) {
lyxerr << "ERROR (InsetList::insert): "
<< "There is an inset in position: " << pos << endl;
} else {
list.insert(it, InsetTable(pos, inset));
}
}
void InsetList::erase(pos_type pos)
{
InsetTable search_elem(pos, 0);
List::iterator it =
lower_bound(list.begin(),
list.end(),
search_elem, MatchIt());
if (it != list.end() && it->pos == pos) {
delete it->inset;
list.erase(it);
}
}
Inset * InsetList::release(pos_type pos)
{
InsetTable search_elem(pos, 0);
List::iterator it =
lower_bound(list.begin(),
list.end(),
search_elem, MatchIt());
if (it != list.end() && it->pos == pos) {
Inset * tmp = it->inset;
it->inset = 0;
return tmp;
}
return 0;
}
Inset * InsetList::get(pos_type pos) const
{
InsetTable search_elem(pos, 0);
List::iterator it =
lower_bound(const_cast<InsetList*>(this)->list.begin(),
const_cast<InsetList*>(this)->list.end(),
search_elem, MatchIt());
if (it != const_cast<InsetList*>(this)->list.end() && it->pos == pos)
return it->inset;
return 0;
}
void InsetList::increasePosAfterPos(pos_type pos)
{
InsetTable search_elem(pos, 0);
List::iterator it = lower_bound(list.begin(),
list.end(),
search_elem, MatchIt());
List::iterator end = list.end();
for (; it != end; ++it) {
++it->pos;
}
}
void InsetList::decreasePosAfterPos(pos_type pos)
{
InsetTable search_elem(pos, 0);
List::iterator end = list.end();
List::iterator it = upper_bound(list.begin(),
end,
search_elem, MatchIt());
for (; it != end; ++it) {
--it->pos;
}
}
void InsetList::deleteInsetsLyXText(BufferView * bv)
{
List::iterator it = list.begin();
List::iterator end = list.end();
for (; it != end; ++it) {
if (it->inset) {
if (it->inset->isTextInset()) {
static_cast<UpdatableInset*>
(it->inset)->deleteLyXText(bv, true);
}
}
}
}
void InsetList::resizeInsetsLyXText(BufferView * bv)
{
List::iterator it = list.begin();
List::iterator end = list.end();
for (; it != end; ++it) {
if (it->inset) {
if (it->inset->isTextInset()) {
static_cast<UpdatableInset*>
(it->inset)->resizeLyXText(bv, true);
}
}
}
}
bool operator==(InsetList::iterator const & i1,
InsetList::iterator const & i2)
{
return i1.it == i2.it;
}
bool operator!=(InsetList::iterator const & i1,
InsetList::iterator const & i2)
{
return !(i1 == i2);
}

91
src/InsetList.h Normal file
View File

@ -0,0 +1,91 @@
// -*- C++ -*-
#ifndef INSET_LIST_H
#define INSET_LIST_H
#include "support/types.h"
class Inset;
class BufferView;
///
class InsetList {
public:
///
struct InsetTable {
///
lyx::pos_type pos;
///
Inset * inset;
///
InsetTable(lyx::pos_type p, Inset * i) : pos(p), inset(i) {}
};
///
typedef std::vector<InsetTable> List;
///
class iterator {
public:
///
iterator() {}
//
iterator(List::iterator const & iter);
///
iterator & operator++();
///
iterator operator++(int);
///
lyx::pos_type getPos() const;
///
Inset * getInset() const;
///
void setInset(Inset * inset);
///
friend bool operator==(iterator const &, iterator const &);
private:
///
List::iterator it;
};
///
~InsetList();
///
iterator begin();
///
iterator end();
///
iterator begin() const;
///
iterator end() const;
///
iterator insetIterator(lyx::pos_type pos);
///
void insert(Inset * inset, lyx::pos_type pos);
///
void erase(lyx::pos_type pos);
///
Inset * release(lyx::pos_type);
///
Inset * get(lyx::pos_type pos) const;
///
void increasePosAfterPos(lyx::pos_type pos);
///
void decreasePosAfterPos(lyx::pos_type pos);
///
void deleteInsetsLyXText(BufferView * bv);
///
void resizeInsetsLyXText(BufferView * bv);
private:
///
List list;
};
///
bool operator==(InsetList::iterator const & i1,
InsetList::iterator const & i2);
///
bool operator!=(InsetList::iterator const & i1,
InsetList::iterator const & i2);
#endif

View File

@ -65,6 +65,8 @@ lyx_SOURCES = \
Floating.h \
FuncStatus.C \
FuncStatus.h \
InsetList.C \
InsetList.h \
LColor.C \
LColor.h \
LString.h \

View File

@ -3871,8 +3871,8 @@ bool Buffer::isMultiLingual()
Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
: par(paragraph)
{
it = par->InsetIterator(pos);
if (it == par->inset_iterator_end()) {
it = par->insetlist.insetIterator(pos);
if (it == par->insetlist.end()) {
par = par->next();
setParagraph();
}
@ -3882,8 +3882,8 @@ Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
void Buffer::inset_iterator::setParagraph()
{
while (par) {
it = par->inset_iterator_begin();
if (it != par->inset_iterator_end())
it = par->insetlist.begin();
if (it != par->insetlist.end())
return;
par = par->next();
}

View File

@ -372,7 +372,7 @@ public:
inset_iterator & operator++() { // prefix ++
if (par) {
++it;
if (it == par->inset_iterator_end()) {
if (it == par->insetlist.end()) {
par = par->next();
setParagraph();
}
@ -384,7 +384,7 @@ public:
inset_iterator tmp(par, it.getPos());
if (par) {
++it;
if (it == par->inset_iterator_end()) {
if (it == par->insetlist.end()) {
par = par->next();
setParagraph();
}
@ -393,7 +393,7 @@ public:
}
///
Inset * operator*() { return *it; }
Inset * operator*() { return it.getInset(); }
///
Paragraph * getPar() { return par; }
@ -409,7 +409,7 @@ public:
///
Paragraph * par;
///
Paragraph::inset_iterator it;
InsetList::iterator it;
};
///

View File

@ -65,16 +65,16 @@ struct InsetVisibleInParagraph {
bool operator()(VisibleParagraph const & vp)
{
Paragraph * par = vp.par;
Paragraph::inset_iterator it = par->inset_iterator_begin();
Paragraph::inset_iterator end = par->inset_iterator_end();
InsetList::iterator it = par->insetlist.begin();
InsetList::iterator end = par->insetlist.end();
// Can't refactor this as a functor because we rely on the
// inset_iterator member function getPos().
for (; it != end; ++it) {
lyx::pos_type const pos = it.getPos();
if (pos >= vp.start && pos <= vp.end) {
if (*it == &inset_ ||
it->getInsetFromID(inset_.id()) != 0)
if (it.getInset() == &inset_ ||
it.getInset()->getInsetFromID(inset_.id()) != 0)
return true;
}
}

View File

@ -878,19 +878,19 @@ bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
Paragraph * p = par;
int const id = inset->id();
while(p) {
Paragraph::inset_iterator it =
p->inset_iterator_begin();
Paragraph::inset_iterator const end =
p->inset_iterator_end();
InsetList::iterator it =
p->insetlist.begin();
InsetList::iterator const end =
p->insetlist.end();
for (; it != end; ++it) {
if ((*it) == inset) {
if (it.getInset() == inset) {
getLyXText(bv)->setCursorIntern(bv, p, it.getPos());
lockInset(bv, inset);
return true;
}
if ((*it)->getInsetFromID(id)) {
if (it.getInset()->getInsetFromID(id)) {
getLyXText(bv)->setCursorIntern(bv, p, it.getPos());
(*it)->edit(bv);
it.getInset()->edit(bv);
return the_locking_inset->lockInsetInInset(bv, inset);
}
}
@ -1968,10 +1968,10 @@ vector<string> const InsetText::getLabelList() const
Paragraph * tpar = par;
while (tpar) {
Paragraph::inset_iterator beg = tpar->inset_iterator_begin();
Paragraph::inset_iterator end = tpar->inset_iterator_end();
InsetList::iterator beg = tpar->insetlist.begin();
InsetList::iterator end = tpar->insetlist.end();
for (; beg != end; ++beg) {
vector<string> const l = (*beg)->getLabelList();
vector<string> const l = beg.getInset()->getLabelList();
label_list.insert(label_list.end(), l.begin(), l.end());
}
tpar = tpar->next();
@ -2560,13 +2560,13 @@ Inset * InsetText::getInsetFromID(int id_arg) const
Paragraph * lp = par;
while (lp) {
for (Paragraph::inset_iterator it = lp->inset_iterator_begin(),
en = lp->inset_iterator_end();
for (InsetList::iterator it = lp->insetlist.begin(),
en = lp->insetlist.end();
it != en; ++it)
{
if ((*it)->id() == id_arg)
return *it;
Inset * in = (*it)->getInsetFromID(id_arg);
if (it.getInset()->id() == id_arg)
return it.getInset();
Inset * in = it.getInset()->getInsetFromID(id_arg);
if (in)
return in;
}
@ -2798,10 +2798,10 @@ void InsetText::addPreview(grfx::PreviewLoader & loader) const
{
Paragraph * par = getFirstParagraph(0);
while (par) {
Paragraph::inset_iterator it = par->inset_iterator_begin();
Paragraph::inset_iterator end = par->inset_iterator_end();
InsetList::iterator it = par->insetlist.begin();
InsetList::iterator end = par->insetlist.end();
for (; it != end; ++it) {
it->addPreview(loader);
it.getInset()->addPreview(loader);
}
par = par->next();

View File

@ -10,7 +10,7 @@ ParIterator & ParIterator::operator++()
// Does the current inset contain more "cells" ?
if (p.index >= 0) {
++p.index;
Paragraph * par = (*p.it)->getFirstParagraph(p.index);
Paragraph * par = p.it.getInset()->getFirstParagraph(p.index);
if (par) {
positions.push(ParPosition(par));
return *this;
@ -20,12 +20,12 @@ ParIterator & ParIterator::operator++()
// The following line is needed because the value of
// p.it may be invalid if inset was added/removed to
// the paragraph pointed by the iterator
p.it = p.par->inset_iterator_begin();
p.it = p.par->insetlist.begin();
// Try to find the next inset that contains paragraphs
Paragraph::inset_iterator end = p.par->inset_iterator_end();
InsetList::iterator end = p.par->insetlist.end();
for (; p.it != end; ++p.it) {
Paragraph * par = (*p.it)->getFirstParagraph(0);
Paragraph * par = p.it.getInset()->getFirstParagraph(0);
if (par) {
p.index = 0;
positions.push(ParPosition(par));

View File

@ -10,11 +10,11 @@
class ParPosition {
public:
ParPosition(Paragraph * p)
: par(p), it(p->inset_iterator_begin()), index(-1) {}
: par(p), it(p->insetlist.begin()), index(-1) {}
///
Paragraph * par;
///
Paragraph::inset_iterator it;
InsetList::iterator it;
///
int index;
};

View File

@ -130,9 +130,9 @@ Paragraph::Paragraph(Paragraph const & lp, bool same_ids)
for (InsetList::iterator it = insetlist.begin();
it != insetlist.end(); ++it)
{
it->inset = it->inset->clone(*current_view->buffer(), same_ids);
it.setInset(it.getInset()->clone(*current_view->buffer(), same_ids));
// tell the new inset who is the boss now
it->inset->parOwner(this);
it.getInset()->parOwner(this);
}
}
@ -145,11 +145,6 @@ Paragraph::~Paragraph()
if (next_)
next_->previous_ = previous_;
for (InsetList::iterator it = insetlist.begin();
it != insetlist.end(); ++it) {
delete it->inset;
}
// ale970302
delete bibkey;
@ -362,12 +357,12 @@ void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, pos_type pos)
InsetList::iterator it = insetlist.begin();
InsetList::iterator end = insetlist.end();
for (; it != end; ++it) {
if (it->pos == pos)
if (it.getPos() == pos)
break;
}
if (it != end && it->pos == pos)
it->inset = 0;
if (it != end && it.getPos() == pos)
it.setInset(0);
// the inset is not in a paragraph anymore
minibuffer_inset->parOwner(0);
} else {
@ -461,12 +456,12 @@ Inset * Paragraph::getInset(pos_type pos)
InsetList::iterator it = insetlist.begin();
InsetList::iterator end = insetlist.end();
for (; it != end; ++it) {
if (it->pos == pos)
if (it.getPos() == pos)
break;
}
if (it != end && it->pos == pos)
return it->inset;
if (it != end && it.getPos() == pos)
return it.getInset();
lyxerr << "ERROR (Paragraph::getInset): "
<< "Inset does not exist: " << pos << endl;
@ -485,26 +480,7 @@ Inset const * Paragraph::getInset(pos_type pos) const
{
lyx::Assert(pos < size());
// Find the inset.
InsetList::const_iterator cit = insetlist.begin();
InsetList::const_iterator end = insetlist.end();
for (; cit != end; ++cit) {
if (cit->pos == pos)
break;
}
if (cit != end && cit->pos == pos)
return cit->inset;
lyxerr << "ERROR (Paragraph::getInset): "
<< "Inset does not exist: " << pos << endl;
//::raise(SIGSTOP);
//text[pos] = ' '; // WHY!!! does this set the pos to ' '????
// Did this commenting out introduce a bug? So far I have not
// see any, please enlighten me. (Lgb)
// My guess is that since the inset does not exist, we might
// as well replace it with a space to prevent craches. (Asger)
return 0;
return insetlist.get(pos);
}
@ -1127,29 +1103,15 @@ Paragraph const * Paragraph::outerHook() const
}
Paragraph::inset_iterator
Paragraph::InsetIterator(pos_type pos)
{
InsetList::iterator it = insetlist.begin();
InsetList::iterator end = insetlist.end();
for (; it != end; ++it) {
if (it->pos >= pos)
break;
}
return inset_iterator(it);
}
// returns -1 if inset not found
int Paragraph::getPositionOfInset(Inset const * inset) const
{
// Find the entry.
InsetList::const_iterator cit = insetlist.begin();
InsetList::const_iterator end = insetlist.end();
for (; cit != end; ++cit) {
if (cit->inset == inset) {
return cit->pos;
InsetList::iterator it = insetlist.begin();
InsetList::iterator end = insetlist.end();
for (; it != end; ++it) {
if (it.getInset() == inset) {
return it.getPos();
}
}
if (inset == bibkey)
@ -1982,11 +1944,11 @@ string const Paragraph::asString(Buffer const * buffer,
void Paragraph::setInsetOwner(Inset * i)
{
pimpl_->inset_owner = i;
InsetList::const_iterator cit = insetlist.begin();
InsetList::const_iterator end = insetlist.end();
for (; cit != end; ++cit) {
if (cit->inset)
cit->inset->setOwner(i);
InsetList::iterator it = insetlist.begin();
InsetList::iterator end = insetlist.end();
for (; it != end; ++it) {
if (it.getInset())
it.getInset()->setOwner(i);
}
}
@ -1994,30 +1956,14 @@ void Paragraph::setInsetOwner(Inset * i)
void Paragraph::deleteInsetsLyXText(BufferView * bv)
{
// then the insets
InsetList::const_iterator cit = insetlist.begin();
InsetList::const_iterator end = insetlist.end();
for (; cit != end; ++cit) {
if (cit->inset && cit->inset->isTextInset()) {
static_cast<UpdatableInset *>
(cit->inset)->deleteLyXText(bv, true);
}
}
insetlist.deleteInsetsLyXText(bv);
}
void Paragraph::resizeInsetsLyXText(BufferView * bv)
{
// then the insets
InsetList::const_iterator cit = insetlist.begin();
InsetList::const_iterator end = insetlist.end();
for (; cit != end; ++cit) {
if (cit->inset) {
if (cit->inset->isTextInset()) {
static_cast<UpdatableInset *>
(cit->inset)->resizeLyXText(bv, true);
}
}
}
insetlist.resizeInsetsLyXText(bv);
}
@ -2089,23 +2035,6 @@ void Paragraph::setChar(pos_type pos, value_type c)
}
Paragraph::inset_iterator::inset_iterator(Paragraph::InsetList::iterator const & iter)
: it(iter)
{}
Paragraph::inset_iterator Paragraph::inset_iterator_begin()
{
return inset_iterator(insetlist.begin());
}
Paragraph::inset_iterator Paragraph::inset_iterator_end()
{
return inset_iterator(insetlist.end());
}
ParagraphParameters & Paragraph::params()
{
return pimpl_->params;

View File

@ -15,6 +15,7 @@
#include "lyxlayout_ptr_fwd.h"
#include "lyxfont.h" // Just for LyXFont::FONT_SIZE
#include "InsetList.h"
#include "insets/inset.h" // Just for Inset::Code
@ -37,8 +38,7 @@ class TexRow;
#define NO_PEXTRA_REALLY 1
// Define this if you want to try out the new storage container for
// paragraphs. std::container instead of obfuscated homegrown
// linked list. (Lgb)
// paragraphs. (Lgb)
// This is non working and far from finished.
// #define NO_NEXT 1
@ -258,9 +258,10 @@ public:
/// pos <= size() (there is a dummy font change at the end of each par)
void setFont(lyx::pos_type pos, LyXFont const & font);
/// Returns the height of the highest font in range
LyXFont::FONT_SIZE highestFontInRange(lyx::pos_type startpos,
lyx::pos_type endpos,
LyXFont::FONT_SIZE const def_size) const;
LyXFont::FONT_SIZE
highestFontInRange(lyx::pos_type startpos,
lyx::pos_type endpos,
LyXFont::FONT_SIZE const def_size) const;
///
void insertChar(lyx::pos_type pos, value_type c);
///
@ -329,76 +330,18 @@ public:
///
bool isFreeSpacing() const;
///
ParagraphParameters & params();
///
ParagraphParameters const & params() const;
private:
///
LyXLayout_ptr layout_;
public:
/** Both these definitions must be made public to keep Compaq cxx 6.5
* happy.
*/
///
struct InsetTable {
///
lyx::pos_type pos;
///
Inset * inset;
///
InsetTable(lyx::pos_type p, Inset * i) : pos(p), inset(i) {}
};
///
typedef std::vector<InsetTable> InsetList;
private:
///
InsetList insetlist;
public:
///
class inset_iterator {
public:
///
inset_iterator() {}
//
inset_iterator(InsetList::iterator const & iter);
///
inset_iterator & operator++() {
++it;
return *this;
}
///
Inset * operator*() { return it->inset; }
///
Inset * operator->() { return it->inset; }
///
lyx::pos_type getPos() const { return it->pos; }
///
bool operator==(inset_iterator const & iter) const {
return it == iter.it;
}
///
bool operator!=(inset_iterator const & iter) const {
return it != iter.it;
}
private:
///
InsetList::iterator it;
};
///
friend class inset_iterator;
///
inset_iterator inset_iterator_begin();
///
inset_iterator inset_iterator_end();
/// returns inset iterator of the first inset at or after pos.
inset_iterator InsetIterator(lyx::pos_type pos);
///
Counters & counters();
private:
///
LyXLayout_ptr layout_;
/// if anything uses this we don't want it to.
Paragraph(Paragraph const &);
///

View File

@ -139,15 +139,9 @@ void Paragraph::Pimpl::insertChar(pos_type pos, value_type c,
it->pos(it->pos() + 1);
}
// Update the inset table.
InsetTable search_inset(pos, 0);
for (InsetList::iterator it = lower_bound(owner_->insetlist.begin(),
owner_->insetlist.end(),
search_inset, matchIT());
it != owner_->insetlist.end(); ++it)
{
++it->pos;
}
// Update the insets
owner_->insetlist.increasePosAfterPos(pos);
owner_->setFont(pos, font);
}
@ -161,18 +155,9 @@ void Paragraph::Pimpl::insertInset(pos_type pos,
insertChar(pos, META_INSET, font);
lyx::Assert(text[pos] == META_INSET);
// Add a new entry in the inset table.
InsetTable search_inset(pos, 0);
InsetList::iterator it = lower_bound(owner_->insetlist.begin(),
owner_->insetlist.end(),
search_inset, matchIT());
if (it != owner_->insetlist.end() && it->pos == pos) {
lyxerr << "ERROR (Paragraph::InsertInset): "
"there is an inset in position: " << pos << endl;
} else {
owner_->insetlist.insert(it, InsetTable(pos, inset));
inset->parOwner(owner_);
}
// Add a new entry in the insetlist.
owner_->insetlist.insert(inset, pos);
inset->parOwner(owner_);
if (inset_owner)
inset->setOwner(inset_owner);
@ -184,16 +169,7 @@ void Paragraph::Pimpl::erase(pos_type pos)
lyx::Assert(pos < size());
// if it is an inset, delete the inset entry
if (text[pos] == Paragraph::META_INSET) {
// find the entry
InsetTable search_inset(pos, 0);
InsetList::iterator it =
lower_bound(owner_->insetlist.begin(),
owner_->insetlist.end(),
search_inset, matchIT());
if (it != owner_->insetlist.end() && it->pos == pos) {
delete it->inset;
owner_->insetlist.erase(it);
}
owner_->insetlist.erase(pos);
}
text.erase(text.begin() + pos);
@ -228,15 +204,8 @@ void Paragraph::Pimpl::erase(pos_type pos)
for (; it != fend; ++it)
it->pos(it->pos() - 1);
// Update the inset table.
InsetTable search_inset(pos, 0);
InsetList::iterator lend = owner_->insetlist.end();
for (InsetList::iterator it =
upper_bound(owner_->insetlist.begin(),
lend,
search_inset, matchIT());
it != lend; ++it)
--it->pos;
// Update the insetlist.
owner_->insetlist.decreasePosAfterPos(pos);
}
@ -637,13 +606,13 @@ void Paragraph::Pimpl::validate(LaTeXFeatures & features,
features.require("ParagraphLeftIndent");
// then the insets
InsetList::const_iterator icit = owner_->insetlist.begin();
InsetList::const_iterator iend = owner_->insetlist.end();
InsetList::iterator icit = owner_->insetlist.begin();
InsetList::iterator iend = owner_->insetlist.end();
for (; icit != iend; ++icit) {
if (icit->inset) {
icit->inset->validate(features);
if (icit.getInset()) {
icit.getInset()->validate(features);
if (layout.needprotect &&
icit->inset->lyxCode() == Inset::FOOT_CODE)
icit.getInset()->lyxCode() == Inset::FOOT_CODE)
features.require("NeedLyXFootnoteCode");
}
}
@ -663,11 +632,11 @@ void Paragraph::Pimpl::validate(LaTeXFeatures & features,
Paragraph * Paragraph::Pimpl::getParFromID(int id) const
{
InsetList::const_iterator cit = owner_->insetlist.begin();
InsetList::const_iterator lend = owner_->insetlist.end();
InsetList::iterator cit = owner_->insetlist.begin();
InsetList::iterator lend = owner_->insetlist.end();
Paragraph * result;
for (; cit != lend; ++cit) {
if ((result = cit->inset->getParFromID(id)))
if ((result = cit.getInset()->getParFromID(id)))
return result;
}
return 0;

View File

@ -62,16 +62,6 @@ struct Paragraph::Pimpl {
///
boost::array<int, 10> counter_;
///
friend struct matchIT;
///
struct matchIT {
/// used by lower_bound and upper_bound
inline
int operator()(InsetTable const & a, InsetTable const & b) const {
return a.pos < b.pos;
}
};
/** A font entry covers a range of positions. Notice that the
entries in the list are inserted in random order.
I don't think it's worth the effort to implement a more effective

View File

@ -93,12 +93,12 @@ TocList const getTocList(Buffer const * buf)
// For each paragraph, traverse its insets and look for
// FLOAT_CODE
Paragraph::inset_iterator it = par->inset_iterator_begin();
Paragraph::inset_iterator end = par->inset_iterator_end();
InsetList::iterator it = par->insetlist.begin();
InsetList::iterator end = par->insetlist.end();
for (; it != end; ++it) {
if ((*it)->lyxCode() == Inset::FLOAT_CODE) {
if (it.getInset()->lyxCode() == Inset::FLOAT_CODE) {
InsetFloat * il =
static_cast<InsetFloat*>(*it);
static_cast<InsetFloat*>(it.getInset());
il->addToToc(toclist, buf);
}
}