From 3420904448b247cc270597c31b52d777e38ac647 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Sat, 31 Jan 2004 15:30:24 +0000 Subject: [PATCH] The func.diff patch. Functors work and some tiny cleanup. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8377 a592a061-630c-0410-9148-cb99ea01b6c8 --- po/POTFILES.in | 2 +- src/ChangeLog | 32 +++++++++++ src/MenuBackend.C | 56 +++++++++++++++---- src/MenuBackend.h | 12 +++- src/bufferlist.C | 4 +- src/converter.C | 41 +++++++------- src/converter.h | 5 +- src/format.C | 33 +++++++---- src/frontends/controllers/ChangeLog | 8 +++ .../controllers/ControlSpellchecker.C | 4 +- src/frontends/controllers/biblio.C | 6 +- src/frontends/controllers/frnt_lang.C | 5 +- src/frontends/xforms/ChangeLog | 5 ++ src/frontends/xforms/RadioButtonGroup.C | 4 +- src/graphics/ChangeLog | 6 ++ src/graphics/PreviewLoader.C | 22 ++++---- src/insets/insettabular.C | 3 +- src/lyxfind.C | 4 +- src/lyxlex_pimpl.C | 9 +-- src/lyxtextclass.C | 27 +++++---- src/lyxtextclass.h | 2 +- src/lyxtextclasslist.C | 13 +++-- src/mathed/formulamacro.C | 4 +- src/mathed/math_hullinset.C | 1 - src/support/ChangeLog | 8 +++ src/support/forkedcontr.C | 4 +- src/support/lstrings.C | 6 +- src/support/lstrings.h | 13 ++--- src/support/lyxalgo.h | 15 ++--- src/text.C | 4 +- 30 files changed, 235 insertions(+), 123 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index 491c498a97..c866841735 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -179,7 +179,7 @@ src/lyxfont.C src/lyxfunc.C src/lyxrc.C src/lyxvc.C -src/mathed/formulabase.C +src/mathed/formula.C src/mathed/formulamacro.C src/mathed/math_hullinset.C src/mathed/math_macrotemplate.C diff --git a/src/ChangeLog b/src/ChangeLog index f28aee93de..dd2164e0f8 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,4 +1,36 @@ +2004-01-31 Lars Gullik Bjonnes + * lyxtextclasslist.C (less_textclass_avail_desc): inherit from + std::binary_function + + * lyxtextclass.C (compare_name): rename to... + (LayoutNamesEqual): ...this + + * lyxlex_pimpl.C (compare_tags): inherit from + std::binary_function, put back into anon namespace + + * lyxfind.C (MatchString): inherig from std::binary_function + (findChange): use empty() istead of !size() + + * format.C (FormatNamesEqual): new functor + (getFormat): use it + (getNumber): use it + (add): use it + (erase): use it + (setViewer): use it + + * converter.C (compare_Converter): rename to... + (ConverterEqual): ...this, and fixup a bit. + (getConverter): use it, and make function const + (getNumber): use it, and make function const + (add): use it + (erase): use it: + + * bufferlist.C: add using boost::bind + + * MenuBackend.C (MenuNamesEqual): new functor + (hasMenu): use it, and make function const + (hasSubmenu): use nested bind to get rid of compare_memfun. 2004-01-30 André Pönitz diff --git a/src/MenuBackend.C b/src/MenuBackend.C index db9dbddf89..8c03ab0cb1 100644 --- a/src/MenuBackend.C +++ b/src/MenuBackend.C @@ -40,10 +40,11 @@ #include "frontends/LyXView.h" #include "support/filetools.h" -#include "support/lyxfunctional.h" #include "support/lstrings.h" #include "support/tostr.h" +#include + #include using lyx::support::compare_ascii_no_case; @@ -51,8 +52,11 @@ using lyx::support::contains; using lyx::support::MakeDisplayPath; using lyx::support::token; +using boost::bind; + using std::auto_ptr; using std::endl; +using std::equal_to; using std::find_if; using std::max; using std::sort; @@ -63,6 +67,23 @@ using std::vector; extern BufferList bufferlist; extern boost::scoped_ptr toplevel_keymap; +namespace { + +class MenuNamesEqual : public std::unary_function { +public: + MenuNamesEqual(string const & name) + : name_(name) {} + bool operator()(Menu const & menu) const + { + return menu.name() == name_; + } +private: + string name_; +}; + +} // namespace anon + + // This is the global menu definition MenuBackend menubackend; @@ -539,7 +560,7 @@ void expandCharStyleInsert(Menu & tomenu, LyXView const * view) view); return; } - CharStyles & charstyles = + CharStyles & charstyles = view->buffer()->params().getLyXTextClass().charstyles(); CharStyles::iterator cit = charstyles.begin(); CharStyles::iterator end = charstyles.end(); @@ -769,9 +790,22 @@ void MenuBackend::expand(Menu const & frommenu, Menu & tomenu, bool Menu::hasSubmenu(string const & name) const { +#if 1 return find_if(begin(), end(), - lyx::compare_memfun(&MenuItem::submenuname, - name)) != end(); + bind(std::equal_to(), + bind(&MenuItem::submenuname, _1), + name)) != end(); +#else + // I would have prefered this, but I am not sure if it + // makes a difference. (Lgb) + return find_if( + make_transform_iterator(begin(), + bind(&MenuItem::submenuname, _1)), + make_transform_iterator(end(), + bind(&MenuItem::submenuname, _1)), + name + ).base() != end(); +#endif } @@ -840,15 +874,13 @@ void MenuBackend::add(Menu const & menu) bool MenuBackend::hasMenu(string const & name) const { - return find_if(begin(), end(), - lyx::compare_memfun(&Menu::name, name)) != end(); + return find_if(begin(), end(), MenuNamesEqual(name)) != end(); } Menu const & MenuBackend::getMenu(string const & name) const { - const_iterator cit = find_if(begin(), end(), - lyx::compare_memfun(&Menu::name, name)); + const_iterator cit = find_if(begin(), end(), MenuNamesEqual(name)); if (cit == end()) lyxerr << "No submenu named " << name << endl; BOOST_ASSERT(cit != end()); @@ -858,10 +890,10 @@ Menu const & MenuBackend::getMenu(string const & name) const Menu & MenuBackend::getMenu(string const & name) { - MenuList::iterator it = - find_if(menulist_.begin(), menulist_.end(), - lyx::compare_memfun(&Menu::name, name)); - BOOST_ASSERT(it != menulist_.end()); + iterator it = find_if(begin(), end(), MenuNamesEqual(name)); + if (it == end()) + lyxerr << "No submenu named " << name << endl; + BOOST_ASSERT(it != end()); return (*it); } diff --git a/src/MenuBackend.h b/src/MenuBackend.h index a8497f8e1c..c704539eb0 100644 --- a/src/MenuBackend.h +++ b/src/MenuBackend.h @@ -55,7 +55,7 @@ public: /** This is a list of importable formats typically for the File->Export menu. */ ImportFormats, - /** This is the list of elements available + /** This is the list of elements available * for insertion into document. */ CharStyles, /** This is the list of floats that we can @@ -186,6 +186,8 @@ public: /// typedef MenuList::const_iterator const_iterator; /// + typedef MenuList::iterator iterator; + /// void read(LyXLex &); /// void add(Menu const &); @@ -211,9 +213,17 @@ public: return menulist_.begin(); } /// + iterator begin() { + return menulist_.begin(); + } + /// const_iterator end() const { return menulist_.end(); } + /// + iterator end() { + return menulist_.end(); + } private: /// MenuList menulist_; diff --git a/src/bufferlist.C b/src/bufferlist.C index 20a0a72e05..8c19a3928f 100644 --- a/src/bufferlist.C +++ b/src/bufferlist.C @@ -39,6 +39,8 @@ using lyx::support::OnlyFilename; using lyx::support::removeAutosaveFile; using lyx::support::prefixIs; +using boost::bind; + using std::auto_ptr; using std::endl; using std::find; @@ -235,7 +237,7 @@ void BufferList::updateIncludedTeXfiles(string const & mastertmpdir, void BufferList::emergencyWriteAll() { for_each(bstore.begin(), bstore.end(), - boost::bind(&BufferList::emergencyWrite, this, _1)); + bind(&BufferList::emergencyWrite, this, _1)); } diff --git a/src/converter.C b/src/converter.C index 1c56579c00..32f03719d7 100644 --- a/src/converter.C +++ b/src/converter.C @@ -85,6 +85,19 @@ string const dvipdfm_options(BufferParams const & bp) return result; } + +class ConverterEqual : public std::binary_function { +public: + ConverterEqual(string const & from, string const & to) + : from_(from), to_(to) {} + bool operator()(Converter const & c) const { + return c.from == from_ && c.to == to_; + } +private: + string const from_; + string const to_; +}; + } // namespace anon @@ -138,26 +151,12 @@ bool operator<(Converter const & a, Converter const & b) } -class compare_Converter { -public: - compare_Converter(string const & f, string const & t) - : from(f), to(t) {} - bool operator()(Converter const & c) { - return c.from == from && c.to == to; - } -private: - string const & from; - string const & to; -}; - - - Converter const * Converters::getConverter(string const & from, - string const & to) + string const & to) const { ConverterList::const_iterator cit = find_if(converterlist_.begin(), converterlist_.end(), - compare_Converter(from, to)); + ConverterEqual(from, to)); if (cit != converterlist_.end()) return &(*cit); else @@ -165,13 +164,13 @@ Converter const * Converters::getConverter(string const & from, } -int Converters::getNumber(string const & from, string const & to) +int Converters::getNumber(string const & from, string const & to) const { ConverterList::const_iterator cit = find_if(converterlist_.begin(), converterlist_.end(), - compare_Converter(from, to)); + ConverterEqual(from, to)); if (cit != converterlist_.end()) - return cit - converterlist_.begin(); + return distance(converterlist_.begin(), cit); else return -1; } @@ -184,7 +183,7 @@ void Converters::add(string const & from, string const & to, formats.add(to); ConverterList::iterator it = find_if(converterlist_.begin(), converterlist_.end(), - compare_Converter(from, to)); + ConverterEqual(from , to)); Converter converter(from, to, command, flags); if (it != converterlist_.end() && !flags.empty() && flags[0] == '*') { @@ -214,7 +213,7 @@ void Converters::erase(string const & from, string const & to) { ConverterList::iterator it = find_if(converterlist_.begin(), converterlist_.end(), - compare_Converter(from, to)); + ConverterEqual(from, to)); if (it != converterlist_.end()) converterlist_.erase(it); } diff --git a/src/converter.h b/src/converter.h index 801b4c3cbf..6775fb0f1a 100644 --- a/src/converter.h +++ b/src/converter.h @@ -77,9 +77,10 @@ public: return converterlist_[i]; } /// - Converter const * getConverter(std::string const & from, std::string const & to); + Converter const * getConverter(std::string const & from, + std::string const & to) const; /// - int getNumber(std::string const & from, std::string const & to); + int getNumber(std::string const & from, std::string const & to) const; /// void add(std::string const & from, std::string const & to, std::string const & command, std::string const & flags); diff --git a/src/format.C b/src/format.C index c91ce4c05b..e3a0b5a2af 100644 --- a/src/format.C +++ b/src/format.C @@ -23,7 +23,6 @@ #include "support/filetools.h" #include "support/path.h" #include "support/systemcall.h" -#include "support/lyxfunctional.h" using lyx::support::bformat; using lyx::support::compare_ascii_no_case; @@ -45,6 +44,19 @@ string const token_from("$$i"); string const token_path("$$p"); string const token_socket("$$a"); + +class FormatNamesEqual : public std::unary_function { +public: + FormatNamesEqual(string const & name) + : name_(name) {} + bool operator()(Format const & f) const + { + return f.name() == name_; + } +private: + string name_; +}; + } //namespace anon bool operator<(Format const & a, Format const & b) @@ -57,11 +69,8 @@ bool operator<(Format const & a, Format const & b) } Format::Format(string const & n, string const & e, string const & p, - string const & s, string const & v): name_(n), - extension_(e), - prettyname_(p), - shortcut_(s), - viewer_(v) + string const & s, string const & v) + : name_(n), extension_(e), prettyname_(p),shortcut_(s), viewer_(v) {} @@ -91,7 +100,7 @@ Format const * Formats::getFormat(string const & name) const { FormatList::const_iterator cit = find_if(formatlist.begin(), formatlist.end(), - lyx::compare_memfun(&Format::name, name)); + FormatNamesEqual(name)); if (cit != formatlist.end()) return &(*cit); else @@ -103,9 +112,9 @@ int Formats::getNumber(string const & name) const { FormatList::const_iterator cit = find_if(formatlist.begin(), formatlist.end(), - lyx::compare_memfun(&Format::name, name)); + FormatNamesEqual(name)); if (cit != formatlist.end()) - return cit - formatlist.begin(); + return distance(formatlist.begin(), cit); else return -1; } @@ -123,7 +132,7 @@ void Formats::add(string const & name, string const & extension, { FormatList::iterator it = find_if(formatlist.begin(), formatlist.end(), - lyx::compare_memfun(&Format::name, name)); + FormatNamesEqual(name)); if (it == formatlist.end()) formatlist.push_back(Format(name, extension, prettyname, shortcut, "")); @@ -138,7 +147,7 @@ void Formats::erase(string const & name) { FormatList::iterator it = find_if(formatlist.begin(), formatlist.end(), - lyx::compare_memfun(&Format::name, name)); + FormatNamesEqual(name)); if (it != formatlist.end()) formatlist.erase(it); } @@ -155,7 +164,7 @@ void Formats::setViewer(string const & name, string const & command) add(name); FormatList::iterator it = find_if(formatlist.begin(), formatlist.end(), - lyx::compare_memfun(&Format::name, name)); + FormatNamesEqual(name)); if (it != formatlist.end()) it->setViewer(command); } diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 9f29b6f72c..e15fb3860a 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,11 @@ +2004-01-31 Lars Gullik Bjonnes + + * biblio.C (RegexMatch): inherit from std::unary_function, make + operator() const and variable regex_ mutable. + + * ControlSpellchecker.C (check): use correct types for the result + from distance. + 2004-01-28 Lars Gullik Bjonnes * ControlSpellchecker.C: add using statements for std::advance and diff --git a/src/frontends/controllers/ControlSpellchecker.C b/src/frontends/controllers/ControlSpellchecker.C index f5f6c82045..9aa770f043 100644 --- a/src/frontends/controllers/ControlSpellchecker.C +++ b/src/frontends/controllers/ControlSpellchecker.C @@ -197,8 +197,8 @@ void ControlSpellchecker::check() PosIterator const beg = buffer()->pos_iterator_begin(); PosIterator const end = buffer()->pos_iterator_end(); - int start = distance(beg, cur); - int const total = start + distance(cur, end); + PosIterator::difference_type start = distance(beg, cur); + PosIterator::difference_type const total = start + distance(cur, end); if (cur != buffer()->pos_iterator_begin()) for (; cur != end && isLetter(cur); ++cur, ++start); diff --git a/src/frontends/controllers/biblio.C b/src/frontends/controllers/biblio.C index caa9be2d32..29213a98c3 100644 --- a/src/frontends/controllers/biblio.C +++ b/src/frontends/controllers/biblio.C @@ -272,14 +272,14 @@ string const escape_special_chars(string const & expr) // A functor for use with std::find_if, used to ascertain whether a // data entry matches the required regex_ -struct RegexMatch +struct RegexMatch : public std::unary_function { // re and icase are used to construct an instance of boost::RegEx. // if icase is true, then matching is insensitive to case RegexMatch(InfoMap const & m, string const & re, bool icase) : map_(m), regex_(re, icase) {} - bool operator()(string const & key) { + bool operator()(string const & key) const { if (!validRE()) return false; @@ -299,7 +299,7 @@ struct RegexMatch private: InfoMap const map_; - boost::RegEx regex_; + mutable boost::RegEx regex_; }; } // namespace anon diff --git a/src/frontends/controllers/frnt_lang.C b/src/frontends/controllers/frnt_lang.C index f627317494..76b9b92253 100644 --- a/src/frontends/controllers/frnt_lang.C +++ b/src/frontends/controllers/frnt_lang.C @@ -24,7 +24,10 @@ using std::vector; namespace { -struct Sorter { +struct Sorter + : public std::binary_function +{ bool operator()(frnt::LanguagePair const & lhs, frnt::LanguagePair const & rhs) const { return lhs.first < rhs.first; diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index a274c1051c..5c19af12b7 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,8 @@ +2004-01-31 Lars Gullik Bjonnes + + * RadioButtonGroup.C (is_set_button): inherit from + std::unary_function + 2004-01-28 Lars Gullik Bjonnes * XFormsToolbar.C: add using statement for std::distance diff --git a/src/frontends/xforms/RadioButtonGroup.C b/src/frontends/xforms/RadioButtonGroup.C index 7509b78378..cdaa0906aa 100644 --- a/src/frontends/xforms/RadioButtonGroup.C +++ b/src/frontends/xforms/RadioButtonGroup.C @@ -72,8 +72,8 @@ void RadioButtonGroup::set(FL_OBJECT * ob) const } -template < typename T > -struct is_set_button { +template +struct is_set_button : public std::unary_function { bool operator() (T const & item) const { return fl_get_button((item).first); diff --git a/src/graphics/ChangeLog b/src/graphics/ChangeLog index 773d00f63f..0a18e061b2 100644 --- a/src/graphics/ChangeLog +++ b/src/graphics/ChangeLog @@ -1,3 +1,9 @@ +2004-01-31 Lars Gullik Bjonnes + + * PreviewLoader.C (FindFirst): inherit from std::unary_function + and make operator() const + (FindSnippet): inherit from unary_function, simplify slightly. + 2004-01-07 Lars Gullik Bjonnes * GraphicsTypes.C: include diff --git a/src/graphics/PreviewLoader.C b/src/graphics/PreviewLoader.C index 140537b60c..7e2b3ae3db 100644 --- a/src/graphics/PreviewLoader.C +++ b/src/graphics/PreviewLoader.C @@ -47,6 +47,8 @@ using std::fill; using std::find_if; using std::make_pair; +using boost::bind; + using std::ifstream; using std::list; using std::map; @@ -75,9 +77,10 @@ Converter const * setConverter(); void setAscentFractions(vector & ascent_fractions, string const & metrics_file); -struct FindFirst { +class FindFirst : public std::unary_function { +public: FindFirst(string const & comp) : comp_(comp) {} - bool operator()(StrPair const & sp) + bool operator()(StrPair const & sp) const { return sp.first == comp_; } @@ -343,19 +346,19 @@ PreviewLoader::Impl::preview(string const & latex_snippet) const namespace { -struct FindSnippet { +class FindSnippet : public std::unary_function { +public: FindSnippet(string const & s) : snippet_(s) {} - bool operator()(InProgressProcess const & process) + bool operator()(InProgressProcess const & process) const { BitmapFile const & snippets = process.second.snippets; - BitmapFile::const_iterator it = snippets.begin(); + BitmapFile::const_iterator beg = snippets.begin(); BitmapFile::const_iterator end = snippets.end(); - it = find_if(it, end, FindFirst(snippet_)); - return it != end; + return find_if(beg, end, FindFirst(snippet_)) != end; } private: - string const & snippet_; + string const snippet_; }; } // namespace anon @@ -491,8 +494,7 @@ void PreviewLoader::Impl::startLoading() // Initiate the conversion from LaTeX to bitmap images files. support::Forkedcall::SignalTypePtr convert_ptr(new support::Forkedcall::SignalType); - convert_ptr->connect( - boost::bind(&Impl::finishedGenerating, this, _1, _2)); + convert_ptr->connect(bind(&Impl::finishedGenerating, this, _1, _2)); support::Forkedcall call; int ret = call.startscript(command, convert_ptr); diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 81e20817ab..7007f10949 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -503,8 +503,7 @@ InsetTabular::priv_dispatch(LCursor & cur, FuncRequest const & cmd) } if (!tablemode) { - - int cell = cur.idx(); + int const cell = cur.idx(); lyxerr << "# InsetTabular::dispatch: A " << cur << endl; result = tabular.getCellInset(cell).dispatch(cur, cmd); diff --git a/src/lyxfind.C b/src/lyxfind.C index 528ca0b3cc..d292505e4a 100644 --- a/src/lyxfind.C +++ b/src/lyxfind.C @@ -210,7 +210,7 @@ bool findNextChange(BufferView * bv) namespace { -class MatchString +class MatchString : public std::binary_function { public: MatchString(string const & str, bool cs, bool mw) @@ -281,7 +281,7 @@ bool findBackwards(PosIterator & cur, PosIterator const & beg, bool findChange(PosIterator & cur, PosIterator const & end) { for (; cur != end; ++cur) { - if ((!cur.pit()->size() || !cur.at_end()) + if ((cur.pit()->empty() || !cur.at_end()) && cur.pit()->lookupChange(cur.pos()) != Change::UNCHANGED) return true; } diff --git a/src/lyxlex_pimpl.C b/src/lyxlex_pimpl.C index e1c061d1a7..ab910d97ba 100644 --- a/src/lyxlex_pimpl.C +++ b/src/lyxlex_pimpl.C @@ -35,10 +35,10 @@ using std::ios; using std::istream; using std::ostream; -// namespace { -struct compare_tags { +namespace { + +struct compare_tags : public std::binary_function { // used by lower_bound, sort and sorted - inline int operator()(keyword_item const & a, keyword_item const & b) const { // we use the ascii version, because in turkish, 'i' // is not the lowercase version of 'I', and thus @@ -46,7 +46,8 @@ struct compare_tags { return compare_ascii_no_case(a.tag, b.tag) < 0; } }; -// } // end of anon namespace + +} // end of anon namespace LyXLex::Pimpl::Pimpl(keyword_item * tab, int num) diff --git a/src/lyxtextclass.C b/src/lyxtextclass.C index 14e89546a8..34e70f2c70 100644 --- a/src/lyxtextclass.C +++ b/src/lyxtextclass.C @@ -36,30 +36,29 @@ using std::string; using std::ostream; -namespace { // anon +namespace { -struct compare_name { - - compare_name(string const & name) +class LayoutNamesEqual : public std::unary_function { +public: + LayoutNamesEqual(string const & name) : name_(name) {} - - bool operator()(boost::shared_ptr const & c) + bool operator()(LyXLayout_ptr const & c) const { return c->name() == name_; } - +private: string name_; - }; -} // anon +} // namespace anon LyXTextClass::LyXTextClass(string const & fn, string const & cln, string const & desc, bool texClassAvail ) : name_(fn), latexname_(cln), description_(desc), - floatlist_(new FloatList), ctrs_(new Counters), texClassAvail_(texClassAvail) + floatlist_(new FloatList), ctrs_(new Counters), + texClassAvail_(texClassAvail) { outputType_ = LATEX; columns_ = 1; @@ -551,7 +550,7 @@ void LyXTextClass::readCharStyle(LyXLex & lexrc, string const & name) LyXFont font(LyXFont::ALL_INHERIT); LyXFont labelfont(LyXFont::ALL_INHERIT); string preamble; - + bool getout = false; while (!getout && lexrc.isOK()) { int le = lexrc.lex(); @@ -790,7 +789,7 @@ bool LyXTextClass::hasLayout(string const & n) const string const name = (n.empty() ? defaultLayoutName() : n); return find_if(layoutlist_.begin(), layoutlist_.end(), - compare_name(name)) + LayoutNamesEqual(name)) != layoutlist_.end(); } @@ -803,7 +802,7 @@ LyXLayout_ptr const & LyXTextClass::operator[](string const & name) const LayoutList::const_iterator cit = find_if(layoutlist_.begin(), layoutlist_.end(), - compare_name(name)); + LayoutNamesEqual(name)); if (cit == layoutlist_.end()) { lyxerr << "We failed to find the layout '" << name @@ -829,7 +828,7 @@ bool LyXTextClass::delete_layout(string const & name) LayoutList::iterator it = remove_if(layoutlist_.begin(), layoutlist_.end(), - compare_name(name)); + LayoutNamesEqual(name)); LayoutList::iterator end = layoutlist_.end(); bool const ret = (it != end); diff --git a/src/lyxtextclass.h b/src/lyxtextclass.h index fd4eeb986a..5f9ccca690 100644 --- a/src/lyxtextclass.h +++ b/src/lyxtextclass.h @@ -227,7 +227,7 @@ private: LayoutList layoutlist_; /// CharStyles available to this layout mutable CharStyles charstylelist_; - + /// available types of float, eg. figure, algorithm. boost::shared_ptr floatlist_; diff --git a/src/lyxtextclasslist.C b/src/lyxtextclasslist.C index 98339a046a..d5c2a678b8 100644 --- a/src/lyxtextclasslist.C +++ b/src/lyxtextclasslist.C @@ -62,16 +62,19 @@ LyXTextClassList::operator[](textclass_type textclass) const // used when sorting the textclass list. -class less_textclass_avail_desc { -public: - int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) { +struct less_textclass_avail_desc + : public std::binary_function +{ + int operator()(LyXTextClass const & tc1, + LyXTextClass const & tc2) const + { // Ordering criteria: // 1. Availability of text class // 2. Description (lexicographic) return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) || - (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() && - tc1.description() < tc2.description()); + (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() && + tc1.description() < tc2.description()); } }; diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index 9c373ddaeb..99f3229378 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -128,8 +128,8 @@ string InsetFormulaMacro::prefix() const void InsetFormulaMacro::metrics(MetricsInfo & mi, Dimension & dim) const { MathNestInset::metrics(mi); - dim = cell(0).dim(); - dim += cell(1).dim(); + dim = cell(0).dim(); + dim += cell(1).dim(); dim.asc += 5; dim.des += 5; dim.wid += 10 + font_metrics::width(prefix(), mi.base.font); diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 10cd59951b..65a5075d87 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -38,7 +38,6 @@ using lyx::support::trim; using std::endl; using std::max; - using std::string; using std::ostream; using std::auto_ptr; diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 5f0eaee7d0..8e7e356f77 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,11 @@ +2004-01-31 Lars Gullik Bjonnes + + * lyxalgo.h (eliminate_duplicates): reimplement with sort and the + unique-erase idom. + + * lstrings.h (contains_functor): inherit from + std::binary_function, remove typedefs. + 2004-01-28 Lars Gullik Bjonnes * globbing.C: add using statement for std::distance, remove std:: diff --git a/src/support/forkedcontr.C b/src/support/forkedcontr.C index 99cc6c7429..3795ec1925 100644 --- a/src/support/forkedcontr.C +++ b/src/support/forkedcontr.C @@ -29,6 +29,8 @@ #include +using boost::bind; + using std::endl; using std::find_if; using std::string; @@ -55,7 +57,7 @@ ForkedcallsController::ForkedcallsController() timeout_ = new Timeout(100, Timeout::ONETIME); timeout_->timeout - .connect(boost::bind(&ForkedcallsController::timer, this)); + .connect(bind(&ForkedcallsController::timer, this)); } diff --git a/src/support/lstrings.C b/src/support/lstrings.C index 6ca5e68f65..337b128a2d 100644 --- a/src/support/lstrings.C +++ b/src/support/lstrings.C @@ -290,10 +290,10 @@ bool prefixIs(string const & a, string const & pre) if (prelen > alen || a.empty()) return false; else { -#if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD) - return ::strncmp(a.c_str(), pre.c_str(), prelen) == 0; -#else +#if defined(STD_STRING_IS_GOOD) return a.compare(0, prelen, pre) == 0; +#else + return ::strncmp(a.c_str(), pre.c_str(), prelen) == 0; #endif } } diff --git a/src/support/lstrings.h b/src/support/lstrings.h index f70d140b5a..7101f24a88 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -103,13 +103,12 @@ bool contains(std::string const & a, std::string const & b); bool contains(std::string const & a, char b); /// This should probably we rewritten to be more general. -class contains_functor { -public: - typedef std::string first_argument_type; - typedef std::string second_argument_type; - typedef bool result_type; - - bool operator()(std::string const & haystack, std::string const & needle) const { +struct contains_functor + : public std::binary_function +{ + bool operator()(std::string const & haystack, + std::string const & needle) const + { return contains(haystack, needle); } }; diff --git a/src/support/lyxalgo.h b/src/support/lyxalgo.h index 87848bb1a5..19ed2e857d 100644 --- a/src/support/lyxalgo.h +++ b/src/support/lyxalgo.h @@ -17,7 +17,6 @@ #include #include #include -#include namespace lyx { @@ -93,16 +92,10 @@ count (Iterator first, Iterator last, T const & value) template void eliminate_duplicates(C & c) { - C unique_c; - std::set s; - - for (typename C::iterator p = c.begin(); p != c.end(); ++p) { - if (s.find(*p) == s.end()) { - unique_c.push_back(*p); - s.insert(*p); - } - } - swap(c, unique_c); + // It is a requirement that the container is sorted for + // std::unique to work properly. + std::sort(c.begin(), c.end()); + c.erase(std::unique(c.begin(), c.end()), c.end()); } } // namespace lyx diff --git a/src/text.C b/src/text.C index db52a26cc5..82cd90bb99 100644 --- a/src/text.C +++ b/src/text.C @@ -1868,7 +1868,7 @@ int LyXText::cursorX(CursorSlice const & cur) const { ParagraphList::iterator pit = getPar(cur); if (pit->rows.empty()) - return xo_; + return xo_; Row const & row = *pit->getRow(cur.pos()); pos_type pos = cur.pos(); pos_type cursor_vpos = 0; @@ -1940,7 +1940,7 @@ int findText(LyXText const * text) CursorBase & cur = text->bv()->cursor().cursor_; //lyxerr << "findText: text: " << text << " cursor: " // << text->bv()->cursor() << endl; - for (int i = cur.size() - 1; i > 0; --i) + for (int i = cur.size() - 1; i > 0; --i) if (cur[i].text() == text) return i; if (text->bv()->text() == text) -- 2.39.5