]> git.lyx.org Git - features.git/commitdiff
Some functor work.
authorLars Gullik Bjønnes <larsbj@gullik.org>
Mon, 5 Jan 2004 15:49:40 +0000 (15:49 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Mon, 5 Jan 2004 15:49:40 +0000 (15:49 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8298 a592a061-630c-0410-9148-cb99ea01b6c8

src/BranchList.C
src/ChangeLog

index 93f117a20ece33a206aeee25338ea89abfd8ca1c..dc09595841052b5a563f02b0df1b9842747e960b 100644 (file)
 
 #include "BranchList.h"
 
-#include <boost/assert.hpp>
+using std::string;
 
-#include <functional>
+namespace {
 
+class BranchNamesEqual : public std::unary_function<Branch, bool> {
+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<Branch, string, bool> {
-       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();
 }
index 635b2ee51e820e123d65ca66f6d8d8e7323f6eba..adb10d34f57b7e154e1b9391b6c381a68fb22e0a 100644 (file)
@@ -1,6 +1,12 @@
+2004-01-05  Lars Gullik Bjonnes  <larsbj@gullik.net>
+
+       * 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  <martin.vermeer@hut.fi>
 
-       * output_docbook.C: moving LatexParam functionality into 
+       * output_docbook.C: moving LatexParam functionality into
        .layout files
 
 2003-12-29  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
 2003-12-14  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
-       * factory.C: 
+       * factory.C:
        * lyxfunc.C: remove insetminipage. "minipage-insert"
        now produces a frameless minipage box inset.
 
 2003-12-12  Alfredo Braunstein  <abraunst@lyx.org>
 
-       * 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_
 2003-12-08  Alfredo Braunstein  <abraunst@libero.it>
 
        * 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  <leeming@lyx.org>
 
        * lyxtext.h:
        * paragraph_funcs.[Ch]: consolidate parts of Buffer::read() and
        InsetText::read() as LyXText::read()
-       
+
 2003-12-02  Angus Leeming  <leeming@lyx.org>
 
        * lyxlex.[Ch] (operator void const *): add the 'const' to the return
 
        * lyxfunc.C: move LFUN_INSET_TOGGLE handling to insets.
 
-       * undo.C: fix cursor positioning 
+       * undo.C: fix cursor positioning
 
 2003-12-01  John Levon  <levon@movementarian.org>
 
 
 2003-11-27  Martin Vermeer  <martin.vermeer@hut.fi>
 
-       * buffer.C: 
+       * buffer.C:
        * lyxtextclass.[Ch]: parametrize SGML document header
 
 2003-11-27  Martin Vermeer  <martin.vermeer@hut.fi>
 2003-11-27  Alfredo Braunstein  <abraunst@lyx.org>
 
        * 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)
 
        * 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  <abraunst@lyx.org>