This fix the const problems in toc the long way round...
? build Index: src/buffer.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v retrieving revision 1.390 diff -u -p -r1.390 buffer.C --- src/buffer.C 4 Nov 2002 02:12:28 -0000 1.390 +++ src/buffer.C 7 Nov 2002 15:35:37 -0000 @@ -3343,6 +3343,18 @@ ParIterator Buffer::par_iterator_end() return ParIterator(); } +ParConstIterator Buffer::par_iterator_begin() const +{ + return ParConstIterator(&*(paragraphs.begin())); +} + + +ParConstIterator Buffer::par_iterator_end() const +{ + return ParConstIterator(); +} + + void Buffer::addUser(BufferView * u) { Index: src/buffer.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.h,v retrieving revision 1.116 diff -u -p -r1.116 buffer.h --- src/buffer.h 21 Oct 2002 16:21:52 -0000 1.116 +++ src/buffer.h 7 Nov 2002 15:35:37 -0000 @@ -35,6 +35,7 @@ class TeXErrors; class LaTeXFeatures; class Language; class ParIterator; +class ParConstIterator; /// @@ -402,7 +403,11 @@ public: /// ParIterator par_iterator_begin(); /// + ParConstIterator par_iterator_begin() const; + /// ParIterator par_iterator_end(); + /// + ParConstIterator par_iterator_end() const; /// Inset * getInsetFromID(int id_arg) const; Index: src/iterators.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/iterators.C,v retrieving revision 1.4 diff -u -p -r1.4 iterators.C --- src/iterators.C 11 Aug 2002 15:03:51 -0000 1.4 +++ src/iterators.C 7 Nov 2002 15:35:37 -0000 @@ -42,3 +42,45 @@ ParIterator & ParIterator::operator++() } return *this; } + + +ParConstIterator & ParConstIterator::operator++() +{ + while (!positions.empty()) { + ParPosition & p = positions.top(); + + // Does the current inset contain more "cells" ? + if (p.index >= 0) { + ++p.index; + Paragraph * par = p.it.getInset()->getFirstParagraph(p.index); + if (par) { + positions.push(ParPosition(par)); + return *this; + } + ++p.it; + } else + // 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->insetlist.begin(); + + // Try to find the next inset that contains paragraphs + InsetList::iterator end = p.par->insetlist.end(); + for (; p.it != end; ++p.it) { + Paragraph * par = p.it.getInset()->getFirstParagraph(0); + if (par) { + p.index = 0; + positions.push(ParPosition(par)); + return *this; + } + } + // Try to go to the next paragarph + if (p.par->next()) { + p = ParPosition(p.par->next()); + return *this; + } + + positions.pop(); + } + return *this; +} Index: src/iterators.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/iterators.h,v retrieving revision 1.5 diff -u -p -r1.5 iterators.h --- src/iterators.h 11 Aug 2002 15:03:51 -0000 1.5 +++ src/iterators.h 7 Nov 2002 15:35:37 -0000 @@ -74,4 +74,46 @@ bool operator!=(ParIterator const & iter return !(iter1 == iter2); } + +class ParConstIterator { +public: + /// + typedef std::stack<ParPosition> PosHolder; + /// + ParConstIterator() {} + /// + ParConstIterator(Paragraph * par) { + positions.push(ParPosition(par)); + } + /// + ParConstIterator & operator++(); + /// + Paragraph const * operator*() { + return positions.top().par; + } + /// + PosHolder::size_type size() const + { return positions.size(); } + /// + friend + bool operator==(ParConstIterator const & iter1, + ParConstIterator const & iter2); +private: + /// + PosHolder positions; +}; + + +/// +inline +bool operator==(ParConstIterator const & iter1, ParConstIterator const & iter2) { + return iter1.positions == iter2.positions; +} + +/// +inline +bool operator!=(ParConstIterator const & iter1, ParConstIterator const & iter2) { + return !(iter1 == iter2); +} + #endif Index: src/paragraph.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v retrieving revision 1.231 diff -u -p -r1.231 paragraph.C --- src/paragraph.C 4 Nov 2002 02:12:29 -0000 1.231 +++ src/paragraph.C 7 Nov 2002 15:35:37 -0000 @@ -1727,7 +1727,7 @@ bool Paragraph::isMultiLingual(BufferPar // Convert the paragraph to a string. // Used for building the table of contents -string const Paragraph::asString(Buffer const * buffer, bool label) +string const Paragraph::asString(Buffer const * buffer, bool label) const { BufferParams const & bparams = buffer->params; string s; @@ -1755,7 +1755,7 @@ string const Paragraph::asString(Buffer string const Paragraph::asString(Buffer const * buffer, - pos_type beg, pos_type end, bool label) + pos_type beg, pos_type end, bool label) const { ostringstream ost; Index: src/paragraph.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.h,v retrieving revision 1.50 diff -u -p -r1.50 paragraph.h --- src/paragraph.h 26 Aug 2002 09:31:09 -0000 1.50 +++ src/paragraph.h 7 Nov 2002 15:35:37 -0000 @@ -77,10 +77,10 @@ public: bool isMultiLingual(BufferParams const &); /// - string const asString(Buffer const *, bool label); + string const asString(Buffer const *, bool label) const; /// string const asString(Buffer const *, lyx::pos_type beg, lyx::pos_type end, - bool label); + bool label) const; /// void write(Buffer const *, std::ostream &, BufferParams const &, Index: src/toc.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/toc.C,v retrieving revision 1.13 diff -u -p -r1.13 toc.C --- src/toc.C 7 Nov 2002 00:37:09 -0000 1.13 +++ src/toc.C 7 Nov 2002 15:35:37 -0000 @@ -76,11 +76,11 @@ TocList const getTocList(Buffer const * LyXTextClass const & textclass = buf->params.getLyXTextClass(); - ParIterator pit = buf->par_iterator_begin(); - ParIterator end = buf->par_iterator_end(); + ParConstIterator pit = buf->par_iterator_begin(); + ParConstIterator end = buf->par_iterator_end(); for (; pit != end; ++pit) { - Paragraph * par = *pit; - + Paragraph const * par = *pit; + #ifdef WITH_WARNINGS #warning bogus type (Lgb) #endif Index: src/toc.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/toc.h,v retrieving revision 1.2 diff -u -p -r1.2 toc.h --- src/toc.h 21 Jul 2002 16:59:01 -0000 1.2 +++ src/toc.h 7 Nov 2002 15:35:37 -0000 @@ -21,7 +21,7 @@ #endif #include <config.h> - + #include "support/LOstream.h" #include "LString.h" @@ -34,12 +34,12 @@ class Paragraph; /** Nice functions and objects to handle TOCs */ -namespace toc +namespace toc { /// struct TocItem { - TocItem(Paragraph * p, int d, string const & s) + TocItem(Paragraph const * p, int d, string const & s) : par(p), depth(d), str(s) {} /// string const asString() const; @@ -48,7 +48,7 @@ struct TocItem { /// the action corresponding to the goTo above int action() const; /// - Paragraph * par; + Paragraph const * par; /// int depth; /// @@ -68,7 +68,7 @@ std::vector<string> const getTypes(Buffe /// void asciiTocList(string const &, Buffer const *, std::ostream &); - + /** Given the cmdName of the TOC param, returns the type used by ControlToc::getContents() */ string const getType(string const & cmdName);
-- Lgb