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