X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fiterators.h;h=a68f7ff12d565886c7c732b4332edd0d79a214b0;hb=67f9c9fdae42211aa3ff8d0c6f62485bd721d8eb;hp=8bc2128a08c297b9a7fb7e3aa855421c86221704;hpb=ef87c26b55b41a848338ada7a4677194ef632289;p=lyx.git diff --git a/src/iterators.h b/src/iterators.h index 8bc2128a08..a68f7ff12d 100644 --- a/src/iterators.h +++ b/src/iterators.h @@ -1,119 +1,135 @@ // -*- C++ -*- +/* \file iterators.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author unknown + * \author Lars Gullik Bjønnes + * + * Full author contact details are available in file CREDITS. + */ #ifndef ITERATORS_H #define ITERATORS_H -#include +#include "ParagraphList_fwd.h" +#include "InsetList.h" + +#include "support/types.h" + +#include + +#include + +class LyXText; +class InsetBase; +class Cursor; +class Buffer; +class PosIterator; -#include "paragraph.h" class ParPosition { public: - ParPosition(Paragraph * p) - : par(p), it(p->insetlist.begin()), index(-1) {} /// - Paragraph * par; + ParPosition(ParagraphList::iterator p, ParagraphList const & pl); /// - InsetList::iterator it; + ParagraphList::iterator pit; /// - int index; + ParagraphList const * plist; + /// + boost::optional it; + /// + boost::optional index; }; -inline -bool operator==(ParPosition const & pos1, ParPosition const & pos2) { - return pos1.par == pos2.par && - pos1.it == pos2.it && - pos1.index == pos2.index; -} - -inline -bool operator!=(ParPosition const & pos1, ParPosition const & pos2) { - return !(pos1 == pos2); -} - - -class ParIterator { +class ParIterator : public std::iterator< + std::forward_iterator_tag, + ParagraphList::value_type> { public: /// - typedef std::stack PosHolder; + ParIterator(ParagraphList::iterator pit, ParagraphList const & pl); /// - ParIterator() {} + ~ParIterator(); /// - ParIterator(Paragraph * par) { - positions.push(ParPosition(par)); - } + ParIterator(ParIterator const &); + /// + ParIterator(PosIterator const &); + /// + void operator=(ParIterator const &); /// ParIterator & operator++(); /// - Paragraph * operator*() { - return positions.top().par; - } + Paragraph & operator*() const; /// - PosHolder::size_type size() const - { return positions.size(); } + ParagraphList::iterator operator->() const; + /// This gives us the top-most parent paragraph + ParagraphList::iterator outerPar() const; /// - friend - bool operator==(ParIterator const & iter1, ParIterator const & iter2); -private: + ParagraphList::iterator pit() const; /// - PosHolder positions; -}; + ParagraphList & plist() const; + /// returns 'innermost' LyXText + LyXText * text(Buffer &) const; + /// returns innermost inset + InsetBase * inset() const; + /// returns index of cell in innermost inset + int index() const; + /// + size_t size() const; + typedef std::vector PosHolder; + PosHolder const & positions() const + { + return positions_; + } +private: + PosHolder positions_; +}; /// -inline -bool operator==(ParIterator const & iter1, ParIterator const & iter2) { - return iter1.positions == iter2.positions; -} - +bool operator==(ParIterator const & iter1, ParIterator const & iter2); /// -inline -bool operator!=(ParIterator const & iter1, ParIterator const & iter2) { - return !(iter1 == iter2); -} +bool operator!=(ParIterator const & iter1, ParIterator const & iter2); -class ParConstIterator { +class ParConstIterator : public std::iterator< + std::forward_iterator_tag, + ParagraphList::value_type> { public: /// - typedef std::stack PosHolder; + ParConstIterator(ParagraphList::iterator pit, ParagraphList const & pl); /// - ParConstIterator() {} + ~ParConstIterator(); /// - ParConstIterator(Paragraph * par) { - positions.push(ParPosition(par)); - } + ParConstIterator(ParConstIterator const &); /// ParConstIterator & operator++(); /// - Paragraph const * operator*() { - return positions.top().par; - } + ParagraphList::const_iterator pit() const; /// - PosHolder::size_type size() const - { return positions.size(); } + Paragraph const & operator*() const; /// - friend - bool operator==(ParConstIterator const & iter1, - ParConstIterator const & iter2); -private: + ParagraphList::const_iterator operator->() const; /// - PosHolder positions; -}; + ParagraphList const & plist() const; + /// depth of nesting + size_t size() const; + typedef std::vector PosHolder; + PosHolder const & positions() const + { + return positions_; + } +private: + PosHolder positions_; +}; -/// -inline -bool operator==(ParConstIterator const & iter1, ParConstIterator const & iter2) { - return iter1.positions == iter2.positions; -} +bool operator==(ParConstIterator const & iter1, + ParConstIterator const & iter2); -/// -inline -bool operator!=(ParConstIterator const & iter1, ParConstIterator const & iter2) { - return !(iter1 == iter2); -} +bool operator!=(ParConstIterator const & iter1, + ParConstIterator const & iter2); #endif