From 36fda753fcf41dffb5da13428accd1760bd52a68 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Mon, 5 Jan 2004 15:49:40 +0000 Subject: [PATCH] Some functor work. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8298 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BranchList.C | 65 ++++++++++++++++-------------------------------- src/ChangeLog | 24 +++++++++++------- 2 files changed, 37 insertions(+), 52 deletions(-) diff --git a/src/BranchList.C b/src/BranchList.C index 93f117a20e..dc09595841 100644 --- a/src/BranchList.C +++ b/src/BranchList.C @@ -12,14 +12,23 @@ #include "BranchList.h" -#include +using std::string; -#include +namespace { +class BranchNamesEqual : public std::unary_function { +public: + BranchNamesEqual(string const & name) + : name_(name) {} + bool operator()(Branch const & branch) const + { + return branch.getBranch() == name_; + } +private: + string name_; +}; -using std::string; -using std::bind2nd; -using std::binary_function; +} // namespace anon string const & Branch::getBranch() const @@ -61,35 +70,22 @@ void Branch::setColor(string const & c) } -namespace { - -struct SameName { - SameName(string const & name) : name_(name) {} - bool operator()(Branch const & branch) const - { return branch.getBranch() == name_; } -private: - string name_; -}; - -}// namespace anon - - Branch * BranchList::find(std::string const & name) { List::iterator it = - std::find_if(list.begin(), list.end(), SameName(name)); + std::find_if(list.begin(), list.end(), BranchNamesEqual(name)); return it == list.end() ? 0 : &*it; } - + Branch const * BranchList::find(std::string const & name) const { List::const_iterator it = - std::find_if(list.begin(), list.end(), SameName(name)); + std::find_if(list.begin(), list.end(), BranchNamesEqual(name)); return it == list.end() ? 0 : &*it; } - + bool BranchList::add(string const & s) { bool added = false; @@ -102,15 +98,9 @@ bool BranchList::add(string const & s) else name = s.substr(i, j - i); // Is this name already in the list? - List::const_iterator it = list.begin(); - List::const_iterator end = list.end(); - bool already = false; - for (; it != end; ++it) { - if (it->getBranch() == name) { - already = true; - break; - } - } + bool const already = + std::find_if(list.begin(), list.end(), + BranchNamesEqual(name)) != list.end(); if (!already) { added = true; Branch br; @@ -127,20 +117,9 @@ bool BranchList::add(string const & s) } -namespace { - -struct match : public binary_function { - bool operator()(Branch const & br, string const & s) const { - return (br.getBranch() == s); - } -}; - -} // namespace anon. - - bool BranchList::remove(string const & s) { List::size_type const size = list.size(); - list.remove_if(bind2nd(match(), s)); + list.remove_if(BranchNamesEqual(s)); return size != list.size(); } diff --git a/src/ChangeLog b/src/ChangeLog index 635b2ee51e..adb10d34f5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,6 +1,12 @@ +2004-01-05 Lars Gullik Bjonnes + + * BranchList.C: new BranchListEqual fuctor, use it. Remove + SameName and match. + (add): replace a finding loop with std::find_if. + 2003-12-31 Martin Vermeer - * output_docbook.C: moving LatexParam functionality into + * output_docbook.C: moving LatexParam functionality into .layout files 2003-12-29 Jürgen Spitzmüller @@ -94,13 +100,13 @@ 2003-12-14 Jürgen Spitzmüller - * factory.C: + * factory.C: * lyxfunc.C: remove insetminipage. "minipage-insert" now produces a frameless minipage box inset. 2003-12-12 Alfredo Braunstein - * textcursor.[Ch] (selStart,selEnd): add new methods + * textcursor.[Ch] (selStart,selEnd): add new methods remove selection::start, end, use LyXCursor::operator< * lyxcursor.[Ch] (operator<): add * BufferView_pimpl.[Ch]: add new struct xsel_cache_ @@ -152,7 +158,7 @@ 2003-12-08 Alfredo Braunstein * lyxtext.h, text2.C (setLayout): don't use cursor to iterate, - when a pit is enough. Standarize a couple of loops. + when a pit is enough. Standarize a couple of loops. 2003-12-05 Angus Leeming @@ -176,7 +182,7 @@ * lyxtext.h: * paragraph_funcs.[Ch]: consolidate parts of Buffer::read() and InsetText::read() as LyXText::read() - + 2003-12-02 Angus Leeming * lyxlex.[Ch] (operator void const *): add the 'const' to the return @@ -217,7 +223,7 @@ * lyxfunc.C: move LFUN_INSET_TOGGLE handling to insets. - * undo.C: fix cursor positioning + * undo.C: fix cursor positioning 2003-12-01 John Levon @@ -276,7 +282,7 @@ 2003-11-27 Martin Vermeer - * buffer.C: + * buffer.C: * lyxtextclass.[Ch]: parametrize SGML document header 2003-11-27 Martin Vermeer @@ -288,7 +294,7 @@ 2003-11-27 Alfredo Braunstein * text2.C (setFont): rework using PosIterator (no more recursive) - (setCharFont): no more needed + (setCharFont): no more needed (setLayout): no more selection cursors fiddling (done by redoCursor) * text.C: cursorRight(bv)->cursorRight(true) (TODO: find and destroy remaining ones) @@ -342,7 +348,7 @@ * rowpainter.C: simplification - * text2.C (updateCounters): remove call to redoParagraph on + * text2.C (updateCounters): remove call to redoParagraph on changed labels as this is far too expensive. 2003-11-24 Alfredo Braunstein -- 2.39.2