Please review this and comment.
? build Index: src/BufferView2.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView2.C,v retrieving revision 1.139 diff -u -p -r1.139 BufferView2.C --- src/BufferView2.C 10 Aug 2002 15:20:56 -0000 1.139 +++ src/BufferView2.C 10 Aug 2002 17:48:27 -0000 @@ -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(UpdatableInse // 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::Cod 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; Index: src/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v retrieving revision 1.872 diff -u -p -r1.872 ChangeLog --- src/ChangeLog 10 Aug 2002 15:20:57 -0000 1.872 +++ src/ChangeLog 10 Aug 2002 17:48:32 -0000 @@ -5,7 +5,7 @@ * paragraph.[Ch] (empty): new function * other files: use the new Paragraph::empty function - + 2002-08-09 John Levon <[EMAIL PROTECTED]> * lyxtext.h: remove unused refresh_height Index: src/InsetList.C =================================================================== RCS file: src/InsetList.C diff -N src/InsetList.C --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/InsetList.C 10 Aug 2002 17:48:32 -0000 @@ -0,0 +1,230 @@ +#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::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); +} Index: src/InsetList.h =================================================================== RCS file: src/InsetList.h diff -N src/InsetList.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/InsetList.h 10 Aug 2002 17:48:32 -0000 @@ -0,0 +1,89 @@ +// -*- 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; + }; + /// + 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 Index: src/Makefile.am =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/Makefile.am,v retrieving revision 1.137 diff -u -p -r1.137 Makefile.am --- src/Makefile.am 9 Aug 2002 00:42:10 -0000 1.137 +++ src/Makefile.am 10 Aug 2002 17:48:32 -0000 @@ -65,6 +65,8 @@ lyx_SOURCES = \ Floating.h \ FuncStatus.C \ FuncStatus.h \ + InsetList.C \ + InsetList.h \ LColor.C \ LColor.h \ LString.h \ Index: src/buffer.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v retrieving revision 1.365 diff -u -p -r1.365 buffer.C --- src/buffer.C 10 Aug 2002 15:20:57 -0000 1.365 +++ src/buffer.C 10 Aug 2002 17:48:34 -0000 @@ -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(P 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(); } Index: src/buffer.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.h,v retrieving revision 1.105 diff -u -p -r1.105 buffer.h --- src/buffer.h 4 Aug 2002 23:11:47 -0000 1.105 +++ src/buffer.h 10 Aug 2002 17:48:34 -0000 @@ -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; }; /// Index: src/iterators.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/iterators.C,v retrieving revision 1.3 diff -u -p -r1.3 iterators.C --- src/iterators.C 16 Feb 2002 15:59:37 -0000 1.3 +++ src/iterators.C 10 Aug 2002 17:48:34 -0000 @@ -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)); Index: src/iterators.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/iterators.h,v retrieving revision 1.4 diff -u -p -r1.4 iterators.h --- src/iterators.h 21 Mar 2002 17:25:09 -0000 1.4 +++ src/iterators.h 10 Aug 2002 17:48:34 -0000 @@ -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; }; Index: src/paragraph.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v retrieving revision 1.216 diff -u -p -r1.216 paragraph.C --- src/paragraph.C 10 Aug 2002 15:21:01 -0000 1.216 +++ src/paragraph.C 10 Aug 2002 17:48:35 -0000 @@ -130,9 +130,9 @@ Paragraph::Paragraph(Paragraph const & l 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); } } @@ -147,7 +147,7 @@ Paragraph::~Paragraph() for (InsetList::iterator it = insetlist.begin(); it != insetlist.end(); ++it) { - delete it->inset; + delete it.getInset(); } // ale970302 @@ -362,12 +362,12 @@ void Paragraph::cutIntoMinibuffer(Buffer 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 +461,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 +485,7 @@ Inset const * Paragraph::getInset(pos_ty { 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 +1108,15 @@ Paragraph const * Paragraph::outerHook() } -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 +1949,11 @@ string const Paragraph::asString(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 +1961,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); } @@ -2086,23 +2037,6 @@ void Paragraph::clearContents() void Paragraph::setChar(pos_type pos, value_type c) { pimpl_->setChar(pos, 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()); } Index: src/paragraph.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.h,v retrieving revision 1.41 diff -u -p -r1.41 paragraph.h --- src/paragraph.h 10 Aug 2002 15:21:02 -0000 1.41 +++ src/paragraph.h 10 Aug 2002 17:48:35 -0000 @@ -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) {} - }; - + ParagraphParameters & params(); /// - typedef std::vector<InsetTable> InsetList; -private: + ParagraphParameters const & params() const; /// 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 &); /// Index: src/paragraph_pimpl.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_pimpl.C,v retrieving revision 1.41 diff -u -p -r1.41 paragraph_pimpl.C --- src/paragraph_pimpl.C 10 Aug 2002 15:21:02 -0000 1.41 +++ src/paragraph_pimpl.C 10 Aug 2002 17:48:36 -0000 @@ -139,15 +139,9 @@ void Paragraph::Pimpl::insertChar(pos_ty 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,19 +155,10 @@ void Paragraph::Pimpl::insertInset(pos_t 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 po 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 po 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(LaTeXFea 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(LaTeXFea 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; Index: src/paragraph_pimpl.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_pimpl.h,v retrieving revision 1.14 diff -u -p -r1.14 paragraph_pimpl.h --- src/paragraph_pimpl.h 10 Aug 2002 15:21:02 -0000 1.14 +++ src/paragraph_pimpl.h 10 Aug 2002 17:48:36 -0000 @@ -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 Index: src/toc.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/toc.C,v retrieving revision 1.7 diff -u -p -r1.7 toc.C --- src/toc.C 8 Aug 2002 22:03:29 -0000 1.7 +++ src/toc.C 10 Aug 2002 17:48:36 -0000 @@ -93,12 +93,12 @@ TocList const getTocList(Buffer const * // 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); } } Index: src/graphics/GraphicsSupport.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/graphics/GraphicsSupport.C,v retrieving revision 1.1 diff -u -p -r1.1 GraphicsSupport.C --- src/graphics/GraphicsSupport.C 15 Jul 2002 11:08:45 -0000 1.1 +++ src/graphics/GraphicsSupport.C 10 Aug 2002 17:48:37 -0000 @@ -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; } } Index: src/insets/insettext.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v retrieving revision 1.314 diff -u -p -r1.314 insettext.C --- src/insets/insettext.C 10 Aug 2002 15:21:06 -0000 1.314 +++ src/insets/insettext.C 10 Aug 2002 17:48:38 -0000 @@ -878,19 +878,19 @@ bool InsetText::lockInsetInInset(BufferV 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::getLabel 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 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::Preview { 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();
-- Lgb