mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-27 06:19:36 +00:00
Lar's ParConstIterator
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5602 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
e1b2b64272
commit
ef87c26b55
@ -1,3 +1,14 @@
|
|||||||
|
2002-11-08 John Levon <levon@movementarian.org>
|
||||||
|
|
||||||
|
* iterators.h:
|
||||||
|
* iterators.C:
|
||||||
|
* buffer.h:
|
||||||
|
* buffer.C:
|
||||||
|
* paragraph.h:
|
||||||
|
* paragraph.C:
|
||||||
|
* toc.h:
|
||||||
|
* toc.C: ParConstIterator, and use it (from Lars)
|
||||||
|
|
||||||
2002-11-07 Ben Stanley <bds02@uow.edu.au>
|
2002-11-07 Ben Stanley <bds02@uow.edu.au>
|
||||||
|
|
||||||
* lyxtextclass.[Ch]: revise and add doxygen comments
|
* lyxtextclass.[Ch]: revise and add doxygen comments
|
||||||
|
12
src/buffer.C
12
src/buffer.C
@ -3343,6 +3343,18 @@ ParIterator Buffer::par_iterator_end()
|
|||||||
return ParIterator();
|
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)
|
void Buffer::addUser(BufferView * u)
|
||||||
{
|
{
|
||||||
|
@ -35,6 +35,7 @@ class TeXErrors;
|
|||||||
class LaTeXFeatures;
|
class LaTeXFeatures;
|
||||||
class Language;
|
class Language;
|
||||||
class ParIterator;
|
class ParIterator;
|
||||||
|
class ParConstIterator;
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -402,7 +403,11 @@ public:
|
|||||||
///
|
///
|
||||||
ParIterator par_iterator_begin();
|
ParIterator par_iterator_begin();
|
||||||
///
|
///
|
||||||
|
ParConstIterator par_iterator_begin() const;
|
||||||
|
///
|
||||||
ParIterator par_iterator_end();
|
ParIterator par_iterator_end();
|
||||||
|
///
|
||||||
|
ParConstIterator par_iterator_end() const;
|
||||||
|
|
||||||
///
|
///
|
||||||
Inset * getInsetFromID(int id_arg) const;
|
Inset * getInsetFromID(int id_arg) const;
|
||||||
|
@ -42,3 +42,45 @@ ParIterator & ParIterator::operator++()
|
|||||||
}
|
}
|
||||||
return *this;
|
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;
|
||||||
|
}
|
||||||
|
@ -74,4 +74,46 @@ bool operator!=(ParIterator const & iter1, ParIterator const & iter2) {
|
|||||||
return !(iter1 == iter2);
|
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
|
#endif
|
||||||
|
@ -1727,7 +1727,7 @@ bool Paragraph::isMultiLingual(BufferParams const & bparams)
|
|||||||
|
|
||||||
// Convert the paragraph to a string.
|
// Convert the paragraph to a string.
|
||||||
// Used for building the table of contents
|
// 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;
|
BufferParams const & bparams = buffer->params;
|
||||||
string s;
|
string s;
|
||||||
@ -1755,7 +1755,7 @@ string const Paragraph::asString(Buffer const * buffer, bool label)
|
|||||||
|
|
||||||
|
|
||||||
string const Paragraph::asString(Buffer const * 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;
|
ostringstream ost;
|
||||||
|
|
||||||
|
@ -77,10 +77,10 @@ public:
|
|||||||
bool isMultiLingual(BufferParams const &);
|
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,
|
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 &,
|
void write(Buffer const *, std::ostream &, BufferParams const &,
|
||||||
|
@ -76,10 +76,11 @@ TocList const getTocList(Buffer const * buf)
|
|||||||
|
|
||||||
LyXTextClass const & textclass = buf->params.getLyXTextClass();
|
LyXTextClass const & textclass = buf->params.getLyXTextClass();
|
||||||
|
|
||||||
ParIterator pit = buf->par_iterator_begin();
|
ParConstIterator pit = buf->par_iterator_begin();
|
||||||
ParIterator end = buf->par_iterator_end();
|
ParConstIterator end = buf->par_iterator_end();
|
||||||
for (; pit != end; ++pit) {
|
for (; pit != end; ++pit) {
|
||||||
Paragraph * par = *pit;
|
|
||||||
|
Paragraph const * par = *pit;
|
||||||
|
|
||||||
#ifdef WITH_WARNINGS
|
#ifdef WITH_WARNINGS
|
||||||
#warning bogus type (Lgb)
|
#warning bogus type (Lgb)
|
||||||
|
10
src/toc.h
10
src/toc.h
@ -21,7 +21,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include "support/LOstream.h"
|
#include "support/LOstream.h"
|
||||||
#include "LString.h"
|
#include "LString.h"
|
||||||
|
|
||||||
@ -34,12 +34,12 @@ class Paragraph;
|
|||||||
|
|
||||||
/** Nice functions and objects to handle TOCs
|
/** Nice functions and objects to handle TOCs
|
||||||
*/
|
*/
|
||||||
namespace toc
|
namespace toc
|
||||||
{
|
{
|
||||||
|
|
||||||
///
|
///
|
||||||
struct TocItem {
|
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) {}
|
: par(p), depth(d), str(s) {}
|
||||||
///
|
///
|
||||||
string const asString() const;
|
string const asString() const;
|
||||||
@ -48,7 +48,7 @@ struct TocItem {
|
|||||||
/// the action corresponding to the goTo above
|
/// the action corresponding to the goTo above
|
||||||
int action() const;
|
int action() const;
|
||||||
///
|
///
|
||||||
Paragraph * par;
|
Paragraph const * par;
|
||||||
///
|
///
|
||||||
int depth;
|
int depth;
|
||||||
///
|
///
|
||||||
@ -68,7 +68,7 @@ std::vector<string> const getTypes(Buffer const *);
|
|||||||
|
|
||||||
///
|
///
|
||||||
void asciiTocList(string const &, Buffer const *, std::ostream &);
|
void asciiTocList(string const &, Buffer const *, std::ostream &);
|
||||||
|
|
||||||
/** Given the cmdName of the TOC param, returns the type used
|
/** Given the cmdName of the TOC param, returns the type used
|
||||||
by ControlToc::getContents() */
|
by ControlToc::getContents() */
|
||||||
string const getType(string const & cmdName);
|
string const getType(string const & cmdName);
|
||||||
|
Loading…
Reference in New Issue
Block a user