diff --git a/src/BufferView.C b/src/BufferView.C index 11a0a477c0..6e1ef133ef 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -535,15 +535,15 @@ bool BufferView::lockInset(UpdatableInset * inset) InsetList::iterator it = pit->insetlist.begin(); InsetList::iterator end = pit->insetlist.end(); for (; it != end; ++it) { - if (it.getInset() == inset) { - text->setCursorIntern(pit, it.getPos()); + if (it->inset == inset) { + text->setCursorIntern(pit, it->pos); theLockingInset(inset); return true; } - if (it.getInset()->getInsetFromID(id)) { - text->setCursorIntern(pit, it.getPos()); + if (it->inset->getInsetFromID(id)) { + text->setCursorIntern(pit, it->pos); FuncRequest cmd(this, LFUN_INSET_EDIT, "left"); - it.getInset()->localDispatch(cmd); + it->inset->localDispatch(cmd); return theLockingInset()->lockInsetInInset(this, inset); } } @@ -629,8 +629,8 @@ bool BufferView::ChangeInsets(Inset::Code code, bool changed_inset = false; for (InsetList::iterator it2 = it->insetlist.begin(); it2 != it->insetlist.end(); ++it2) { - if (it2.getInset()->lyxCode() == code) { - InsetCommand * inset = static_cast(it2.getInset()); + if (it2->inset->lyxCode() == code) { + InsetCommand * inset = static_cast(it2->inset); if (inset->getContents() == from) { inset->setContents(to); changed_inset = true; diff --git a/src/ChangeLog b/src/ChangeLog index 3db57c1dc5..d08116d749 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,25 @@ 2003-05-29 Lars Gullik Bjønnes + * toc.C (getTocList): adjust + + * paragraph_pimpl.C (validate): adjust + + * paragraph_funcs.C (optArgInset): use const_iterator, adjust + + * paragraph.C (Paragraph): adjust + (getPositionOfInset): use const_iterator, adjust + (bibitem): use const_iterator, adjust + (setInsetOwner): adjust + + * iterators.C (operator++): adjust + + * InsetList.[Ch]: Replace selfmade iterator with standard + vector::iterator also introduce const_iterator. Remove getPos, + getInset and setInset from InsetTable. Adjust accordingly. + + * BufferView.C (lockInset): adjust + (ChangeInsets): adjust + * tabular.[Ch]: delete commented same_id functions 2003-05-28 John Levon diff --git a/src/InsetList.C b/src/InsetList.C index 9547133383..6d98e03590 100644 --- a/src/InsetList.C +++ b/src/InsetList.C @@ -25,45 +25,7 @@ struct MatchIt { } }; -} - - -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; -} +} // namespace anon InsetList::~InsetList() @@ -80,25 +42,25 @@ InsetList::~InsetList() InsetList::iterator InsetList::begin() { - return iterator(list.begin()); + return list.begin(); } InsetList::iterator InsetList::end() { - return iterator(list.end()); + return list.end(); } -InsetList::iterator InsetList::begin() const +InsetList::const_iterator InsetList::begin() const { - return iterator(const_cast(this)->list.begin()); + return list.begin(); } -InsetList::iterator InsetList::end() const +InsetList::const_iterator InsetList::end() const { - return iterator(const_cast(this)->list.end()); + return list.end(); } @@ -109,17 +71,18 @@ InsetList::insetIterator(pos_type pos) List::iterator it = lower_bound(list.begin(), list.end(), search_elem, MatchIt()); - return iterator(it); + return it; } void InsetList::insert(Inset * inset, lyx::pos_type pos) { InsetTable search_elem(pos, 0); + List::iterator end = list.end(); List::iterator it = lower_bound(list.begin(), - list.end(), + end, search_elem, MatchIt()); - if (it != list.end() && it->pos == pos) { + if (it != end && it->pos == pos) { lyxerr << "ERROR (InsetList::insert): " << "There is an inset in position: " << pos << endl; } else { @@ -131,11 +94,12 @@ void InsetList::insert(Inset * inset, lyx::pos_type pos) void InsetList::erase(pos_type pos) { InsetTable search_elem(pos, 0); + List::iterator end = list.end(); List::iterator it = lower_bound(list.begin(), - list.end(), + end, search_elem, MatchIt()); - if (it != list.end() && it->pos == pos) { + if (it != end && it->pos == pos) { delete it->inset; list.erase(it); } @@ -145,11 +109,12 @@ void InsetList::erase(pos_type pos) Inset * InsetList::release(pos_type pos) { InsetTable search_elem(pos, 0); + List::iterator end = list.end(); List::iterator it = lower_bound(list.begin(), - list.end(), + end, search_elem, MatchIt()); - if (it != list.end() && it->pos == pos) { + if (it != end && it->pos == pos) { Inset * tmp = it->inset; it->inset = 0; return tmp; @@ -161,11 +126,12 @@ Inset * InsetList::release(pos_type pos) Inset * InsetList::get(pos_type pos) const { InsetTable search_elem(pos, 0); - List::iterator it = - lower_bound(const_cast(this)->list.begin(), - const_cast(this)->list.end(), + List::const_iterator end = list.end(); + List::const_iterator it = + lower_bound(list.begin(), + end, search_elem, MatchIt()); - if (it != const_cast(this)->list.end() && it->pos == pos) + if (it != end && it->pos == pos) return it->inset; return 0; } @@ -174,10 +140,10 @@ Inset * InsetList::get(pos_type pos) const 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(); + List::iterator it = lower_bound(list.begin(), + end, + search_elem, MatchIt()); for (; it != end; ++it) { ++it->pos; } @@ -225,19 +191,3 @@ void InsetList::resizeInsetsLyXText(BufferView * bv) } } } - - - -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); -} diff --git a/src/InsetList.h b/src/InsetList.h index 30dfea3fc4..f542f7fb05 100644 --- a/src/InsetList.h +++ b/src/InsetList.h @@ -5,7 +5,6 @@ #include "support/types.h" - class Inset; class BufferView; @@ -24,30 +23,11 @@ public: }; /// typedef std::vector 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; - }; + typedef List::iterator iterator; + /// + typedef List::const_iterator const_iterator; + /// ~InsetList(); /// @@ -55,9 +35,9 @@ public: /// iterator end(); /// - iterator begin() const; + const_iterator begin() const; /// - iterator end() const; + const_iterator end() const; /// iterator insetIterator(lyx::pos_type pos); /// @@ -81,11 +61,4 @@ private: List list; }; -/// -bool operator==(InsetList::iterator const & i1, - InsetList::iterator const & i2); -/// -bool operator!=(InsetList::iterator const & i1, - InsetList::iterator const & i2); - #endif diff --git a/src/buffer.C b/src/buffer.C index 0e0a47d04d..2200f0dc84 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -2417,13 +2417,13 @@ Buffer::inset_iterator Buffer::inset_iterator::operator++(int) Buffer::inset_iterator::reference Buffer::inset_iterator::operator*() { - return *it.getInset(); + return *it->inset; } Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->() { - return it.getInset(); + return it->inset; } @@ -2435,7 +2435,7 @@ ParagraphList::iterator Buffer::inset_iterator::getPar() const lyx::pos_type Buffer::inset_iterator::getPos() const { - return it.getPos(); + return it->pos; } diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index bcec3e7810..b41afc6a58 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,5 +1,10 @@ 2003-05-29 Lars Gullik Bjønnes + * insettext.C (lockInsetInInset): adjust + (getLabelList): use const_iterator, adjust + (getInsetFromID): use const_iterator, adjust + (addPreview): use const_iterator, adjust + * insetwrap.C (clone): remove const_cast * insetnote.C (clone): remove const_cast diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 0b03644572..c2e92f51d6 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -681,14 +681,14 @@ bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset) InsetList::iterator const end = pit->insetlist.end(); for (; it != end; ++it) { - if (it.getInset() == inset) { - getLyXText(bv)->setCursorIntern(pit, it.getPos()); + if (it->inset == inset) { + getLyXText(bv)->setCursorIntern(pit, it->pos); lockInset(bv, inset); return true; } - if (it.getInset()->getInsetFromID(id)) { - getLyXText(bv)->setCursorIntern(pit, it.getPos()); - it.getInset()->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT)); + if (it->inset->getInsetFromID(id)) { + getLyXText(bv)->setCursorIntern(pit, it->pos); + it->inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT)); return the_locking_inset->lockInsetInInset(bv, inset); } } @@ -1821,10 +1821,10 @@ vector const InsetText::getLabelList() const ParagraphList::const_iterator pit = paragraphs.begin(); ParagraphList::const_iterator pend = paragraphs.end(); for (; pit != pend; ++pit) { - InsetList::iterator beg = pit->insetlist.begin(); - InsetList::iterator end = pit->insetlist.end(); + InsetList::const_iterator beg = pit->insetlist.begin(); + InsetList::const_iterator end = pit->insetlist.end(); for (; beg != end; ++beg) { - vector const l = beg.getInset()->getLabelList(); + vector const l = beg->inset->getLabelList(); label_list.insert(label_list.end(), l.begin(), l.end()); } } @@ -2359,12 +2359,12 @@ Inset * InsetText::getInsetFromID(int id_arg) const ParagraphList::const_iterator pit = paragraphs.begin(); ParagraphList::const_iterator pend = paragraphs.end(); for (; pit != pend; ++pit) { - InsetList::iterator it = pit->insetlist.begin(); - InsetList::iterator end = pit->insetlist.end(); + InsetList::const_iterator it = pit->insetlist.begin(); + InsetList::const_iterator end = pit->insetlist.end(); for (; it != end; ++it) { - if (it.getInset()->id() == id_arg) - return it.getInset(); - Inset * in = it.getInset()->getInsetFromID(id_arg); + if (it->inset->id() == id_arg) + return it->inset; + Inset * in = it->inset->getInsetFromID(id_arg); if (in) return in; } @@ -2654,10 +2654,10 @@ void InsetText::addPreview(grfx::PreviewLoader & loader) const ParagraphList::const_iterator pend = paragraphs.end(); for (; pit != pend; ++pit) { - InsetList::iterator it = pit->insetlist.begin(); - InsetList::iterator end = pit->insetlist.end(); + InsetList::const_iterator it = pit->insetlist.begin(); + InsetList::const_iterator end = pit->insetlist.end(); for (; it != end; ++it) { - it.getInset()->addPreview(loader); + it->inset->addPreview(loader); } } } diff --git a/src/iterators.C b/src/iterators.C index 72d8627044..0821d0e667 100644 --- a/src/iterators.C +++ b/src/iterators.C @@ -103,7 +103,7 @@ ParIterator & ParIterator::operator++() // Does the current inset contain more "cells" ? if (p.index) { ++(*p.index); - ParagraphList * plist = p.it->getInset()->getParagraphs(*p.index); + ParagraphList * plist = (*p.it)->inset->getParagraphs(*p.index); if (plist && !plist->empty()) { pimpl_->positions.push(ParPosition(plist->begin(), *plist)); return *this; @@ -118,7 +118,7 @@ ParIterator & ParIterator::operator++() // Try to find the next inset that contains paragraphs InsetList::iterator end = p.pit->insetlist.end(); for (; *p.it != end; ++(*p.it)) { - ParagraphList * plist = p.it->getInset()->getParagraphs(0); + ParagraphList * plist = (*p.it)->inset->getParagraphs(0); if (plist && !plist->empty()) { p.index.reset(0); pimpl_->positions.push(ParPosition(plist->begin(), *plist)); @@ -215,7 +215,7 @@ ParConstIterator & ParConstIterator::operator++() // Does the current inset contain more "cells" ? if (p.index) { ++(*p.index); - ParagraphList * plist = p.it->getInset()->getParagraphs(*p.index); + ParagraphList * plist = (*p.it)->inset->getParagraphs(*p.index); if (plist && !plist->empty()) { pimpl_->positions.push(ParPosition(plist->begin(), *plist)); return *this; @@ -230,7 +230,7 @@ ParConstIterator & ParConstIterator::operator++() // Try to find the next inset that contains paragraphs InsetList::iterator end = p.pit->insetlist.end(); for (; *p.it != end; ++(*p.it)) { - ParagraphList * plist = p.it->getInset()->getParagraphs(0); + ParagraphList * plist = (*p.it)->inset->getParagraphs(0); if (plist && !plist->empty()) { p.index.reset(0); pimpl_->positions.push(ParPosition(plist->begin(), *plist)); diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 04713ba293..be5b8d97db 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -142,7 +142,7 @@ void InsetFormulaBase::validate(LaTeXFeatures &) const void InsetFormulaBase::metrics(BufferView * bv, LyXFont const & f, - Dimension & dim) const + Dimension & /*dim*/) const { font_ = f; metrics(bv); diff --git a/src/paragraph.C b/src/paragraph.C index a8ef2aa214..229d223184 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -99,9 +99,9 @@ Paragraph::Paragraph(Paragraph const & lp) InsetList::iterator it = insetlist.begin(); InsetList::iterator end = insetlist.end(); for (; it != end; ++it) { - it.setInset(it.getInset()->clone(**buffer_)); + it->inset = it->inset->clone(**buffer_); // tell the new inset who is the boss now - it.getInset()->parOwner(this); + it->inset->parOwner(this); } } @@ -718,20 +718,20 @@ int Paragraph::beginningOfBody() const int Paragraph::getPositionOfInset(Inset const * inset) const { // Find the entry. - InsetList::iterator it = insetlist.begin(); - InsetList::iterator end = insetlist.end(); + InsetList::const_iterator it = insetlist.begin(); + InsetList::const_iterator end = insetlist.end(); for (; it != end; ++it) - if (it.getInset() == inset) - return it.getPos(); + if (it->inset == inset) + return it->pos; return -1; } InsetBibitem * Paragraph::bibitem() const { - InsetList::iterator it = insetlist.begin(); - if (it != insetlist.end() && it.getInset()->lyxCode() == Inset::BIBTEX_CODE) - return static_cast(it.getInset()); + InsetList::const_iterator it = insetlist.begin(); + if (it != insetlist.end() && it->inset->lyxCode() == Inset::BIBTEX_CODE) + return static_cast(it->inset); return 0; } @@ -1220,8 +1220,8 @@ void Paragraph::setInsetOwner(Inset * i) InsetList::iterator it = insetlist.begin(); InsetList::iterator end = insetlist.end(); for (; it != end; ++it) - if (it.getInset()) - it.getInset()->setOwner(i); + if (it->inset) + it->inset->setOwner(i); } diff --git a/src/paragraph_funcs.C b/src/paragraph_funcs.C index 2a8adf3af4..0842302dbb 100644 --- a/src/paragraph_funcs.C +++ b/src/paragraph_funcs.C @@ -425,10 +425,10 @@ TeXEnvironment(Buffer const * buf, InsetOptArg * optArgInset(Paragraph const & par) { // Find the entry. - InsetList::iterator it = par.insetlist.begin(); - InsetList::iterator end = par.insetlist.end(); + InsetList::const_iterator it = par.insetlist.begin(); + InsetList::const_iterator end = par.insetlist.end(); for (; it != end; ++it) { - Inset * ins = it.getInset(); + Inset * ins = it->inset; if (ins->lyxCode() == Inset::OPTARG_CODE) { return static_cast(ins); } diff --git a/src/paragraph_pimpl.C b/src/paragraph_pimpl.C index bb19f8af42..912538e72d 100644 --- a/src/paragraph_pimpl.C +++ b/src/paragraph_pimpl.C @@ -821,10 +821,10 @@ void Paragraph::Pimpl::validate(LaTeXFeatures & features, InsetList::iterator icit = owner_->insetlist.begin(); InsetList::iterator iend = owner_->insetlist.end(); for (; icit != iend; ++icit) { - if (icit.getInset()) { - icit.getInset()->validate(features); + if (icit->inset) { + icit->inset->validate(features); if (layout.needprotect && - icit.getInset()->lyxCode() == Inset::FOOT_CODE) + icit->inset->lyxCode() == Inset::FOOT_CODE) features.require("NeedLyXFootnoteCode"); } } diff --git a/src/toc.C b/src/toc.C index 96ea0364ee..5709cf8894 100644 --- a/src/toc.C +++ b/src/toc.C @@ -97,13 +97,13 @@ TocList const getTocList(Buffer const * buf) InsetList::iterator it = pit->insetlist.begin(); InsetList::iterator end = pit->insetlist.end(); for (; it != end; ++it) { - if (it.getInset()->lyxCode() == Inset::FLOAT_CODE) { + if (it->inset->lyxCode() == Inset::FLOAT_CODE) { InsetFloat * il = - static_cast(it.getInset()); + static_cast(it->inset); il->addToToc(toclist, buf); - } else if (it.getInset()->lyxCode() == Inset::WRAP_CODE) { + } else if (it->inset->lyxCode() == Inset::WRAP_CODE) { InsetWrap * il = - static_cast(it.getInset()); + static_cast(it->inset); il->addToToc(toclist, buf); } }