]> git.lyx.org Git - features.git/commitdiff
- parts of Lars' diff-6.diff
authorAndré Pönitz <poenitz@gmx.net>
Tue, 20 Aug 2002 17:18:21 +0000 (17:18 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Tue, 20 Aug 2002 17:18:21 +0000 (17:18 +0000)
- move inline functions from buffer.h to buffer.C

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5038 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView2.C
src/BufferView_pimpl.C
src/ChangeLog
src/buffer.C
src/buffer.h
src/graphics/PreviewLoader.C
src/graphics/Previews.C
src/insets/insetquotes.C
src/insets/insettext.C
src/text.C

index 6361c7e365e1c86e0d8c7bb49a47315d42c6b0c7..1b6a774fd32bbfe35a386b7da1824baf41c68238 100644 (file)
@@ -315,17 +315,16 @@ bool BufferView::insertInset(Inset * inset, string const & lout)
 }
 
 
-/* This is also a buffer property (ale) */
+// This is also a buffer property (ale)
 // Not so sure about that. a goto Label function can not be buffer local, just
-// think how this will work in a multiwindo/buffer environment, all the
+// think how this will work in a multiwindow/buffer environment, all the
 // cursors in all the views showing this buffer will move. (Lgb)
 // OK, then no cursor action should be allowed in buffer. (ale)
 bool BufferView::gotoLabel(string const & label)
