// -*- 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 <vector>
+#include "ParagraphList.h"
-#include "paragraph.h"
+#include <boost/scoped_ptr.hpp>
-class ParPosition {
+class ParIterator {
public:
- ParPosition(Paragraph * p)
- : par(p), it(p->inset_iterator_begin()), index(-1) {}
///
- Paragraph * par;
+ ParIterator(ParagraphList::iterator pit, ParagraphList const & pl);
+ ///
+ ~ParIterator();
+ ///
+ ParIterator(ParIterator const &);
+ ///
+ void operator=(ParIterator const &);
+ ///
+ ParIterator & operator++();
+ ///
+ Paragraph & operator*() const;
///
- Paragraph::inset_iterator it;
+ ParagraphList::iterator operator->() const;
+ /// This gives us the top-most parent paragraph
+ ParagraphList::iterator outerPar() const;
///
- int index;
+ ParagraphList::iterator pit() const;
+ ///
+ ParagraphList & plist() const;
+ ///
+ size_t size() const;
+ ///
+ friend
+ bool operator==(ParIterator const & iter1, ParIterator const & iter2);
+private:
+ struct Pimpl;
+ boost::scoped_ptr<Pimpl> pimpl_;
};
+///
+bool operator==(ParIterator const & iter1, ParIterator const & iter2);
-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);
-}
+///
+bool operator!=(ParIterator const & iter1, ParIterator const & iter2);
-class ParIterator {
+class ParConstIterator {
public:
///
- ParIterator() {}
- //
- ParIterator(Paragraph * par)
- : positions(1, ParPosition(par)) {}
+ ParConstIterator(ParagraphList::iterator pit, ParagraphList const & pl);
///
- ParIterator & operator++();
+ ~ParConstIterator();
+ ///
+ ParConstIterator(ParConstIterator const &);
+ ///
+ ParConstIterator & operator++();
+ ///
+ ParagraphList::const_iterator pit() const;
///
- Paragraph * operator*() { return positions.back().par; }
+ Paragraph const & operator*() const;
///
- vector<ParPosition>::size_type size() const
- { return positions.size(); }
+ ParagraphList::const_iterator operator->() const;
+
+ /// depth of nesting
+ size_t size() const;
///
friend
- bool operator==(ParIterator const & iter1, ParIterator const & iter2);
+ bool operator==(ParConstIterator const & iter1,
+ ParConstIterator const & iter2);
private:
- ///
- std::vector<ParPosition> positions;
+ struct Pimpl;
+ boost::scoped_ptr<Pimpl> pimpl_;
};
+bool operator==(ParConstIterator const & iter1,
+ ParConstIterator const & iter2);
-///
-inline
-bool operator==(ParIterator const & iter1, ParIterator const & iter2) {
- return iter1.positions == iter2.positions;
-}
-
-
-///
-inline
-bool operator!=(ParIterator const & iter1, ParIterator const & iter2) {
- return !(iter1 == iter2);
-}
+bool operator!=(ParConstIterator const & iter1,
+ ParConstIterator const & iter2);
#endif