X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FBranchList.C;h=6d89551b74c9c8235155327d46d387c744d63bac;hb=37d42d45f3f4a5d3e916a080af50b37ae4a9d118;hp=2198a7cc70ab6347c177f2a0f4a97c34516e12cb;hpb=cba1fa5848f23cdddfe5f7b1d98f00a0039b2170;p=lyx.git diff --git a/src/BranchList.C b/src/BranchList.C index 2198a7cc70..6d89551b74 100644 --- a/src/BranchList.C +++ b/src/BranchList.C @@ -1,27 +1,22 @@ /** - * \file BranchList.C + * \file BranchList.C * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * * \author Martin Vermeer - * + * * Full author contact details are available in file CREDITS. */ #include #include "BranchList.h" -#include "support/LAssert.h" - -#include +#include -using std::bind2nd; -using std::remove_if; -using std::binary_function; -using namespace lyx::support; +using std::string; -string const Branch::getBranch() const +string const & Branch::getBranch() const { return branch_; } @@ -39,13 +34,16 @@ bool Branch::getSelected() const } -void Branch::setSelected(bool b) +bool Branch::setSelected(bool b) { + if (b == selected_) + return false; selected_ = b; + return true; } -string const Branch::getColor() const +string const & Branch::getColor() const { return color_; } @@ -57,73 +55,39 @@ void Branch::setColor(string const & c) } -void BranchList::clear() -{ - list.clear(); -} - - -string BranchList::getColor(string const & s) const -{ - List::const_iterator it = list.begin(); - List::const_iterator end = list.end(); - for (; it != end; ++it) { - if (s == it->getBranch()) { - return it->getColor(); - } - } - Assert(false); // Always - return string(); // never gets here -} - - - -void BranchList::setColor(string const & s, string const & val) +Branch * BranchList::find(std::string const & name) { - List::iterator it = list.begin(); - List::iterator end = list.end(); - for (; it != end; ++it) { - if (s == it->getBranch()) { - it->setColor(val); - return; - } - } - Assert(false); + List::iterator it = + std::find_if(list.begin(), list.end(), BranchNamesEqual(name)); + return it == list.end() ? 0 : &*it; } -void BranchList::setSelected(string const & s, bool val) +Branch const * BranchList::find(std::string const & name) const { - List::iterator it = list.begin(); - List::iterator end = list.end(); - for (; it != end; ++it) { - if (s.find(it->getBranch(), 0) != string::npos) - it->setSelected(val); - } + List::const_iterator it = + std::find_if(list.begin(), list.end(), BranchNamesEqual(name)); + return it == list.end() ? 0 : &*it; } -void BranchList::add(string const & s) +bool BranchList::add(string const & s) { + bool added = false; string::size_type i = 0; while (true) { - string::size_type const j = s.find_first_of(separator(), i); + string::size_type const j = s.find_first_of(separator_, i); string name; if (j == string::npos) name = s.substr(i); 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; br.setBranch(name); br.setSelected(false); @@ -132,74 +96,15 @@ void BranchList::add(string const & s) } if (j == string::npos) break; - i = j + 1; - } -} - - -namespace { - -struct match : public binary_function { - bool operator()(Branch const & br, string const & s) const { - return (br.getBranch() == s); - } -}; - -} // namespace anon. - - -void BranchList::remove(string const & s) -{ - list.remove_if(bind2nd(match(), s)); -} - - -bool BranchList::selected(string const & s) const -{ - List::const_iterator it = list.begin(); - List::const_iterator end = list.end(); - for (; it != end; ++it) { - if (s == it->getBranch()) - return it->getSelected(); - } - return false; -} - - -string BranchList::allBranches() const -{ - List::const_iterator it = list.begin(); - List::const_iterator end = list.end(); - string ret; - for (; it != end; ++it) { - ret += it->getBranch() + separator(); - } - // remove final '|': - string::size_type i = ret.find_last_of(separator()); - if (i != string::npos) - ret.erase(i); - return ret; -} - - -string BranchList::allSelected() const -{ - List::const_iterator it = list.begin(); - List::const_iterator end = list.end(); - string ret; - for (; it != end; ++it) { - if (it->getSelected()) - ret += it->getBranch() + separator(); + i = j + 1; } - // remove final '|': - string::size_type i = ret.find_last_of(separator()); - if (i != string::npos) - ret.erase(i); - return ret; + return added; } -string const BranchList::separator() const +bool BranchList::remove(string const & s) { - return separator_; + List::size_type const size = list.size(); + list.remove_if(BranchNamesEqual(s)); + return size != list.size(); }