-
 {
        for (Buffer::inset_iterator it = buffer()->inset_iterator_begin();
             it != buffer()->inset_iterator_end(); ++it) {
-               vector<string> labels = (*it)->getLabelList();
+               vector<string> labels = it->getLabelList();
                if (find(labels.begin(),labels.end(),label)
                     != labels.end()) {
                        beforeChange(text);
index dff9337f515c254521b12f8756808c4c642cbf40..b5b68341d375429471ab8590aabb52c99909aab7 100644 (file)
@@ -1400,6 +1400,7 @@ void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
 
 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
 {
+#if 0
        LyXCursor cursor = bv_->getLyXText()->cursor;
        Buffer::inset_iterator it =
                find_if(Buffer::inset_iterator(
@@ -1407,6 +1408,42 @@ Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
                        buffer_->inset_iterator_end(),
                        lyx::compare_memfun(&Inset::lyxCode, code));
        return it != buffer_->inset_iterator_end() ? (*it) : 0;
+#else
+       // Ok, this is a little bit too brute force but it
+       // should work for now. Better infrastructure is comming. (Lgb)
+
+       Buffer * b = bv_->buffer();
+       LyXCursor cursor = bv_->getLyXText()->cursor;
+
+       Buffer::inset_iterator beg = b->inset_iterator_begin();
+       Buffer::inset_iterator end = b->inset_iterator_end();
+
+       bool cursor_par_seen = false;
+       
+       for (; beg != end; ++beg) {
+               if (beg.getPar() == cursor.par()) {
+                       cursor_par_seen = true;
+               }
+               if (cursor_par_seen) {
+                       if (beg.getPar() == cursor.par()
+                           && beg.getPos() >= cursor.pos()) {
+                               break;
+                       } else if (beg.getPar() != cursor.par()) {
+                               break;
+                       }
+               }
+               
+       }
+       if (beg != end) {
+               // Now find the first inset that matches code.
+               for (; beg != end; ++beg) {
+                       if (beg->lyxCode() == code) {
+                               return &(*beg);
+                       }
+               }
+       }
+       return 0;
+#endif
 }
 
 
index c479c620b1258a531d4bbfac2d1256f3d6e19e33..9c1501d2325185d070d0a093d5eb4e733067369a 100644 (file)
@@ -1,3 +1,13 @@
+
+2002-08-20  André Pönitz <poenitz@gmx.net>
+
+       * buffer.[Ch]: move inline functions to .C
+               
+       * BufferView2.C:
+       * BufferView_pimpl.C:
+       * text.C:
+       * buffer.[Ch]: use improved inset_iterator
+
 2002-08-20  Dekel Tsur  <dekelts@tau.ac.il>
 
        * BufferView_pimpl.C (dispatch): Insert insetbibtex with "plain"
index d45fb87f960450fecc75ddcd2b32b5000a282a75..498d21937de11143632f4f17ffafac57a5e8bf03 100644 (file)
@@ -1888,7 +1888,7 @@ pair<int, string> const addDepth(int depth, int ldepth)
 }
 
 
-string const Buffer::asciiParagraph(Paragraph const * par,
+string const Buffer::asciiParagraph(Paragraph const & par,
                                    unsigned int linelen,
                                    bool noparbreak) const
 {
@@ -1912,11 +1912,11 @@ string const Buffer::asciiParagraph(Paragraph const * par,
                }
        }
 #else
-       depth = par->params().depth();
+       depth = par.params().depth();
 #endif
 
        // First write the layout
-       string const & tmp = par->layout()->name();
+       string const & tmp = par.layout()->name();
        if (compare_no_case(tmp, "itemize") == 0) {
                ltype = 1;
                ltype_depth = depth + 1;
@@ -1958,7 +1958,7 @@ string const Buffer::asciiParagraph(Paragraph const * par,
 //             lyxerr << "Should this ever happen?" << endl;
 //     }
 
-       // linelen <= 0 is special and means we don't have pargraph breaks
+       // linelen <= 0 is special and means we don't have paragraph breaks
 
        string::size_type currlinelen = 0;
 
@@ -2005,7 +2005,7 @@ string const Buffer::asciiParagraph(Paragraph const * par,
                        break;
                default:
                {
-                       string const parlab = par->params().labelString();
+                       string const parlab = par.params().labelString();
                        buffer << parlab << " ";
                        currlinelen += parlab.length() + 1;
                }
@@ -2026,12 +2026,12 @@ string const Buffer::asciiParagraph(Paragraph const * par,
 
        string word;
 
-       for (pos_type i = 0; i < par->size(); ++i) {
-               char c = par->getUChar(params, i);
+       for (pos_type i = 0; i < par.size(); ++i) {
+               char c = par.getUChar(params, i);
                switch (c) {
                case Paragraph::META_INSET:
                {
-                       Inset const * inset = par->getInset(i);
+                       Inset const * inset = par.getInset(i);
                        if (inset) {
                                if (linelen > 0) {
                                        buffer << word;
@@ -2116,15 +2116,15 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
 }
 
 
-void Buffer::writeFileAscii(ostream & ofs, int linelen)
+void Buffer::writeFileAscii(ostream & os, int linelen)
 {
        ParagraphList::iterator beg = paragraphs.begin();
        ParagraphList::iterator end = paragraphs.end();
        ParagraphList::iterator it = beg;
        for (; it != end; ++it) {
-               ofs << asciiParagraph(&*it, linelen, it == beg);
+               os << asciiParagraph(*it, linelen, it == beg);
        }
-       ofs << "\n";
+       os << "\n";
 }
 
 
@@ -2642,7 +2642,7 @@ void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
        while (par != endpar) {
                Inset * in = par->inInset();
                // well we have to check if we are in an inset with unlimited
-               // lenght (all in one row) if that is true then we don't allow
+               // length (all in one row) if that is true then we don't allow
                // any special options in the paragraph and also we don't allow
                // any environment other then "Standard" to be valid!
                if ((in == 0) || !in->forceDefaultParagraphs(in)) {
@@ -3669,13 +3669,12 @@ string const Buffer::getIncludeonlyList(char delim)
        string lst;
        for (inset_iterator it = inset_iterator_begin();
            it != inset_iterator_end(); ++it) {
-               if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
-                       InsetInclude * insetinc =
-                               static_cast<InsetInclude *>(*it);
-                       if (insetinc->isIncludeOnly()) {
+               if (it->lyxCode() == Inset::INCLUDE_CODE) {
+                       InsetInclude & inc = static_cast<InsetInclude &>(*it);
+                       if (inc.isIncludeOnly()) {
                                if (!lst.empty())
                                        lst += delim;
-                               lst += insetinc->getRelFileBaseName();
+                               lst += inc.getRelFileBaseName();
                        }
                }
        }
@@ -3698,7 +3697,7 @@ vector<string> const Buffer::getLabelList() const
        vector<string> label_list;
        for (inset_iterator it = inset_const_iterator_begin();
             it != inset_const_iterator_end(); ++it) {
-               vector<string> const l = (*it)->getLabelList();
+               vector<string> const l = it->getLabelList();
                label_list.insert(label_list.end(), l.begin(), l.end());
        }
        return label_list;
@@ -3736,13 +3735,13 @@ vector<pair<string, string> > const Buffer::getBibkeyList() const
                for (inset_iterator it = inset_const_iterator_begin();
                        it != inset_const_iterator_end(); ++it) {
                        // Search for Bibtex or Include inset
-                       if ((*it)->lyxCode() == Inset::BIBTEX_CODE) {
+                       if (it->lyxCode() == Inset::BIBTEX_CODE) {
                                vector<StringPair> tmp =
-                                       static_cast<InsetBibtex*>(*it)->getKeys(this);
+                                       static_cast<InsetBibtex &>(*it).getKeys(this);
                                keys.insert(keys.end(), tmp.begin(), tmp.end());
-                       } else if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
+                       } else if (it->lyxCode() == Inset::INCLUDE_CODE) {
                                vector<StringPair> const tmp =
-                                       static_cast<InsetInclude*>(*it)->getKeys();
+                                       static_cast<InsetInclude &>(*it).getKeys();
                                keys.insert(keys.end(), tmp.begin(), tmp.end());
                        }
                }
@@ -3857,27 +3856,14 @@ Counters & Buffer::counters() const
 }
 
 
-Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
-       : par(paragraph)
-{
-       it = par->insetlist.insetIterator(pos);
-       if (it == par->insetlist.end()) {
-               par = par->next();
-               setParagraph();
-       }
-}
-
-
 void Buffer::inset_iterator::setParagraph()
 {
-       while (par) {
-               it = par->insetlist.begin();
-               if (it != par->insetlist.end())
+       while (pit != pend) {
+               it = pit->insetlist.begin();
+               if (it != pit->insetlist.end())
                        return;
-               par = par->next();
+               ++pit;
        }
-       //it = 0;
-       // We maintain an invariant that whenever par = 0 then it = 0
 }
 
 
@@ -3886,9 +3872,9 @@ Inset * Buffer::getInsetFromID(int id_arg) const
        for (inset_iterator it = inset_const_iterator_begin();
                 it != inset_const_iterator_end(); ++it)
        {
-               if ((*it)->id() == id_arg)
-                       return *it;
-               Inset * in = (*it)->getInsetFromID(id_arg);
+               if (it->id() == id_arg)
+                       return &(*it);
+               Inset * in = it->getInsetFromID(id_arg);
                if (in)
                        return in;
        }
@@ -3926,3 +3912,181 @@ ParIterator Buffer::par_iterator_end()
 {
        return ParIterator();
 }
+
+
+void Buffer::addUser(BufferView * u)
+{
+       users = u;
+}
+
+
+void Buffer::delUser(BufferView *)
+{
+       users = 0;
+}
+
+
+Language const * Buffer::getLanguage() const
+{
+       return params.language;
+}
+
+
+bool Buffer::isClean() const
+{
+       return lyx_clean;
+}
+
+
+bool Buffer::isBakClean() const
+{
+       return bak_clean;
+}
+
+
+void Buffer::markClean() const
+{
+       if (!lyx_clean) {
+               lyx_clean = true;
+               updateTitles();
+       }
+       // if the .lyx file has been saved, we don't need an
+       // autosave
+       bak_clean = true;
+}
+
+
+void Buffer::markBakClean()
+{
+       bak_clean = true;
+}
+
+
+void Buffer::setUnnamed(bool flag)
+{
+       unnamed = flag;
+}
+
+
+bool Buffer::isUnnamed()
+{
+       return unnamed;
+}
+
+
+void Buffer::markDirty()
+{
+       if (lyx_clean) {
+               lyx_clean = false;
+               updateTitles();
+       }
+       bak_clean = false;
+       DEPCLEAN * tmp = dep_clean;
+       while (tmp) {
+               tmp->clean = false;
+               tmp = tmp->next;
+       }
+}
+
+
+string const & Buffer::fileName() const
+{
+       return filename_;
+}
+
+
+string const & Buffer::filePath() const
+{
+       return filepath_;
+}
+
+
+bool Buffer::isReadonly() const
+{
+       return read_only;
+}
+
+
+BufferView * Buffer::getUser() const
+{
+       return users;
+}
+
+
+void Buffer::setParentName(string const & name)
+{
+       params.parentname = name;
+}
+
+
+Buffer::inset_iterator::inset_iterator()
+       : pit(0), pend(0)
+{}
+
+
+Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
+       : pit(p), pend(e)
+{
+       setParagraph();
+}
+
+
+Buffer::inset_iterator & Buffer::inset_iterator::operator++()
+{
+       if (pit != pend) {
+               ++it;
+               if (it == pit->insetlist.end()) {
+                       ++pit;
+                       setParagraph();
+               }
+       }
+       return *this;
+}
+
+
+Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
+{
+       inset_iterator tmp = *this;
+       ++*this;
+       return tmp;
+}
+
+
+Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
+{
+       return *it.getInset();
+}
+
+
+Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
+{
+       return it.getInset();
+}
+
+
+Paragraph * Buffer::inset_iterator::getPar()
+{
+       return &(*pit);
+}
+
+
+lyx::pos_type Buffer::inset_iterator::getPos() const
+{
+       return it.getPos();
+}
+
+
+bool operator==(Buffer::inset_iterator const & iter1,
+                Buffer::inset_iterator const & iter2)
+{
+       return iter1.pit == iter2.pit
+               && (iter1.pit == iter1.pend || iter1.it == iter2.it);
+}
+
+
+bool operator!=(Buffer::inset_iterator const & iter1,
+                Buffer::inset_iterator const & iter2)
+{
+       return !(iter1 == iter2);
+}
+
index 14ad3ac9f0ae9e4caa3208193d1df49614cdcf39..8aad387abe94167ebad97c37c6ad4d740827751b 100644 (file)
@@ -155,7 +155,7 @@ public:
        ///
        void writeFileAscii(std::ostream &, int);
        ///
-       string const asciiParagraph(Paragraph const *, unsigned int linelen,
+       string const asciiParagraph(Paragraph const &, unsigned int linelen,
                                    bool noparbreak = false) const;
        /// Just a wrapper for the method below, first creating the ofstream.
        void makeLaTeXFile(string const & filename,
@@ -367,47 +367,28 @@ public:
                typedef ptrdiff_t difference_type;
                typedef Inset * pointer;
                typedef Inset & reference;
-
-
-               ///
-               inset_iterator() : par(0) /*, it(0)*/ {}
-               //
-               inset_iterator(Paragraph * paragraph) : par(paragraph) {
-                       setParagraph();
-               }
-               ///
-               inset_iterator(Paragraph * paragraph, lyx::pos_type pos);
+               typedef ParagraphList::iterator base_type;
+
+               ///
+               inset_iterator();
+               ///
+               inset_iterator(base_type p, base_type e);
+               ///
+               inset_iterator(base_type p, lyx::pos_type pos, base_type e);
+
+               /// prefix ++
+               inset_iterator & operator++();
+               /// postfix ++
+               inset_iterator operator++(int);
                ///
-               inset_iterator & operator++() { // prefix ++
-                       if (par) {
-                               ++it;
-                               if (it == par->insetlist.end()) {
-                                       par = par->next();
-                                       setParagraph();
-                               }
-                       }
-                       return *this;
-               }
+               reference operator*();
                ///
-               inset_iterator operator++(int) { // postfix ++
-                       inset_iterator tmp(par, it.getPos());
-                       if (par) {
-                               ++it;
-                               if (it == par->insetlist.end()) {
-                                       par = par->next();
-                                       setParagraph();
-                               }
-                       }
-                       return tmp;
-               }
+               pointer operator->();
 
                ///
-               Inset * operator*() { return it.getInset(); }
-
-               ///
-               Paragraph * getPar() { return par; }
+               Paragraph * getPar();
                ///
-               lyx::pos_type getPos() const { return it.getPos(); }
+               lyx::pos_type getPos() const;
                ///
                friend
                bool operator==(inset_iterator const & iter1,
@@ -416,23 +397,28 @@ public:
                ///
                void setParagraph();
                ///
-               Paragraph * par;
+               ParagraphList::iterator pit;
+               ///
+               ParagraphList::iterator pend;
                ///
                InsetList::iterator it;
        };
 
        ///
        inset_iterator inset_iterator_begin() {
-               return inset_iterator(&*paragraphs.begin());
+               return inset_iterator(paragraphs.begin(), paragraphs.end());
        }
+
        ///
        inset_iterator inset_iterator_end() {
                return inset_iterator();
        }
+
        ///
        inset_iterator inset_const_iterator_begin() const {
-               return inset_iterator(&*paragraphs.begin());
+               return inset_iterator(paragraphs.begin(), paragraphs.end());
        }
+
        ///
        inset_iterator inset_const_iterator_end() const {
                return inset_iterator();
@@ -447,143 +433,4 @@ public:
        Inset * getInsetFromID(int id_arg) const;
 };
 
-
-inline
-void Buffer::addUser(BufferView * u)
-{
-       users = u;
-}
-
-
-inline
-void Buffer::delUser(BufferView *)
-{
-       users = 0;
-}
-
-
-inline
-Language const * Buffer::getLanguage() const
-{
-       return params.language;
-}
-
-
-inline
-bool Buffer::isClean() const
-{
-       return lyx_clean;
-}
-
-
-inline
-bool Buffer::isBakClean() const
-{
-       return bak_clean;
-}
-
-
-inline
-void Buffer::markClean() const
-{
-       if (!lyx_clean) {
-               lyx_clean = true;
-               updateTitles();
-       }
-       // if the .lyx file has been saved, we don't need an
-       // autosave
-       bak_clean = true;
-}
-
-
-inline
-void Buffer::markBakClean()
-{
-       bak_clean = true;
-}
-
-
-inline
-void Buffer::setUnnamed(bool flag)
-{
-       unnamed = flag;
-}
-
-
-inline
-bool Buffer::isUnnamed()
-{
-       return unnamed;
-}
-
-
-inline
-void Buffer::markDirty()
-{
-       if (lyx_clean) {
-               lyx_clean = false;
-               updateTitles();
-       }
-       bak_clean = false;
-       DEPCLEAN * tmp = dep_clean;
-       while (tmp) {
-               tmp->clean = false;
-               tmp = tmp->next;
-       }
-}
-
-
-inline
-string const & Buffer::fileName() const
-{
-       return filename_;
-}
-
-
-inline
-string const & Buffer::filePath() const
-{
-       return filepath_;
-}
-
-
-inline
-bool Buffer::isReadonly() const
-{
-       return read_only;
-}
-
-
-inline
-BufferView * Buffer::getUser() const
-{
-       return users;
-}
-
-
-inline
-void Buffer::setParentName(string const & name)
-{
-       params.parentname = name;
-}
-
-
-///
-inline
-bool operator==(Buffer::inset_iterator const & iter1,
-               Buffer::inset_iterator const & iter2)
-{
-       return iter1.par == iter2.par
-               && (iter1.par == 0 || iter1.it == iter2.it);
-}
-
-
-///
-inline
-bool operator!=(Buffer::inset_iterator const & iter1,
-               Buffer::inset_iterator const & iter2)
-{
-       return !(iter1 == iter2);
-}
-
 #endif
index 091d9ac9b582c2e5ea59f847786b434b21a7a837..f78ca67bd3a2c8ae76a1a376f3b025cc7ec1c9ed 100644 (file)
@@ -583,11 +583,9 @@ void PreviewLoader::Impl::dumpPreamble(ostream & os) const
        Buffer::inset_iterator it  = buffer_.inset_const_iterator_begin();
        Buffer::inset_iterator end = buffer_.inset_const_iterator_end();
 
-       for (; it != end; ++it) {
-               if ((*it)->lyxCode() == Inset::MATHMACRO_CODE) {
-                       (*it)->latex(&buffer_, os, true, true);
-               }
-       }
+       for (; it != end; ++it)
+               if (it->lyxCode() == Inset::MATHMACRO_CODE)
+                       it->latex(&buffer_, os, true, true);
 
        // All equation lables appear as "(#)" + preview.sty's rendering of
        // the label name
index 14834038eb3fad00589366007458f9f43d4878cf..8a9618d040aaca672574825a3ea35b404cf20e79 100644 (file)
@@ -93,9 +93,8 @@ void Previews::generateBufferPreviews(Buffer const & buffer) const
        Buffer::inset_iterator it  = buffer.inset_const_iterator_begin();
        Buffer::inset_iterator end = buffer.inset_const_iterator_end();
 
-       for (; it != end; ++it) {
-               (*it)->addPreview(ploader);
-       }
+       for (; it != end; ++it)
+               it->addPreview(ploader);
 
        ploader.startLoading();
 }
index 4567f4ab037b11e01fea19d69bdc4420c6f5bfe6..3e01fe80799a09ec669ba8880d6c55b1395abca7 100644 (file)
@@ -205,7 +205,7 @@ int InsetQuotes::width(BufferView *, LyXFont const & font) const
        for (string::size_type i = 0; i < text.length(); ++i) {
                if (text[i] == ' ')
                        w += font_metrics::width('i', font);
-               else if (i == 0 || text[i] != text[i-1])
+               else if (i == 0 || text[i] != text[i - 1])
                        w += font_metrics::width(text[i], font);
                else
                        w += font_metrics::width(',', font);
index d78da4a61d60fdd122f3d592915c0e0e2f988484..23b23b16250e189894e4a58edc2c77943c75a110 100644 (file)
@@ -1563,7 +1563,7 @@ int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
        ParagraphList::iterator end = paragraphs.end();
        ParagraphList::iterator it = beg;
        for (; it != end; ++it) {
-               string const tmp = buf->asciiParagraph(&*it, linelen, it == beg);
+               string const tmp = buf->asciiParagraph(*it, linelen, it == beg);
                lines += lyx::count(tmp.begin(), tmp.end(), '\n');
                os << tmp;
        }
index c662d635703869005efcf494f78d723d42fa1723..4c822ea8b70181c505d01933506edc5f47780808 100644 (file)
@@ -80,7 +80,7 @@ int LyXText::workWidth(BufferView * bview, Inset * inset) const
                Buffer::inset_iterator it = bview->buffer()->inset_iterator_begin();
                Buffer::inset_iterator end = bview->buffer()->inset_iterator_end();
                for (; it != end; ++it) {
-                       if (*it == inset) {
+                       if (&(*it) == inset) {
                                par = it.getPar();
                                pos = it.getPos();
                                break;
@@ -735,8 +735,7 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
        } else {
                // find the next level paragraph
 
-               Paragraph * newpar =
-                       row->par()->outerHook();
+               Paragraph * newpar = row->par()->outerHook();
 
                // make a corresponding row. Needed to call LeftMargin()