Update lyx examples to latest file format (for 1.5.0 release)
[lyx.git] / src / BranchList.h
blob0da9fe261f5e4b456dc55a784ce822c3aaa05d54
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
8 * Full author contact details are available in file CREDITS.
11 * \class Branch
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.
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.
21 * \class BranchList
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.
30 #ifndef BRANCHES_H
31 #define BRANCHES_H
33 #include "Color.h"
35 #include <list>
38 namespace lyx {
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.
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.
65 void setColor(std::string const &);
67 private:
68 ///
69 docstring branch_;
70 ///
71 bool selected_;
72 ///
73 RGBColor color_;
77 class BranchList {
78 ///
79 typedef std::list<Branch> List;
80 public:
81 typedef List::const_iterator const_iterator;
83 ///
84 BranchList() : separator_(from_ascii("|")) {}
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(); }
94 /** \returns the Branch with \c name. If not found, returns 0.
96 Branch * find(docstring const & name);
97 Branch const * find(docstring const & name) const;
99 /** Add (possibly multiple (separated by separator())) branches to list
100 * \returns true if a branch is added.
102 bool add(docstring const &);
103 /** remove a branch from list by name
104 * \returns true if a branch is removed.
106 bool remove(docstring const &);
108 private:
110 List list;
112 docstring separator_;
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
122 return branch.getBranch() == name_;
124 private:
125 docstring name_;
129 } // namespace lyx
131 #endif