]> git.lyx.org Git - lyx.git/blob - src/BranchList.h
Paragraph:
[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 BRANCHLIST_H
31 #define BRANCHLIST_H
32
33 #include "ColorCode.h"
34
35 #include "support/docstring.h"
36
37 #include <list>
38
39
40 namespace lyx {
41
42 class Branch {
43 public:
44         ///
45         Branch();
46         ///
47         docstring const & branch() const;
48         ///
49         void setBranch(docstring const &);
50         ///
51         bool isSelected() const;
52         /** Select/deselect the branch.
53          *  \return true if the selection status changes.
54          */
55         bool setSelected(bool);
56         ///
57         RGBColor const & color() const;
58         ///
59         void setColor(RGBColor const &);
60         /**
61          * Set color from a string "#rrggbb".
62          * Use Color: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 Color:background.
65          */
66         void setColor(std::string const &);
67
68 private:
69         ///
70         docstring 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_(from_ascii("|")) {}
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(docstring const & name);
98         Branch const * find(docstring 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(docstring const &);
104         /** remove a branch from list by name
105          *  \returns true if a branch is removed.
106          */
107         bool remove(docstring const &);
108
109 private:
110         ///
111         List list;
112         ///
113         docstring separator_;
114 };
115
116 } // namespace lyx
117
118 #endif // BRANCHLIST_H