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"
14 #include "support/LAssert.h"
20 using std::binary_function;
21 using namespace lyx::support;
24 string const Branch::getBranch() const
30 void Branch::setBranch(string const & s)
36 bool Branch::getSelected() const
42 void Branch::setSelected(bool b)
48 string const Branch::getColor() const
54 void Branch::setColor(string const & c)
60 void BranchList::clear()
66 string BranchList::getColor(string const & s) const
68 List::const_iterator it = list.begin();
69 List::const_iterator end = list.end();
70 for (; it != end; ++it) {
71 if (s == it->getBranch()) {
72 return it->getColor();
75 Assert(false); // Always
76 return string(); // never gets here
81 void BranchList::setColor(string const & s, string const & val)
83 List::iterator it = list.begin();
84 List::iterator end = list.end();
85 for (; it != end; ++it) {
86 if (s == it->getBranch()) {
95 void BranchList::setSelected(string const & s, bool val)
97 List::iterator it = list.begin();
98 List::iterator end = list.end();
99 for (; it != end; ++it) {
100 if (s.find(it->getBranch(), 0) != string::npos)
101 it->setSelected(val);
106 void BranchList::add(string const & s)
108 string::size_type i = 0;
110 string::size_type const j = s.find_first_of(separator(), i);
112 if (j == string::npos)
115 name = s.substr(i, j - i);
116 // Is this name already in the list?
117 List::const_iterator it = list.begin();
118 List::const_iterator end = list.end();
119 bool already = false;
120 for (; it != end; ++it) {
121 if (it->getBranch() == name) {
129 br.setSelected(false);
133 if (j == string::npos)
142 struct match : public binary_function<Branch, string, bool> {
143 bool operator()(Branch const & br, string const & s) const {
144 return (br.getBranch() == s);
151 void BranchList::remove(string const & s)
153 list.remove_if(bind2nd(match(), s));
157 bool BranchList::selected(string const & s) const
159 List::const_iterator it = list.begin();
160 List::const_iterator end = list.end();
161 for (; it != end; ++it) {
162 if (s == it->getBranch())
163 return it->getSelected();
169 string BranchList::allBranches() const
171 List::const_iterator it = list.begin();
172 List::const_iterator end = list.end();
174 for (; it != end; ++it) {
175 ret += it->getBranch() + separator();
178 string::size_type i = ret.find_last_of(separator());
179 if (i != string::npos)
185 string BranchList::allSelected() const
187 List::const_iterator it = list.begin();
188 List::const_iterator end = list.end();
190 for (; it != end; ++it) {
191 if (it->getSelected())
192 ret += it->getBranch() + separator();
195 string::size_type i = ret.find_last_of(separator());
196 if (i != string::npos)
202 string const BranchList::separator() const