From: André Pönitz Date: Tue, 20 Aug 2002 17:18:21 +0000 (+0000) Subject: - parts of Lars' diff-6.diff X-Git-Tag: 1.6.10~18524 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=53cc89eed61955dc9510bd853be433939e23b393;p=features.git - parts of Lars' diff-6.diff - 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 --- diff --git a/src/BufferView2.C b/src/BufferView2.C index 6361c7e365..1b6a774fd3 100644 --- a/src/BufferView2.C +++ b/src/BufferView2.C @@ -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 labels = (*it)->getLabelList(); + vector labels = it->getLabelList(); if (find(labels.begin(),labels.end(),label) != labels.end()) { beforeChange(text); diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index dff9337f51..b5b68341d3 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -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 } diff --git a/src/ChangeLog b/src/ChangeLog index c479c620b1..9c1501d232 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ + +2002-08-20 André Pönitz + + * 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 * BufferView_pimpl.C (dispatch): Insert insetbibtex with "plain" diff --git a/src/buffer.C b/src/buffer.C index d45fb87f96..498d21937d 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1888,7 +1888,7 @@ pair 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(*it); - if (insetinc->isIncludeOnly()) { + if (it->lyxCode() == Inset::INCLUDE_CODE) { + InsetInclude & inc = static_cast(*it); + if (inc.isIncludeOnly()) { if (!lst.empty()) lst += delim; - lst += insetinc->getRelFileBaseName(); + lst += inc.getRelFileBaseName(); } } } @@ -3698,7 +3697,7 @@ vector const Buffer::getLabelList() const vector label_list; for (inset_iterator it = inset_const_iterator_begin(); it != inset_const_iterator_end(); ++it) { - vector const l = (*it)->getLabelList(); + vector const l = it->getLabelList(); label_list.insert(label_list.end(), l.begin(), l.end()); } return label_list; @@ -3736,13 +3735,13 @@ vector > 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 tmp = - static_cast(*it)->getKeys(this); + static_cast(*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 const tmp = - static_cast(*it)->getKeys(); + static_cast(*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); +} + diff --git a/src/buffer.h b/src/buffer.h index 14ad3ac9f0..8aad387abe 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -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 diff --git a/src/graphics/PreviewLoader.C b/src/graphics/PreviewLoader.C index 091d9ac9b5..f78ca67bd3 100644 --- a/src/graphics/PreviewLoader.C +++ b/src/graphics/PreviewLoader.C @@ -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 diff --git a/src/graphics/Previews.C b/src/graphics/Previews.C index 14834038eb..8a9618d040 100644 --- a/src/graphics/Previews.C +++ b/src/graphics/Previews.C @@ -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(); } diff --git a/src/insets/insetquotes.C b/src/insets/insetquotes.C index 4567f4ab03..3e01fe8079 100644 --- a/src/insets/insetquotes.C +++ b/src/insets/insetquotes.C @@ -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); diff --git a/src/insets/insettext.C b/src/insets/insettext.C index d78da4a61d..23b23b1625 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -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; } diff --git a/src/text.C b/src/text.C index c662d63570..4c822ea8b7 100644 --- a/src/text.C +++ b/src/text.C @@ -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()