]> git.lyx.org Git - features.git/commitdiff
return a Paragraph & from ParIterator::operator*()
authorAndré Pönitz <poenitz@gmx.net>
Thu, 12 Jun 2003 11:09:55 +0000 (11:09 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 12 Jun 2003 11:09:55 +0000 (11:09 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7161 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.C
src/BufferView_pimpl.C
src/ChangeLog
src/CutAndPaste.C
src/buffer.C
src/frontends/controllers/ControlErrorList.C
src/iterators.C
src/iterators.h
src/lyxfunc.C
src/text.C
src/toc.C

index 6e1ef133efa0d6cc3ee6f8d63d2d95992ee3f5e9..016f495ae5a0b0e407ede88cf688de8bfe76f36a 100644 (file)
@@ -379,7 +379,7 @@ void BufferView::setCursorFromRow(int row)
                texrowpar = text->ownerParagraphs().begin();
                tmppos = 0;
        } else {
-               texrowpar = *buffer()->getParFromID(tmpid);
+               texrowpar = buffer()->getParFromID(tmpid).pit();
        }
        text->setCursor(texrowpar, tmppos);
 }
@@ -645,7 +645,7 @@ bool BufferView::ChangeInsets(Inset::Code code,
                        // The test it.size()==1 was needed to prevent crashes.
                        // How to set the cursor corretly when it.size()>1 ??
                        if (it.size() == 1) {
-                               text->setCursorIntern(*it, 0);
+                               text->setCursorIntern(it.pit(), 0);
                                text->redoParagraphs(text->cursor,
                                                     boost::next(text->cursor.par()));
                                text->fullRebreak();
index 04f1f311a31311191264c2540c3df7761e233420..f8f8fd4bbcad0e4108f3c547a03aa7ef8a1ca20d 100644 (file)
@@ -651,8 +651,8 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
        if (par == buffer_->par_iterator_end())
                return;
 
-       bv_->text->setCursor(*par,
-                            min((*par)->size(), saved_positions[i].par_pos));
+       bv_->text->setCursor(par.pit(),
+                            min(par->size(), saved_positions[i].par_pos));
 
        update(BufferView::SELECT);
        if (i > 0)
@@ -861,9 +861,8 @@ void BufferView::Pimpl::trackChanges()
 
        if (!tracking) {
                ParIterator const end = buf->par_iterator_end();
-               for (ParIterator it = buf->par_iterator_begin(); it != end; ++it) {
-                       (*it)->trackChanges();
-               }
+               for (ParIterator it = buf->par_iterator_begin(); it != end; ++it) 
+                       it->trackChanges();
                buf->params.tracking_changes = true;
 
                // we cannot allow undos beyond the freeze point
@@ -881,9 +880,8 @@ void BufferView::Pimpl::trackChanges()
                }
 
                ParIterator const end = buf->par_iterator_end();
-               for (ParIterator it = buf->par_iterator_begin(); it != end; ++it) {
-                       (*it)->untrackChanges();
-               }
+               for (ParIterator it = buf->par_iterator_begin(); it != end; ++it)
+                       it->untrackChanges();
                buf->params.tracking_changes = false;
        }
 
index dad0094c64e15498824d908e43fff47beead9ac7..4a3ab61726322a11444be82fb859e538384bcb3f 100644 (file)
@@ -1,3 +1,15 @@
+
+2003-06-12  André Pönitz  <poenitz@gmx.net>
+
+       * BufferView.C:
+       * BufferView_pimpl.C:
+       * CutAndPaste.C:
+       * buffer.C:
+       * iterators.[Ch]:
+       * lyxfunc.C:
+       * text.C:
+       * toc.C: Return a Paragraph & for ParIterator::operator*()
+
 2003-06-11  John Levon  <levon@movementarian.org>
 
        * lyx_main.C:
index 4a220f144d6803231a423427cd540e259b379305..0fbb7848abea02557d642a9392b1d23c5eaf4451 100644 (file)
@@ -377,25 +377,24 @@ int CutAndPaste::SwitchLayoutsBetweenClasses(textclass_type c1,
        LyXTextClass const & tclass2 = textclasslist[c2];
        ParIterator end = ParIterator(pars.end(), pars);
        for (ParIterator it = ParIterator(pars.begin(), pars); it != end; ++it) {
-               Paragraph * par = &*(*it);
-               string const name = par->layout()->name();
+               string const name = it->layout()->name();
                bool hasLayout = tclass2.hasLayout(name);
 
                if (hasLayout)
-                       par->layout(tclass2[name]);
+                       it->layout(tclass2[name]);
                else
-                       par->layout(tclass2.defaultLayout());
+                       it->layout(tclass2.defaultLayout());
 
                if (!hasLayout && name != tclass1.defaultLayoutName()) {
                        ++ret;
                        string const s = bformat(
                                _("Layout had to be changed from\n%1$s to %2$s\n"
                                "because of class conversion from\n%3$s to %4$s"),
-                        name, par->layout()->name(), tclass1.name(), tclass2.name());
+                        name, it->layout()->name(), tclass1.name(), tclass2.name());
                        // To warn the user that something had to be done.
                        errorlist.push_back(ErrorItem("Changed Layout", s,
-                                                     par->id(), 0,
-                                                     par->size()));
+                                                     it->id(), 0,
+                                                     it->size()));
                }
        }
        return ret;
