mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 19:25:39 +00:00
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:
parent
d98ffe9eb4
commit
36fda753fc
@ -12,14 +12,23 @@
|
|||||||
|
|
||||||
#include "BranchList.h"
|
#include "BranchList.h"
|
||||||
|
|
||||||
#include <boost/assert.hpp>
|
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
|
|
||||||
using std::string;
|
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
|
string const & Branch::getBranch() const
|
||||||
@ -61,23 +70,10 @@ 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)
|
Branch * BranchList::find(std::string const & name)
|
||||||
{
|
{
|
||||||
List::iterator it =
|
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;
|
return it == list.end() ? 0 : &*it;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +81,7 @@ Branch * BranchList::find(std::string const & name)
|
|||||||
Branch const * BranchList::find(std::string const & name) const
|
Branch const * BranchList::find(std::string const & name) const
|
||||||
{
|
{
|
||||||
List::const_iterator it =
|
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;
|
return it == list.end() ? 0 : &*it;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,15 +98,9 @@ bool BranchList::add(string const & s)
|
|||||||
else
|
else
|
||||||
name = s.substr(i, j - i);
|
name = s.substr(i, j - i);
|
||||||
// Is this name already in the list?
|
// Is this name already in the list?
|
||||||
List::const_iterator it = list.begin();
|
bool const already =
|
||||||
List::const_iterator end = list.end();
|
std::find_if(list.begin(), list.end(),
|
||||||
bool already = false;
|
BranchNamesEqual(name)) != list.end();
|
||||||
for (; it != end; ++it) {
|
|
||||||
if (it->getBranch() == name) {
|
|
||||||
already = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!already) {
|
if (!already) {
|
||||||
added = true;
|
added = true;
|
||||||
Branch br;
|
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)
|
bool BranchList::remove(string const & s)
|
||||||
{
|
{
|
||||||
List::size_type const size = list.size();
|
List::size_type const size = list.size();
|
||||||
list.remove_if(bind2nd(match(), s));
|
list.remove_if(BranchNamesEqual(s));
|
||||||
return size != list.size();
|
return size != list.size();
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
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>
|
2003-12-31 Martin Vermeer <martin.vermeer@hut.fi>
|
||||||
|
|
||||||
* output_docbook.C: moving LatexParam functionality into
|
* output_docbook.C: moving LatexParam functionality into
|
||||||
|
Loading…
Reference in New Issue
Block a user