3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Martin Vermeer
8 * Full author contact details are available in file CREDITS.
13 #include "BranchList.h"
19 class BranchNamesEqual : public std::unary_function<Branch, bool> {
21 BranchNamesEqual(string const & name)
23 bool operator()(Branch const & branch) const
25 return branch.getBranch() == name_;
34 string const & Branch::getBranch() const
40 void Branch::setBranch(string const & s)
46 bool Branch::getSelected() const
52 bool Branch::setSelected(bool b)
61 string const & Branch::getColor() const
67 void Branch::setColor(string const & c)
73 Branch * BranchList::find(std::string const & name)
76 std::find_if(list.begin(), list.end(), BranchNamesEqual(name));
77 return it == list.end() ? 0 : &*it;
81 Branch const * BranchList::find(std::string const & name) const
83 List::const_iterator it =
84 std::find_if(list.begin(), list.end(), BranchNamesEqual(name));
85 return it == list.end() ? 0 : &*it;
89 bool BranchList::add(string const & s)
92 string::size_type i = 0;
94 string::size_type const j = s.find_first_of(separator_, i);
96 if (j == string::npos)
99 name = s.substr(i, j - i);
100 // Is this name already in the list?
102 std::find_if(list.begin(), list.end(),
103 BranchNamesEqual(name)) != list.end();
108 br.setSelected(false);
112 if (j == string::npos)
120 bool BranchList::remove(string const & s)
122 List::size_type const size = list.size();
123 list.remove_if(BranchNamesEqual(s));
124 return size != list.size();