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"
15 #include <boost/assert.hpp>
22 using std::binary_function;
25 string const & Branch::getBranch() const
31 void Branch::setBranch(string const & s)
37 bool Branch::getSelected() const
43 bool Branch::setSelected(bool b)
52 string const & Branch::getColor() const
58 void Branch::setColor(string const & c)
67 SameName(string const & name) : name_(name) {}
68 bool operator()(Branch const & branch) const
69 { return branch.getBranch() == name_; }
77 Branch * BranchList::find(std::string const & name)
80 std::find_if(list.begin(), list.end(), SameName(name));
81 return it == list.end() ? 0 : &*it;
85 Branch const * BranchList::find(std::string const & name) const
87 List::const_iterator it =
88 std::find_if(list.begin(), list.end(), SameName(name));
89 return it == list.end() ? 0 : &*it;
93 bool BranchList::add(string const & s)
96 string::size_type i = 0;
98 string::size_type const j = s.find_first_of(separator_, i);
100 if (j == string::npos)
103 name = s.substr(i, j - i);
104 // Is this name already in the list?
105 List::const_iterator it = list.begin();
106 List::const_iterator end = list.end();
107 bool already = false;
108 for (; it != end; ++it) {
109 if (it->getBranch() == name) {
118 br.setSelected(false);
122 if (j == string::npos)
132 struct match : public binary_function<Branch, string, bool> {
133 bool operator()(Branch const & br, string const & s) const {
134 return (br.getBranch() == s);
141 bool BranchList::remove(string const & s)
143 List::size_type const size = list.size();
144 list.remove_if(bind2nd(match(), s));
145 return size != list.size();