Some functor work.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8298 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2004-01-05 15:49:40 +00:00
parent d98ffe9eb4
commit 36fda753fc
2 changed files with 39 additions and 54 deletions

View File

@ -12,14 +12,23 @@
#include "BranchList.h"
#include <boost/assert.hpp>
#include <functional>
using std::string;
using std::bind2nd;
using std::binary_function;
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_;
};
} // 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();
}

View 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>
@ -94,13 +100,13 @@
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_
@ -152,7 +158,7 @@
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>
@ -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 <leeming@lyx.org>
* 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 <levon@movementarian.org>
@ -276,7 +282,7 @@
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>
@ -288,7 +294,7 @@
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)
@ -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 <abraunst@lyx.org>