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 void Branch::setSelected(bool b)
49 string const Branch::getColor() const
55 void Branch::setColor(string const & c)
61 void BranchList::clear()
67 string BranchList::getColor(string const & s) const
69 List::const_iterator it = list.begin();
70 List::const_iterator end = list.end();
71 for (; it != end; ++it) {
72 if (s == it->getBranch()) {
73 return it->getColor();
76 BOOST_ASSERT(false); // Always
77 return string(); // never gets here
82 void BranchList::setColor(string const & s, string const & val)
84 List::iterator it = list.begin();
85 List::iterator end = list.end();
86 for (; it != end; ++it) {
87 if (s == it->getBranch()) {
96 void BranchList::setSelected(string const & s, bool val)
98 List::iterator it = list.begin();
99 List::iterator end = list.end();
100 for (; it != end; ++it) {
101 if (s.find(it->getBranch(), 0) != string::npos)
102 it->setSelected(val);
107 void BranchList::add(string const & s)
109 string::size_type i = 0;
111 string::size_type const j = s.find_first_of(separator(), i);
113 if (j == string::npos)
116 name = s.substr(i, j - i);
117 // Is this name already in the list?
118 List::const_iterator it = list.begin();
119 List::const_iterator end = list.end();
120 bool already = false;
121 for (; it != end; ++it) {
122 if (it->getBranch() == name) {
130 br.setSelected(false);
134 if (j == string::npos)
143 struct match : public binary_function<Branch, string, bool> {
144 bool operator()(Branch const & br, string const & s) const {
145 return (br.getBranch() == s);
152 void BranchList::remove(string const & s)
154 list.remove_if(bind2nd(match(), s));
158 bool BranchList::selected(string const & s) const
160 List::const_iterator it = list.begin();
161 List::const_iterator end = list.end();
162 for (; it != end; ++it) {
163 if (s == it->getBranch())
164 return it->getSelected();
170 string BranchList::allBranches() const
172 List::const_iterator it = list.begin();
173 List::const_iterator end = list.end();
175 for (; it != end; ++it) {
176 ret += it->getBranch() + separator();
179 string::size_type i = ret.find_last_of(separator());
180 if (i != string::npos)
186 string BranchList::allSelected() const
188 List::const_iterator it = list.begin();
189 List::const_iterator end = list.end();
191 for (; it != end; ++it) {
192 if (it->getSelected())
193 ret += it->getBranch() + separator();
196 string::size_type i = ret.find_last_of(separator());
197 if (i != string::npos)
203 string const BranchList::separator() const