2003-08-17 11:28:23 +00:00
|
|
|
/**
|
2003-09-09 17:25:35 +00:00
|
|
|
* \file BranchList.C
|
2003-08-17 11:28:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2003-08-23 00:17:00 +00:00
|
|
|
*
|
2003-08-17 11:28:23 +00:00
|
|
|
* \author Martin Vermeer
|
2003-09-09 17:25:35 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-08-17 11:28:23 +00:00
|
|
|
*/
|
|
|
|
|
2003-08-23 00:17:00 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
#include "BranchList.h"
|
2003-09-09 17:25:35 +00:00
|
|
|
|
|
|
|
#include <boost/assert.hpp>
|
2003-08-17 11:28:23 +00:00
|
|
|
|
2003-09-05 22:17:02 +00:00
|
|
|
#include <functional>
|
2003-08-17 11:28:23 +00:00
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
|
|
using std::string;
|
2003-08-17 11:28:23 +00:00
|
|
|
using std::bind2nd;
|
|
|
|
using std::binary_function;
|
|
|
|
|
|
|
|
|
2003-12-14 16:33:56 +00:00
|
|
|
string const & Branch::getBranch() const
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
|
|
|
return branch_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Branch::setBranch(string const & s)
|
|
|
|
{
|
|
|
|
branch_ = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Branch::getSelected() const
|
|
|
|
{
|
|
|
|
return selected_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-14 16:33:56 +00:00
|
|
|
bool Branch::setSelected(bool b)
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2003-12-14 16:33:56 +00:00
|
|
|
if (b == selected_)
|
|
|
|
return false;
|
2003-08-17 11:28:23 +00:00
|
|
|
selected_ = b;
|
2003-12-14 16:33:56 +00:00
|
|
|
return true;
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-14 16:33:56 +00:00
|
|
|
string const & Branch::getColor() const
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
|
|
|
return color_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Branch::setColor(string const & c)
|
|
|
|
{
|
|
|
|
color_ = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-14 16:33:56 +00:00
|
|
|
namespace {
|
2003-08-17 11:28:23 +00:00
|
|
|
|
2003-12-14 16:33:56 +00:00
|
|
|
struct SameName {
|
|
|
|
SameName(string const & name) : name_(name) {}
|
|
|
|
bool operator()(Branch const & branch) const
|
|
|
|
{ return branch.getBranch() == name_; }
|
|
|
|
private:
|
|
|
|
string name_;
|
|
|
|
};
|
2003-08-17 11:28:23 +00:00
|
|
|
|
2003-12-14 16:33:56 +00:00
|
|
|
}// namespace anon
|
2003-08-17 11:28:23 +00:00
|
|
|
|
|
|
|
|
2003-12-14 16:33:56 +00:00
|
|
|
Branch * BranchList::find(std::string const & name)
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2003-12-14 16:33:56 +00:00
|
|
|
List::iterator it =
|
|
|
|
std::find_if(list.begin(), list.end(), SameName(name));
|
|
|
|
return it == list.end() ? 0 : &*it;
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
2003-12-14 16:33:56 +00:00
|
|
|
|
|
|
|
Branch const * BranchList::find(std::string const & name) const
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2003-12-14 16:33:56 +00:00
|
|
|
List::const_iterator it =
|
|
|
|
std::find_if(list.begin(), list.end(), SameName(name));
|
|
|
|
return it == list.end() ? 0 : &*it;
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
2003-12-14 16:33:56 +00:00
|
|
|
|
|
|
|
bool BranchList::add(string const & s)
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2003-12-14 16:33:56 +00:00
|
|
|
bool added = false;
|
2003-08-17 11:28:23 +00:00
|
|
|
string::size_type i = 0;
|
|
|
|
while (true) {
|
2003-12-14 16:33:56 +00:00
|
|
|
string::size_type const j = s.find_first_of(separator_, i);
|
2003-08-17 11:28:23 +00:00
|
|
|
string name;
|
|
|
|
if (j == string::npos)
|
|
|
|
name = s.substr(i);
|
|
|
|
else
|
|
|
|
name = s.substr(i, j - i);
|
|
|
|
// Is this name already in the list?
|
|
|
|
List::const_iterator it = list.begin();
|
|
|
|
List::const_iterator end = list.end();
|
|
|
|
bool already = false;
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
if (it->getBranch() == name) {
|
|
|
|
already = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!already) {
|
2003-12-14 16:33:56 +00:00
|
|
|
added = true;
|
2003-08-17 11:28:23 +00:00
|
|
|
Branch br;
|
|
|
|
br.setBranch(name);
|
|
|
|
br.setSelected(false);
|
|
|
|
br.setColor("none");
|
|
|
|
list.push_back(br);
|
|
|
|
}
|
|
|
|
if (j == string::npos)
|
|
|
|
break;
|
2003-09-09 17:25:35 +00:00
|
|
|
i = j + 1;
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
2003-12-14 16:33:56 +00:00
|
|
|
return added;
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct match : public binary_function<Branch, string, bool> {
|
|
|
|
bool operator()(Branch const & br, string const & s) const {
|
|
|
|
return (br.getBranch() == s);
|
2003-09-09 17:25:35 +00:00
|
|
|
}
|
2003-08-17 11:28:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace anon.
|
|
|
|
|
|
|
|
|
2003-12-14 16:33:56 +00:00
|
|
|
bool BranchList::remove(string const & s)
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2003-12-14 16:33:56 +00:00
|
|
|
List::size_type const size = list.size();
|
2003-08-17 11:28:23 +00:00
|
|
|
list.remove_if(bind2nd(match(), s));
|
2003-12-14 16:33:56 +00:00
|
|
|
return size != list.size();
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|