]> git.lyx.org Git - lyx.git/blob - src/BranchList.C
Remove the inset and view member functions from PreviewedInset.
[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.find(it->getBranch(), 0) != string::npos)
102                         it->setSelected(val);
103         }
104 }
105
106
107 void BranchList::add(string const & s)
108 {
109         string::size_type i = 0;
110         while (true) {
111                 string::size_type const j = s.find_first_of(separator(), i);
112                 string name;
113                 if (j == string::npos)
114                         name = s.substr(i);
115                 else
116                         name = s.substr(i, j - i);
117                 // Is this name already in the list?
118                 List::const_iterator it = list.begin();
119                 List::const_iterator end = list.end();
120                 bool already = false;
121                 for (; it != end; ++it) {
122                         if (it->getBranch() == name) {
123                                 already = true;
124                                 break;
125                         }
126                 }
127                 if (!already) {
128                         Branch br;
129                         br.setBranch(name);
130                         br.setSelected(false);
131                         br.setColor("none");
132                         list.push_back(br);
133                 }
134                 if (j == string::npos)
135                         break;
136                 i = j + 1;
137         }
138 }
139
140
141 namespace {
142
143 struct match : public binary_function<Branch, string, bool> {
144         bool operator()(Branch const & br, string const & s) const {
145         return (br.getBranch() == s);
146         }
147 };
148
149 } // namespace anon.
150
151
152 void BranchList::remove(string const & s)
153 {
154         list.remove_if(bind2nd(match(), s));
155 }
156
157
158 bool BranchList::selected(string const & s) const
159 {
160         List::const_iterator it = list.begin();
161         List::const_iterator end = list.end();
162         for (; it != end; ++it) {
163                 if (s == it->getBranch())
164                         return it->getSelected();
165         }
166         return false;
167 }
168
169
170 string BranchList::allBranches() const
171 {
172         List::const_iterator it = list.begin();
173         List::const_iterator end = list.end();
174         string ret;
175         for (; it != end; ++it) {
176                 ret += it->getBranch() + separator();
177         }
178         // remove final '|':
179         string::size_type i = ret.find_last_of(separator());
180         if (i != string::npos)
181                 ret.erase(i);
182         return ret;
183 }
184
185
186 string BranchList::allSelected() const
187 {
188         List::const_iterator it = list.begin();
189         List::const_iterator end = list.end();
190         string ret;
191         for (; it != end; ++it) {
192                 if (it->getSelected())
193                         ret += it->getBranch() + separator();
194         }
195         // remove final '|':
196         string::size_type i = ret.find_last_of(separator());
197         if (i != string::npos)
198                 ret.erase(i);
199         return ret;
200 }
201
202
203 string const BranchList::separator() const
204 {
205         return separator_;
206 }