]> git.lyx.org Git - features.git/blobdiff - src/ParagraphList.C
parlist-23-a,diff
[features.git] / src / ParagraphList.C
index 9ebcdebe61d6f0a23c2aad26070fad9972edf260..3e19224f9cb66385d4d822697506906e51cf3b2c 100644 (file)
@@ -80,6 +80,80 @@ bool operator!=(ParagraphList::iterator const & i1,
        return !(i1 == i2);
 }
 
+////////// The ParagraphList::const_iterator
+
+ParagraphList::const_iterator::const_iterator()
+       : ptr(0)
+{}
+
+
+ParagraphList::const_iterator::const_iterator(Paragraph * p)
+       : ptr(p)
+{}
+
+
+ParagraphList::const_iterator::const_reference
+ParagraphList::const_iterator::operator*()
+{
+       return *ptr;
+}
+
+
+ParagraphList::const_iterator::const_pointer
+ParagraphList::const_iterator::operator->()
+{
+       return ptr;
+}
+
+
+ParagraphList::const_iterator &
+ParagraphList::const_iterator::operator++()
+{
+       ptr = ptr->next_par_;
+       return *this;
+}
+
+
+ParagraphList::const_iterator
+ParagraphList::const_iterator::operator++(int)
+{
+       const_iterator tmp = *this;
+       ++*this;
+       return tmp;
+}
+
+
+ParagraphList::const_iterator &
+ParagraphList::const_iterator::operator--()
+{
+       ptr = ptr->prev_par_;
+       return *this;
+}
+
+
+ParagraphList::const_iterator
+ParagraphList::const_iterator::operator--(int)
+{
+       const_iterator tmp = *this;
+       --*this;
+       return tmp;
+}
+
+
+bool operator==(ParagraphList::const_iterator const & i1,
+               ParagraphList::const_iterator const & i2)
+{
+       return &(*const_cast<ParagraphList::const_iterator&>(i1))
+           == &(*const_cast<ParagraphList::const_iterator&>(i2));
+}
+
+
+bool operator!=(ParagraphList::const_iterator const & i1,
+               ParagraphList::const_iterator const & i2)
+{
+       return !(i1 == i2);
+}
+
 //////////
 ////////// The ParagraphList proper
 //////////
@@ -93,8 +167,8 @@ ParagraphList::ParagraphList(ParagraphList const & pl)
        : parlist(0)
 {
        // Deep copy.
-       ParagraphList::iterator it = pl.begin();
-       ParagraphList::iterator end = pl.end();
+       ParagraphList::const_iterator it = pl.begin();
+       ParagraphList::const_iterator end = pl.end();
        for (; it != end; ++it) {
                push_back(*it);
        }
@@ -110,8 +184,10 @@ ParagraphList & ParagraphList::operator=(ParagraphList const & rhs)
 
 
 ParagraphList::iterator
-ParagraphList::insert(ParagraphList::iterator it, Paragraph * par)
+ParagraphList::insert(ParagraphList::iterator it, Paragraph const & p)
 {
+       Paragraph * par = new Paragraph(p);
+
        if (it != end()) {
                Paragraph * prev = it->prev_par_;
                par->next_par_ = &*it;
@@ -136,7 +212,7 @@ ParagraphList::insert(ParagraphList::iterator it, Paragraph * par)
 void ParagraphList::insert(iterator pos, iterator beg, iterator end)
 {
        for (; beg != end; ++beg) {
-               insert(pos, new Paragraph(*beg, false));
+               insert(pos, *beg);
        }
 }
 
@@ -229,9 +305,9 @@ ParagraphList::iterator ParagraphList::begin()
 }
 
 
-ParagraphList::iterator ParagraphList::begin() const
+ParagraphList::const_iterator ParagraphList::begin() const
 {
-       return iterator(parlist);
+       return const_iterator(parlist);
 }
 
 
@@ -241,9 +317,9 @@ ParagraphList::iterator ParagraphList::end()
 }
 
 
-ParagraphList::iterator ParagraphList::end() const
+ParagraphList::const_iterator ParagraphList::end() const
 {
-       return iterator();
+       return const_iterator();
 }
 
 
@@ -279,7 +355,7 @@ Paragraph & ParagraphList::back()
 
 void ParagraphList::push_back(Paragraph const & pr)
 {
-       Paragraph * p = new Paragraph(pr, false);
+       Paragraph * p = new Paragraph(pr);
 
        if (!parlist) {
                parlist = p;