]> git.lyx.org Git - lyx.git/blob - src/BranchList.C
remove Inset::getParagraphs()
[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 #include <boost/assert.hpp>
16
17 #include <functional>
18
19
20 using std::string;
21 using std::bind2nd;
22 using std::binary_function;
23
24
25 string const Branch::getBranch() const
26 {
27         return branch_;
28 }
29
30
31 void Branch::setBranch(string const & s)
32 {
33         branch_ = s;
34 }
35
36
37 bool Branch::getSelected() const
38 {
39         return selected_;
40 }
41
42
43 void Branch::setSelected(bool b)
44 {
45         selected_ = b;
46 }
47
48
49 string const Branch::getColor() const
50 {
51         return color_;
52 }
53
54
55 void Branch::setColor(string const & c)
56 {
57         color_ = c;
58 }
59
60
61 void BranchList::clear()
62 {
63         list.clear();
64 }
65
66
67 string BranchList::getColor(string const & s) const
68 {
69         List::const_iterator it = list.begin();
70         List::const_iterator end = list.end();
71         for (; it != end; ++it) {
72                 if (s == it->getBranch()) {
73                         return it->getColor();
74                 }
75         }
76         BOOST_ASSERT(false); // Always
77         return string(); // never gets here
78 }
79
80
81
82 void BranchList::setColor(string const & s, string const & val)
83 {
84         List::iterator it = list.begin();
85         List::iterator end = list.end();
86         for (; it != end; ++it) {
87                 if (s == it->getBranch()) {
88                         it->setColor(val);
89                         return;
90                 }
91         }
92         BOOST_ASSERT(false);
93 }
94
95
96 void BranchList::setSelected(string const & s, bool val)
97 {
98         List::iterator it = list.begin();
99         List::iterator end = list.end();
100         for (; it != end; ++it) {
101                 if (s == it->getBranch()) {
102                         it->setSelected(val);
103                         return;
104                 }
105         }
106         BOOST_ASSERT(false);
107 }
108
109
110 void BranchList::add(string const & s)
111 {
112         string::size_type i = 0;
113         while (true) {
114                 string::size_type const j = s.find_first_of(separator(), i);
115                 string name;
116                 if (j == string::npos)
117                         name = s.substr(i);
118                 else
119                         name = s.substr(i, j - i);
120                 // Is this name already in the list?
121                 List::const_iterator it = list.begin();
122                 List::const_iterator end = list.end();
123                 bool already = false;
124                 for (; it != end; ++it) {
125                         if (it->getBranch() == name) {
126                                 already = true;
127                                 break;
128                         }
129                 }
130                 if (!already) {
131                         Branch br;
132                         br.setBranch(name);
133                         br.setSelected(false);
134                         br.setColor("none");
135                         list.push_back(br);
136                 }
137                 if (j == string::npos)
138                         break;
139                 i = j + 1;
140         }
141 }
142
143
144 namespace {
145
146 struct match : public binary_function<Branch, string, bool> {
147         bool operator()(Branch const & br, string const & s) const {
148         return (br.getBranch() == s);
149         }
150 };
151
152 } // namespace anon.
153
154
155 void BranchList::remove(string const & s)
156 {
157         list.remove_if(bind2nd(match(), s));
158 }
159
160
161 bool BranchList::selected(string const & s) const
162 {
163         List::const_iterator it = list.begin();
164         List::const_iterator end = list.end();
165         for (; it != end; ++it) {
166                 if (s == it->getBranch())
167                         return it->getSelected();
168         }
169         return false;
170 }
171
172
173 string BranchList::allBranches() const
174 {
175         List::const_iterator it = list.begin();
176         List::const_iterator end = list.end();
177         string ret;
178         for (; it != end; ++it) {
179                 ret += it->getBranch() + separator();
180         }
181         // remove final '|':
182         string::size_type i = ret.find_last_of(separator());
183         if (i != string::npos)
184                 ret.erase(i);
185         return ret;
186 }
187
188
189 string BranchList::allSelected() const
190 {
191         List::const_iterator it = list.begin();
192         List::const_iterator end = list.end();
193         string ret;
194         for (; it != end; ++it) {
195                 if (it->getSelected())
196                         ret += it->getBranch() + separator();
197         }
198         // remove final '|':
199         string::size_type i = ret.find_last_of(separator());
200         if (i != string::npos)
201                 ret.erase(i);
202         return ret;
203 }
204
205
206 string const BranchList::separator() const
207 {
208         return separator_;
209 }