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"
19 using std::binary_function;
20 using namespace lyx::support;
23 string const Branch::getBranch() const
29 void Branch::setBranch(string const & s)
35 bool Branch::getSelected() const
41 void Branch::setSelected(bool b)
47 string const Branch::getColor() const
53 void Branch::setColor(string const & c)
59 void BranchList::clear()
65 string BranchList::getColor(string const & s) const
67 List::const_iterator it = list.begin();
68 List::const_iterator end = list.end();
69 for (; it != end; ++it) {
70 if (s == it->getBranch()) {
71 return it->getColor();
74 Assert(false); // Always
75 return string(); // never gets here
80 void BranchList::setColor(string const & s, string const & val)
82 List::iterator it = list.begin();
83 List::iterator end = list.end();
84 for (; it != end; ++it) {
85 if (s == it->getBranch()) {
94 void BranchList::setSelected(string const & s, bool val)
96 List::iterator it = list.begin();
97 List::iterator end = list.end();
98 for (; it != end; ++it) {
99 if (s.find(it->getBranch(), 0) != string::npos)
100 it->setSelected(val);
105 void BranchList::add(string const & s)
107 string::size_type i = 0;
109 string::size_type const j = s.find_first_of(separator(), i);
111 if (j == string::npos)
114 name = s.substr(i, j - i);
115 // Is this name already in the list?
116 List::const_iterator it = list.begin();
117 List::const_iterator end = list.end();
118 bool already = false;
119 for (; it != end; ++it) {
120 if (it->getBranch() == name) {
128 br.setSelected(false);
132 if (j == string::npos)
141 struct match : public binary_function<Branch, string, bool> {
142 bool operator()(Branch const & br, string const & s) const {
143 return (br.getBranch() == s);
150 void BranchList::remove(string const & s)
152 list.remove_if(bind2nd(match(), s));
156 bool BranchList::selected(string const & s) const
158 List::const_iterator it = list.begin();
159 List::const_iterator end = list.end();
160 for (; it != end; ++it) {
161 if (s == it->getBranch())
162 return it->getSelected();
168 string BranchList::allBranches() const
170 List::const_iterator it = list.begin();
171 List::const_iterator end = list.end();
173 for (; it != end; ++it) {
174 ret += it->getBranch() + separator();
177 string::size_type i = ret.find_last_of(separator());
178 if (i != string::npos)
184 string BranchList::allSelected() const
186 List::const_iterator it = list.begin();
187 List::const_iterator end = list.end();
189 for (; it != end; ++it) {
190 if (it->getSelected())
191 ret += it->getBranch() + separator();
194 string::size_type i = ret.find_last_of(separator());
195 if (i != string::npos)
201 string const BranchList::separator() const