3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
5 * \author Martin Vermeer
7 * Full author contact details are available in file CREDITS
10 #include "BranchList.h"
11 #include "support/LAssert.h"
17 using std::binary_function;
18 using namespace lyx::support;
21 string const Branch::getBranch() const
27 void Branch::setBranch(string const & s)
33 bool Branch::getSelected() const
39 void Branch::setSelected(bool b)
45 string const Branch::getColor() const
51 void Branch::setColor(string const & c)
57 void BranchList::clear()
63 string BranchList::getColor(string const & s) const
65 List::const_iterator it = list.begin();
66 List::const_iterator end = list.end();
67 for (; it != end; ++it) {
68 if (s == it->getBranch()) {
69 return it->getColor();
72 Assert(false); // Always
73 return string(); // never gets here
78 void BranchList::setColor(string const & s, string const & val)
80 List::iterator it = list.begin();
81 List::iterator end = list.end();
82 for (; it != end; ++it) {
83 if (s.find(it->getBranch(), 0) != string::npos) {
92 void BranchList::setSelected(string const & s, bool val)
94 List::iterator it = list.begin();
95 List::iterator end = list.end();
96 for (; it != end; ++it) {
97 if (s.find(it->getBranch(), 0) != string::npos)
103 void BranchList::add(string const & s)
105 string::size_type i = 0;
107 string::size_type const j = s.find_first_of(separator(), i);
109 if (j == string::npos)
112 name = s.substr(i, j - i);
113 // Is this name already in the list?
114 List::const_iterator it = list.begin();
115 List::const_iterator end = list.end();
116 bool already = false;
117 for (; it != end; ++it) {
118 if (it->getBranch() == name) {
126 br.setSelected(false);
130 if (j == string::npos)
139 struct match : public binary_function<Branch, string, bool> {
140 bool operator()(Branch const & br, string const & s) const {
141 return (br.getBranch() == s);
148 void BranchList::remove(string const & s)
150 list.remove_if(bind2nd(match(), s));
154 bool BranchList::selected(string const & s) const
156 List::const_iterator it = list.begin();
157 List::const_iterator end = list.end();
158 for (; it != end; ++it) {
159 if (s == it->getBranch())
160 return it->getSelected();
166 string BranchList::allBranches() const
168 List::const_iterator it = list.begin();
169 List::const_iterator end = list.end();
171 for (; it != end; ++it) {
172 ret += it->getBranch() + separator();
175 string::size_type i = ret.find_last_of(separator());
176 if (i != string::npos)
182 string BranchList::allSelected() const
184 List::const_iterator it = list.begin();
185 List::const_iterator end = list.end();
187 for (; it != end; ++it) {
188 if (it->getSelected())
189 ret += it->getBranch() + separator();
192 string::size_type i = ret.find_last_of(separator());
193 if (i != string::npos)
199 string const BranchList::separator() const