From f8d516c7afcb84b73930fb9de5738fafa8a921c9 Mon Sep 17 00:00:00 2001 From: Stefan Schimanski Date: Mon, 25 Feb 2008 22:02:48 +0000 Subject: [PATCH] Revert "* compile fix" git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23234 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 15 ++++++++ src/Buffer.h | 6 ++++ src/Paragraph.cpp | 66 ------------------------------------ src/Paragraph.h | 9 ----- src/Text.cpp | 9 +++-- src/Text.h | 2 +- src/WordList.cpp | 28 ++------------- src/WordList.h | 6 +--- src/insets/InsetText.cpp | 6 ++-- src/support/weighted_btree.h | 4 +-- 10 files changed, 34 insertions(+), 117 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index de4b9ccd2e..bd6b7f7fc7 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -204,6 +204,9 @@ public: /// A cache for the bibfiles (including bibfiles of loaded child /// documents), needed for appropriate update of natbib labels. mutable EmbeddedFileList bibfilesCache_; + + /// + WordList words_; }; /// Creates the per buffer temporary directory @@ -2665,4 +2668,16 @@ void Buffer::bufferErrors(TeXErrors const & terr, ErrorList & errorList) const } } + +void Buffer::registerWord(docstring const & word) +{ + d->words_.insert(word); +} + + +WordList const & Buffer::registeredWords() const +{ + return d->words_; +} + } // namespace lyx diff --git a/src/Buffer.h b/src/Buffer.h index c35a2479c0..ace9986f23 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -50,6 +50,7 @@ class TeXErrors; class TexRow; class TocBackend; class Undo; +class WordList; namespace frontend { class GuiBufferDelegate; @@ -451,6 +452,11 @@ public: bool isExportable(std::string const & format) const; /// std::vector exportableFormats(bool only_viewable) const; + + /// Register word for completion word list. + void registerWord(docstring const & word); + /// + WordList const & registeredWords() const; private: /// search for macro in local (buffer) table or in children diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 08fb7c527d..5d773ee34c 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -39,9 +39,7 @@ #include "sgml.h" #include "TextClass.h" #include "TexRow.h" -#include "Text.h" #include "VSpace.h" -#include "WordList.h" #include "frontends/alert.h" @@ -198,10 +196,6 @@ public: typedef docstring TextContainer; /// TextContainer text_; - - typedef std::set Words; - /// - Words words_; }; @@ -1063,7 +1057,6 @@ Paragraph & Paragraph::operator=(Paragraph const & par) Paragraph::~Paragraph() { - deregisterWords(); delete d; } @@ -2685,63 +2678,4 @@ bool Paragraph::isSeparator(pos_type pos) const } -void Paragraph::deregisterWords() -{ - // deregister words - Private::Words::const_iterator it; - WordList & wl = theWordList(); - for (it = d->words_.begin(); it != d->words_.end(); ++it) - wl.remove(*it); - d->words_.clear(); -} - - -void Paragraph::registerWords(Cursor const & cur) -{ - // find new words - bool inword = false; - - lyxerr << "Words: "; - pos_type n = size(); - for (pos_type pos = 0; pos != n; ++pos) { - if (isDeleted(pos)) - continue; - - if (!isLetter(pos)) { - inword = false; - continue; - } - - if (inword) - continue; - - inword = true; - CursorSlice from = cur.top(); - CursorSlice to = cur.top(); - from.pos() = pos; - to.pos() = pos; - from.text()->getWord(from, to, NEXT_WORD); - if (to.pos() - from.pos() < 6) - continue; - docstring word - = asString(cur.buffer(), from.pos(), to.pos(), false); - d->words_.insert(word); - lyxerr << word << " "; - } - lyxerr << std::endl; - - // register words - Private::Words::const_iterator it; - WordList & wl = theWordList(); - for (it = d->words_.begin(); it != d->words_.end(); ++it) - wl.insert(*it); -} - - -void Paragraph::updateWords(Cursor const & cur) -{ - deregisterWords(); - registerWords(cur); -} - } // namespace lyx diff --git a/src/Paragraph.h b/src/Paragraph.h index eb24df8dbc..3c9e533562 100644 --- a/src/Paragraph.h +++ b/src/Paragraph.h @@ -31,7 +31,6 @@ class Buffer; class BufferParams; class Change; class Counters; -class Cursor; class Inset; class InsetBibitem; class LaTeXFeatures; @@ -368,16 +367,8 @@ public: bool mw, ///< pos_type pos, ///< start from here. bool del = true) const; - - /// - void updateWords(Cursor const & cur); private: - /// - void deregisterWords(); - /// - void registerWords(Cursor const & cur); - /// Pimpl away stuff class Private; /// diff --git a/src/Text.cpp b/src/Text.cpp index 9066213668..98aef7a70e 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -581,8 +581,7 @@ void Text::charInserted(Cursor & cur) && !par.isLetter(cur.pos() - 1)) { // get the word in front of cursor BOOST_ASSERT(this == cur.text()); - cur.paragraph().updateWords(cur); - /* CursorSlice focus = cur.top(); + CursorSlice focus = cur.top(); focus.backwardPos(); CursorSlice from = focus; CursorSlice to = focus; @@ -594,7 +593,7 @@ void Text::charInserted(Cursor & cur) // register words longer than 5 characters if (word.length() > 5) - cur.buffer().registerWord(word);*/ + cur.buffer().registerWord(word); } } @@ -1130,7 +1129,7 @@ bool Text::dissolveInset(Cursor & cur) { void Text::getWord(CursorSlice & from, CursorSlice & to, - word_location const loc) const + word_location const loc) { Paragraph const & from_par = pars_[from.pit()]; switch (loc) { @@ -1162,7 +1161,7 @@ void Text::getWord(CursorSlice & from, CursorSlice & to, break; } to = from; - Paragraph const & to_par = pars_[to.pit()]; + Paragraph & to_par = pars_[to.pit()]; while (to.pos() < to_par.size() && to_par.isLetter(to.pos())) ++to.pos(); } diff --git a/src/Text.h b/src/Text.h index 323bdabaa9..0f8ba1c7f0 100644 --- a/src/Text.h +++ b/src/Text.h @@ -134,7 +134,7 @@ public: * @param from return here the start of the word * @param to return here the end of the word */ - void getWord(CursorSlice & from, CursorSlice & to, word_location const) const; + void getWord(CursorSlice & from, CursorSlice & to, word_location const); /// just selects the word the cursor is in void selectWord(Cursor & cur, word_location loc); diff --git a/src/WordList.cpp b/src/WordList.cpp index 5d4debf1e9..a5a8f4a78f 100644 --- a/src/WordList.cpp +++ b/src/WordList.cpp @@ -21,20 +21,12 @@ namespace lyx { -/// -WordList theGlobalWordList; - -WordList & theWordList() -{ - return theGlobalWordList; -} - /// struct WordList::Impl { /// size_t c_; /// - typedef stx::weighted_btree Words; + typedef stx::weighted_btree Words; /// Words words_; }; @@ -75,22 +67,8 @@ size_t WordList::size() const void WordList::insert(docstring const & w) { - Impl::Words::iterator it = d->words_.find(w); - if (it == d->words_.end()) - d->words_.insert(w, size_t(1), 1); - else - it.data()++; -} - - -void WordList::remove(docstring const & w) -{ - Impl::Words::iterator it = d->words_.find(w); - if (it != d->words_.end()) { - it.data()--; - if (it.data() == 0) - d->words_.erase(w); - } + d->words_.insert(w, size_t(1), stx::Void()); } + } // namespace lyx diff --git a/src/WordList.h b/src/WordList.h index d02b0b7b88..263c4d40da 100644 --- a/src/WordList.h +++ b/src/WordList.h @@ -29,16 +29,12 @@ public: size_t size() const; /// void insert(docstring const & w); - /// - void remove(docstring const & w); - + private: struct Impl; Impl * d; }; -WordList & theWordList(); - } // namespace lyx #endif // WORDLIST_H diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index f3404281bc..42d5cff3ce 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -80,14 +80,12 @@ public: /// virtual size_t size() const { -// return buf_.registeredWords().size(); - return theWordList().size(); + return buf_.registeredWords().size(); } /// virtual docstring const & data(size_t idx) const { -// return buf_.registeredWords().word(idx); - return theWordList().word(idx); + return buf_.registeredWords().word(idx); } private: diff --git a/src/support/weighted_btree.h b/src/support/weighted_btree.h index d5d6c300c1..4418a83136 100644 --- a/src/support/weighted_btree.h +++ b/src/support/weighted_btree.h @@ -2547,7 +2547,7 @@ private: left->weights[left->slotuse + i] = right->weights[i]; } left->slotuse += right->slotuse; - left->weight += right->weight; + left->weight += right.weight; left->nextleaf = right->nextleaf; if (left->nextleaf) @@ -2600,7 +2600,7 @@ private: left->childid[left->slotuse + i] = right->childid[i]; } left->slotuse += right->slotuse; - left->weight += right->weight; + left->weight += right.weight; left->childid[left->slotuse] = right->childid[right->slotuse]; -- 2.39.5