]> git.lyx.org Git - lyx.git/blob - src/BranchList.C
- Add missing STL includes for correctness - gcc is too forgiving
[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 #include <algorithm>
15
16 using std::string;
17
18
19 string const & Branch::getBranch() const
20 {
21         return branch_;
22 }
23
24
25 void Branch::setBranch(string const & s)
26 {
27         branch_ = s;
28 }
29
30
31 bool Branch::getSelected() const
32 {
33         return selected_;
34 }
35
36
37 bool Branch::setSelected(bool b)
38 {
39         if (b == selected_)
40                 return false;
41         selected_ = b;
42         return true;
43 }
44
45
46 string const & Branch::getColor() const
47 {
48         return color_;
49 }
50
51
52 void Branch::setColor(string const & c)
53 {
54         color_ = c;
55 }
56
57
58 Branch * BranchList::find(std::string const & name)
59 {
60         List::iterator it =
61                 std::find_if(list.begin(), list.end(), BranchNamesEqual(name));
62         return it == list.end() ? 0 : &*it;
63 }
64
65
66 Branch const * BranchList::find(std::string const & name) const
67 {
68         List::const_iterator it =
69                 std::find_if(list.begin(), list.end(), BranchNamesEqual(name));
70         return it == list.end() ? 0 : &*it;
71 }
72
73
74 bool BranchList::add(string const & s)
75 {
76         bool added = false;
77         string::size_type i = 0;
78         while (true) {
79                 string::size_type const j = s.find_first_of(separator_, i);
80                 string name;
81                 if (j == string::npos)
82                         name = s.substr(i);
83                 else
84                         name = s.substr(i, j - i);
85                 // Is this name already in the list?
86                 bool const already =
87                         std::find_if(list.begin(), list.end(),
88                                      BranchNamesEqual(name)) != list.end();
89                 if (!already) {
90                         added = true;
91                         Branch br;
92                         br.setBranch(name);
93                         br.setSelected(false);
94                         br.setColor("none");
95                         list.push_back(br);
96                 }
97                 if (j == string::npos)
98                         break;
99                 i = j + 1;
100         }
101         return added;
102 }
103
104
105 bool BranchList::remove(string const & s)
106 {
107         List::size_type const size = list.size();
108         list.remove_if(BranchNamesEqual(s));
109         return size != list.size();
110 }