]> git.lyx.org Git - lyx.git/blob - src/BranchList.h
77b8d2be93c768b4d064fe105fa7ded1cb6e3ea4
[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 <string>
36 #include <list>
37
38
39 namespace lyx {
40
41
42 class Branch {
43 public:
44         ///
45         Branch();
46         ///
47         std::string const & getBranch() const;
48         ///
49         void setBranch(std::string const &);
50         ///
51         bool getSelected() const;
52         /** Select/deselect the branch.
53          *  \return true if the selection status changes.
54          */
55         bool setSelected(bool);
56         ///
57         RGBColor const & getColor() const;
58         ///
59         void setColor(RGBColor const &);
60         /**
61          * Set color from a string "#rrggbb".
62          * Use LColor:background if the string is no valid color.
63          * This ensures compatibility with LyX 1.4.0 that had the symbolic
64          * color "none" that was displayed as LColor:background.
65          */
66         void setColor(std::string const &);
67
68 private:
69         ///
70         std::string branch_;
71         ///
72         bool selected_;
73         ///
74         RGBColor color_;
75 };
76
77
78 class BranchList {
79         ///
80         typedef std::list<Branch> List;
81 public:
82         typedef List::const_iterator const_iterator;
83
84         ///
85         BranchList() : separator_("|") {}
86
87         ///
88         bool empty() const { return list.empty(); }
89         ///
90         void clear() { list.clear(); }
91         ///
92         const_iterator begin() const { return list.begin(); }
93         const_iterator end() const { return list.end(); }
94
95         /** \returns the Branch with \c name. If not found, returns 0.
96          */
97         Branch * find(std::string const & name);
98         Branch const * find(std::string const & name) const;
99
100         /** Add (possibly multiple (separated by separator())) branches to list
101          *  \returns true if a branch is added.
102          */
103         bool add(std::string const &);
104         /** remove a branch from list by name
105          *  \returns true if a branch is removed.
106          */
107         bool remove(std::string const &);
108
109 private:
110         ///
111         List list;
112         ///
113         std::string separator_;
114 };
115
116
117 class BranchNamesEqual : public std::unary_function<Branch, bool> {
118 public:
119         BranchNamesEqual(std::string const & name)
120                 : name_(name) {}
121         bool operator()(Branch const & branch) const
122         {
123                 return branch.getBranch() == name_;
124         }
125 private:
126         std::string name_;
127 };
128
129
130 } // namespace lyx
131
132 #endif