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