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