]> git.lyx.org Git - features.git/blob - src/BranchList.h
Some more functor work.
[features.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         const_iterator begin() const { return list.begin(); }
78         const_iterator end() const { return list.end(); }
79
80         /** \returns the Branch with \c name. If not found, returns 0.
81          */
82         Branch * find(std::string const & name);
83         Branch const * find(std::string const & name) const;
84
85         /** Add (possibly multiple (separated by separator())) branches to list
86          *  \returns true if a branch is added.
87          */
88         bool add(std::string const &);
89         /** remove a branch from list by name
90          *  \returns true if a branch is removed.
91          */
92         bool remove(std::string const &);
93
94 private:
95         ///
96         List list;
97         ///
98         std::string separator_;
99 };
100
101
102 class BranchNamesEqual : public std::unary_function<Branch, bool> {
103 public:
104         BranchNamesEqual(std::string const & name)
105                 : name_(name) {}
106         bool operator()(Branch const & branch) const
107         {
108                 return branch.getBranch() == name_;
109         }
110 private:
111         std::string name_;
112 };
113
114 #endif