]> git.lyx.org Git - lyx.git/blob - src/BranchList.h
update build instructions (Qt 4.2.2 etc.)
[lyx.git] / src / BranchList.h
1 // -*- C++ -*-
2 /**
3  * \file BranchList.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  * \author Martin Vermeer
7  *
8  * Full author contact details are available in file CREDITS.
9  *
10  *
11  * \class Branch
12  *
13  * A class describing a 'branch', i.e., a named alternative for
14  * selectively outputting some parts of a document while suppressing
15  * other parts.
16  *
17  * A branch has a name, can either be selected or not, and uses a
18  * user-specifyable background colour. All these can be set and
19  * queried.
20  *
21  * \class BranchList
22  *
23  * A class containing a vector of all defined branches within a
24  * document. Has methods for selecting or deselecting branches by
25  * name, for outputting a '|'-separated string of all elements or only
26  * the selected ones, and for adding and removing elements.
27  */
28
29
30 #ifndef BRANCHES_H
31 #define BRANCHES_H
32
33 #include "Color.h"
34
35 #include "support/docstring.h"
36
37 #include <list>
38
39
40 namespace lyx {
41
42
43 class Branch {
44 public:
45         ///
46         Branch();
47         ///
48         docstring const & getBranch() const;
49         ///
50         void setBranch(docstring const &);
51         ///
52         bool getSelected() const;
53         /** Select/deselect the branch.
54          *  \return true if the selection status changes.
55          */
56         bool setSelected(bool);
57         ///
58         RGBColor const & getColor() const;
59         ///
60         void setColor(RGBColor const &);
61         /**
62          * Set color from a string "#rrggbb".
63          * Use LColor:background if the string is no valid color.
64          * This ensures compatibility with LyX 1.4.0 that had the symbolic
65          * color "none" that was displayed as LColor:background.
66          */
67         void setColor(std::string const &);
68
69 private:
70         ///
71         docstring branch_;
72         ///
73         bool selected_;
74         ///
75         RGBColor color_;
76 };
77
78
79 class BranchList {
80         ///
81         typedef std::list<Branch> List;
82 public:
83         typedef List::const_iterator const_iterator;
84
85         ///
86         BranchList() : separator_(from_ascii("|")) {}
87
88         ///
89         bool empty() const { return list.empty(); }
90         ///
91         void clear() { list.clear(); }
92         ///
93         const_iterator begin() const { return list.begin(); }
94         const_iterator end() const { return list.end(); }
95
96         /** \returns the Branch with \c name. If not found, returns 0.
97          */
98         Branch * find(docstring const & name);
99         Branch const * find(docstring const & name) const;
100
101         /** Add (possibly multiple (separated by separator())) branches to list
102          *  \returns true if a branch is added.
103          */
104         bool add(docstring const &);
105         /** remove a branch from list by name
106          *  \returns true if a branch is removed.
107          */
108         bool remove(docstring const &);
109
110 private:
111         ///
112         List list;
113         ///
114         docstring separator_;
115 };
116
117
118 class BranchNamesEqual : public std::unary_function<Branch, bool> {
119 public:
120         BranchNamesEqual(docstring const & name)
121                 : name_(name) {}
122         bool operator()(Branch const & branch) const
123         {
124                 return branch.getBranch() == name_;
125         }
126 private:
127         docstring name_;
128 };
129
130
131 } // namespace lyx
132
133 #endif