]> git.lyx.org Git - lyx.git/blobdiff - src/ParagraphList.h
Fix bug #12772
[lyx.git] / src / ParagraphList.h
index aaa41c28eab9144cfa80bfd09ee8f6d68b974b6f..7e5cc1a869ff50b54150f09d1c85d2448731ba9c 100644 (file)
@@ -1,90 +1,47 @@
 // -*- C++ -*-
+/**
+ * \file ParagraphList.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
+ */
 
 #ifndef PARAGRAPH_LIST_H
 #define PARAGRAPH_LIST_H
 
-#include <iterator>
+#include "Paragraph.h"
 
-class Paragraph;
+#include "support/RandomAccessList.h"
 
-///
-class ParagraphList {
+
+namespace lyx {
+
+/// Container for all kind of Paragraphs used in LyX.
+class ParagraphList : public RandomAccessList<Paragraph> {
 public:
        ///
-       class iterator {
-       public:
-               ///
-               typedef std::bidirectional_iterator_tag iterator_category;
-               ///
-               typedef Paragraph * value_type;
-               ///
-               typedef ptrdiff_t difference_type;
-               ///
-               typedef Paragraph * pointer;
-               ///
-               typedef Paragraph & reference;
-               ///
-               iterator();
-               ///
-               iterator(value_type);
-               ///
-               reference operator*();
-               ///
-               pointer operator->();
-               ///
-               iterator & operator++();
-               ///
-               iterator operator++(int);
-               ///
-               iterator & operator--();
-               ///
-               iterator operator--(int);
-       private:
-               ///
-               Paragraph * ptr;
-       };
-       ///
-       ParagraphList();
-       ///
-       iterator insert(iterator it, Paragraph * par);
-       ///
-       void clear();
-       ///
-       void erase(iterator it);
-       ///
-       iterator begin();
-       ///
-       iterator begin() const;
-       ///
-       iterator end();
-       ///
-       iterator end() const;
+       ParagraphList() {}
        ///
-       void set(Paragraph *);
-       ///
-       void push_back(Paragraph *);
-       ///
-       Paragraph const & front() const;
-       ///
-       Paragraph & front();
-       ///
-       Paragraph const & back() const;
-       ///
-       Paragraph & back();
-       ///
-       int size() const;
-       ///
-       bool empty() const;
-private:
-       ///
-       Paragraph * parlist;
+       template<class InputIterator>
+       ParagraphList(InputIterator first, InputIterator last)
+               : RandomAccessList<Paragraph>(first, last)
+       {}
+
+       const Paragraph * getParagraphBefore(const_iterator const & par) const
+       {
+               // No previous paragraph.
+               if (par == begin())
+                       return nullptr;
+
+               auto prevpar = par;
+               --prevpar;
+               return &*prevpar;
+       }
 };
 
-///
-bool operator==(ParagraphList::iterator const & i1,
-               ParagraphList::iterator const & i2);
-///
-bool operator!=(ParagraphList::iterator const & i1,
-               ParagraphList::iterator const & i2);
+} // namespace lyx
 
 #endif