index 9b7ceb0e82cb0f166a6aad8b0b5fb471860e8da2..24b8d16677e2a15ee08b6e7f7e81d1e7692eb551 100644 (file)
@@ -2134,7 +2134,7 @@ void Buffer::changeLanguage(Language const * from, Language const * to)
 
        ParIterator end = par_iterator_end();
        for (ParIterator it = par_iterator_begin(); it != end; ++it)
-               (*it)->changeLanguage(params, from, to);
+               it->changeLanguage(params, from, to);
 }
 
 
@@ -2148,7 +2148,7 @@ bool Buffer::isMultiLingual()
 {
        ParIterator end = par_iterator_end();
        for (ParIterator it = par_iterator_begin(); it != end; ++it)
-               if ((*it)->isMultiLingual(params))
+               if (it->isMultiLingual(params))
                        return true;
 
        return false;
@@ -2195,7 +2195,7 @@ ParIterator Buffer::getParFromID(int id) const
        }
 
        for (; it != end; ++it)
-               if ((*it)->id() == id)
+               if (it->id() == id)
                        return it;
 
        return end;
@@ -2204,8 +2204,8 @@ ParIterator Buffer::getParFromID(int id) const
 
 bool Buffer::hasParWithID(int id) const
 {
-       ParIterator it(const_cast<Buffer*>(this)->par_iterator_begin());
-       ParIterator end(const_cast<Buffer*>(this)->par_iterator_end());
+       ParConstIterator it = par_iterator_begin();
+       ParConstIterator end = par_iterator_end();
 
        if (id < 0) {
                // John says this is called with id == -1 from undo
@@ -2214,7 +2214,7 @@ bool Buffer::hasParWithID(int id) const
        }
 
        for (; it != end; ++it)
-               if ((*it)->id() == id)
+               if (it->id() == id)
                        return true;
 
        return false;
index 4613989f7ba2d95f443e16151aa8e24de99142b0..f7eab0039ac1edc07aa1fceea9198495ed9414cb 100644 (file)
@@ -54,15 +54,12 @@ string const & ControlErrorList::name()
 
 void ControlErrorList::goTo(int item)
 {
-       BufferView * const bv = kernel().bufferview();
-       Buffer * const buf = kernel().buffer();
-
        ErrorItem const & err = errorlist_[item];
 
-
        if (err.par_id == -1)
                return;
 
+       Buffer * const buf = kernel().buffer();
        ParIterator pit = buf->getParFromID(err.par_id);
 
        if (pit == buf->par_iterator_end()) {
@@ -72,14 +69,15 @@ void ControlErrorList::goTo(int item)
 
        int range = err.pos_end - err.pos_start;
 
-       if (err.pos_end > (*pit)->size() || range <= 0)
-               range = (*pit)->size() - err.pos_start;
+       if (err.pos_end > pit->size() || range <= 0)
+               range = pit->size() - err.pos_start;
 
        // Now make the selection.
+       BufferView * const bv = kernel().bufferview();
        bv->insetUnlock();
        bv->toggleSelection();
        bv->text->clearSelection();
-       bv->text->setCursor(*pit, err.pos_start);
+       bv->text->setCursor(pit.pit(), err.pos_start);
        bv->text->setSelectionRange(range);
        bv->toggleSelection(false);
        bv->fitCursor();
index 5bd591273f6e578e1930286282705de3bb76afb0..5865272ff1c020977787b2558d28ed7d1639bce8 100644 (file)
@@ -47,7 +47,7 @@ public:
 ParPosition::ParPosition(ParagraphList::iterator p, ParagraphList const & pl)
        : pit(p), plist(&pl)
 {
-       if (p != const_cast<ParagraphList&>(pl).end()) {
+       if (p != pl.end()) {
                it.reset(p->insetlist.begin());
        }
 }
@@ -129,7 +129,7 @@ ParIterator & ParIterator::operator++()
                }
 
                // Try to go to the next paragarph
-               if (next(p.pit) != const_cast<ParagraphList*>(p.plist)->end()
+               if (next(p.pit) != p.plist->end()
                    || pimpl_->positions.size() == 1) {
                        ++p.pit;
                        p.index.reset();
@@ -145,7 +145,13 @@ ParIterator & ParIterator::operator++()
 }
 
 
-ParagraphList::iterator ParIterator::operator*() const
+Paragraph & ParIterator::operator*() const
+{
+       return *pimpl_->positions.back().pit;
+}
+
+
+ParagraphList::iterator ParIterator::pit() const
 {
        return pimpl_->positions.back().pit;
 }
@@ -247,7 +253,7 @@ ParConstIterator & ParConstIterator::operator++()
                }
 
                // Try to go to the next paragarph
-               if (next(p.pit) != const_cast<ParagraphList*>(p.plist)->end()
+               if (next(p.pit) != p.plist->end()
                    || pimpl_->positions.size() == 1) {
                        ++p.pit;
                        p.index.reset();
@@ -264,13 +270,19 @@ ParConstIterator & ParConstIterator::operator++()
 }
 
 
-ParagraphList::iterator ParConstIterator::operator*() const
+Paragraph const & ParConstIterator::operator*() const
+{
+       return *pimpl_->positions.back().pit;
+}
+
+
+ParagraphList::const_iterator ParConstIterator::pit() const
 {
        return pimpl_->positions.back().pit;
 }
 
 
-ParagraphList::iterator ParConstIterator::operator->() const
+ParagraphList::const_iterator ParConstIterator::operator->() const
 {
        return pimpl_->positions.back().pit;
 }
index f3153ad8e604b553ee039525dc80f3611ee95309..dcb896acc357075e0c4dff583cedc7872b96f841 100644 (file)
@@ -29,12 +29,14 @@ public:
        ///
        ParIterator & operator++();
        ///
-       ParagraphList::iterator operator*() const;
+       Paragraph & operator*() const;
        ///
        ParagraphList::iterator operator->() const;
        ///
        ParagraphList::iterator outerPar() const;
        ///
+       ParagraphList::iterator pit() const;
+       ///
        ParagraphList & plist() const;
        ///
        size_t size() const;
@@ -64,11 +66,13 @@ public:
        ///
        ParConstIterator & operator++();
        ///
-       ParagraphList::iterator operator*() const;
+       ParagraphList::const_iterator pit() const;
        ///
-       ParagraphList::iterator operator->() const;
-
+       Paragraph const & operator*() const;
        ///
+       ParagraphList::const_iterator operator->() const;
+
+       /// depth of nesting
        size_t size() const;
        ///
        friend
index 332f0eb267e73c260b93ada64eb4de96a49e1b99..bf551cd8b55ba52548abb52d28b459770eb39c6b 100644 (file)
@@ -1363,18 +1363,18 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                                            << id << ']' << endl;
                        break;
                } else {
-                       lyxerr[Debug::INFO] << "Paragraph " << (*par)->id()
+                       lyxerr[Debug::INFO] << "Paragraph " << par->id()
                                            << " found." << endl;
                }
 
                if (view()->theLockingInset())
                        view()->unlockInset(view()->theLockingInset());
-               if ((*par)->inInset()) {
+               if (par->inInset()) {
                        FuncRequest cmd(view(), LFUN_INSET_EDIT, "left");
-                       (*par)->inInset()->localDispatch(cmd);
+                       par->inInset()->localDispatch(cmd);
                }
                // Set the cursor
-               view()->getLyXText()->setCursor(*par, 0);
+               view()->getLyXText()->setCursor(par.pit(), 0);
                view()->switchKeyMap();
                owner->view_state_changed();
 
index bcc7c640e008e901c24ae79c6fc840d38e1f7a41..02761b87e33dc43e0a7a789ad4b3eaac6a88ddbb 100644 (file)
@@ -770,8 +770,7 @@ pos_type addressBreakPoint(pos_type i, Paragraph const & par)
 };
 
 
-pos_type
-LyXText::rowBreakPoint(Row const & row) const
+pos_type LyXText::rowBreakPoint(Row const & row) const
 {
        ParagraphList::iterator pit = row.par();
 
@@ -800,7 +799,7 @@ LyXText::rowBreakPoint(Row const & row) const
        // or the end of the par, then choose the possible break
        // nearest that.
 
-       int const left = leftMargin(const_cast<Row&>(row));
+       int const left = leftMargin(row);
        int x = left;
 
        // pixel width since last breakpoint
index 5709cf8894bbfa03e02912e7332bd9da3596d832..de0ce39226d10b3e3e54ed8b913c882e2960294e 100644 (file)
--- a/src/toc.C
+++ b/src/toc.C
@@ -94,8 +94,8 @@ TocList const getTocList(Buffer const * buf)
 
                // For each paragraph, traverse its insets and look for
                // FLOAT_CODE or WRAP_CODE
-               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->inset->lyxCode() == Inset::FLOAT_CODE) {
                                InsetFloat * il =