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 == it->getBranch()) {
102 it->setSelected(val);
110 void BranchList::add(string const & s)
112 string::size_type i = 0;
114 string::size_type const j = s.find_first_of(separator(), i);
116 if (j == string::npos)
119 name = s.substr(i, j - i);
120 // Is this name already in the list?
121 List::const_iterator it = list.begin();
122 List::const_iterator end = list.end();
123 bool already = false;
124 for (; it != end; ++it) {
125 if (it->getBranch() == name) {
133 br.setSelected(false);
137 if (j == string::npos)
146 struct match : public binary_function<Branch, string, bool> {
147 bool operator()(Branch const & br, string const & s) const {
148 return (br.getBranch() == s);
155 void BranchList::remove(string const & s)
157 list.remove_if(bind2nd(match(), s));
161 bool BranchList::selected(string const & s) const
163 List::const_iterator it = list.begin();
164 List::const_iterator end = list.end();
165 for (; it != end; ++it) {
166 if (s == it->getBranch())
167 return it->getSelected();
173 string BranchList::allBranches() const
175 List::const_iterator it = list.begin();
176 List::const_iterator end = list.end();
178 for (; it != end; ++it) {
179 ret += it->getBranch() + separator();
182 string::size_type i = ret.find_last_of(separator());
183 if (i != string::npos)
189 string BranchList::allSelected() const
191 List::const_iterator it = list.begin();
192 List::const_iterator end = list.end();
194 for (; it != end; ++it) {
195 if (it->getSelected())
196 ret += it->getBranch() + separator();
199 string::size_type i = ret.find_last_of(separator());
200 if (i != string::npos)
206 string const BranchList::separator() const