]> git.lyx.org Git - lyx.git/blob - src/BranchList.C
changelogs
[lyx.git] / src / BranchList.C
1 /**
2  * \file BranchList.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Martin Vermeer
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "BranchList.h"
14
15 using std::string;
16
17
18 string const & Branch::getBranch() const
19 {
20         return branch_;
21 }
22
23
24 void Branch::setBranch(string const & s)
25 {
26         branch_ = s;
27 }
28
29
30 bool Branch::getSelected() const
31 {
32         return selected_;
33 }
34
35
36 bool Branch::setSelected(bool b)
37 {
38         if (b == selected_)
39                 return false;
40         selected_ = b;
41         return true;
42 }
43
44
45 string const & Branch::getColor() const
46 {
47         return color_;
48 }
49
50
51 void Branch::setColor(string const & c)
52 {
53         color_ = c;
54 }
55
56
57 Branch * BranchList::find(std::string const & name)
58 {
59         List::iterator it =
60                 std::find_if(list.begin(), list.end(), BranchNamesEqual(name));
61         return it == list.end() ? 0 : &*it;
62 }
63
64
65 Branch const * BranchList::find(std::string const & name) const
66 {
67         List::const_iterator it =
68                 std::find_if(list.begin(), list.end(), BranchNamesEqual(name));
69         return it == list.end() ? 0 : &*it;
70 }
71
72
73 bool BranchList::add(string const & s)
74 {
75         bool added = false;
76         string::size_type i = 0;
77         while (true) {
78                 string::size_type const j = s.find_first_of(separator_, i);
79                 string name;
80                 if (j == string::npos)
81                         name = s.substr(i);
82                 else
83                         name = s.substr(i, j - i);
84                 // Is this name already in the list?
85                 bool const already =
86                         std::find_if(list.begin(), list.end(),
87                                      BranchNamesEqual(name)) != list.end();
88                 if (!already) {
89                         added = true;
90                         Branch br;
91                         br.setBranch(name);
92                         br.setSelected(false);
93                         br.setColor("none");
94                         list.push_back(br);
95                 }
96                 if (j == string::npos)
97                         break;
98                 i = j + 1;
99         }
100         return added;
101 }
102
103
104 bool BranchList::remove(string const & s)
105 {
106         List::size_type const size = list.size();
107         list.remove_if(BranchNamesEqual(s));
108         return size != list.size();
109 }